Skip to content

Testing

Charles Solar edited this page Jun 13, 2018 · 2 revisions

We test business rules using the testing package Aggregates.NET.Testing and NServiceBus.Testing

More about the testing syntax here: https://github.com/volak/Aggregates.NET/wiki/Testing

[Theory, AutoFakeItEasyData]
public async Task Should_not_double_mark_reorder(
    TestableContext context,
    Handler handler
    )
{
    context.UoW.Plan<Product>(context.Id())
        .HasEvent<Events.Added>(x =>
        {
            x.ProductId = context.Id();
            x.CatalogBrandId = context.Id();
            x.CatalogTypeId = context.Id();
            x.Name = "test";
            x.Price = 1;
        })
        .HasEvent<Events.ReorderMarked>(x =>
        {
            x.ProductId = context.Id();
        });
    
    await Assert.ThrowsAsync<BusinessException>(() => handler.Handle(new Commands.MarkReordered
    {
        ProductId = context.Id()
    }, context)).ConfigureAwait(false);

}
Clone this wiki locally