Exemple #1
0
        public void GetRecipeHistory_ReturnsBadRequestResult_IfRecipeIdIsLessThanZero()
        {
            //Arrange
            var repoMock   = new Mock <IRecipesRepository>(MockBehavior.Loose);
            var controller = new RecipesController(repoMock.Object);
            var invalidId  = -5;

            //Act
            var result = controller.GetRecipeHistory(invalidId);

            //Assert
            Assert.IsType <BadRequestResult>(result);
        }
Exemple #2
0
        public void GetRecipeHistory_ReturnsJsonResultWithLogEntryDtos_GivenValidRecipeId()
        {
            //Arrange
            var repoMock = new Mock <IRecipesRepository>();
            var validId  = 5;

            repoMock.Setup(repo => repo.GetLogEntries(validId)).Returns(new[]
            {
                new RecipeLogEntry()
                {
                    VersionID = 1, RecipeID = validId, Title = "Recipe", Description = "Description"
                },
                new RecipeLogEntry()
                {
                    VersionID = 1, RecipeID = validId, Title = "Recipe version 1", Description = "Description 1"
                },
                new RecipeLogEntry()
                {
                    VersionID = 1, RecipeID = validId, Title = "Recipe version 2", Description = "Description 2"
                }
            });
            var expectedResult = new[]
            {
                new RecipeLogEntryDto()
                {
                    Title = "Recipe", Description = "Description"
                },
                new RecipeLogEntryDto()
                {
                    Title = "Recipe version 1", Description = "Description 1"
                },
                new RecipeLogEntryDto()
                {
                    Title = "Recipe version 2", Description = "Description 2"
                },
            };
            var controller = new RecipesController(repoMock.Object);

            //Act
            var result = controller.GetRecipeHistory(validId);

            //Assert
            var actualResult = Assert.IsType <JsonResult>(result);

            Assert.True(expectedResult.SequenceEqual((IEnumerable <RecipeLogEntryDto>)(actualResult.Value), new LogEntryDtoEqualityComparer()));
        }