public void RedirectToActionIndexWhenValidModelForEdit() { _mockProductRepository.Setup(products => products.Find("abc123")).Returns(GetProduct()); _sut = new ProductManagerController(_mockProductRepository.Object, _mockProductCategoryRepository.Object, _mockEnvironment.Object); var product = new Product { Category = "Sneakers", CreatedAt = DateTimeOffset.Now, Description = "White sneakers", Id = "abc123", Image = "/path/image.jpg", Name = "Nike Air Force One", Price = 10 }; IFormFile file = null; var result = _sut.Edit(product, file); var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Index", redirectToActionResult.ActionName); }
public void ReturnEditWithProductManagerViewModel() { _mockProductRepository.Setup(products => products.Find("abc123")).Returns(GetProduct()); _mockProductCategoryRepository.Setup(productCategories => productCategories.Collection()).Returns(GetProductCategories()); _sut = new ProductManagerController(_mockProductRepository.Object, _mockProductCategoryRepository.Object, _mockEnvironment.Object); IActionResult result = _sut.Edit("abc123"); var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsType <ProductManagerViewModel>(viewResult.Model); Assert.Equal(GetProduct().Category, model.Product.Category); Assert.Equal(GetProduct().Id, model.Product.Id); Assert.Equal(GetProduct().CreatedAt.Minute, model.Product.CreatedAt.Minute); Assert.Equal(GetProduct().Description, model.Product.Description); Assert.Equal(GetProduct().Name, model.Product.Name); Assert.Equal(GetProduct().Price, model.Product.Price); Assert.Equal(GetProduct().Image, model.Product.Image); Assert.Equal(GetProductCategories().First().Category, model.ProductCategories.First().Category); }
public void EditProductWhenValidModel() { _mockProductRepository.Setup(products => products.Find("abc123")).Returns(GetProduct()); _sut = new ProductManagerController(_mockProductRepository.Object, _mockProductCategoryRepository.Object, _mockEnvironment.Object); var product = new Product { Category = "Sneakers", CreatedAt = DateTimeOffset.Now, Description = "White sneakers", Id = "abc123", Image = "/path/image.jpg", Name = "Nike Air Force One", Price = 10 }; IFormFile file = null; _sut.Edit(product, file); _mockProductRepository.Verify( x => x.Commit(), Times.Once); }
public void ReturnEditWithProductManagerViewModelWhenInvalidModelState() { _mockProductRepository.Setup(products => products.Find("abc123")).Returns(GetProduct()); _mockProductCategoryRepository.Setup(productCategories => productCategories.Collection()).Returns(GetProductCategories()); _sut = new ProductManagerController(_mockProductRepository.Object, _mockProductCategoryRepository.Object, _mockEnvironment.Object); _sut.ModelState.AddModelError("x", "Test Error"); var product = new Product { Category = "Sneakers", Id = "abc123" }; IFormFile file = null; IActionResult result = _sut.Edit(product, file); var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsType <ProductManagerViewModel>(viewResult.Model); Assert.Equal(product.Category, model.Product.Category); }
public void TestEdit_Product_fail() { var helper = new MockHelper(); var context = helper.MakeFakeContext(); // var controller = new Controllers.ProductManagerController(); var controller = new ProductManagerController(); controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), controller); var serverMock = new Mock <HttpServerUtilityBase>(); serverMock.Setup(x => x.MapPath("~/App_Data")).Returns(@"D:\Anh_Quoc\K\Năm 2\SOFTWARE TESTING\Team Project\Final project team\Code\FinalProj\ClockUniverse\ClockUniverse\App_Data"); context.Setup(x => x.Server).Returns(serverMock.Object); // var file1Mock = new Mock<HttpPostedFileBase>(); // file1Mock.Setup(x => x.FileName).Returns("30_0"); var Producttable = new ProductTable { Watch_ID = 1089, Watch_Name = "KhacHuy", Watch_Description = "dsadasdal", WatchType_ID = 1, //Original_Price = 1000, //Selling_Price = 100, InStock = 1, Watch_Static = "cc", }; var actual = controller.Edit(Producttable) as RedirectToRouteResult; Assert.IsNull(actual); }
public void TestEditG() { var controller = new ProductManagerController(); var result0 = controller.Edit(0); Assert.IsInstanceOfType(result0, typeof(HttpNotFoundResult)); var db = new CsK23T3bEntities(); var item = db.ProductTables.First(); var result1 = controller.Edit(item.Watch_ID) as ViewResult; Assert.IsNotNull(result1); var model = result1.Model as ProductTable; Assert.AreEqual(item.Watch_ID, model.Watch_ID); }
public void ReturnNotFoundForEdit() { _sut = new ProductManagerController(_mockProductRepository.Object, _mockProductCategoryRepository.Object, _mockEnvironment.Object); IActionResult result = _sut.Edit("abc123"); Assert.IsType <NotFoundResult>(result); }
public void ReturnNotFoundForEditAfterPost() { _sut = new ProductManagerController(_mockProductRepository.Object, _mockProductCategoryRepository.Object, _mockEnvironment.Object); IFormFile file = null; IActionResult result = _sut.Edit(new Product(), file); Assert.IsType <NotFoundResult>(result); }
public void TestEdit_Product_success() { var helper = new MockHelper(); var context = helper.MakeFakeContext(); // var controller = new Controllers.ProductManagerController(); var controller = new ProductManagerController(); controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), controller); var serverMock = new Mock <HttpServerUtilityBase>(); serverMock.Setup(x => x.MapPath("~/App_Data")).Returns(@"D:\Anh_Quoc\K\Năm 2\SOFTWARE TESTING\Team Project\Final project team\Code\FinalProj\ClockUniverse\ClockUniverse\App_Data"); var request = new Mock <HttpRequestBase>(MockBehavior.Strict); //request.Setup(r => r.Files).Returns(new System.Web.HttpRequestBase.Files()); context.Setup(x => x.Server).Returns(serverMock.Object); var file1Mock = new Mock <HttpPostedFileBase>(); file1Mock.Setup(x => x.FileName).Returns("1087_0"); var image = file1Mock.Object; var Producttable = new ProductTable { Watch_ID = 1087, Watch_Name = "KhacHuy", Watch_Description = "dsadasdal", WatchType_ID = 1, Original_Price = 1000, Selling_Price = 100, InStock = 1, Watch_Static = "cc", Image = "image", }; var actual = controller.Edit(Producttable) as RedirectToRouteResult; Assert.AreEqual("Index", actual.RouteValues["Action"]); }
public void NotEditProductWhenModelError() { _mockProductRepository.Setup(products => products.Find("abc123")).Returns(GetProduct()); _sut = new ProductManagerController(_mockProductRepository.Object, _mockProductCategoryRepository.Object, _mockEnvironment.Object); _sut.ModelState.AddModelError("x", "Test Error"); var product = new Product { Category = "Sneakers", Id = "abc123" }; IFormFile file = null; _sut.Edit(product, file); _mockProductRepository.Verify( x => x.Update(It.IsAny <Product>()), Times.Never); }