Skip to main content
A newer version of this page is available. .

Test Conditional Appearance Rules

  • 3 minutes to read

Conditional Appearance rules potentially can be very complex. It is often possible to make a mistake, for instance, with a typo that will change the behavior of a rule. To ensure that your Conditional Appearance rules behave as expected, it is recommended that you implement automatic testing. You can test Conditional Appearance rules in XAF via functional tests. This topic demonstrates how to implement such tests, using the EasyTest functional testing framework.

Tip

A complete sample project is available in the DevExpress Code Examples database at https://supportcenter.devexpress.com/ticket/details/e3250/how-to-test-conditional-appearance-rules.

To see beginner’s step-by-step testing instructions, refer to the How to: Test an Action topic.

Suppose you have the MyPerson persistent object that exposes the Name, IsMarried and SpouseName properties. The requirement is that the SpouseName property’s editor is disabled when IsMarried is false. This can be achieved by applying the AppearanceAttribute to the SpouseName property. The following code snippet and image illustrate this.

using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.ConditionalAppearance;
// ...
[DefaultClassOptions, ImageName("BO_Person"), ModelDefault("Caption", "Person")]
public class MyPerson : BaseObject {
    public MyPerson(Session session) : base(session) { }
    private string name;
    public string Name {
        get { return name; }
        set { SetPropertyValue(nameof(Name), ref name, value); }
    }
    private bool isMarried;
    [ImmediatePostData]
    public bool IsMarried {
        get { return isMarried; }
        set { 
            SetPropertyValue(nameof(IsMarried), ref isMarried, value);
            if (!String.IsNullOrEmpty(SpouseName) && !value) SpouseName = String.Empty;
        }
    }
    private string spouseName;
    [Appearance("DisableSpouseName", Criteria="!IsMarried", Enabled=false)]
    public string SpouseName {
        get { return spouseName; }
        set { SetPropertyValue(nameof(SpouseName), ref spouseName, value); }
    }
}

TestConditionalAppearanceRules

Note

This Conditional Appearance rule is very simple and of course there is no need to test such rules in real applications. We will test it here, however, for learning purposes. It is recommended to test rules that have complex criteria or interfere with each other (see AppearanceAttribute.Priority).

To test the MyPerson object’s Conditional Appearance rule, you can use the following EasyTest script.

#Application TestConditionalAppearanceRulesWin
#Application TestConditionalAppearanceRulesWeb

;Create a new Person:
*Action New(Person)

;Set IsMarried to true
*FillForm
 Name = Jane Smith
 Is Married = true

;Test that the SpouseName field is editable
*FillForm
 Spouse Name = John Smith

;Set IsMarried to false
*FillForm
 Is Married = false

;Test that the SpouseName field is not editable
!FillForm
 Spouse Name = John Smith

You can accidentally configure a Conditional Appearance rule to always disable an editor, instead of disabling it only when necessary. Thus, always test the behavior of a rule for different cases when its criteria is valid and invalid.

Note

Currently, you can only test visibility and an enabled/disabled state with EasyTest.

See Also