Beispiel #1
0
        public void Should_Modify_Product_Category()
        {
            var dbName = nameof(Should_Modify_Product_Category);

            var options = TestUtils.GetOptions(dbName);

            using (var arrangeContext = new WHMSContext(options))
            {
                arrangeContext.Products.Add(new Product()
                {
                    Name = "Name", Category = new Category()
                    {
                        Name = "CATEGORY"
                    }
                });
                arrangeContext.Categories.Add(new Category()
                {
                    Name = "newCATEGORY"
                });
                arrangeContext.SaveChanges();
            }
            using (var assertContext = new WHMSContext(options))
            {
                var sut      = new ProductService(assertContext);
                var category = assertContext.Categories.First(u => u.Name == "newCATEGORY");
                var product  = assertContext.Products.First(u => u.Name == "Name");
                sut.ModifyCategory(product, category);

                Assert.AreEqual("Name", product.Name);
                Assert.IsNotNull(product);
                Assert.IsInstanceOfType(product, typeof(Product));
                Assert.AreEqual("newCATEGORY", product.Category.Name);
            }
        }
Beispiel #2
0
        public void Succeed()
        {
            //Arrange
            var     dbName   = ((nameof(AddProduct_Should)) + (nameof(Succeed)));
            var     options  = TestUtils.GetOptions(dbName);
            Product product1 = new Product {
                Name = "Product1"
            };
            Product product2 = new Product {
                Name = "Product2"
            };

            using (var arrangeContext = new WHMSContext(options))
            {
                //arrangeContext.Partners.Add(partner);
                arrangeContext.Orders.Add(new Order {
                    Id = 1, Products = new List <Product> {
                        product1
                    }
                });
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new WHMSContext(options))
            {
                var sut        = new OrderService(assertContext);
                var addProduct = sut.AddProductToOrder(1, product2, 1);
                Assert.IsTrue(addProduct.Products.Contains(product2));
            }
        }
Beispiel #3
0
        public void Should_Return_Deleted_Product()
        {
            var dbName = nameof(Should_Return_Deleted_Product);

            var options = TestUtils.GetOptions(dbName);

            using (var arrangeContext = new WHMSContext(options))
            {
                arrangeContext.Products.Add(new Product()
                {
                    Name = "Name", IsDeleted = true
                });
                arrangeContext.SaveChanges();
            }
            using (var assertContext = new WHMSContext(options))
            {
                var sut     = new ProductService(assertContext);
                var product = sut.UndeleteProduct("Name");

                Assert.AreEqual("Name", product.Name);
                Assert.IsNotNull(product);
                Assert.IsInstanceOfType(product, typeof(Product));
                Assert.IsTrue(product.IsDeleted == false);
            }
        }
Beispiel #4
0
        public void Partner_ShouldSucceed()  //int orderId, Partner newPartner
        {
            Partner partner = new Partner {
                Name = "Partner1"
            };
            Partner newPartner = new Partner {
                Name = "Partner2"
            };

            var dbName  = ((nameof(Edit)) + (nameof(Partner_ShouldSucceed)));
            var options = TestUtils.GetOptions(dbName);

            using (var arrangeContext = new WHMSContext(options))
            {
                arrangeContext.Orders.Add(new Order {
                    Id = 1, Partner = partner
                });
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new WHMSContext(options))
            {
                var sut         = new OrderService(assertContext);
                var editPartner = sut.EditPartner(1, newPartner);
                Assert.AreEqual(newPartner, editPartner.Partner);
            }
        }
Beispiel #5
0
        public void Should_Modify_Product_Unit()
        {
            var dbName = nameof(Should_Modify_Product_Unit);

            var options = TestUtils.GetOptions(dbName);

            using (var arrangeContext = new WHMSContext(options))
            {
                arrangeContext.Products.Add(new Product()
                {
                    Name = "Name", Unit = new Unit()
                    {
                        UnitName = "unit"
                    }
                });
                arrangeContext.Units.Add(new Unit()
                {
                    UnitName = "newUnit"
                });
                arrangeContext.SaveChanges();
            }
            using (var assertContext = new WHMSContext(options))
            {
                var sut     = new ProductService(assertContext);
                var unit    = assertContext.Units.First(u => u.UnitName == "newUnit");
                var product = assertContext.Products.First(u => u.Name == "Name");
                sut.ModifyUnit(product, unit);

                Assert.AreEqual("Name", product.Name);
                Assert.IsNotNull(product);
                Assert.IsInstanceOfType(product, typeof(Product));
                Assert.AreEqual("newUnit", product.Unit.UnitName);
            }
        }
Beispiel #6
0
 public void Should_Not_Throw_Exception_If_Null()
 {
     using (var assertContext = new WHMSContext(TestUtils.GetOptions(nameof(Should_Not_Throw_Exception_If_Null))))
     {
         var sut     = new ProductService(assertContext);
         var product = sut.FindByNameInclncludingDeleted("productName");
         Assert.IsNull(product);
     }
 }
Beispiel #7
0
 public void Throw_Exception_If_Product_Buy_Price_Is_Less_Than_Zero(string number)
 {
     using (var assertContext = new WHMSContext(TestUtils.GetOptions(nameof(Throw_Exception_If_Product_Buy_Price_Is_Less_Than_Zero))))
     {
         var sut             = new ProductService(assertContext);
         var ex              = Assert.ThrowsException <ArgumentException>(() => (sut.CreateProduct("ProductName", null, null, decimal.Parse(number), 0, null)));
         var expectedMessage = $"Price cannot be negative number";
         Assert.AreEqual(expectedMessage, ex.Message);
     }
 }
Beispiel #8
0
 public void Throw_Exception_If_Margin_Less_Than_Zero(double margin)
 {
     using (var assertContext = new WHMSContext(TestUtils.GetOptions(nameof(Throw_Exception_If_Margin_Less_Than_Zero))))
     {
         var sut             = new ProductService(assertContext);
         var ex              = Assert.ThrowsException <ArgumentException>(() => (sut.CreateProduct("ProductName", null, null, 0, margin, null)));
         var expectedMessage = $"The price margin cannot be negative number";
         Assert.AreEqual(expectedMessage, ex.Message);
     }
 }
Beispiel #9
0
 public void Properly_Set_Description_On_Product_Creation()
 {
     using (var assertContext = new WHMSContext(TestUtils.GetOptions(nameof(Properly_Set_Description_On_Product_Creation))))
     {
         var sut     = new ProductService(assertContext);
         var product = sut.CreateProduct("ProductName", null, null, 0, 0, "Goody two shoes Description");
         assertContext.SaveChanges();
         Assert.AreEqual("Goody two shoes Description", product.Description);
     }
 }
Beispiel #10
0
 public void Should_Throw_Exception_If_Null_ByID()
 {
     using (var assertContext = new WHMSContext(TestUtils.GetOptions(nameof(Should_Throw_Exception_If_Null_ByID))))
     {
         var    sut      = new ProductService(assertContext);
         var    ex       = Assert.ThrowsException <ArgumentException>(() => sut.GetProductById(1));
         string expected = "Product does not exist!";
         Assert.AreEqual(expected, ex.Message);
     }
 }
Beispiel #11
0
 public void Properly_Set_Margin_On_Product_Creation()
 {
     using (var assertContext = new WHMSContext(TestUtils.GetOptions(nameof(Properly_Set_Margin_On_Product_Creation))))
     {
         var sut     = new ProductService(assertContext);
         var product = sut.CreateProduct("ProductName", null, null, 0, 30, null);
         assertContext.SaveChanges();
         Assert.AreEqual(30, product.MarginInPercent);
     }
 }
Beispiel #12
0
 public void Should_Throw_Exception_If_Product_Not_Found_Null_SM()
 {
     using (var assertContext = new WHMSContext(TestUtils.GetOptions(nameof(Should_Throw_Exception_If_Product_Not_Found_Null_SM))))
     {
         var    sut      = new ProductService(assertContext);
         var    ex       = Assert.ThrowsException <ArgumentException>(() => sut.SetMargin(1, 5.0000212));
         string expected = "Product does not exist!";
         Assert.AreEqual(expected, ex.Message);
     }
 }
Beispiel #13
0
 public void Should_Throw_Exception_If_Null_Category()
 {
     using (var assertContext = new WHMSContext(TestUtils.GetOptions(nameof(Should_Throw_Exception_If_Null_Category))))
     {
         var    sut      = new ProductService(assertContext);
         var    ex       = Assert.ThrowsException <ArgumentException>(() => sut.ProductsByCategory(null));
         string expected = "Category does not exists";
         Assert.AreEqual(expected, ex.Message);
     }
 }
Beispiel #14
0
 public void Should_Throw_Exception_If_Null()
 {
     using (var assertContext = new WHMSContext(TestUtils.GetOptions(nameof(Should_Throw_Exception_If_Null))))
     {
         var    sut      = new ProductService(assertContext);
         var    ex       = Assert.ThrowsException <ArgumentException>(() => sut.FindByName("productName"));
         string expected = "Product `productName` doesn't exist!";
         Assert.AreEqual(expected, ex.Message);
     }
 }
Beispiel #15
0
 public void Should_Throw_Exception_If_Product_Is_Null()
 {
     using (var assertContext = new WHMSContext(TestUtils.GetOptions(nameof(Should_Throw_Exception_If_Product_Is_Null))))
     {
         var    sut      = new ProductService(assertContext);
         var    ex       = Assert.ThrowsException <ArgumentException>(() => sut.ModifyProductName("oldName", "newName"));
         string expected = "Product oldName does not exists";
         Assert.AreEqual(expected, ex.Message);
     }
 }
Beispiel #16
0
        public void Create_Product()
        {
            using (var assertContext = new WHMSContext(TestUtils.GetOptions(nameof(Create_Product))))
            {
                var sut     = new ProductService(assertContext);
                var product = sut.CreateProduct("ProductName", null, null, 0, 0, null);
                assertContext.SaveChanges();

                Assert.IsNotNull(product);
                Assert.AreEqual("ProductName", product.Name);
            }
        }
Beispiel #17
0
        public void ThrowException_WhenOrderIsDeleted()  //int orderId
        {
            OrderType type      = OrderType.Sell;
            DateTime  outPeriod = DateTime.ParseExact("30/01/2000", "dd/mm/yyyy", CultureInfo.InvariantCulture);
            DateTime  fromDate  = DateTime.ParseExact("01/01/2018", "dd/mm/yyyy", CultureInfo.InvariantCulture);
            DateTime  inPeriod  = DateTime.ParseExact("01/02/2019", "dd/mm/yyyy", CultureInfo.InvariantCulture);
            DateTime  toDate    = DateTime.ParseExact("01/03/2020", "dd/mm/yyyy", CultureInfo.InvariantCulture);
            Partner   partner   = new Partner {
                Name = "Partner"
            };
            Product product = new Product {
                Name = "Product"
            };

            var dbName  = ((nameof(GetOrdersByType_Should)) + (nameof(ThrowException_WhenOrderIsDeleted)));
            var options = TestUtils.GetOptions(dbName);

            using (var arrangeContext = new WHMSContext(options))
            {
                arrangeContext.Orders.Add(new Order {
                    Id = 1, Type = type, CreatedOn = inPeriod, Partner = partner, Products = new List <Product> {
                        product
                    }, IsDeleted = true
                });
                arrangeContext.Orders.Add(new Order {
                    Id = 2, Type = type, CreatedOn = inPeriod, Partner = partner, Products = new List <Product> {
                        product
                    }, IsDeleted = true
                });
                arrangeContext.Orders.Add(new Order {
                    Id = 3, Type = type, CreatedOn = outPeriod, Partner = partner, Products = new List <Product> {
                        product
                    }
                });
                arrangeContext.Orders.Add(new Order {
                    Id = 4, Type = OrderType.Buy, CreatedOn = inPeriod, Partner = partner, Products = new List <Product> {
                        product
                    }
                });
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new WHMSContext(options))
            {
                var sut = new OrderService(assertContext);
                var ex  = Assert.ThrowsException <ArgumentException>(() => sut.GetOrdersByType(OrderType.Sell, fromDate, toDate));
                Assert.AreEqual($"Order with Type: {type} from date {fromDate} to date {toDate} doesn't exist!", ex.Message);
            }
        }
Beispiel #18
0
        public void Succeed()  //(OrderType type, DateTime fromDate, DateTime toDate)
        {
            DateTime outPeriod = DateTime.ParseExact("30/01/2000", "dd/mm/yyyy", CultureInfo.InvariantCulture);
            DateTime fromDate  = DateTime.ParseExact("01/01/2018", "dd/mm/yyyy", CultureInfo.InvariantCulture);
            DateTime inPeriod  = DateTime.ParseExact("01/02/2019", "dd/mm/yyyy", CultureInfo.InvariantCulture);
            DateTime toDate    = DateTime.ParseExact("01/03/2020", "dd/mm/yyyy", CultureInfo.InvariantCulture);
            Partner  partner   = new Partner {
                Name = "Partner"
            };
            Product product = new Product {
                Name = "Product"
            };

            var dbName  = ((nameof(GetOrdersByType_Should)) + (nameof(Succeed)));
            var options = TestUtils.GetOptions(dbName);

            using (var arrangeContext = new WHMSContext(options))
            {
                arrangeContext.Orders.Add(new Order {
                    Id = 1, Type = OrderType.Sell, CreatedOn = inPeriod, Partner = partner, Products = new List <Product> {
                        product
                    }
                });
                arrangeContext.Orders.Add(new Order {
                    Id = 2, Type = OrderType.Sell, CreatedOn = inPeriod, Partner = partner, Products = new List <Product> {
                        product
                    }
                });
                arrangeContext.Orders.Add(new Order {
                    Id = 3, Type = OrderType.Sell, CreatedOn = outPeriod, Partner = partner, Products = new List <Product> {
                        product
                    }
                });
                arrangeContext.Orders.Add(new Order {
                    Id = 4, Type = OrderType.Buy, CreatedOn = inPeriod, Partner = partner, Products = new List <Product> {
                        product
                    }
                });
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new WHMSContext(options))
            {
                var sut             = new OrderService(assertContext);
                var getOrdersByType = sut.GetOrdersByType(OrderType.Sell, fromDate, toDate);
                Assert.AreEqual(2, getOrdersByType.Count);
            }
        }
Beispiel #19
0
        public void Should_Return_Collection_Of_Products_In_Category()
        {
            var dbName = nameof(Should_Return_Collection_Of_Products_In_Category);

            var options = TestUtils.GetOptions(dbName);

            using (var arrangeContext = new WHMSContext(options))
            {
                arrangeContext.Categories.Add(new Category()
                {
                    Name = "categoryName"
                });
                arrangeContext.SaveChanges();
                var category = arrangeContext.Categories.First(c => c.Name == "categoryName");
                arrangeContext.Products.Add(new Product()
                {
                    Name = "product1", Category = category
                });
                arrangeContext.Products.Add(new Product()
                {
                    Name = "product2", Category = null
                });
                arrangeContext.Products.Add(new Product()
                {
                    Name = "product3", Category = category
                });
                arrangeContext.Products.Add(new Product()
                {
                    Name = "product4", Category = category
                });

                arrangeContext.SaveChanges();
            }
            using (var assertContext = new WHMSContext(options))
            {
                var sut      = new ProductService(assertContext);
                var category = assertContext.Categories.First(c => c.Name == "categoryName");
                var products = sut.ProductsByCategory(category);
                Assert.AreEqual(3, products.Count);
                Assert.IsNotNull(products);
                Assert.IsTrue(products.Any(n => n.Name == "product1"));
            }
        }
Beispiel #20
0
        public void Succeed()
        {
            Partner partner = new Partner {
                Name = "Partner"
            };
            Product product = new Product {
                Name = "Product"
            };
            Partner partnerOther = new Partner {
                Name = "Other Partner"
            };

            var dbName  = ((nameof(GetOrdersByPartner_Should)) + (nameof(Succeed)));
            var options = TestUtils.GetOptions(dbName);

            using (var arrangeContext = new WHMSContext(options))
            {
                arrangeContext.Orders.Add(new Order {
                    Partner = partner, Products = new List <Product> {
                        product
                    }
                });
                arrangeContext.Orders.Add(new Order {
                    Partner = partner, Products = new List <Product> {
                        product
                    }
                });
                arrangeContext.Orders.Add(new Order {
                    Partner = partnerOther, Products = new List <Product> {
                        product
                    }
                });

                arrangeContext.SaveChanges();
            }

            using (var assertContext = new WHMSContext(options))
            {
                var sut = new OrderService(assertContext);
                var getOrdersByPartner = sut.GetOrdersByPartner(partner);
                Assert.AreEqual(2, getOrdersByPartner.Count);
            }
        }
Beispiel #21
0
        public void ThrowException_WhenOrderIsDeleted()  //int orderId
        {
            var   dbName  = ((nameof(GetOrderById_Should)) + (nameof(ThrowException_WhenOrderIsDeleted)));
            var   options = TestUtils.GetOptions(dbName);
            Order order   = new Order {
                Id = 1, IsDeleted = true
            };

            using (var arrangeContext = new WHMSContext(options))
            {
                arrangeContext.Orders.Add(order);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new WHMSContext(options))
            {
                var sut = new OrderService(assertContext);
                var ex  = Assert.ThrowsException <ArgumentException>(() => sut.GetOrderById(1));
                Assert.AreEqual($"Order with ID: {1} doesn't exist!", ex.Message);
            }
        }
Beispiel #22
0
        public void Comment_ShouldSucceed()  //int orderId, string comment
        {
            string comment = "some comments";

            var dbName  = ((nameof(Edit)) + (nameof(Comment_ShouldSucceed)));
            var options = TestUtils.GetOptions(dbName);

            using (var arrangeContext = new WHMSContext(options))
            {
                arrangeContext.Orders.Add(new Order {
                    Id = 1
                });
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new WHMSContext(options))
            {
                var sut         = new OrderService(assertContext);
                var editComment = sut.EditComment(1, comment);
                Assert.AreEqual(comment, editComment.Comment);
            }
        }
Beispiel #23
0
        public void Type_ShouldSucceed()  //int orderId, OrderType type
        {
            OrderType type = OrderType.Sell;

            var dbName  = ((nameof(Edit)) + (nameof(Type_ShouldSucceed)));
            var options = TestUtils.GetOptions(dbName);

            using (var arrangeContext = new WHMSContext(options))
            {
                arrangeContext.Orders.Add(new Order {
                    Id = 1, Type = OrderType.Buy
                });
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new WHMSContext(options))
            {
                var sut      = new OrderService(assertContext);
                var editType = sut.EditType(1, type);
                Assert.AreEqual(type, editType.Type);
            }
        }
Beispiel #24
0
        public void Should_Throw_Exception_If_Product_Deleted()
        {
            var dbName = nameof(Should_Throw_Exception_If_Product_Deleted);

            var options = TestUtils.GetOptions(dbName);

            using (var arrangeContext = new WHMSContext(options))
            {
                arrangeContext.Products.Add(new Product()
                {
                    Name = "productName", IsDeleted = true
                });
                arrangeContext.SaveChanges();
            }
            using (var assertContext = new WHMSContext(options))
            {
                var    sut      = new ProductService(assertContext);
                var    ex       = Assert.ThrowsException <ArgumentException>(() => sut.FindByName("productName"));
                string expected = "Product `productName` doesn't exist!";
                Assert.AreEqual(expected, ex.Message);
            }
        }
Beispiel #25
0
        public void Throw_Exception_If_Product_Exists()
        {
            var dbName = nameof(Throw_Exception_If_Product_Exists);

            var options = TestUtils.GetOptions(dbName);

            using (var arrangeContext = new WHMSContext(options))
            {
                arrangeContext.Products.Add(new Product()
                {
                    Name = "ProductName"
                });
                arrangeContext.SaveChanges();
            }
            using (var assertContext = new WHMSContext(options))
            {
                var sut             = new ProductService(assertContext);
                var ex              = Assert.ThrowsException <ArgumentException>(() => (sut.CreateProduct("ProductName", null, null, 0, 0, null)));
                var expectedMessage = $"Product ProductName already exists";
                Assert.AreEqual(expectedMessage, ex.Message);
            }
        }
Beispiel #26
0
        public void Succeed()  //int orderId
        {
            Order order = new Order {
                Id = 1
            };

            var dbName  = ((nameof(GetOrderById_Should)) + (nameof(Succeed)));
            var options = TestUtils.GetOptions(dbName);

            using (var arrangeContext = new WHMSContext(options))
            {
                arrangeContext.Orders.Add(order);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new WHMSContext(options))
            {
                var sut      = new OrderService(assertContext);
                var getOrder = sut.GetOrderById(1);
                Assert.AreEqual(order.Id, getOrder.Id);
            }
        }
Beispiel #27
0
        public void Should_Throw_Exception_If_Product_Is_Deleted_SM()
        {
            var dbName = nameof(Should_Throw_Exception_If_Product_Is_Deleted_SM);

            var options = TestUtils.GetOptions(dbName);

            using (var arrangeContext = new WHMSContext(options))
            {
                arrangeContext.Products.Add(new Product()
                {
                    IsDeleted = true
                });
                arrangeContext.SaveChanges();
            }
            using (var assertContext = new WHMSContext(options))
            {
                var    sut      = new ProductService(assertContext);
                var    ex       = Assert.ThrowsException <ArgumentException>(() => sut.SetBuyPrice(1, 43.432m));
                string expected = "Product does not exist!";
                Assert.AreEqual(expected, ex.Message);
            }
        }
Beispiel #28
0
        public void Succeed()  //(OrderType type, Partner partner, Product product, int qty, string comment = null)
        {
            //Arrange
            OrderType type    = OrderType.Sell;
            Partner   partner = new Partner {
                Name = "Partner1"
            };
            Product product = new Product {
                Name = "Product1"
            };

            //Act&Assert
            using (var assertContext = new WHMSContext(TestUtils.GetOptions(nameof(Add_Should) + nameof(Succeed))))
            {
                var sut      = new OrderService(assertContext);
                var addOrder = sut.Add(type, partner, product, 5);

                Assert.AreEqual(type, addOrder.Type);
                Assert.AreEqual(partner, addOrder.Partner);
                Assert.AreEqual(product, addOrder.Products.FirstOrDefault());
            }
        }
Beispiel #29
0
        public void Throw_Exception_If_Product_Margin_Is_Less_Than_Zero_SM(double number)
        {
            var dbName = nameof(Throw_Exception_If_Product_Margin_Is_Less_Than_Zero_SM);

            var options = TestUtils.GetOptions(dbName);

            using (var arrangeContext = new WHMSContext(options))
            {
                arrangeContext.Products.Add(new Product()
                {
                    Name = "Name", MarginInPercent = 0
                });
                arrangeContext.SaveChanges();
            }
            using (var assertContext = new WHMSContext(options))
            {
                var sut             = new ProductService(assertContext);
                var ex              = Assert.ThrowsException <ArgumentException>(() => (sut.SetMargin(1, number)));
                var expectedMessage = $"The price margin cannot be negative number";
                Assert.AreEqual(expectedMessage, ex.Message);
            }
        }
Beispiel #30
0
        public void Throw_Exception_If_Product_Buy_Price_Is_Less_Than_Zero_SP(string number)
        {
            var dbName = nameof(Throw_Exception_If_Product_Buy_Price_Is_Less_Than_Zero_SP);

            var options = TestUtils.GetOptions(dbName);

            using (var arrangeContext = new WHMSContext(options))
            {
                arrangeContext.Products.Add(new Product()
                {
                    Name = "Name", BuyPrice = 0
                });
                arrangeContext.SaveChanges();
            }
            using (var assertContext = new WHMSContext(options))
            {
                var sut             = new ProductService(assertContext);
                var ex              = Assert.ThrowsException <ArgumentException>(() => (sut.SetBuyPrice(1, decimal.Parse(number))));
                var expectedMessage = $"Price cannot be negative number";
                Assert.AreEqual(expectedMessage, ex.Message);
            }
        }