Back to Devexpress

Test an Action

expressappframework-113218-debugging-testing-and-error-handling-functional-tests-easy-test-write-tests-human-readable-test-an-action.md

latest4.3 KB
Original Source

Test an Action

  • Feb 21, 2026
  • 3 minutes to read

This topic explains how to test an XAF application. A custom Controller that comes with the Postpone Action is implemented in this example. Then, this Action’s functionality is tested with EasyTest functional testing.

Implement a Custom Action

Create a new custom Controller that will perform an Action over Task business objects. The sample Task business class exposes two properties - Description and DueDate.

csharp
using System;
using System.ComponentModel.DataAnnotations;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl.EF;

namespace MySolution.Module.BusinessObjects {
    [DefaultClassOptions]
    public class Task : BaseObject {
        public virtual string Description { get; set; }
        public virtual DateTime DueDate { get; set; }
    }
}

// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.
csharp
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Xpo;
using System;

namespace MySolution.Module.BusinessObjects {
    [DefaultClassOptions]
    public class Task : BaseObject {
        public Task(Session session) : base(session) { }

        private string description;
        public string Description {
            get => description;
            set => SetPropertyValue(nameof(Description), ref description, value);
        }

        private DateTime dueDate;
        public DateTime DueDate {
            get => dueDate;
            set => SetPropertyValue(nameof(DueDate), ref dueDate, value);
        }
    }
}

The custom Controller is targeted for List Views and contains the Postpone Action. This Action processes the selected objects in a Task List View. The Action adds one day to the objects’ DueDate property values.

csharp
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using MySolution.Module.BusinessObjects;
using System;

namespace MySolution.Module.Controllers {
    public class PostponeController : ViewController {
        public PostponeController() {
            TargetObjectType = typeof(Task);
            var postpone = new SimpleAction(this, "Postpone", PredefinedCategory.Edit);
            postpone.SelectionDependencyType = SelectionDependencyType.RequireMultipleObjects;
            postpone.Execute += (s, e) => {
                foreach (object selectedObject in View.SelectedObjects) {
                    Task selectedTask = (Task)selectedObject;
                    selectedTask.DueDate = selectedTask.DueDate == DateTime.MinValue ? DateTime.Today : selectedTask.DueDate.AddDays(1);                    
                }
            };
        }
    }
}

Create a Functional Test in a Human-Readable Language

This section describes how to create an EasyTest script that ensures that the implemented Postpone Action works as expected.

  1. In Solution Explorer , navigate to the module project. Right-click the FunctionalTests folder and select Add | New Item.

  2. Save the test script.

  3. Run Tests in Console.

See Also

EasyTest Script Reference

Test Conditional Appearance Rules

Test Validation Rules