Base classes
To simplify unit testing, several base classes are available for your XUnit test classes.
TestBase class
This class is provided by Neos and should be used (directly or indirectly) as a base class for your test classes.
This is the most generic class, exposing basic methods. If you need to test some specific rules (ex: entity validation rule, entity view), you should use domain or application test classes wich extend TestBase class with associated methods.
For more information about how to use theses classes, see this article.
Mocker property
To simplify your test, an AutoMocker instance is available via this property. This instance is configured to :
- Redirect
NeosLoggerlogs to XUnit output. - Configure default return value for common cases. For example, all methods that return a Result return
Result.Ok().
The AutoMocker Verify method is automatically called when the test class is disposed.
Derived classes, exposed later in this section, add additional configurations to the AutoMocker instance.
GetMock method
This method is just a shortcut for Mocker.GetMock. The two following instructions are equivalent:
Mock<ICustomerRepository> m1 = GetMock<ICustomerRepository>();
Mock<ICustomerRepository> m1 = Mocker.GetMock<ICustomerRepository>();
Informations about the constructor
You must provide a constructor with a ITestOutputHelper parameter and pass it to the base class constructor.
public class TestClass : TestBase
{
public TestClass(ITestOutputHelper output)
: base(output)
{
}
}
This parameter is necessary to redirect logs to XUnit ouput.
Base classes for domain layer tests (entities)
All base classes in this layer automatically configure entity repositories in the AutoMocker instance.
When creating a validation rule or an event rule on an entity, a corresponding test class will be created on the domain test project of the module.
For example if a Saved event rule is created for a Territory entity of a Partners module, a SavedTests.cs class will be created in the directory EventRules/Territory of the project Partners.Domain.Tests.UnitTests.
For more information see :
Base classes for application layer tests (entity views & server methods)
All base classes in this layer automatically configure entity repositories and entity view repositories in the AutoMocker instance.
We creating a server method or an entity view rule (event, validation), a corresponding test class will be created on the application test project of the module.
For example if a Retrieving event rule is created for a EnabledEmployeeView entity view of a Partners module, a RetrievingTests.cs class will be created in the directory EventRules/EnabledEmployeeView of the project Partners.Application.Tests.UnitTests.
For a server method CopyOrder of a Sales module, a CopyOrderTests.cs class will be created in the directory Methods or the project Sales.Application.Tests.UnitsTests.
For more information see :
They expose the following methods:
GetEntityViewRepositoryMock
This method allows to get the entity view repository mock associated to an entity view type:
Mock<IEntityViewRepository<ICustomerView>> customerViewRepositoryMock = GetEntityViewRepositoryMock<ICustomerView>();
GetEntityViewRepository
This is a shortcut for GetEntityViewRepositoryMock<TEntityView>().Object.
Base classes for entity view related code testing
Those classes expose a method to get the entity view repository:
IEntityViewRepository<ICustomerView> customerViewRepository = GetEntityViewRepository();