예제 #1
0
        public async void DeleteConfirmed_ActionExecutes_ReturnRedirectToIndexAction(int productid)
        {
            var result = await _controller.DeleteConfirmed(productid);


            Assert.IsType <RedirectToActionResult>(result);
        }
예제 #2
0
        public async void DeletePOST_ActionExecutes_ReturnRedirectToIndexPage(int Id)
        {
            var result = await _controller.DeleteConfirmed(Id);

            var redirectResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("Index", redirectResult.ActionName);
        }
예제 #3
0
        public async void DeleteConfirmed_ActionExecute_ReturnRedirectToActionIndex(int productId)
        {
            var result = await _controller.DeleteConfirmed(productId);

            var viewResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("Index", viewResult.ActionName);
        }
        public void DeleteConfirmedSuccess()
        {
            var id      = 1;
            var result  = controller.DeleteConfirmed(id); // valid ID
            var product = _context.Products.Find(id);

            Assert.AreEqual(product, null);
        }
        public async void DeleteConfirmed_ActionExecutes_ReturnRedirectToActionResult(int id)
        {
            _mockRepository.Setup(x => x.GetById(id)).ReturnsAsync(products.First(x => x.Id == id));
            var result = await _controller.DeleteConfirmed(id);

            var redToAction = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("Index", redToAction.ActionName);
        }
        public async Task DeleteConfirmed_ReturnsRedirectToIndex()
        {
            //Arrange
            int productId = 1;
            var products  = new Products {
                ProductId = productId
            };
            var mockService = new Mock <IProductsService>();

            mockService.Setup(srv => srv.GetByIdAsync(productId)).ReturnsAsync(new Products()
            {
                ProductId = productId
            });
            mockService.Setup(srv => srv.Delete(productId)).Returns(Task.CompletedTask);
            var controller = new ProductsController(mockService.Object, null, null);

            // Act
            var result = await controller.DeleteConfirmed(productId);

            //Assert
            var redirectToActionResult =
                Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("Index", redirectToActionResult.ActionName);
        }
        public void DB_DeletesSpecificEntry_Collection()
        {
            ProductsController controller  = new ProductsController(db);
            Product            testProduct = new Product
            {
                Name        = "Gummi Couch",
                Description = "Maybe not practical, but definitely possible.",
                Cost        = 299.99m
            };
            Product testProduct2 = new Product
            {
                Name        = "Gummi Dignity",
                Description = "Dignity is hard to preserve sometimes, but when it's gummi maybe it's more resilent and tasty.",
                Cost        = 19.99m
            };

            controller.Create(testProduct, null);
            controller.Create(testProduct2, null);
            var collection = (controller.Index() as ViewResult).ViewData.Model as List <Product>;

            controller.DeleteConfirmed(collection[0].ProductId);
            var collection2 = (controller.Index() as ViewResult).ViewData.Model as List <Product>;

            CollectionAssert.DoesNotContain(collection2, testProduct);
        }
        public async Task SoftDeleteProduct_Valid_ActiveIsFalse()
        {
            var brands     = Data.Brands();
            var categories = Data.Categories();
            var products   = Data.Products();
            var context    = new MockProductsContext(products, brands, categories);
            var controller = new ProductsController(context, null);

            var result = await controller.DeleteConfirmed(1);

            var resultContent  = context.GetProductAsync(1).Result;
            var expectedResult = products.FirstOrDefault(p => p.Id == 1);

            if (expectedResult != null)
            {
                expectedResult.Active = false;
            }

            Assert.IsNotNull(expectedResult);
            Assert.IsNotNull(result);
            var productResult = result as RedirectToActionResult;

            Assert.IsNotNull(productResult);

            Assert.AreEqual(expectedResult.Id, resultContent.Id);
            Assert.AreEqual(expectedResult.Name, resultContent.Name);
            Assert.AreEqual(expectedResult.Active, resultContent.Active);
            Assert.AreEqual(expectedResult.BrandId, resultContent.BrandId);
            Assert.AreEqual(expectedResult.CategoryId, resultContent.CategoryId);
            Assert.AreEqual(expectedResult.Description, resultContent.Description);
        }
        public void DeleteConfirmedValidId()
        {
            var result         = controller.DeleteConfirmed(87).Result;
            var redirectResult = (RedirectToActionResult)result;

            Assert.AreEqual("Index", redirectResult.ActionName);
        }
예제 #10
0
        public void DeleteConfirmedNull()
        {
            var obj       = new ProductsController();
            var actResult = obj.DeleteConfirmed(700) as RedirectToRouteResult;

            Assert.AreEqual("Index", actResult.RouteValues["action"]);
        }
예제 #11
0
        public void DeleteProduct_DeleteProductFromCollection()
        {
            //Arrange
            DbSetup();
            ProductsController controller  = new ProductsController(mock.Object);
            Product            testProduct = new Product
            {
                Id          = 1,
                Cost        = 10,
                Description = "Dummy Bear shaped lollipop with rainbow sprinkles",
                Name        = "Dummy Bear Pop"
            };
            Product testProduct2 = new Product
            {
                Id          = 2,
                Cost        = 100,
                Description = "Contains all magic spells from the CareBears, including the Care Bear stare",
                Name        = "Care Bear Spellbook"
            };

            //Act
            controller.Create(testProduct);
            controller.Create(testProduct2);

            var collection = (controller.Index() as ViewResult).ViewData.Model as List <Product>;

            controller.DeleteConfirmed(collection[0].Id);
            var collection2 = (controller.Index() as ViewResult).ViewData.Model as List <Product>;

            //Assert
            CollectionAssert.DoesNotContain(collection2, testProduct);
        }
        public void DeleteConfirmed()
        {
            ProductsController    controller = new ProductsController(_mockSupRepository.Object, _mockProdRepository.Object);
            RedirectToRouteResult redirect   = controller.DeleteConfirmed(1) as RedirectToRouteResult;

            Assert.IsNotNull(redirect);
            Assert.AreEqual("Index", redirect.RouteValues["action"]);
        }
예제 #13
0
        public async void Should_DeleteConfirmAction_Returns_RedirectToIndex(int productId)
        {
            _mockRepo.Setup(x => x.GetEntity(productId)).Returns(Task.FromResult(products.FirstOrDefault(x => x.Id == productId)));
            _mockRepo.Setup(x => x.Delete(products.FirstOrDefault(x => x.Id == productId)));

            var result = await controller.DeleteConfirmed(productId);

            Assert.IsType <RedirectToActionResult>(result);
        }
예제 #14
0
        public void Mock_GetViewResultDeletePost_ActionResult() // Confirms route returns view
        {
            DbSetup();
            Product product = new Product {
                ProductId = 3, Name = "Test 3", Description = "Its one more test", Cost = 6
            };
            ProductsController controller = new ProductsController(mock.Object);
            var result = controller.DeleteConfirmed(2);

            Assert.IsInstanceOfType(result, typeof(RedirectToActionResult));
        }
예제 #15
0
        public async Task DeleteProductController()
        {
            DatabaseContext context = GetInMemoryDbMetData();

            var controller = new ProductsController(context, _hostingEnvironment);

            var result = await controller.DeleteConfirmed(products[1].Id);

            var viewResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("Index", viewResult.ActionName);
        }
        public void DeleteComfirmedPOST_ActionExecute_ReturnRedirectToActionIndex(int id)
        {
            _productRepositoryMock.Setup(p => p.GetById(id)).Returns(Product);
            _productRepositoryMock.Setup(p => p.Delete(Product));

            IActionResult actionResult = _productsController.DeleteConfirmed(id);

            _productRepositoryMock.Verify(p => p.Delete(It.IsAny <Product>()), Times.Once); //1 kere çalışması lazım.

            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(actionResult);

            Assert.Equal("Index", redirectToActionResult.ActionName);
        }
예제 #17
0
        public void DB_DeleteEntry_Test()
        {
            ProductsController controller = new ProductsController(db);
            Product            cherries   = new Product("Cherries", 1.00, "USA");
            Product            tomatoes   = new Product("Tomatoes", 1.00, "USA");

            controller.Create(cherries);
            controller.Create(tomatoes);
            controller.DeleteConfirmed(cherries.ProductId);

            var collection = (controller.Index() as ViewResult).ViewData.Model as List <Product>;

            Assert.AreEqual(tomatoes.Name, collection[0].Name);
        }
        public async Task DeletePOST_Returns_ProductInfoForDeleting()
        {
            int id      = 4;
            var product = GetProducts().FirstOrDefault(p => p.Id == id);

            //Arrange
            mock.Setup(p => p.DeleteAsync(product.Id)).Throws(new Exception());
            controller = new ProductsController(mock.Object);

            //Act
            var result = await controller.DeleteConfirmed(product.Id);

            //Assert
            var viewResult = Assert.IsType <ViewResult>(result);
        }
예제 #19
0
        public async Task DeleteProductInvalid()
        {
            var context = MockContext.GetContext("test8");

            context.Seed();
            var controller = new ProductsController(_userManager, _signInManager, context);

            //await controller.Delete(product.Id);
            await controller.DeleteConfirmed(10);

            var plants = context.Products;
            var count  = plants.Count();

            Assert.Equal(2, count);
        }
예제 #20
0
        public void TestDeleteConfirmedMethod()
        {
            Products products = new Products {
                ProductId = 1, ProductName = "Harry Porter", Price = 10
            };

            //Mock IRepository of products
            Mock <IRepository <Products> > mockProductsController = new Mock <IRepository <Products> >();

            mockProductsController.Setup(b => b.Delete(It.IsAny <int>()));

            //Pass in the IRepository products
            ProductsController productsController = new ProductsController(mockProductsController.Object);
            var result = productsController.DeleteConfirmed(1) as RedirectToRouteResult;

            Assert.AreEqual(result.RouteValues["action"], "Index");
        }
        public void DB_DeleteConfirmedEntryPOST_Test()
        {
            CreateProduct();
            //Arange
            var productController = new ProductsController(db);
            int productId         = db.Products.ToList()[0].ProductId;
            var viewResult        = productController.Delete(productId) as ViewResult;
            var productToDelete   = viewResult.ViewData.Model as Product;

            //Act
            productController.DeleteConfirmed(productId);
            var indexViewResult = productController.Index() as ViewResult;
            var collection      = indexViewResult.ViewData.Model as List <Product>;

            //Assert
            CollectionAssert.DoesNotContain(collection, productToDelete);
        }
예제 #22
0
        public async Task DeletePost_ReturnsARedirectAndDeleteProduct()
        {
            // Arrange
            _mockService
            .MockGetByIdAsync(_testProductId, _testProduct)
            .MockDeleteAsync(_testProductId);

            // Act
            var result = await _controller.DeleteConfirmed(_testProductId);

            // Assert
            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Null(redirectToActionResult.ControllerName);
            Assert.Equal("Index", redirectToActionResult.ActionName);
            _mockService.Verify();
            _mockService.VerifyDeleteAsync(Times.Once);
        }
        public async Task DeletePOST_Returns_RedirectToActionResult()
        {
            int id      = 4;
            var product = GetProducts().FirstOrDefault(p => p.Id == id);

            //Arrange
            mock.Setup(p => p.DeleteAsync(product.Id));
            controller = new ProductsController(mock.Object);

            //Act
            var result = await controller.DeleteConfirmed(product.Id);

            //Assert
            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Null(redirectToActionResult.ControllerName);
            Assert.Equal("Index", redirectToActionResult.ActionName);
            mock.Verify(p => p.DeleteAsync(product.Id));
        }
예제 #24
0
        public void TestDeleteP()
        {
            var db      = new CS4PEntities();
            var product = db.Products.AsNoTracking().First();

            var controller = new ProductsController();

            var context = new Mock <HttpContextBase>();
            var server  = new Mock <HttpServerUtilityBase>();

            context.Setup(c => c.Server).Returns(server.Object);
            controller.ControllerContext = new ControllerContext(context.Object,
                                                                 new System.Web.Routing.RouteData(), controller);

            var filePath = String.Empty;
            var tempDir  = System.IO.Path.GetTempFileName();

            server.Setup(s => s.MapPath(It.IsAny <string>())).Returns <string>(s =>
            {
                filePath = s;
                return(tempDir);
            });

            using (var scope = new TransactionScope())
            {
                System.IO.File.Delete(tempDir);
                System.IO.Directory.CreateDirectory(tempDir);
                tempDir = tempDir + "/";
                System.IO.File.Create(tempDir + product.id).Close();
                Assert.IsTrue(System.IO.File.Exists(tempDir + product.id));

                var result = controller.DeleteConfirmed(product.id) as RedirectToRouteResult;
                Assert.IsNotNull(result);
                Assert.AreEqual("Index", result.RouteValues["action"]);

                var entity = db.Products.Find(product.id);
                Assert.IsNull(entity);

                Assert.AreEqual("~/Upload/Products/", filePath);
                Assert.IsFalse(System.IO.File.Exists(tempDir + product.id));
            }
        }
예제 #25
0
        public async Task Delete_ReturnsNotFoundResult()
        {
            var product = new Product
            {
                Id          = Guid.NewGuid(),
                Name        = "Keyboard",
                Description = "",
                Quantity    = 10,
                Enable      = true
            };

            var mockService = new Mock <IEntityService <Product> >();
            var controller  = new ProductsController(mockService.Object);

            var result = await controller.DeleteConfirmed(product.Id); // as ViewResult;

            var viewResult = Assert.IsType <NotFoundResult>(result);

            Assert.NotNull(viewResult);
            Assert.Equal(404, viewResult.StatusCode);
        }
        public void DB_DeleteProduct_Collection()
        {
            //arrange
            ProductsController controller   = new ProductsController(db);
            Product            testProduct1 = new Product("sponge", "Sponges up liquid", (decimal)1.99);
            Product            testProduct2 = new Product("many sponges", "Sponges up liquid", (decimal)5.00);

            controller.Create(testProduct1);
            controller.Create(testProduct2);

            //act
            List <Product> result = new List <Product> {
                testProduct1
            };

            controller.DeleteConfirmed(testProduct2.ProductId);
            var collection = (controller.Index() as ViewResult).ViewData.Model as List <Product>;

            //assert
            CollectionAssert.AreEqual(collection, result);
        }
        public async Task SoftDeleteProduct_OutOfBounds_NoChange()
        {
            var brands     = Data.Brands();
            var categories = Data.Categories();
            var products   = Data.Products();
            var context    = new MockProductsContext(products, brands, categories);
            var controller = new ProductsController(context, null);

            var unchangedResult = context.GetAll().Result.ToList();
            var result          = await controller.DeleteConfirmed(outOfBoundsId);

            var resultContent = context.GetAll().Result.ToList();

            Assert.AreEqual(unchangedResult.Count, resultContent.Count);
            Assert.IsNotNull(result);
            var productResult = result as RedirectToActionResult;

            Assert.IsNotNull(productResult);

            CollectionAssert.AreEqual(unchangedResult, resultContent);
        }
예제 #28
0
        public async void CanDelete()
        {
            var options = new DbContextOptionsBuilder <ProductDbContext>()
                          .UseInMemoryDatabase(databaseName: "testDb")
                          .Options;
            var builder = new ConfigurationBuilder().AddEnvironmentVariables();

            builder.AddUserSecrets <Startup>();
            var configuration = builder.Build();

            using (var context = new ProductDbContext(options))
            {
                context.Products.AddRange(
                    new Product {
                    Name = "Fighter Gear", Description = "All you need", Cost = 10.99m, Url = "http://placehold.it/300x300"
                },
                    new Product {
                    Name = "Rogue Gear", Description = "All you need", Cost = 10.99m, Url = "http://placehold.it/300x300"
                },
                    new Product {
                    Name = "Ranger Gear", Description = "All you need", Cost = 10.99m, Url = "http://placehold.it/300x300"
                },
                    new Product {
                    Name = "Wizard Gear", Description = "All you need", Cost = 10.99m, Url = "http://placehold.it/300x300"
                }
                    );
                context.SaveChanges();

                var controller = new ProductsController(context);

                var result = await controller.DeleteConfirmed(1);

                var product = await context.Products
                              .SingleOrDefaultAsync(m => m.Id == 1);

                Assert.DoesNotContain <Product>(product, context.Products.ToListAsync().Result);
            }
        }
예제 #29
0
        public void DB_PostDeleteProduct_Product()
        {
            //Arrange
            ProductsController controller   = new ProductsController(db);
            Product            testProduct1 = new Product(4, "plummi beer", "beer made of plums", 3, 2);

            testProduct1.Reviews = new List <Review>();
            controller.Create(testProduct1);

            Product testProduct2 = new Product(5, "gummi bear", "yummy treat", 3, 2);

            controller.Create(testProduct2);

            //Act
            var result = controller.DeleteConfirmed(testProduct1.ProductId) as RedirectToActionResult;

            var            indexView  = controller.Index() as ViewResult;
            List <Product> collection = indexView.ViewData.Model as List <Product>;

            //Assert
            Assert.AreEqual(5, collection[0].ProductId);
            Assert.IsInstanceOfType(result, typeof(RedirectToActionResult));
        }
예제 #30
0
        public void DeleteConfirmedPostRedirect()
        {
            RedirectToRouteResult result = pc.DeleteConfirmed(0) as RedirectToRouteResult;

            Assert.AreEqual("Index", result.RouteValues["action"]);
        }