예제 #1
0
        public void AndResourceUriIsNotProvidedThenValidationFails()
        {
            var command = new CreateAccountEventCommand {
                Event = "ABC"
            };

            Assert.ThrowsAsync <ValidationException>(() => Handler.Handle(command));
        }
        public async Task ThenTheEventIsCreated()
        {
            var command = new CreateAccountEventCommand {
                ResourceUri = "/api/accounts/ABC123", Event = "Some Event"
            };

            await Handler.Handle(command);

            EventsLogger.Verify(x => x.Info($"Received message {command.Event}", command.ResourceUri, null, command.Event), Times.Once);
            Repository.Verify(x => x.Create(It.Is <AccountEvent>(e => e.ResourceUri == command.ResourceUri && e.Event == command.Event)));
            EventsLogger.Verify(x => x.Info($"Finished processing message {command.Event}", null, null, null), Times.Once);
        }
        public void AndTheEventCreationFailsThenTheExceptionIsLogged()
        {
            var command = new CreateAccountEventCommand {
                ResourceUri = "/api/accounts/ABC123", Event = "Some Event"
            };
            var expectedException = new Exception("Test");

            Repository.Setup(x => x.Create(It.Is <AccountEvent>(e => e.ResourceUri == command.ResourceUri && e.Event == command.Event))).Throws(expectedException);

            Assert.ThrowsAsync <Exception>(() => Handler.Handle(command));

            EventsLogger.Verify(x => x.Error(expectedException, $"Error processing message {command.Event} - {expectedException.Message}", command.ResourceUri, null, command.Event), Times.Once);
        }