public void Can_Send_Email() {

            // Arrange - create and populate a cart
            Cart cart = new Cart();
            cart.AddItem(new Product { ProductID = 1, Name = "Banana", Price = 10M }, 2);
            cart.AddItem(new Product { ProductID = 2, Name = "Apple", Price = 5M }, 2);

            // Arrange - create and populate some shipping details
            ShippingDetails shipDetails = new ShippingDetails {
                Name = "Joe Smith",
                Line1 = "Apartment 4a",
                Line2 = "123 West Street",
                City = "Northtown",
                State = "GA",
                Country = "USA",
                Zip = "12345"
            };

            // Arrange - create the test-specific email settings
            EmailSettings settings = new EmailSettings {
            
                // put test specific settings here
                WriteAsFile = true
            };

            // Arrange - create the EmailOrderProcessor class
            EmailOrderProcessor proc = new EmailOrderProcessor(settings);

            // Act - process the order
            proc.ProcessOrder(cart, shipDetails);

            // NOTE - there is assert in this test

        }
Пример #2
0
 public void AddItem_AddExistingItem_QtyIncreased()
 {
     Product p1 = new Product { ProductName = "P1", ProductID = 1 };
     Cart cart = new Cart();
     cart.AddItem(p1, 2);
     cart.AddItem(p1, 1);
     CartLine[] lineCollection = cart.Lines.ToArray();
     Assert.IsTrue(lineCollection.Length == 1);
     Assert.AreEqual(p1.ProductName, lineCollection[0].Product.ProductName);
     Assert.AreEqual(3, lineCollection[0].Quantity);
 }
Пример #3
0
        public void Calculate_Card_Total()
        {
            Product p1 = new Product { ProductID = 1, Name = "P1",Price=100 };
            Product p2 = new Product { ProductID = 2, Name = "P2",Price=150 };

            Cart target = new Cart();
            target.AddItem(p1, 1);
            target.AddItem(p2, 1);
            decimal res= target.ComputeTotalValue();

            Assert.AreEqual(res, 250);
        }
Пример #4
0
        public void Calculate_Car_Total()
        {
            Product p1 = new Product { ProductID = 1, Name = "P1", Price=10 };
            Product p2 = new Product { ProductID = 2, Name = "P2", Price=5};

            Cart target = new Cart();

            target.AddItem(p1, 1);
            target.AddItem(p2, 3);

            Assert.AreEqual(target.ComputeTotalValue(), 25);
        }
Пример #5
0
 public void AddItem_NewItem_Added()
 {
     Product p1 = new Product { ProductName = "P1", ProductID = 1 };
     Product p2 = new Product { ProductName = "P2", ProductID = 2 };
     Cart cart = new Cart();
     cart.AddItem(p1, 2);
     cart.AddItem(p2, 1);
     CartLine[] lineCollection = cart.Lines.ToArray();
     Assert.IsTrue(lineCollection.Length == 2);
     Assert.AreEqual(p1.ProductName, lineCollection[0].Product.ProductName);
     Assert.AreEqual(p2.ProductName, lineCollection[1].Product.ProductName);
 }
Пример #6
0
        public void Delete_All_Lines_From_Cart()
        {
            Cart target = new Cart(); // TODO: Initialize to an appropriate value

            target.AddItem(products[0], 5);
            target.AddItem(products[1], 2);
            target.AddItem(products[2], 3);

            target.Clear();

            Assert.IsTrue( target.Lines.Count() == 0);
        }
Пример #7
0
        public void CalculateCartTotal()
        {
            Product p1 = new Product() { Id = 1, Name = "P1", Price = 100M};
            Product p2 = new Product() { Id = 2, Name = "P2", Price = 50M};
            Cart target = new Cart();

            target.AddItem(p1, 1);
            target.AddItem(p2, 1);
            target.AddItem(p1, 3);
            decimal result = target.ComputeTotalValue();

            Assert.AreEqual(result, 450M);
        }
Пример #8
0
        public void Add_New_Lines_To_Cart()
        {
            Product p1 = new Product { ProductID = 1, Name = "P1" };
            Product p2 = new Product { ProductID = 2, Name = "P2" };

            Cart target = new Cart();
            target.AddItem(p1,1);
            target.AddItem(p2, 1);
            CartLine[] res = target.Lines.ToArray();

            Assert.AreEqual(res.Length,2);
            Assert.AreEqual(res[0].Product, p1);
            Assert.AreEqual(res[1].Product, p2);
        }
Пример #9
0
        public void Calculate_Cart_Total()
        {
            var p1 = new Product { ProductID = 1, Name = "P1", Price = 100M };
            var p2 = new Product { ProductID = 2, Name = "P2", Price = 50M };

            var target = new Cart();

            target.AddItem(p1, 1);
            target.AddItem(p2, 1);
            target.AddItem(p1, 3);
            decimal result = target.ComputeTotalValue();

            Assert.AreEqual(result, 450M);
        }
Пример #10
0
        public void CanAddNewLines()
        {
            Product p1 = new Product() { ProductID = 1, Name = "P1" };
            Product p2 = new Product() { ProductID = 2, Name = "P2" };

            Cart cart = new Cart();

            cart.AddItem(p1, 1);
            cart.AddItem(p2, 1);

            Assert.AreEqual(2, cart.Lines.Count());
            Assert.AreEqual(1, cart.Lines.Single(x => x.Product.ProductID == p1.ProductID).Quantity);
            Assert.AreEqual(1, cart.Lines.Single(x => x.Product.ProductID == p2.ProductID).Quantity);
        }
Пример #11
0
 public void Calculate_Cart_Total()
 {
     // Arrange - create some test products
     Product p1 = new Product { ProductID = 1, Name = "P1", Price = 100M };
     Product p2 = new Product { ProductID = 2, Name = "P2", Price = 50M };
     // Arrange - create a new cart
     Cart target = new Cart();
     // Act
     target.AddItem(p1, 1);
     target.AddItem(p2, 1);
     target.AddItem(p1, 3);
     decimal result = target.ComputeTotalValue(); // Assert
     Assert.AreEqual(result, 450M);
 }
Пример #12
0
        public void Can_Add_New_Lines()
        {
            var p1 = new Product {ProductId = 1, Name = "P1"};
            var p2 = new Product {ProductId = 2, Name = "P2"};

            var target = new Cart();

            target.AddItem(p1,1);
            target.AddItem(p2,2);
            var results = target.Lines.ToArray();
            Assert.AreEqual(results.Length, 2);
            Assert.AreEqual(results[0].Product, p1);
            Assert.AreEqual(results[1].Product, p2);
        }
Пример #13
0
        public void Add_New_Cart_Lines()
        {
            Product p1 = new Product { ProductID = 1, Name = "Apple" };
            Product p2 = new Product { ProductID = 2, Name = "Orange" };

            Cart target = new Cart();

            target.AddItem(p1, 1);
            target.AddItem(p2, 1);
            CartLine[] results = target.Lines.ToArray();

            Assert.AreEqual(results[0].Product, p1);
            Assert.AreEqual(results[1].Product, p2);
        }
Пример #14
0
        public void Can_Clear_Contents()
        {
            Product p1 = new Product { ProductID = 1, Name = "P1", Price = 100M };
            Product p2 = new Product { ProductID = 2, Name = "P2", Price = 50M };

            Cart target = new Cart();

            target.AddItem(p1, 1);
            target.AddItem(p2, 1);

            target.Clear();

            Assert.AreEqual(target.Lines.Count(), 0);
        }
Пример #15
0
        public void CanAddNewLines()
        {
            Product p1 = new Product() { Id = 1, Name = "P1" };
            Product p2 = new Product() { Id = 2, Name = "P2" };
            Cart target = new Cart();

            target.AddItem(p1, 1);
            target.AddItem(p2, 1);
            CartLine[] results = target.Lines.ToArray();

            Assert.AreEqual(results.Length, 2);
            Assert.AreEqual(results[0].Product, p1);
            Assert.AreEqual(results[1].Product, p2);
        }
Пример #16
0
        public void Can_Add_New_Lines()
        {
            Product p1 = new Product {ProductId = 1, Name = "P1"};
            Product p2 = new Product {ProductId = 2, Name = "P2"};

            Cart target = new Cart();
            target.AddItem(p1, 1);
            target.AddItem(p2, 1);
            CartLine[] results = target.Lines.ToArray();

            Assert.AreEqual(2, results.Length);
            Assert.AreEqual(p1, results[0].Product);
            Assert.AreEqual(p2, results[1].Product);
        }
Пример #17
0
        public void Calculate_Cart_Total()
        {
            Product p1 = new Product() { ProductID = 1, Name = "P1", Price = 25M };
            Product p2 = new Product() { ProductID = 2, Name = "P2", Price = 20M };
            Product p3 = new Product() { ProductID = 3, Name = "P3", Price = 5M };
            Cart cart = new Cart();
            cart.AddItem(p1, 2);
            cart.AddItem(p2, 2);
            cart.AddItem(p3, 1);
            cart.AddItem(p1, 6);

            decimal result = cart.ComputeTotalValue();

            Assert.AreEqual(result, 245);
        }
Пример #18
0
        public void CanAddQuantityForExistingLines()
        {
            Product p1 = new Product() { Id = 1, Name = "P1" };
            Product p2 = new Product() { Id = 2, Name = "P2" };
            Cart target = new Cart();

            target.AddItem(p1, 1);
            target.AddItem(p2, 1);
            target.AddItem(p1, 10);
            CartLine[] results = target.Lines.ToArray();

            Assert.AreEqual(results.Length, 2);
            Assert.AreEqual(results[0].Quantity, 11);
            Assert.AreEqual(results[1].Quantity, 1);
        }
Пример #19
0
 public void Can_Add_New_Lines() {
     // Arrange - create some test products
     Product p1 = new Product { ProductID = 1, Name = "P1" };
     Product p2 = new Product { ProductID = 2, Name = "P2" };
     // Arrange - create a new cart
     Cart target = new Cart();
     // Act
     target.AddItem(p1, 1);
     target.AddItem(p2, 1);
     CartLine[] results = target.Lines.ToArray();
     // Assert
     Assert.AreEqual(results.Length, 2);
     Assert.AreEqual(results[0].Product, p1);
     Assert.AreEqual(results[1].Product, p2);
 }
Пример #20
0
        public void Add_New_Quantity()
        {
            Product p1 = new Product { ProductID = 1, Name = "Orrange" };
            Product p2 = new Product { ProductID = 1, Name = "Apple" };
            Product p3 = new Product { ProductID = 2, Name = "Orange" };

            Cart target = new Cart();

            target.AddItem(p1, 1);
            target.AddItem(p2, 10);
            CartLine[] results = target.Lines.OrderBy(c => c.Product.ProductID).ToArray();

            Assert.AreEqual(results[0].Quantity, 1);
            Assert.AreEqual(results[1].Quantity, 10);
        }
Пример #21
0
        public void Calculate_Total_Cost()
        {
            Product p1 = new Product { ProductID = 1, Name = "p1", Price = 500M };
            Product p2 = new Product { ProductID = 2, Name = "p2", Price = 150M };

            Cart target = new Cart();

            target.AddItem(p1, 1);
            target.AddItem(p2, 2);
            target.AddItem(p1, 4);

            decimal result = target.ComputeTotalValue();

            Assert.AreEqual(result, 2800M);
        }
Пример #22
0
        public void Can_Add_Quantity_For_Existing_Lines()
        {
            var p1 = new Product { ProductId = 1, Name = "P1" };
            var p2 = new Product { ProductId = 2, Name = "P2" };

            var target = new Cart();

            target.AddItem(p1, 1);
            target.AddItem(p2, 2);
            target.AddItem(p1, 10);
            var results = target.Lines.ToArray();
            Assert.AreEqual(results.Length, 2);
            Assert.AreEqual(results[0].Quantity, 11);
            Assert.AreEqual(results[1].Quantity, 2);
        }
Пример #23
0
        public void Compute_TotalValue_Of_Cart()
        {
            //Arrange
            Cart target = new Cart(); // TODO: Initialize to an appropriate value

            target.AddItem(products[0], 5);
            target.AddItem(products[1], 2);
            target.AddItem(products[2], 3);

            //Act
            decimal total = target.ComputeTotalValue();

            //Assert
            Assert.AreEqual(total, 139M);
        }
Пример #24
0
        public void Can_Add_Quantity_For_Existing_Lines()
        {
            Product p1 = new Product { ProductId = 1, Name = "P1" };
            Product p2 = new Product { ProductId = 2, Name = "P2" };

            Cart target = new Cart();
            target.AddItem(p1, 1);
            target.AddItem(p2, 1);
            target.AddItem(p1, 10);
            CartLine[] results = target.Lines.OrderBy(c => c.Product.ProductId).ToArray();

            Assert.AreEqual(2, results.Length);
            Assert.AreEqual(11, results[0].Quantity);
            Assert.AreEqual(1, results[1].Quantity);
        }
Пример #25
0
 public void Can_Clear_Contents()
 {
     // Arrange - create some test products
     Product p1 = new Product { ProductID = 1, Name = "P1", Price = 100M };
     Product p2 = new Product { ProductID = 2, Name = "P2", Price = 50M };
     // Arrange - create a new cart
     Cart target = new Cart();
     // Arrange - add some items
     target.AddItem(p1, 1);
     target.AddItem(p2, 1);
     // Act - reset the cart
     target.Clear();
     // Assert
     Assert.AreEqual(target.Lines.Count(), 0);
 }
Пример #26
0
 public void Can_Add_Quantity_For_Existing_Lines() {
     // Arrange - create some test products
     Product p1 = new Product { ProductID = 1, Name = "P1" };
     Product p2 = new Product { ProductID = 2, Name = "P2" };
     // Arrange - create a new cart
     Cart target = new Cart();
     // Act
     target.AddItem(p1, 1);
     target.AddItem(p2, 1);
     target.AddItem(p1, 10);
     CartLine[] results = target.Lines.OrderBy(c => c.Product.ProductID).ToArray();
     // Assert
     Assert.AreEqual(results.Length, 2);
     Assert.AreEqual(results[0].Quantity, 11);
     Assert.AreEqual(results[1].Quantity, 1);
 }
Пример #27
0
        public void Can_Add_New_Lines()
        {
            Product p1 = new Product() {ProductID = 1, Name = "P1"};
            Product p2 = new Product() {ProductID = 2, Name = "P2"};

            Cart cart = new Cart();

            cart.AddItem(p1,1);
            cart.AddItem(p2,1);

            CartLine[] lines = cart.Lines.ToArray();

            Assert.AreEqual(lines.Length,2);
            Assert.AreEqual(lines[0].Product, p1);
            Assert.AreEqual(lines[1].Product, p2);
        }
Пример #28
0
        public void Calculate_Cart_Total()
        {
            //arrange
            Product p1 = new Product { ProductID = 1, Name = "P1", Price = 100m };
            Product p2 = new Product { ProductID = 2, Name = "P2", Price = 50m };
            Cart target = new Cart();

            //act
            target.AddItem(p1, 1);
            target.AddItem(p2, 1);
            target.AddItem(p1, 3);
            decimal result = target.ComputeTotalValue();

            //assert
            Assert.AreEqual(result, 450m);
        }
Пример #29
0
        public void Calculate_Cart_Total()
        {
            var p1 = new Product { ProductId = 1, Name = "P1", Price = 1m};
            var p2 = new Product { ProductId = 2, Name = "P2" , Price = 2m};
            var p3 = new Product { ProductId = 3, Name = "P3" , Price = 3m};

            var target = new Cart();

            target.AddItem(p1, 1);
            target.AddItem(p2, 2);
            target.AddItem(p3, 10);
            target.AddItem(p2, 3);
            var results = target.Lines.ToArray();
            Assert.AreEqual(results.Length, 3);
            Assert.AreEqual(target.ComputeTotalValue(), 41m);
        }
Пример #30
0
        public void Cannot_Checkout_Invalid_ShippingDetails()
        {
            // Arrange - create a mock order processor
            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();

            // Arrange - create a cart with an item
            Cart cart = new Cart();
            cart.AddItem(new Product(), 1);

            // Arrange - create an instance of the controller
            CartController target = new CartController(null, mock.Object);

            // Arrange - add an error to the model
            target.ModelState.AddModelError("error", "error");

            // Act - try to checkout
            ViewResult result = target.Checkout(cart, new ShippingDetails());

            // Assert - check that the order hasn't been passed on to the processor
            mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()),
            Times.Never());

            // Assert - check that the method is returning the default view
            Assert.AreEqual("", result.ViewName);

            // Assert - check that we are passing an invalid model to the view
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }