Esempio n. 1
0
        public async Task CommandsInterceptor__CommandIsNotRegistered__Throws()
        {
            PrepareServicesForInterception(out var _,
                                           out var messageCancellationService,
                                           out var messageCancellationRegistry,
                                           out var logFactory);

            var notRegisteredMessage = new OneMoreMessageWithSomeId()
            {
                MessageId = Guid.NewGuid()
            };
            var messageCancellationCommandInterceptor =
                new MessageCancellationCommandInterceptor(
                    messageCancellationService,
                    messageCancellationRegistry,
                    logFactory.Object);
            var interceptionContext = new Mock <ICommandInterceptionContext>();

            interceptionContext.Setup(x => x.Command).Returns(notRegisteredMessage);
            interceptionContext.Setup(x => x.HandlerObject).Returns(this);
            interceptionContext.Setup(x => x.InvokeNextAsync())
            .Returns(Task.FromResult(CommandHandlingResult.Fail(TimeSpan.Zero)));

            await Assert.ThrowsAsync <MessageCancellationInterceptionException>(async() =>
            {
                var result = await messageCancellationCommandInterceptor.InterceptAsync(interceptionContext.Object);
            });
        }
Esempio n. 2
0
        public async Task CommandsInterceptor__CancellationRequested__FlowIsCancelled()
        {
            var command = PrepareServicesForInterception(out var operationId,
                                                         out var messageCancellationService,
                                                         out var messageCancellationRegistry,
                                                         out var logFactory);

            var messageCancellationCommandInterceptor =
                new MessageCancellationCommandInterceptor(
                    messageCancellationService,
                    messageCancellationRegistry,
                    logFactory.Object);
            var interceptionContext = new Mock <ICommandInterceptionContext>();

            interceptionContext.Setup(x => x.Command).Returns(command);
            interceptionContext.Setup(x => x.HandlerObject).Returns(this);
            interceptionContext.Setup(x => x.InvokeNextAsync())
            .Returns(Task.FromResult(CommandHandlingResult.Fail(TimeSpan.Zero)));
            var result = await messageCancellationCommandInterceptor.InterceptAsync(interceptionContext.Object);

            Assert.False(result.Retry);
        }