Skip to content

DevExpress-Examples/XAFUnitTestEFCore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XAF - How to Unit Test Controllers, Actions, and Business Logic (EF Core)

This example creates unit tests for an Entity Framework Core ORM-powered XAF application. The solution illustrates best practices for testing XAF Controllers, Actions, business object behavior, and security-related usage scenarios via xUnit and Moq.

Implementation Details

The E2E test project addresses the following testing patterns:

Test Class What It Tests
ActionsInViewTests The test checks action enable and disable behavior based on TargetObjectsCriteria and SelectionDependencyType in Detail and List Views.
SetTaskActionExecuteTest The test runs a SingleChoiceAction and updates properties on selected objects.
SetTaskActionStateTest The test evaluates action state based on security permissions through ISecurityStrategyBase.
FindBySubjectActionExecuteTest The test runs a ParametrizedAction that finds and displays an object by criteria.
CreateLinkedSaleBaseDescendantControllerTest The test verifies event subscription and copies properties from parent objects to child objects in nested frames.
CaptionHelperTests The test sets up CaptionHelper localization through ModelApplication and ExpressApplicationSetupParameters.

Testing Actions in Views (Mocking Approach)

The tests mock IObjectSpace, XafApplication, Frame, and View objects (DetailView/ListView) to evaluate action behavior without running the full application. Key mocking patterns include:

  • Mocking IObjectSpace and its LINQ query methods for object retrieval.
  • Creating DetailView/ListView instances with mocked CollectionSource and ListEditor.
  • Setting up Frame objects to activate controllers and register actions.
  • Verifying CommitChanges() is called after action execution.

Testing Security-Dependent Logic

SetTaskActionStateTest demonstrates how to mock ISecurityStrategyBase to simulate granted or denied field-level permissions and verify that action state reflects the current user's access rights.

Testing Event Subscriptions

CreateLinkedSaleBaseDescendantControllerTest uses reflection to verify that a controller correctly subscribes to the NewObjectViewController.ObjectCreated event.

Files to Review

Does this example address your development requirements/scenarios?

(you will be redirected to DevExpress.com to submit your response)

Does This Example Address Your Development Requirements/Objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Create unit tests for an Entity Framework Core ORM-powered XAF application.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors