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));
            }
        }
Esempio n. 2
0
        public void Test_map_From_recipeVieModel_To_recipe()
        {
            RecipeViewModel acctual = new MockDBHandler().buildMockRecipeView();
            DbContextOptions <RepositoryContext> options = new MockDBHandler().CategoryWithThreeMember().CountryWithThreeMember().UnitWithThreeMember().IngredientWithThreeMember().ReciptWithThreeMember().build();

            using (var context = new RepositoryContext(options))
            {
                _custumMapper = new CustomMapper(context);

                //Act
                var recipDes = _custumMapper.Map(acctual);
                var expected = _custumMapper.Map(recipDes);

                // Assert
                Assert.True(expected.Equals(acctual));
            }
        }
        public void Delete_InvalidID_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.Delete(68);

                // Assert
                Assert.IsType <Microsoft.AspNetCore.Mvc.NotFoundObjectResult>(notFoundResult);
            }
        }
        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);
            }
        }
Esempio n. 5
0
        public void Add_ValidObject_Then_Get_Should_bring_Something()
        {
            // Arrange

            DbContextOptions <RepositoryContext> options = new MockDBHandler().CategoryWithThreeMember().build();

            using (var context = new RepositoryContext(options))
            {
                IDataRepository <Category> mockRepository = new CategoryManager(context);
                CategoryController         categoryCont   = new CategoryController(mockRepository);
                FilterModel fm = new FilterModel();
                //Act
                var okResult = categoryCont.Get(fm) as ActionResult <PagedCollectionResponse <Category> >;

                // Assert
                var retObj = Assert.IsType <ActionResult <PagedCollectionResponse <Category> > >(okResult);
                Assert.Equal(3, retObj.Value.Items.ToList().Count);
            }
        }
        public void Put_Null_Should_ReturnsBadRequest()
        {
            // 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 badRequest = recipecontroller.Put(1, null);

                // Assert
                Assert.IsType <Microsoft.AspNetCore.Mvc.BadRequestObjectResult>(badRequest);
            }
        }
Esempio n. 7
0
        public void Delete_ShouldWork()
        {
            // Arrange
            DbContextOptions <RepositoryContext> options = new MockDBHandler().UnitWithThreeMember().build();

            using (var context = new RepositoryContext(options))
            {
                IDataRepository <Unit> mockRepository = new UnitManager(context);
                UnitController         unitCont       = new UnitController(mockRepository);
                FilterModel            fm             = new FilterModel();
                //Act
                var putResult = unitCont.Delete(2) as OkObjectResult;
                var okResult  = unitCont.Get(fm);
                // Assert
                var retObj = Assert.IsType <ActionResult <PagedCollectionResponse <Unit> > >(okResult);
                Assert.Equal(2, retObj.Value.Items.ToList().Count);
                Assert.Equal("Unit1", retObj.Value.Items.ToList()[0].Name);
                Assert.Equal("Unit3", retObj.Value.Items.ToList()[1].Name);
            }
        }
        public void Put_Invalid_ID_Should_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 forEdit = new MockDBHandler().buildMockRecipeView();
                forEdit.ID = 1; // Because In mock it is something else and in equalation assert result to false

                var notFoundResult = recipecontroller.Put(68, forEdit);

                // Assert
                Assert.IsType <Microsoft.AspNetCore.Mvc.NotFoundObjectResult>(notFoundResult);
            }
        }
Esempio n. 9
0
        public void Test_map_From_recipe_To_recipeVieModel()
        {
            DbContextOptions <RepositoryContext> options = new MockDBHandler().CategoryWithThreeMember().CountryWithThreeMember().UnitWithThreeMember().IngredientWithThreeMember().ReciptWithThreeMember().build();

            using (var context = new RepositoryContext(options))
            {
                _custumMapper = new CustomMapper(context);
                var acctual = context.Recipe.Include(y => y.Category)
                              .Include(r => r.Country)
                              .Include(w => w.Ingredients)
                              .FirstOrDefaultAsync().Result;
                acctual.Ingredients = context.RecipeIngredient.Include(x => x.Ingredient).Include(y => y.Unit).Where(T => T.RecipeID == acctual.ID).ToList();

                //Act
                var recipDes = _custumMapper.Map(acctual);
                var expected = _custumMapper.Map(recipDes);

                // Assert
                Assert.True(expected.Equals(acctual));
            }
        }
        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);
            }
        }
        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);
            }
        }
        public void Add_ValidObjectPassed_ReturnedResponseHasCreatedItem()
        {
            // 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);

                AuthenticateController aut = new AuthenticateController(_usermanager);

                RecipeController recipecontroller = new RecipeController(mockRepository, _mapper, _customMapper, _usermanager);

                // Act
                IActionResult actionResult  = recipecontroller.Post(new MockDBHandler().buildMockRecipeView());
                var           createdResult = actionResult as CreatedAtRouteResult;
                // Assert
                Assert.NotNull(createdResult);
                Assert.Equal("N", ((RecipeViewModel)createdResult.Value).Name);
                Assert.Equal(2, ((RecipeViewModel)createdResult.Value).Ingredients.Count);
            }
        }
Esempio n. 13
0
        public void After_Edit_ValidObject_Get_Should_Changed()
        {
            // Arrange
            DbContextOptions <RepositoryContext> options = new MockDBHandler().UnitWithThreeMember().build();

            using (var context = new RepositoryContext(options))
            {
                IDataRepository <Unit> mockRepository = new UnitManager(context);
                UnitController         unitCont       = new UnitController(mockRepository);
                FilterModel            fm             = new FilterModel();
                //Act
                Unit newUnit = new Unit()
                {
                    IsValid = false, Name = "Changed"
                };
                var putResult = unitCont.Put(2, newUnit) as OkObjectResult;
                var okResult  = unitCont.Get(fm);
                // Assert
                var retObj = Assert.IsType <ActionResult <PagedCollectionResponse <Unit> > >(okResult);
                Assert.Equal(3, retObj.Value.Items.ToList().Count);
                Assert.False(retObj.Value.Items.ToList()[1].IsValid);
                Assert.Equal("Changed", retObj.Value.Items.ToList()[1].Name);
            }
        }