public void non_admin_product_add_product()
        {
            //Arrange
            var controller = new ProductController(new ProductBLL(new ProductDALStub()));

            //Act
            var result = (RedirectToRouteResult)controller.addProduct();

            //Assert
            Assert.AreEqual("LogIn", result.RouteValues["Action"]);
            Assert.AreEqual("Main", result.RouteValues["Controller"]);
        }
        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_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_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);
        }