public async Task ThenTheCommandIsValidated() { var command = new CreateApprenticeshipEventCommandBuilder().Build(); await Handler.Handle(command); Validator.Verify(x => x.Validate(It.Is <CreateApprenticeshipEventCommand>(c => c == command)), Times.Once); }
public async Task ThenTheEventIsCreated() { var command = new CreateApprenticeshipEventCommandBuilder().Build(); await Handler.Handle(command); EventsLogger.Verify(x => x.Info($"Received message {command.Event}", command.EmployerAccountId, command.ProviderId, command.Event), Times.Once); Repository.Verify(x => x.Create(It.Is <ApprenticeshipEvent>(e => EventMatchesCommand(e, command)))); EventsLogger.Verify(x => x.Info($"Finished processing message {command.Event}", command.EmployerAccountId, command.ProviderId, command.Event), Times.Once); }
public void AndTheEventCreationFailsThenTheExceptionIsLogged() { var command = new CreateApprenticeshipEventCommandBuilder().Build(); var expectedException = new Exception("Test"); Repository.Setup(x => x.Create(It.Is <ApprenticeshipEvent>(e => EventMatchesCommand(e, command)))).Throws(expectedException); Assert.ThrowsAsync <Exception>(() => Handler.Handle(command)); EventsLogger.Verify(x => x.Error(expectedException, $"Error processing message {command.Event} - {expectedException.Message}", command.EmployerAccountId, command.ProviderId, command.Event), Times.Once); }