Beispiel #1
0
        public async Task Should_Capture_TimeoutRequest_Operation()
        {
            var expectedSagaId   = "a-saga-id";
            var expectedSagaType = "a-saga-type";

            var scenarioContext = new IntegrationScenarioContext();
            var context         = new TestableOutgoingSendContext
            {
                Message = new OutgoingLogicalMessage(typeof(AMessage), new AMessage())
            };

            context.Headers.Add(Headers.SagaId, expectedSagaId);
            context.Headers.Add(Headers.SagaType, expectedSagaType);
            context.Headers.Add(Headers.IsSagaTimeoutMessage, bool.TrueString);

            var sut = new InterceptSendOperations("fake-endpoint", scenarioContext);;
            await sut.Invoke(context, () => Task.CompletedTask).ConfigureAwait(false);

            var requestTimeoutOperation = scenarioContext.OutgoingMessageOperations.SingleOrDefault() as RequestTimeoutOperation;

            Assert.AreEqual(1, scenarioContext.OutgoingMessageOperations.Count());
            Assert.IsNotNull(requestTimeoutOperation);
            Assert.AreEqual(expectedSagaId, requestTimeoutOperation.SagaId);
            Assert.AreEqual(expectedSagaType, requestTimeoutOperation.SagaTypeAssemblyQualifiedName);
        }
        public async Task Should_Reschedule_Timeouts()
        {
            var expectedDeliveryAt = new DateTimeOffset(new DateTime(2020, 1, 1));

            var scenarioContext = new IntegrationScenarioContext();

            scenarioContext.RegisterTimeoutRescheduleRule <AMessage>((msg, currentDelay) =>
            {
                return(new DoNotDeliverBefore(expectedDeliveryAt));
            });

            var context = new TestableOutgoingSendContext
            {
                Message = new OutgoingLogicalMessage(typeof(AMessage), new AMessage())
            };

            context.Headers.Add(Headers.SagaId, "a-saga-id");
            context.Headers.Add(Headers.SagaType, "a-saga-type");
            context.Headers.Add(Headers.IsSagaTimeoutMessage, bool.TrueString);

            var properties = new DispatchProperties {
                DoNotDeliverBefore = new DoNotDeliverBefore(new DateTime(2030, 1, 1))
            };

            context.Extensions.Set(properties);

            var sut = new RescheduleTimeoutsBehavior(scenarioContext);;
            await sut.Invoke(context, () => Task.CompletedTask).ConfigureAwait(false);

            var rescheduledDoNotDeliverBefore = properties.DoNotDeliverBefore;

            Assert.AreEqual(expectedDeliveryAt, rescheduledDoNotDeliverBefore.At);
        }
        public static bool EventWasPublished <TEvent>(this IntegrationScenarioContext context)
        {
            var operation = context.OutgoingMessageOperations.SingleOrDefault(o =>
                                                                              o is PublishOperation &&
                                                                              typeof(TEvent).IsAssignableFrom(o.MessageType));

            return(operation != null);
        }
        public static bool TimeoutWasScheduled <TTimeout>(this IntegrationScenarioContext context)
        {
            var operation = context.OutgoingMessageOperations.SingleOrDefault(o =>
                                                                              o is RequestTimeoutOperation &&
                                                                              typeof(TTimeout).IsAssignableFrom(o.MessageType));

            return(operation != null);
        }
        public static bool ReplyWasSent <TReply>(this IntegrationScenarioContext context)
        {
            var operation = context.OutgoingMessageOperations.SingleOrDefault(o =>
                                                                              o is ReplyOperation &&
                                                                              typeof(TReply).IsAssignableFrom(o.MessageType));

            return(operation != null);
        }
        public void MessageWasProcessedBySaga_condition_should_match_base_type()
        {
            var scenarioContext = new IntegrationScenarioContext();

            scenarioContext.CaptureInvokedSaga(new SagaInvocation()
            {
                Message = new InheritedMessage(), EndpointName = "fake-endpoint", SagaType = typeof(TestSaga), MessageType = typeof(InheritedMessage)
            });

            Assert.IsTrue(scenarioContext.MessageWasProcessedBySaga <IMessageInterface, TestSaga>());
        }
Beispiel #7
0
        public void MessageWasProcessed_condition_should_match_base_type()
        {
            var scenarioContext = new IntegrationScenarioContext();

            scenarioContext.CaptureInvokedHandler(new HandlerInvocation()
            {
                Message       = new InheritedMessage(),
                EndpointName  = "fake-endpoint",
                HandlerType   = typeof(MessageInterfaceHandler),
                HandlingError = null,
                MessageType   = typeof(InheritedMessage)
            });

            Assert.IsTrue(scenarioContext.MessageWasProcessed <IMessageInterface>());
        }
Beispiel #8
0
        public void MessageWasProcessedByHandler_condition_should_match_type()
        {
            var scenarioContext = new IntegrationScenarioContext();

            scenarioContext.CaptureInvokedHandler(new HandlerInvocation()
            {
                Message       = new TestMessage(),
                EndpointName  = "fake-endpoint",
                HandlerType   = typeof(TestMessageHandler),
                HandlingError = null,
                MessageType   = typeof(TestMessage)
            });

            Assert.IsTrue(scenarioContext.MessageWasProcessedByHandler <TestMessage, TestMessageHandler>());
        }
        public void MessageWasProcessed_condition_should_match_type()
        {
            var scenarioContext = new IntegrationScenarioContext();

            scenarioContext.CaptureInvokedSaga(new SagaInvocation()
            {
                Message       = new TestMessage(),
                EndpointName  = "fake-endpoint",
                SagaType      = typeof(TestSaga),
                HandlingError = null,
                MessageType   = typeof(TestMessage)
            });

            Assert.IsTrue(scenarioContext.MessageWasProcessed <TestMessage>());
        }
        public async Task Should_Capture_Reply_Message_Operation()
        {
            var scenarioContext = new IntegrationScenarioContext();
            var context         = new TestableOutgoingReplyContext
            {
                Message = new OutgoingLogicalMessage(typeof(AMessage), new AMessage())
            };

            var sut = new InterceptReplyOperations("fake-endpoint", scenarioContext);
            await sut.Invoke(context, () => Task.CompletedTask).ConfigureAwait(false);

            var operation = scenarioContext.OutgoingMessageOperations.SingleOrDefault() as ReplyOperation;

            Assert.AreEqual(1, scenarioContext.OutgoingMessageOperations.Count());
            Assert.IsNotNull(operation);
        }