public async Task HandleAsync_WithValidPoll_ShouldCallSuccess() { // Arrange IEmailSender emailSenderStub = A.Fake <IEmailSender>(); IPollGateway pollGatewayStub = A.Fake <IPollGateway>(); ICreatePollOutputPort OutputPortMock = A.Fake <ICreatePollOutputPort>(); var useCase = new CreatePollUseCase(null, emailSenderStub, pollGatewayStub); CreatePollInput input = GetValidCreatePollInput(); // Act await useCase.HandleAsync(input, OutputPortMock); // Assert A.CallTo(() => OutputPortMock.Success( A <CreatePollOutput> .That.Matches( p => p.Id == 0))) .MustHaveHappenedOnceExactly(); }
public async Task HandleAsync(CreatePollInput input, ICreatePollOutputPort output) { try { var poll = new Poll(input.Title, input.Note, input.SingleOptionLimitation, input.DueDate); foreach (string option in input.Options) { poll.AddOption(option); } await this.pollGateway.CreateAsync(poll); await this.emailSender.SendAsync("SUBJECT", "PLAIN_TEXT_CONTENT", input.ParticipantEmailAddresses); output.Success(new CreatePollOutput(poll.Id)); } catch (DomainException ex) { this.loggerService.LogInformation("{@excepton} occured when trying to create a poll with {@input}", ex, input); output.Error(ex.Message); } }