public void non_admin_product_add_product_httppost() { //Arrange var controller = new ProductController(new ProductBLL(new ProductDALStub())); //Act var result = (RedirectToRouteResult)controller.addProduct(null); //Assert Assert.AreEqual("LogIn", result.RouteValues["Action"]); Assert.AreEqual("Main", result.RouteValues["Controller"]); }
public void product_list_products_name() { // Arrange TestControllerBuilder builder = new TestControllerBuilder(); var controller = new ProductController(new ProductBLL(new ProductDALStub())); builder.InitializeController(controller); builder.HttpContext.Session["loggedInUser"] = new Customer() { id = 1, admin = true }; // Act var action = (ViewResult)controller.ListProducts(2, 2, "Name", null, null); var result = (IPagedList<ProductInfo>)action.Model; // Assert Assert.IsNotNull(result); Assert.AreEqual(2, result.PageNumber); Assert.IsTrue(string.Compare(result[0].name, result[1].name) < 0); }
public void product_delete_product_httppost_OK() { // Arrange TestControllerBuilder builder = new TestControllerBuilder(); var controller = new ProductController(new ProductBLL(new ProductDALStub())); builder.InitializeController(controller); builder.HttpContext.Session["loggedInUser"] = new Customer() { id = 1, admin = true }; // Act var action = (JsonResult)controller.deleteProduct(2); var success = (bool)(new PrivateObject(action.Data, "success")).Target; //Assert Assert.IsTrue(success); }
public void product_add_product_httpPost_modelstate_is_valid() { // Arrange TestControllerBuilder builder = new TestControllerBuilder(); var controller = new ProductController(new ProductBLL(new ProductDALStub())); builder.InitializeController(controller); builder.HttpContext.Session["loggedInUser"] = new Customer() { id = 1, admin = true }; ProductDetail p = new ProductDetail() { name = "Pilsner", description = "gul", longDescription = "gulere" }; // Act var result = (JsonResult)controller.addProduct(p); var success = (bool)(new PrivateObject(result.Data, "success")).Target; // Assert Assert.IsTrue(success); }
public void product_add_product_httpPost_modelstate_is_invalid() { // Arrange TestControllerBuilder builder = new TestControllerBuilder(); var controller = new ProductController(new ProductBLL(new ProductDALStub())); builder.InitializeController(controller); controller.ViewData.ModelState.AddModelError("feil", "dette ble feil gitt"); builder.HttpContext.Session["loggedInUser"] = new Customer() { id = 1, admin = true }; ProductDetail p = new ProductDetail() { name = "", description = "", longDescription = "" }; // Act var result = (JsonResult)controller.addProduct(p); var success = (bool)(new PrivateObject(result.Data, "success")).Target; // Assert Assert.IsFalse(success); }
public void product_add_product_view() { // Arrange TestControllerBuilder builder = new TestControllerBuilder(); var controller = new ProductController(new ProductBLL(new ProductDALStub())); builder.InitializeController(controller); builder.HttpContext.Session["loggedInUser"] = new Customer() { id = 1, admin = true }; // Act var action = (ViewResult)controller.addProduct(); var result = (ProductDetail)action.Model; // Assert Assert.AreEqual("", action.ViewName); Assert.IsNotNull(result); Assert.IsNotNull(result.countryList); Assert.IsNotNull(result.subCategoryList); Assert.IsNotNull(result.producerList); }
public void product_update_detail_HTTPPOST_modelState_Is_INValid() { // Arrange TestControllerBuilder builder = new TestControllerBuilder(); var controller = new ProductController(new ProductBLL(new ProductDALStub())); builder.InitializeController(controller); builder.HttpContext.Session["loggedInUser"] = new Customer() { id = 1, admin = true }; controller.ViewData.ModelState.AddModelError("feil", "dette ble feil gitt"); ProductDetail expected = new ProductDetail() { itemnumber = 1, name = "Tullball", description = "Hei", price = 123, volum = 50, producerid = 2, longDescription = "Tullball er et fantastisk godt drikkeprodukt", subCategoryid = 3, countryid = 1 }; // Act var result = (JsonResult)controller.ProductDetails(1, expected); var success = (bool)(new PrivateObject(result.Data, "success")).Target; //Assert Assert.IsFalse(success); }
public void product_detail_view() { // Arrange TestControllerBuilder builder = new TestControllerBuilder(); var controller = new ProductController(new ProductBLL(new ProductDALStub())); builder.InitializeController(controller); builder.HttpContext.Session["loggedInUser"] = new Customer() { id = 1, admin = true }; ProductDetail expected = new ProductDetail() { itemnumber = 1, name = "Tullball", description = "Hei", price = 123, volum = 50, producerid = 2, longDescription = "Tullball er et fantastisk godt drikkeprodukt", subCategoryid = 3, countryid = 1 }; // Act var action = (ViewResult)controller.ProductDetails(expected.itemnumber); var result = (ProductDetail)action.Model; // Assert Assert.AreEqual(expected.itemnumber, result.itemnumber); Assert.AreEqual(expected.name, result.name); Assert.AreEqual(expected.description, result.description); Assert.AreEqual(expected.price, result.price); Assert.AreEqual(expected.volum, result.volum); Assert.AreEqual(expected.producerid, result.producerid); Assert.AreEqual(expected.longDescription, result.longDescription); Assert.AreEqual(expected.countryid, result.countryid); }