public void TestShoppingCart_一二三四五集各買了一本_價格應為375元()
        {
            //Scenario: 一次買了整套,一二三四五集各買了一本,價格應為100*5*0.75=375
            //    Given 第一集買了 1 本
            //    And 第二集買了 1 本
            //    And 第三集買了 1 本
            //    And 第四集買了 1 本
            //    And 第五集買了 1 本
            //    When 結帳
            //    Then 價格應為 375 元

            //arrange
            var target = new ShoppingCart();
            target.AddBooks(new Book { Name = "哈利波特第一集" });
            target.AddBooks(new Book { Name = "哈利波特第二集" });
            target.AddBooks(new Book { Name = "哈利波特第三集" });
            target.AddBooks(new Book { Name = "哈利波特第四集" });
            target.AddBooks(new Book { Name = "哈利波特第五集" });

            var expected = 375;

            //act
            target.Checkout();

            //assert
            Assert.AreEqual(expected, target.TotalAmount);
        }
Exemplo n.º 2
0
        public void Test_Buy_Book1x1()
        {
            var shoppingCart = new ShoppingCart();

            shoppingCart.Items.Add(new ShoppingItem() { BookType = 1, Num = 1, UnitPrice = 100 });

            shoppingCart.CalTotalPrice();
            Assert.AreEqual(shoppingCart.TotalPrice, 100);
        }
Exemplo n.º 3
0
        public void TEST_Buy_episode_1_And_Buy_episode_2_Should_Be_190()
        {
            //Arrange
            ShoppingCart target = new ShoppingCart();
            target.PickUp(new BOOK { Name = "Holly Potter 1", Cost = 100 });
            target.PickUp(new BOOK { Name = "Holly Potter 2", Cost = 100 });

            //Act
            var actual = target.CalculateTotalAmount();

            //Assert
            var expected = 190;
            Assert.AreEqual(expected, actual);
        }
        public void GetTotalPriceTest_第一集買了一本_其他都沒買_價格應為100元()
        {
            // Arrange
            var books = new List<Book>()
            {
                new Book { Name="Harry Potter", Series = 1, SellPrice = 100}
            };
            var expected = 100;
            var target = new ShoppingCart(books);

            // Act
            var actual = target.GetTotalPrice();

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void Test_buy_2_diff_book_return_amount_190()
        {
            var orders = new List<Order>
            {
                new Order {Id = 1, Quantity = 1,Price = 100},
                new Order {Id = 2, Quantity = 1,Price = 100},
                new Order {Id = 3, Quantity = 0,Price = 100},
                new Order {Id = 4, Quantity = 0,Price = 100},
                new Order {Id = 5, Quantity = 0,Price = 100},
            };

            var target = new ShoppingCart();

            var expected = 190d;

            var actual = target.GetAmount(orders);

            Assert.AreEqual(expected, actual);
        }
        public void GetTotalPriceTest_一二三四集各買了一本_價格應為320()
        {
            // Arrange
            var books = new List<Book>()
            {
                new Book { Name="Harry Potter", Series = 1, SellPrice = 100},
                new Book { Name="Harry Potter", Series = 2, SellPrice = 100},
                new Book { Name="Harry Potter", Series = 3, SellPrice = 100},
                new Book { Name="Harry Potter", Series = 4, SellPrice = 100}
            };
            var expected = 320;
            var target = new ShoppingCart(books);

            // Act
            var actual = target.GetTotalPrice();

            // Assert
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 7
0
        public void GetPrice_一二三集各買了一本_價格應為100_乘_3_乘_0_點_9_等於_270()
        {
            //arrange
            var books = new List<Book>
            {
                new Book{ Name = "第一集", Price = 100 },
                new Book{ Name = "第二集", Price = 100 },
                new Book{ Name = "第三集", Price = 100 }
            };

            var target = new ShoppingCart();
            target.SetBooks(books);

            var expected = 270;

            //act
            var actual = target.GetPrice();

            //assert

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 8
0
        public void Test_Buy_Book1x1_Book2x1_Book3x1_Book4x1_Book5x1()
        {
            var shoppingCart = new ShoppingCart();

            shoppingCart.Items.Add(new ShoppingItem() { BookType = 1, Num = 1, UnitPrice = 100 });
            shoppingCart.Items.Add(new ShoppingItem() { BookType = 2, Num = 1, UnitPrice = 100 });
            shoppingCart.Items.Add(new ShoppingItem() { BookType = 3, Num = 1, UnitPrice = 100 });
            shoppingCart.Items.Add(new ShoppingItem() { BookType = 4, Num = 1, UnitPrice = 100 });
            shoppingCart.Items.Add(new ShoppingItem() { BookType = 5, Num = 1, UnitPrice = 100 });

            shoppingCart.CalTotalPrice();
            Assert.AreEqual(shoppingCart.TotalPrice, 375);
        }
        public void TestShoppingCart_第一集買一本_第二集也買一本_價格應為190元()
        {
            //Scenario: 第一集買了一本,第二集也買了一本,價格應為100*2*0.95=190
            //    Given 第一集買了 1 本
            //    And 第二集買了 1 本
            //    And 第三集買了 0 本
            //    And 第四集買了 0 本
            //    And 第五集買了 0 本
            //    When 結帳
            //    Then 價格應為 190 元

            //arrange
            var target = new ShoppingCart();
            target.AddBooks(new Book { Name = "哈利波特第一集" });
            target.AddBooks(new Book { Name = "哈利波特第二集" });

            var expected = 190;

            //act
            target.Checkout();

            //assert
            Assert.AreEqual(expected, target.TotalAmount);
        }
        public void TestShoppingCart_一二集各買一本_第三集買了兩本_價格應為370元()
        {
            //Scenario: 一二集各買了一本,第三集買了兩本,價格應為100*3*0.9 + 100 = 370
            //    Given 第一集買了 1 本
            //    And 第二集買了 1 本
            //    And 第三集買了 2 本
            //    And 第四集買了 0 本
            //    And 第五集買了 0 本
            //    When 結帳
            //    Then 價格應為 370 元

            //arrange
            var target = new ShoppingCart();
            target.AddBooks(new Book { Name = "哈利波特第一集" });
            target.AddBooks(new Book { Name = "哈利波特第二集" });
            target.AddBooks(new Book { Name = "哈利波特第三集" }, 2);

            var expected = 370;

            //act
            target.Checkout();

            //assert
            Assert.AreEqual(expected, target.TotalAmount);
        }
Exemplo n.º 11
0
        public void GetPrice_一次買了整套_一二三四五集各買了一本_價格應為100_乘_5_乘_0_點_75_等於_375()
        {
            //arrange
            var books = new List<Book>
            {
                new Book{ Name = "第一集", Price = 100 },
                new Book{ Name = "第二集", Price = 100 },
                new Book{ Name = "第三集", Price = 100 },
                new Book{ Name = "第四集", Price = 100 },
                new Book{ Name = "第五集", Price = 100 }
            };

            var target = new ShoppingCart();
            target.SetBooks(books);

            var expected = 375;

            //act
            var actual = target.GetPrice();

            //assert

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 12
0
        public void GetPrice_第一集買了一本_其他都沒買_價格應為100_乘_1_等於_100元()
        {
            //arrange
            var books = new List<Book>
            {
                new Book{ Name = "第一集", Price = 100}
            };

            var target = new ShoppingCart();
            target.SetBooks(books);

            var expected = 100;

            //act
            var actual = target.GetPrice();

            //assert

            Assert.AreEqual(expected, actual);
        }