Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }