예제 #1
0
        public void DeletingProductAlsoDeletesOptionsTest()
        {
            ProductBusinessLayer layer = new ProductBusinessLayer();

            Guid testProductId       = new Guid();
            Guid testProductOptionId = new Guid();

            Product testProduct = new Product(testProductId, "TestProduct", "This Product is made by a unit test", 1, 2);

            layer.SaveNewProduct(testProduct);

            ProductOption testProductOption = new ProductOption(testProductOptionId, testProductId, "TestProductOption", "This option is made by a unit test");

            layer.SaveNewProductOption(testProductOption);

            //Check that they were saved successfully
            Product       postInsertProduct = layer.GetProductByID(testProductId);
            ProductOption postInsertOption  = layer.GetOptionById(testProductOptionId);

            Assert.IsNotNull(postInsertOption);
            Assert.IsNotNull(postInsertProduct);

            Assert.AreEqual(postInsertProduct.Id, postInsertOption.ProductId);

            layer.DeleteProduct(testProductId);

            Product       postDeleteProduct = layer.GetProductByID(testProductId);
            ProductOption postDeleteOption  = layer.GetOptionById(testProductOptionId);

            Assert.IsNull(postDeleteOption);
            Assert.IsNull(postDeleteProduct);
        }
예제 #2
0
        public void GetOptionsForProductTest()
        {
            ProductBusinessLayer layer = new ProductBusinessLayer();

            List <ProductOption> options = layer.GetOptionsForProduct(Guid.Parse("8f2e9176-35ee-4f0a-ae55-83023d2db1a3"));

            Assert.AreEqual(2, options.Count);
        }
예제 #3
0
        public void GetAllProductsTest()
        {
            ProductBusinessLayer layer = new ProductBusinessLayer();

            List <Product> allProducts = layer.GetAllProducts();

            Assert.AreEqual(2, allProducts.Count);
        }
예제 #4
0
        public void GetOptionByIdTest()
        {
            ProductBusinessLayer layer = new ProductBusinessLayer();

            ProductOption test = layer.GetOptionById(Guid.Parse("0643ccf0-ab00-4862-b3c5-40e2731abcc9"));

            Assert.AreEqual("White", test.Name);
            Assert.AreEqual("White Samsung Galaxy S7", test.Description);
            Assert.AreEqual(Guid.Parse("8f2e9176-35ee-4f0a-ae55-83023d2db1a3"), test.ProductId);
        }
예제 #5
0
        public void GetByProductIdTest()
        {
            ProductBusinessLayer layer = new ProductBusinessLayer();

            Product test = layer.GetProductByID(Guid.Parse("8f2e9176-35ee-4f0a-ae55-83023d2db1a3"));

            Assert.AreEqual("Samsung Galaxy S7", test.Name);
            Assert.AreEqual("Newest mobile product from Samsung.", test.Description);
            Assert.AreEqual(decimal.Parse("1024.99"), test.Price);
            Assert.AreEqual(decimal.Parse("16.99"), test.DeliveryPrice);
        }
예제 #6
0
        public void GetProductByNameTest()
        {
            ProductBusinessLayer layer = new ProductBusinessLayer();

            List <Product> results = layer.GetProductByName("Samsung");

            Assert.IsTrue(results.Count == 1);

            Assert.AreEqual("Samsung Galaxy S7", results[0].Name);
            Assert.AreEqual("Newest mobile product from Samsung.", results[0].Description);
            Assert.AreEqual(decimal.Parse("1024.99"), results[0].Price);
            Assert.AreEqual(decimal.Parse("16.99"), results[0].DeliveryPrice);
        }
예제 #7
0
        public void UpdateProductTest()
        {
            ProductBusinessLayer layer = new ProductBusinessLayer();

            Product test = layer.GetProductByID(Guid.Parse("8f2e9176-35ee-4f0a-ae55-83023d2db1a3"));

            string description = test.Description;

            test.Description = "This is changed for a unit test";

            layer.UpdateProduct(test);

            Product postUpdate = layer.GetProductByID(Guid.Parse("8f2e9176-35ee-4f0a-ae55-83023d2db1a3"));

            Assert.AreEqual(test.Description, postUpdate.Description);

            postUpdate.Description = description;

            layer.UpdateProduct(postUpdate);
        }
예제 #8
0
        public void UpdateProductOptionTest()
        {
            ProductBusinessLayer layer = new ProductBusinessLayer();

            ProductOption test = layer.GetOptionById(Guid.Parse("0643ccf0-ab00-4862-b3c5-40e2731abcc9"));

            string description = test.Description;

            test.Description = "This has been changed by a unit test";

            layer.UpdateProductOption(test);

            ProductOption postUpdate = layer.GetOptionById(Guid.Parse("0643ccf0-ab00-4862-b3c5-40e2731abcc9"));

            Assert.AreEqual(test.Description, postUpdate.Description);

            postUpdate.Description = description;

            layer.UpdateProductOption(postUpdate);
        }
예제 #9
0
        public void SaveAndDeleteProductTest()
        {
            ProductBusinessLayer layer = new ProductBusinessLayer();

            Guid    id   = new Guid();
            Product Test = new Product(id, "TestProduct", "This is a test product for unit testing purposes", 1, 2);

            layer.SaveNewProduct(Test);

            Product postInsert = layer.GetProductByID(id);

            Assert.AreEqual(Test.Id, postInsert.Id);
            Assert.AreEqual(Test.Name, postInsert.Name);
            Assert.AreEqual(Test.Description, postInsert.Description);
            Assert.AreEqual(Test.Price, postInsert.Price);
            Assert.AreEqual(Test.DeliveryPrice, postInsert.DeliveryPrice);

            layer.DeleteProduct(postInsert.Id);

            Product postDelete = layer.GetProductByID(id);

            Assert.IsNull(postDelete);
        }
예제 #10
0
        public void SaveAndDeleteProductOptionTest()
        {
            ProductBusinessLayer layer = new ProductBusinessLayer();

            Guid id = new Guid();

            ProductOption test = new ProductOption(id, Guid.Parse("8f2e9176-35ee-4f0a-ae55-83023d2db1a3"), "TestProductOption", "This is a unit test created product option");

            layer.SaveNewProductOption(test);

            ProductOption postInsert = layer.GetOptionById(id);

            Assert.AreEqual(test.Id, postInsert.Id);
            Assert.AreEqual(test.ProductId, postInsert.ProductId);
            Assert.AreEqual(test.Name, postInsert.Name);
            Assert.AreEqual(test.Description, postInsert.Description);

            layer.DeleteProductOption(postInsert.Id);

            ProductOption postDelete = layer.GetOptionById(id);

            Assert.IsNull(postDelete);
        }