Verify that MarkAsComplete was called from unit test


I have some question about unit testing.

Does anybody know if it is possible to verify that markAsComplete was called in a saga-messagehandler?

Regards Nikias,

Hi Nikias

Assuming you use the AAA-style you can simply do the following

    public async Task ShouldProcessDiscountOrder()
        // arrange
        var saga = new DiscountPolicy
            Data = new DiscountPolicyData()
        var context = new TestableMessageHandlerContext();

        var discountOrder = new SubmitOrder
            CustomerId = Guid.NewGuid(),
            OrderId = Guid.NewGuid(),
            TotalAmount = 1000

        // act
        await saga.Handle(discountOrder, context)

        // assert
        var processMessage = (ProcessOrder)context.SentMessages[0].Message;
        Assert.That(processMessage.TotalAmount, Is.EqualTo(900));
        Assert.That(saga.Completed, Is.True);

I have updated the documentation to include an assert on the completed flag.


Ok great thanks for the info!