示例#1
0
        public void GivenEmptyCartAndProduct_WhenUserAddsProductItemsToCart_ThenCartShowsCorrectTotalPrice()
        {
            // Arrange
            var product = new Product("Dove Soap", 39.99);
            var cart    = new ShoppingCart.ShoppingCart();

            // Act
            var productItem = new ProductItem(product, 5);

            cart.AddProductItem(productItem);

            // Assert
            Assert.That(cart.TotalPrice, Is.EqualTo(199.95));
        }
示例#2
0
        public void 第一集買了一本_共買一本_價格為100()
        {
            // Arrange
            var target = new ShoppingCart();
            var books = new List<book>()
            {
                new book() { Id = 1,Name="HarryPorter1",Price=100},
            };

            // Act
            var actual = target.CalculateAmount(books);

            // Assert
            var expectedResult = 100;
            Assert.AreEqual(expectedResult, actual);
        }
        public void CalAmountTest_一二集各買了一本_第三集買了兩本_價格應為370()
        {
            //arrange
            ShoppingCart target = new ShoppingCart();
            target.Add(new ProductModel() { ID = 1, Price = 100m });
            target.Add(new ProductModel() { ID = 2, Price = 100m });
            target.Add(new ProductModel() { ID = 3, Price = 100m });
            target.Add(new ProductModel() { ID = 3, Price = 100m });
            decimal expected = 370;

            //act
            decimal actual;
            actual = target.CalAmount();

            //assert
            Assert.AreEqual(expected, actual);
        }
        public void TestMethod1()
        {
            ShoppingCartClass mainClass = new ShoppingCartClass();

            Category food        = new Category("food");
            Category electronics = new Category("electronics");

            Product apple   = new Product("Apple", 10.25, food);
            Product almonds = new Product("Almonds", 15.40, food);
            Product macbook = new Product("MacBook", 4990.50, electronics);
            Product iPad    = new Product("iPad", 2999.90, electronics);

            ShoppingCartItem item1 = new ShoppingCartItem(apple, 2);
            ShoppingCartItem item2 = new ShoppingCartItem(almonds, 3);
            ShoppingCartItem item3 = new ShoppingCartItem(macbook, 1);
            ShoppingCartItem item4 = new ShoppingCartItem(iPad, 1);

            ShoppingCart.ShoppingCart cart = new ShoppingCart.ShoppingCart();

            cart.Items = new List <ShoppingCartItem>();
            cart.Items.Add(item1);
            cart.Items.Add(item2);
            cart.Items.Add(item3);
            cart.Items.Add(item4);

            Campaign discount1 = new Campaign(food, 20.00, 3, DiscountType.Rate);
            Campaign discount2 = new Campaign(food, 50.00, 5, DiscountType.Rate);
            Campaign discount3 = new Campaign(electronics, 50.00, 2, DiscountType.Amount);

            Coupon coupon1 = new Coupon(100.00, 10, DiscountType.Rate);

            List <Campaign> discounts = new List <Campaign>();

            discounts.Add(discount1);
            discounts.Add(discount2);
            discounts.Add(discount3);

            List <Coupon> coupons = new List <Coupon>();

            coupons.Add(coupon1);

            mainClass.Shopping(ref cart, ref discounts, ref coupons);
        }
示例#5
0
        public void 一二三四集各買一本_共買四本_價格為320()
        {
            // Arrange
            var target = new ShoppingCart();
            var books = new List<book>()
            {
                new book() { Id = 1,Name="HarryPorter1",Price=100},
                new book() { Id = 2,Name="HarryPorter2",Price=100},
                new book() { Id = 3,Name="HarryPorter3",Price=100},
                new book() { Id = 4,Name="HarryPorter4",Price=100},
            };

            // Act
            var actual = target.CalculateAmount(books);

            // Assert
            var expectedResult = 320;
            Assert.AreEqual(expectedResult, actual);
        }
示例#6
0
        public void GivenEmptyCartAndProduct_WhenUserAddsProductItemsToCart_ThenCartShowsCorrectProductItem()
        {
            // Arrange
            const string expectedProductItemName      = "Dove Soap";
            const double expectedProductItemUnitPrice = 39.99;
            const uint   expectedProductItemQuantity  = 5;

            var product = new Product(expectedProductItemName, expectedProductItemUnitPrice);
            var cart    = new ShoppingCart.ShoppingCart();

            // Act
            var productItem = new ProductItem(product, expectedProductItemQuantity);

            cart.AddProductItem(productItem);
            var productItemFromCart = cart.ProductItems.First();

            // Assert
            Assert.That(productItemFromCart.Name, Is.EqualTo(expectedProductItemName));
            Assert.That(productItemFromCart.UnitPrice, Is.EqualTo(expectedProductItemUnitPrice));
            Assert.That(productItemFromCart.Quantity, Is.EqualTo(expectedProductItemQuantity));
        }
        public void CalAmountTest_第一集買了一本_其他都沒買_價格應為100()
        {
            //arrange
            ShoppingCart target = new ShoppingCart();
            target.Add(new ProductModel() { ID = 1, Price = 100m });
            decimal expected = 100m;

            //act
            decimal actual;
            actual = target.CalAmount();

            //assert
            Assert.AreEqual(expected, actual);
        }