Пример #1
0
        public void importUpdateProduct_Test()
        {
            // arrange
            // set up the data access fake
            int     id          = 1;
            string  idNumber    = "123";
            string  description = "A product description";
            int     quantity    = 1;
            float   price       = 0;
            Product newProduct  = new Product(id, idNumber, description, quantity, price);
            var     productDAO  = A.Fake <Model.DataAccessLayer.IProductDAO>();
            bool    updateProductMethodCalled = false;

            A.CallTo(() => productDAO.importUpdateProduct(newProduct)).Invokes(() => updateProductMethodCalled = true);
            // set up the class under test
            this.productService = new ProductOps(productDAO);
            // subscribe to the event
            bool eventFired = false;

            productService.GetAllProducts += (sender, args) => { eventFired = true; };

            // act
            productService.importUpdateProduct(newProduct);

            // assert
            NUnit.Framework.Assert.IsTrue(eventFired);
            NUnit.Framework.Assert.IsTrue(updateProductMethodCalled);
        }
Пример #2
0
        public HttpResponseMessage Get(string type)
        {
            string items = "";

            switch (type)
            {
            case "calendar":
            case "news":
                List <FarmInfoItem> infoItems = InfoItemOps.GetInfoItems(type);
                items = new JavaScriptSerializer().Serialize(infoItems);
                break;

            case "map":
                List <MapItem> mapItems = MapItemOps.GetMapItems("none");
                items = new JavaScriptSerializer().Serialize(mapItems);
                break;

            case "shop":
                List <Product> products = ProductOps.GetProducts();
                items = new JavaScriptSerializer().Serialize(products);
                break;
            }

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(items);

            return(response);
        }
Пример #3
0
        public void getProduct_Test()
        {
            // should return either a null or a product object

            // arrange
            // set up the data access fake
            int    id          = 1;
            string idNumber    = "123";
            string description = "A product description";
            int    quantity    = 1;
            float  price       = 0;
            var    productDAO  = A.Fake <Model.DataAccessLayer.IProductDAO>();

            A.CallTo(() => productDAO.getProduct(idNumber)).Returns(new Product(id, idNumber, description, quantity, price));
            A.CallTo(() => productDAO.getProduct("0")).Returns(null);
            // initialise the class under test
            productService = new Model.ServiceLayer.ProductOps(productDAO);

            // act
            IProduct productThatExists       = this.productService.getProduct(idNumber);
            IProduct productThatDoesNotExist = this.productService.getProduct("0");

            // assert
            NUnit.Framework.Assert.IsNull(productThatDoesNotExist);
            NUnit.Framework.Assert.AreEqual(id, productThatExists.ProductID);
            NUnit.Framework.Assert.AreEqual(idNumber, productThatExists.ProductIDNumber);
            NUnit.Framework.Assert.AreEqual(description, productThatExists.Description);
            NUnit.Framework.Assert.AreEqual(quantity, productThatExists.Quantity);
            NUnit.Framework.Assert.AreEqual(price, productThatExists.price);
        }
Пример #4
0
        public ActionResult LoadEditProduct(int id)
        {
            List <Product> model = new List <Product>();
            Product        item  = ProductOps.FindProduct(id);

            model.Add(item);
            return(PartialView("EditProductPartial", model));
        }
Пример #5
0
 public ActionResult UpdateProduct(Product item)
 {
     try
     {
         ProductOps.UpdateProduct(item);
         return(Json(item.Id.ToString()));
     }
     catch (Exception e)
     {
         return(new HttpStatusCodeResult(500, e.ToString()));
     }
 }
Пример #6
0
 public ActionResult AddProduct(Product item)
 {
     try
     {
         ProductOps.AddProduct(item);
         return(new HttpStatusCodeResult(200));
     }
     catch (Exception e)
     {
         return(new HttpStatusCodeResult(500, e.ToString()));
     }
 }
Пример #7
0
 public ActionResult DeleteProduct(int id)
 {
     try
     {
         Product item = ProductOps.FindProduct(id);
         ProductOps.DeleteProduct(item);
         return(new HttpStatusCodeResult(200));
     }
     catch (Exception e)
     {
         return(new HttpStatusCodeResult(500, e.ToString()));
     }
 }
Пример #8
0
        public void deleteProduct_Test()
        {
            // arrange
            // set up the data access fake
            string productIDNumber           = "123";
            var    productDAO                = A.Fake <Model.DataAccessLayer.IProductDAO>();
            bool   deleteProductMethodCalled = false;

            A.CallTo(() => productDAO.deleteProduct(productIDNumber)).Invokes(() => deleteProductMethodCalled = true);
            // initialise the class under test
            this.productService = new Model.ServiceLayer.ProductOps(productDAO);
            // subscribe to the event
            bool eventFired = false;

            productService.GetAllProducts += (sender, args) => { eventFired = true; };

            // act
            this.productService.deleteProduct(productIDNumber);

            // assert
            NUnit.Framework.Assert.IsTrue(deleteProductMethodCalled);
            NUnit.Framework.Assert.IsTrue(eventFired);
        }
Пример #9
0
        public ActionResult LoadShop()
        {
            List <Product> model = ProductOps.GetProducts();

            return(PartialView("ShopPartial", model));
        }