public async Task HandleAsync_WhenPollDoesNotExist_ShouldCallNotFound() { // Arrange const int pollId = 1; const string expectedResultMessage = "Poll not found"; ILoggerService <GetPollUseCase> loggerServiceStub = A.Fake <ILoggerService <GetPollUseCase> >(); IPollGateway pollGatewayStub = A.Fake <IPollGateway>(); A.CallTo(() => pollGatewayStub.GetAsync(pollId)) .Returns((Poll)null); IGetPollOutputPort OutputPortMock = A.Fake <IGetPollOutputPort>(); var useCase = new GetPollUseCase(loggerServiceStub, pollGatewayStub); // Act await useCase.HandleAsync(pollId, OutputPortMock); // Assert A.CallTo( () => OutputPortMock.NotFound( A <string> .That.Contains(expectedResultMessage))) .MustHaveHappenedOnceExactly(); }
public async Task HandleAsync_WhenPollDoesNotExist_ShouldLogInformation() { // Arrange const int pollId = 1; const string expectedLogMessage = "Cannot retrieve a poll with {@id}"; IPollGateway pollGatewayStub = A.Fake <IPollGateway>(); A.CallTo(() => pollGatewayStub.GetAsync(pollId)) .Returns((Poll)null); IGetPollOutputPort OutputPortStub = A.Fake <IGetPollOutputPort>(); ILoggerService <GetPollUseCase> loggerServiceMock = A.Fake <ILoggerService <GetPollUseCase> >(); var useCase = new GetPollUseCase(loggerServiceMock, pollGatewayStub); // Act await useCase.HandleAsync(pollId, OutputPortStub); // Assert A.CallTo( () => loggerServiceMock.LogInformation( A <string> .That.Contains(expectedLogMessage), A <int> .That.IsEqualTo(pollId))) .MustHaveHappenedOnceExactly(); }
public async Task HandleAsync_WhenPollExists_ShouldCallSuccess() { // Arrange const int pollId = 1; Poll poll = this.GetFakePoll(); poll.AddOption("test option"); var expectedGetPollOutput = new GetPollOutput(poll.Id, poll.Title, poll.Note, poll.DueDate, poll.SingleOptionLimitation, poll.Options); IPollGateway pollGatewayStub = A.Fake <IPollGateway>(); A.CallTo(() => pollGatewayStub.GetAsync(pollId)) .Returns(poll); IGetPollOutputPort getPollOutputPortMock = A.Fake <IGetPollOutputPort>(); var useCase = new GetPollUseCase(null, pollGatewayStub); // Act await useCase.HandleAsync(pollId, getPollOutputPortMock); // Assert A.CallTo( () => getPollOutputPortMock.Success( A <GetPollOutput> .That.Matches( m => m.Title == poll.Title && m.Note == poll.Note && m.DueDate == poll.DueDate && m.SingleOptionLimitation == poll.SingleOptionLimitation))) .MustHaveHappenedOnceExactly(); }
public async Task HandleAsync(int id, IGetPollOutputPort output) { Poll poll = await this.pollGateway.GetAsync(id); if (poll is null) { output.NotFound("Poll not found"); this.loggerService.LogInformation("Cannot retrieve a poll with {@id}", id); return; } output.Success(new GetPollOutput(poll.Id, poll.Title, poll.Note, poll.DueDate, poll.SingleOptionLimitation, poll.Options)); }