A testable implementation of IMessageHandlerContext.
    public async Task ShouldReplyWithResponseMessage()
    {
        var handler = new MyReplyingHandler();
        var context = new TestableMessageHandlerContext();

        await handler.Handle(new MyRequest(), context);

        Assert.AreEqual(1, context.RepliedMessages.Length);
        Assert.IsInstanceOf<MyResponse>(context.RepliedMessages[0].Message);
    }
Beispiel #2
0
        public override void Validate(TestableMessageHandlerContext context)
        {
            var sentMessages = context.SentMessages
                               .Containing <TMessage>()
                               .Where(s => s.Options.GetDeliveryDelay().HasValue)
                               .ToList();

            if (sentMessages.Any(s => check(s.Message, s.Options.GetDeliveryDelay().Value)))
            {
                Fail($"Expected no message of type {typeof(TMessage).Name} to be deferred, but a message matching your constraints was deferred.");
            }
        }
Beispiel #3
0
        public override void Validate(TestableMessageHandlerContext context)
        {
            var sentMessages = context.SentMessages.Containing <TMessage>()
                               .Where(i => string.IsNullOrWhiteSpace(i.Options.GetCorrelationId()) &&
                                      !string.IsNullOrWhiteSpace(i.Options.GetDestination()))
                               .ToList();

            if (!sentMessages.Any(i => check(i.Message, i.Options.GetDestination())))
            {
                Fail($"Expected a message of type {typeof(TMessage).Name} to be sent to a specific destination but a message matching your constraints was not found.");
            }
        }
        public override void Validate(TestableMessageHandlerContext context)
        {
            var repliedMessages = context.RepliedMessages
                                  .Containing <TMessage>()
                                  .Where(i => !string.IsNullOrWhiteSpace(i.Options.GetCorrelationId()) &&
                                         !string.IsNullOrWhiteSpace(i.Options.GetDestination()))
                                  .ToList();

            if (!repliedMessages.Any(i => check(i.Message)))
            {
                Fail($"Expected a reply of type {typeof(TMessage).Name} but no message matching your constraints was sent.");
            }
        }
Beispiel #5
0
        public static Task Validate <TMessage>(this TestableMessageHandlerContext context, TMessage message)
            where TMessage : class
        {
            var         builder = context.Builder;
            List <Task> tasks   = new()
            {
                validator.Validate(message.GetType(), builder, message, context.Headers, context.Extensions)
            };

            tasks.AddRange(context.PublishedMessages.Select(publishedMessage => Validate(publishedMessage, builder)));
            tasks.AddRange(context.SentMessages.Select(sentMessage => Validate(sentMessage, builder)));
            tasks.AddRange(context.RepliedMessages.Select(repliedMessage => Validate(repliedMessage, builder)));
            tasks.AddRange(context.TimeoutMessages.Select(timeoutMessage => Validate(timeoutMessage, builder)));

            return(Task.WhenAll(tasks));
        }
    public async Task ShouldProcessRegularOrder()
    {
        var saga = new DiscountPolicy
        {
            Data = new DiscountPolicyData()
        };
        var context = new TestableMessageHandlerContext();

        var regularOrder = new SubmitOrder
        {
            CustomerId = Guid.NewGuid(),
            OrderId = Guid.NewGuid(),
            TotalAmount = 50
        };

        await saga.Handle(regularOrder, context);

        var processMessage = (ProcessOrder)context.SentMessages[0].Message;
        Assert.AreEqual(50, processMessage.TotalAmount);
    }