Skip to main content
.NET Framework 4.6.2+

Test Conditional Appearance Rules

  • 3 minutes to read

The EasyTest functional testing framework allows you to test Conditional Appearance rules. This topic demonstrates how to implement such tests.

To see beginner’s step-by-step testing instructions, refer to the 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. To do this, apply the AppearanceAttribute to the SpouseName property:

using DevExpress.ExpressApp.ConditionalAppearance;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl.EF;
using System.ComponentModel.DataAnnotations;
// ...
[DefaultClassOptions]
public class MyPerson : BaseObject {
    public virtual string Name { get; set; }

    private bool isMarried;
    [ImmediatePostData]
    public virtual bool IsMarried {
        get => isMarried;
        set {
            isMarried = value;
            if (!string.IsNullOrEmpty(SpouseName) && !value) SpouseName = string.Empty;
        }
    }

    [Appearance("DisableSpouseName", Criteria = "!IsMarried", Enabled = false)]
    public virtual string SpouseName { get; set; }
}

// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.

TestConditionalAppearanceRules

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

;#DropDB MySolutionEasyTest

#Application MySolutionWin
#Application MySolutionWeb
#Application MySolutionBlazor

*Action Navigation(Person)

*Action New

;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

Note

EasyTest supports only test visibility and an enabled/disabled state.

See Also