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 void Success(GetPollOutput output) { var optionsResponse = output.Options .Select(option => new OptionResponse { Id = option.Id, Option = option.Text }) .ToList(); var response = new GetPollResponse { Id = output.Id, Title = output.Title, Note = output.Note, DueDate = output.DueDate, SingleOptionLimitation = output.SingleOptionLimitation, Options = optionsResponse }; this.ViewModel = new OkObjectResult(response); }