Skip to main content
.NET Framework 4.5.2+

Test an Action

  • 4 minutes to read

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

EasyTest_HowToPostponeController

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.

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.

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);                    
                }
            };
        }
    }
}

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. The test can be used for Windows Forms, ASP.NET Core Blazor, and ASP.NET Web Forms applications.

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

    EasyTest_HowToPostponeController2

    In the Add New Item dialog, select Text File, set its name to “PostponeControllerTest.ets”. Open the newly created file and enter the following code.

    #DropDB MySolutionEasyTest
    
    #Application MySolutionWin
    #Application MySolutionWeb
    #Application MySolutionBlazor
    
    *Action Navigation(Task)
    
    *Action New
    
    *FillForm
    Description = Test Task One
    Due Date = 06/06/2011
    
    *Action Save
    
    *Action New
    
    *FillForm
    Description = Test Task Two
    Due Date = 07/07/2011
    
    *Action Save
    
    *Action Navigation(Task)
    
    *SelectRecords
    Columns = Description
    Row = Test Task One
    Row = Test Task Two
    
    *Action Postpone
    
    *CheckTable
    Columns = 'Due Date'
    Row = 6/7/2011
    Row = 7/8/2011
    

    This script creates two Task objects, selects them in the List View and executes the Postpone Action. After that, the script ensures that the test objects’ DueDate property values change as expected. For detailed information on the EasyTest command syntax, refer to the EasyTest Script Reference topic.

    Note

    By default, the FunctionalTests folder contains the Sample.ets script. You can use it as a starting point when creating tests. If you do not need this file, you can delete it. Another file, initially located in the FunctionalTests folder, is Config.xml. This file specifies the EasyTest configuration settings and should not be deleted.

  2. Save the test script.

    • For WinForms and ASP.NET Web Forms applications: right-click this file in Solution Explorer and select Run:

      EasyTest_HowToPostponeController3

      The test is first be executed for Windows Forms, and then for ASP.NET Web Forms application (this is specified by the second and third commands of the test script). The following output is then displayed to indicate that all tests passed successfully:

      EasyTest_HowToPostponeController4

    • For ASP.NET Core Blazor applications: Run Tests in Console.
See Also