expressappframework-113218-debugging-testing-and-error-handling-functional-tests-easy-test-write-tests-human-readable-test-an-action.md
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.
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.
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.
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.
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);
}
};
}
}
}
This section describes how to create an EasyTest script that ensures that the implemented Postpone Action works as expected.
In Solution Explorer , navigate to the module project. Right-click the FunctionalTests folder and select Add | New Item.
Save the test script.
See Also