-
Notifications
You must be signed in to change notification settings - Fork 0
Add readme #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add readme #3
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # XAF - How to Unit Test Controllers, Actions, and Business Logic (EF Core) | ||
|
|
||
| This example creates unit tests for an XAF application that uses Entity Framework Core as its ORM. The solution illustrates best practices for testing XAF Controllers, Actions, business object behavior, and security-related scenarios using [xUnit](https://www.nuget.org/packages/xunit/) and [Moq](https://www.nuget.org/packages/Moq/). | ||
|
|
||
| ## Implementation Details | ||
|
|
||
| The E2E test project covers the following testing patterns: | ||
|
|
||
| | Test Class | What It Tests | | ||
| |---|---| | ||
| | [`ActionsInViewTests`](CS/XAFUnitTestEFCore/XAFUnitTestEFCore.E2E.Tests/ActionsInViewTests.cs) | The test checks action enable and disable behavior based on `TargetObjectsCriteria` and `SelectionDependencyType` in Detail and List Views. | | ||
| | [`SetTaskActionExecuteTest`](CS/XAFUnitTestEFCore/XAFUnitTestEFCore.E2E.Tests/SetTaskActionExecuteTest.cs) | The test runs a `SingleChoiceAction` and updates properties on selected objects. | | ||
| | [`SetTaskActionStateTest`](CS/XAFUnitTestEFCore/XAFUnitTestEFCore.E2E.Tests/SetTaskActionStateTest.cs) | The test evaluates action state based on security permissions through `ISecurityStrategyBase`. | | ||
| | [`FindBySubjectActionExecuteTest`](CS/XAFUnitTestEFCore/XAFUnitTestEFCore.E2E.Tests/FindBySubjectActionExecuteTest.cs) | The test runs a `ParametrizedAction` that finds and displays an object by criteria. | | ||
| | [`CreateLinkedSaleBaseDescendantControllerTest`](CS/XAFUnitTestEFCore/XAFUnitTestEFCore.E2E.Tests/CreateLinkedSaleBaseDescendantControllerTest.cs)` | The test verifies event subscription and copies properties from parent objects to child objects in nested frames. | | ||
| | [`CaptionHelperTests`](CS/XAFUnitTestEFCore/XAFUnitTestEFCore.E2E.Tests/CaptionHelperTests.cs) | 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 | ||
|
|
||
| - [ActionsInViewTests.cs](CS/XAFUnitTestEFCore/XAFUnitTestEFCore.E2E.Tests/ActionsInViewTests.cs) | ||
| - [SetTaskActionExecuteTest.cs](CS/XAFUnitTestEFCore/XAFUnitTestEFCore.E2E.Tests/SetTaskActionExecuteTest.cs) | ||
| - [SetTaskActionStateTest.cs](CS/XAFUnitTestEFCore/XAFUnitTestEFCore.E2E.Tests/SetTaskActionStateTest.cs) | ||
| - [FindBySubjectActionExecuteTest.cs](CS/XAFUnitTestEFCore/XAFUnitTestEFCore.E2E.Tests/FindBySubjectActionExecuteTest.cs) | ||
| - [CreateLinkedSaleBaseDescendantControllerTest.cs](CS/XAFUnitTestEFCore/XAFUnitTestEFCore.E2E.Tests/CreateLinkedSaleBaseDescendantControllerTest.cs) | ||
| - [CaptionHelperTests.cs](CS/XAFUnitTestEFCore/XAFUnitTestEFCore.E2E.Tests/CaptionHelperTests.cs) | ||
|
|
||
| ## Documentation | ||
|
|
||
| - [EF Core Unit Tests](https://docs.devexpress.com/eXpressAppFramework/405947/debugging-testing-and-error-handling/ef-core-unit-tests) | ||
|
|
||
| ## Does this example address your development requirements/scenarios? | ||
|
|
||
| [<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=XAF_unit-test-ef-core&utm_term=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=XAF_unit-test-ef-core&utm_term=no) | ||
|
|
||
| (you will be redirected to DevExpress.com to submit your response) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.