public async Task FizzBuzzController_ResultsWithValidModel_AwaitsLogger() { //arrange var sut = CreateSut(); sut.ModelState.Clear(); var isAwaited = false; UserInputLoggerMock .Setup(logger => logger.LogAsync(Convert.ToInt32(GeneratedMaxValue), GeneratedPageNumber)) .Returns(() => Task .Delay(TimeSpan.FromMilliseconds(100)) .ContinueWith(task => isAwaited = task.IsCompleted)); //act await sut.Results(new FizzBuzzViewModel { MaxValue = GeneratedMaxValue, PageNumber = GeneratedPageNumber }); //assert isAwaited.Should().BeTrue(); }
public async Task FizzBuzzController_ResultsWithInvalidModel_DoesNotLogUserInputOnce() { //arrange var sut = CreateSut(); sut.ModelState.AddModelError("Some key", "Some error message"); //act await sut.Results(new FizzBuzzViewModel { MaxValue = GeneratedMaxValue, PageNumber = GeneratedPageNumber }); //assert UserInputLoggerMock.Verify( logger => logger.LogAsync(It.IsAny <int>(), It.IsAny <int>()), Times.Never); }
public async Task FizzBuzzController_ResultsWithValidModel_LogsUserInputOnce() { //arrange var sut = CreateSut(); sut.ModelState.Clear(); //act await sut.Results(new FizzBuzzViewModel { MaxValue = GeneratedMaxValue, PageNumber = GeneratedPageNumber }); //assert UserInputLoggerMock.Verify( logger => logger.LogAsync(It.IsAny <int>(), It.IsAny <int>()), Times.Once); }
public async Task FizzBuzzController_ResultsWithValidModel_LogsCorrectUserInput() { //arrange var sut = CreateSut(); sut.ModelState.Clear(); //act await sut.Results(new FizzBuzzViewModel { MaxValue = GeneratedMaxValue, PageNumber = GeneratedPageNumber }); //assert UserInputLoggerMock .Verify(logger => logger.LogAsync( Convert.ToInt32(GeneratedMaxValue), GeneratedPageNumber)); }
public async Task FizzBuzzController_ResultsWithValidModelButInvalidPageNumber_DoesNotLogUserInputOnce() { //arrange PagerMock .Setup(pager => pager.HasPage(GeneratedFizzBuzzItems, 20, GeneratedPageNumber)) .Returns(() => false); var sut = CreateSut(); sut.ModelState.Clear(); //act await sut.Results(new FizzBuzzViewModel { MaxValue = GeneratedMaxValue, PageNumber = GeneratedPageNumber }); //assert UserInputLoggerMock.Verify( logger => logger.LogAsync(It.IsAny <int>(), It.IsAny <int>()), Times.Never); }
public void FizzBuzzController_ResultsWithLoggerThrowing_ThrowsSameException() { //arrange var exception = GenerateException(); UserInputLoggerMock .Setup(logger => logger.LogAsync(It.IsAny <int>(), It.IsAny <int>())) .Throws(exception); var sut = CreateSut(); //act Func <Task> act = () => sut.Results(new FizzBuzzViewModel { MaxValue = GeneratedMaxValue, PageNumber = GeneratedPageNumber }); //assert act .ShouldThrow <Exception>() .Which.Should().BeSameAs(exception); }