Table of Contents

Testing an event rule

When creating the event rule, a test class is automatically created. The following table shows the base class to use depending on the type of rule:

Event rule Base class
Entity Saving SavingRuleTest<TSavingRule, TEntity>
Entity Saved SavedRuleTest<TSavingRule, TEntity>
Entity view Retrieving RetrievingRuleTest<TSavingRule, TEntityView>
Entity view Retrieved RetrievedRuleTest<TSavingRule, TEntityView>
Entity view Saving SavingRuleTest<TSavingRule, TEntityView>
Entity view Saved SavedRuleTest<TSavingRule, TEntityView>

Executing the event rule in a test

Entity saving rule

You must call the ExecuteSavingRuleAsync method and configure the arguments with the argsBuilder parameter. Code example:

// Arrange
Customer c1;
Customer c2;
Customer c3;
Customer c4;
...

// Act
ISavingRuleArguments args = await ExecuteSavingRuleAsync(b => b
    .WithCreatedItems(c1)
    .WithModifiedItems(c2, c3)
    .WithDeletedItems(c4));

// Assert
args.Cancel.Should().BeFalse();

Entity saved rule

You must call the ExecuteSavedRuleAsync method and configure the arguments with the argsBuilder parameter. Code example:

// Arrange
Customer c1;
Customer c2;
Customer c3;
Customer c4;
...

// Act
ISavedRuleArguments args = await ExecuteSavedRuleAsync(b => b
    .WithCreatedItems(c1)
    .WithModifiedItems(c2, c3)
    .WithDeletedItems(c4));

// Assert
...

Entity view retrieving rule

You must call the ExecuteRetrievingRuleAsync method and configure the arguments with the argsBuilder parameter. Code example:

// Act
IRetrievingRuleArguments args = await ExecuteRetrievingRuleAsync(b => b
    .WithPagination(skip: 20, top:10));

// Assert
args.Cancel.Should().BeTrue();
args.Items.Should().BeEquivalentTo(...);

Entity view retrieved rule

You must call the ExecuteRetrievedRuleAsync method and configure the arguments with the argsBuilder parameter. Code example:

// Arrange
ICustomerView c1;
ICustomerView c2;
ICustomerView c3;
ICustomerView c4;

// Act
IRetrievedRuleArguments args = await ExecuteRetrievedRuleAsync(b => b
    .WithItems(c1, c2, c3, c4));

// Assert
...

Entity view saving rule

You must call the ExecuteSavingRuleAsync method and configure the arguments with the argsBuilder parameter. Code example:

// Arrange
ICustomerView c1;
ICustomerView c2;
ICustomerView c3;
ICustomerView c4;
...

// Act
ISavingRuleArguments args = await ExecuteSavingRuleAsync(b => b
    .WithCreatedItems(c1)
    .WithModifiedItems(c2, c3)
    .WithDeletedItems(c4));

// Assert
args.Cancel.Should().BeFalse();

Entity view saved rule

You must call the ExecuteSavedRuleAsync method and configure the arguments with the argsBuilder parameter. Code example:

// Arrange
ICustomerView c1;
ICustomerView c2;
ICustomerView c3;
ICustomerView c4;
...

// Act
ISavedRuleArguments args = await ExecuteSavedRuleAsync(b => b
    .WithCreatedItems(c1)
    .WithModifiedItems(c2, c3)
    .WithDeletedItems(c4));

// Assert
...