public void After_Edit_ValidObject_Get_Should_Changed()
        {
            // Arrange
            DbContextOptions <RepositoryContext> options = new MockDBHandler().CategoryWithThreeMember().CountryWithThreeMember().UnitWithThreeMember().IngredientWithThreeMember().ReciptWithThreeMember().build();

            using (var context = new RepositoryContext(options))
            {
                ICustomMapper            _customMapper  = new CustomMapper(context);
                IDataRepository <Recipe> mockRepository = new RecipeManager(context);

                RecipeController recipecontroller = new RecipeController(mockRepository, _mapper, _customMapper, _usermanager);
                //Act
                var forEdit = new MockDBHandler().buildMockRecipeView();
                forEdit.ID = 1; // Because In mock it is something else and in equalation assert result to false
                OkObjectResult  okresult = recipecontroller.Get(1) as OkObjectResult;
                RecipeViewModel origin   = okresult.Value as RecipeViewModel;
                recipecontroller.Put(origin.ID, forEdit);

                OkObjectResult  okresultAfterEdit = recipecontroller.Get(1) as OkObjectResult;
                RecipeViewModel afterEdit         = okresultAfterEdit.Value as RecipeViewModel;

                // Assert

                Assert.True(forEdit.Equals(afterEdit));
                Assert.False(origin.Equals(afterEdit));
            }
        }
Exemple #2
0
        public void GetById_WhenCalled_ReturnOkResult(int id)
        {
            //Act
            var okResult = _controller.Get(id);

            //Assert
            Assert.IsType <OkObjectResult>(okResult.Result);
        }
Exemple #3
0
        public void GetEasyRecipes_ShouldReturnEasyRecipes()
        {
            var testShops  = GetTestRecipes().FindAll(r => r.Difficulty == RecipeDifficulty.EASY);
            var controller = new RecipeController(GetRepository());

            var result = controller.Get(RecipeDifficulty.EASY) as List <Recipe>;

            Assert.AreEqual(testShops.Count, result.Count);
        }
Exemple #4
0
        public void GetAllRecipes_ShouldReturnAllRecipes()
        {
            var testShops  = GetTestRecipes();
            var controller = new RecipeController(GetRepository());

            var result = controller.Get(null) as List <RecipeDto>;

            Assert.AreEqual(testShops.Count, result.Count);
        }
        public void Delete_ShouldWork()
        {
            // Arrange
            DbContextOptions <RepositoryContext> options = new MockDBHandler().CategoryWithThreeMember().CountryWithThreeMember().UnitWithThreeMember().IngredientWithThreeMember().ReciptWithThreeMember().build();

            using (var context = new RepositoryContext(options))
            {
                ICustomMapper            _customMapper  = new CustomMapper(context);
                IDataRepository <Recipe> mockRepository = new RecipeManager(context);

                RecipeController recipecontroller = new RecipeController(mockRepository, _mapper, _customMapper, _usermanager);
                FilterModel      fm = new FilterModel();
                //Act
                var okResultBeforDelete = recipecontroller.Get(fm);
                var itemsBeforeDelete   = Assert.IsType <ActionResult <PagedCollectionResponse <RecipeViewModel> > >(okResultBeforDelete);
                Assert.Equal(1, itemsBeforeDelete.Value.Items.ToList().Count);
                var notFoundResult      = recipecontroller.Delete(1);
                var okResultAfterDelete = recipecontroller.Get(fm);
                var itemsAfterDelete    = Assert.IsType <ActionResult <PagedCollectionResponse <RecipeViewModel> > >(okResultAfterDelete);
                Assert.Equal(0, itemsAfterDelete.Value.Items.ToList().Count);
            }
        }
Exemple #6
0
        public void GetSpecificRecipe_Failed()
        {
            //Arrange
            _recipeService.Setup(c => c.GetRecipe(Guid.Empty)).Returns((Recipe)null);
            RecipeController recipeController = new RecipeController(_recipeService.Object);

            //Act
            var result         = recipeController.Get(Guid.Empty);
            var notFoundResult = result as NotFoundResult;

            //Assert
            Assert.NotNull(result);
            Assert.Equal(404, notFoundResult.StatusCode);
        }
        public void Get_Returns_List_Of_Recipes()
        {
            var expectedRecipes = new List <Recipe>()
            {
                new Recipe(1, "Chocolate Bar", "410", "Homemade Chocolate Bars"),
                new Recipe(2, "Biscuits", "310", "Preheat oven to 450 degrees")
            };

            recipeRepo.GetAll().Returns(expectedRecipes);

            var result = underTest.Get();

            Assert.Equal(expectedRecipes, result.ToList());
        }
Exemple #8
0
        public void Get_ReturnsExpected()
        {
            var expected = new List <Recipe>();

            _mockUserRepo.Setup(s => s.GetByAuthId("test")).Returns(new User
            {
                Id     = 1,
                AuthId = "test"
            });
            _mockRepo.Setup(r => r.GetRecipesForUser(It.IsAny <string>())).Returns(expected);
            var result = _controller.Get("test") as OkObjectResult;

            Assert.AreEqual(expected, result?.Value);
        }
Exemple #9
0
        public void GetRecipesMockedTest()
        {
            // Arrange
            var service = new RecipeController(new MockedDatabaseFactory());
            var mock    = new MockedDatabaseFactory();

            service.Request       = new System.Net.Http.HttpRequestMessage();
            service.Configuration = new System.Web.Http.HttpConfiguration();

            // Act
            var result = service.Get();

            // Assert
            Assert.AreEqual(result.Count, 3);
        }
Exemple #10
0
        public void GetSpecificRecipe_Success()
        {
            //Arrange
            Recipe recipe = new Recipe();

            _recipeService.Setup(c => c.GetRecipe(Guid.Empty)).Returns(recipe);
            RecipeController recipeController = new RecipeController(_recipeService.Object);

            //Act
            var result         = recipeController.Get(Guid.Empty);
            var okObjectResult = result as OkObjectResult;

            //Assert
            Assert.NotNull(result);
            Assert.Equal(200, okObjectResult.StatusCode);
        }
Exemple #11
0
        public void GetRecipes_Failed()
        {
            //Arrange
            _recipeService.Setup(c => c.GetRecipes(25, 1)).Returns((List <RecipeDto>)null);
            RecipeController recipeController = new RecipeController(_recipeService.Object);

            //Act
            var result = recipeController.Get(new Paging {
                Size = 25, Page = 1
            });
            var notFoundResult = result as NotFoundResult;

            //Assert
            Assert.NotNull(result);
            Assert.Equal(404, notFoundResult.StatusCode);
        }
        public void GetById_UnknownintPassed_ReturnsNotFoundResult()
        {
            // Arrange
            DbContextOptions <RepositoryContext> options = new MockDBHandler().CategoryWithThreeMember().CountryWithThreeMember().UnitWithThreeMember().IngredientWithThreeMember().ReciptWithThreeMember().build();

            using (var context = new RepositoryContext(options))
            {
                ICustomMapper            _customMapper  = new CustomMapper(context);
                IDataRepository <Recipe> mockRepository = new RecipeManager(context);

                RecipeController recipecontroller = new RecipeController(mockRepository, _mapper, _customMapper, _usermanager);
                //Act
                var notFoundResult = recipecontroller.Get(68);

                // Assert
                Assert.IsType <Microsoft.AspNetCore.Mvc.NotFoundObjectResult>(notFoundResult);
            }
        }
Exemple #13
0
        public void GetRecipes_Success()
        {
            //Arrange
            List <RecipeDto> fakeList = new List <RecipeDto>();

            _recipeService.Setup(c => c.GetRecipes(1, 25, "")).Returns(fakeList);
            RecipeController recipeController = new RecipeController(_recipeService.Object);

            //Act
            var result = recipeController.Get(new Paging {
                Size = 1, Page = 25, Uid = ""
            });
            var okresult = result as OkObjectResult;

            //Assert
            Assert.NotNull(result);
            Assert.Equal(200, okresult.StatusCode);
        }
        public void Get_WhenCalled_ReturnsOkResult()
        {
            DbContextOptions <RepositoryContext> options = new MockDBHandler().CategoryWithThreeMember().CountryWithThreeMember().UnitWithThreeMember().IngredientWithThreeMember().ReciptWithThreeMember().build();

            using (var context = new RepositoryContext(options))
            {
                ICustomMapper _customMapper = new CustomMapper(context);
                // Arrange
                IDataRepository <Recipe> mockRepository = Substitute.For <IDataRepository <Recipe> >();
                RecipeController         recipeCont     = new RecipeController(mockRepository, _mapper, _customMapper, _usermanager);
                FilterModel fm = new FilterModel();
                // Act

                var okResult = recipeCont.Get(fm);

                // Assert
                Assert.IsType <ActionResult <PagedCollectionResponse <RecipeViewModel> > >(okResult);
            }
        }
        public void Add_ValidObject_Then_Get_Should_bring_Something()
        {
            // Arrange
            DbContextOptions <RepositoryContext> options = new MockDBHandler().CategoryWithThreeMember().CountryWithThreeMember().UnitWithThreeMember().IngredientWithThreeMember().ReciptWithThreeMember().build();

            using (var context = new RepositoryContext(options))
            {
                ICustomMapper            _customMapper  = new CustomMapper(context);
                IDataRepository <Recipe> mockRepository = new RecipeManager(context);

                RecipeController recipecontroller = new RecipeController(mockRepository, _mapper, _customMapper, _usermanager);
                FilterModel      fm = new FilterModel();
                //Act
                recipecontroller.Post(new MockDBHandler().buildMockRecipeView());
                var okResult = recipecontroller.Get(fm);

                // Assert

                var retObj = Assert.IsType <ActionResult <PagedCollectionResponse <RecipeViewModel> > >(okResult);
                Assert.Equal(2, retObj.Value.Items.ToList().Count);
            }
        }