예제 #1
0
        public void Buy_1_Of_Each_Vol_1_to_3_Cost_270()
        {
            //arrange
            var target            = new PotterShoppingCart();
            var shoppingCartItem1 = new PotterShoppingCartItem()
            {
                Volumn   = HarryPotter.VOL_1,
                Quantity = 1
            };
            var shoppingCartItem2 = new PotterShoppingCartItem()
            {
                Volumn   = HarryPotter.VOL_2,
                Quantity = 1
            };
            var shoppingCartItem3 = new PotterShoppingCartItem()
            {
                Volumn   = HarryPotter.VOL_3,
                Quantity = 1
            };
            var expectedCost = 270;

            //act
            int actualCost;

            target.AddToCart(shoppingCartItem1);
            target.AddToCart(shoppingCartItem2);
            target.AddToCart(shoppingCartItem3);
            actualCost = target.CheckOut();

            //assert
            Assert.AreEqual(expectedCost, actualCost);
        }
예제 #2
0
        public void Buy_Vol1_1Book_Vol2_1Book_Vol3_1Book_Vol4_1Book_Should_Be_320()
        {
            //arrange
            var cart     = new PotterShoppingCart();
            var products = new List <PotterBook>
            {
                new PotterBook {
                    Name = "Vol1", Price = 100
                },
                new PotterBook {
                    Name = "Vol2", Price = 100
                },
                new PotterBook {
                    Name = "Vol3", Price = 100
                },
                new PotterBook {
                    Name = "Vol4", Price = 100
                },
            };

            var expected = 100 * 4 * 0.8m;

            //act
            var actual = cart.CalculatePrice(products);

            //assert
            Assert.AreEqual(expected, actual);
        }
        public void 第一集買了一本_第二集也買了一本_價格應為190元()
        {
            //arrange
            var target = new PotterShoppingCart();

            //act
            target.AddToCart(
                new Book
            {
                ISBN  = "9789573317241",
                Name  = "哈利波特1",
                Price = 100
            }
                );
            target.AddToCart(
                new Book
            {
                ISBN  = "9789573317586",
                Name  = "哈利波特2",
                Price = 100
            }
                );

            var totalPrice = target.CheckOut();

            //assert
            var expected = 190;

            Assert.AreEqual(expected, totalPrice);
        }
        public void 第一集買了一本_第二三集各買了兩本_價格應為460元()
        {
            //arrange
            var target = new PotterShoppingCart();

            //act
            target.AddToCart(
                new Book
            {
                ISBN  = "9573317249",
                Name  = "哈利波特1",
                Price = 100
            }
                );
            target.AddToCart(
                new Book
            {
                ISBN  = "9573317583",
                Name  = "哈利波特2",
                Price = 100
            }
                );
            target.AddToCart(
                new Book
            {
                ISBN  = "9573317583",
                Name  = "哈利波特2",
                Price = 100
            }
                );
            target.AddToCart(
                new Book
            {
                ISBN  = "9573318008",
                Name  = "哈利波特3",
                Price = 100
            }
                );

            target.AddToCart(
                new Book
            {
                ISBN  = "9573318008",
                Name  = "哈利波特3",
                Price = 100
            }
                );


            var totalPrice = target.CheckOut();

            //assert
            var expected = 460;

            Assert.AreEqual(expected, totalPrice);
        }
        public void 一次買了整套_一二三四五集各買了一本_價格應為375元()
        {
            //arrange
            var target = new PotterShoppingCart();

            //act
            target.AddToCart(
                new Book
            {
                ISBN  = "9573317249",
                Name  = "哈利波特1",
                Price = 100
            }
                );
            target.AddToCart(
                new Book
            {
                ISBN  = "9573317583",
                Name  = "哈利波特2",
                Price = 100
            }
                );
            target.AddToCart(
                new Book
            {
                ISBN  = "9573318008",
                Name  = "哈利波特3",
                Price = 100
            }
                );

            target.AddToCart(
                new Book
            {
                ISBN  = "9573318318",
                Name  = "哈利波特4",
                Price = 100
            }
                );

            target.AddToCart(
                new Book
            {
                ISBN  = "9573319861",
                Name  = "哈利波特5",
                Price = 100
            }
                );

            var totalPrice = target.CheckOut();

            //assert
            var expected = 375;

            Assert.AreEqual(expected, totalPrice);
        }
        public void getTotalAmountTest_第一集買了一本_其他都沒買_價格應為100元()
        {
            var target = new PotterShoppingCart();

            target.addToCart(1);
            var actual   = target.getTotalAmount();
            var expected = 100;

            Assert.AreEqual(expected, actual);
        }
        public void getTotalAmountTest_一二三集各買了一本_價格應為270()
        {
            var target = new PotterShoppingCart();

            target.addToCart(1);
            target.addToCart(2);
            target.addToCart(3);
            var actual   = target.getTotalAmount();
            var expected = 270;

            Assert.AreEqual(expected, actual);
        }
        public void getTotalAmountTest_一次買了整套_一二三四五集各買了一本_價格應為375()
        {
            var target = new PotterShoppingCart();

            target.addToCart(1);
            target.addToCart(2);
            target.addToCart(3);
            target.addToCart(4);
            target.addToCart(5);
            var actual   = target.getTotalAmount();
            var expected = 375;

            Assert.AreEqual(expected, actual);
        }
        public void CalculateTotalPriceTest_第一集1本_預計回傳100()
        {
            //Arrange
            var books = new Dictionary <string, int>()
            {
                { EPISODE1_ISBN, 1 }
            };
            var expected = 100;

            //Act
            var actual = PotterShoppingCart.CalculateTotalPrice(books);

            //Assert
            Assert.AreEqual(expected, actual);
        }
        public void CalculateTotalPriceTest_第一集1本_第二集1本_預計回傳190()
        {
            //Arrange
            var books = new Dictionary <string, int>()
            {
                { "哈利波特_1", 1 },
                { "哈利波特_2", 1 }
            };
            var expected = 190;

            //Act
            var actual = PotterShoppingCart.CalculateTotalPrice(books);

            //Assert
            Assert.AreEqual(expected, actual);
        }
예제 #11
0
        public void Test_PotterShoppingCart_1_first_1_second_2_third_book_should_be_370()
        {
            //Arrange
            var target = new PotterShoppingCart();

            var order = new Dictionary<PotterEpisode, int>();
            order.Add(PotterEpisode.First, 1);
            order.Add(PotterEpisode.Second, 1);
            order.Add(PotterEpisode.Third, 2);

            decimal expected = 370;

            //Act
            decimal actual = target.ComputeOrderAmount(order);

            //Assert
            Assert.AreEqual(expected, actual);
        }
예제 #12
0
        public void Buy_1_First_Vol_Cost_100()
        {
            //arrange
            var target           = new PotterShoppingCart();
            var shoppingCartItem = new PotterShoppingCartItem()
            {
                Volumn   = HarryPotter.VOL_1,
                Quantity = 1
            };
            var expectedCost = 100;

            //act
            int actualCost;

            target.AddToCart(shoppingCartItem);
            actualCost = target.CheckOut();

            //assert
            Assert.AreEqual(expectedCost, actualCost);
        }
        public void CalculateTotalPriceTest_第一集1本_第二集1本_第三集1本_第四集1本_第五集1本_預計回傳375()
        {
            //Arrange

            var books = new Dictionary <string, int>()
            {
                { EPISODE1_ISBN, 1 },
                { EPISODE2_ISBN, 1 },
                { EPISODE3_ISBN, 1 },
                { EPISODE4_ISBN, 1 },
                { EPISODE5_ISBN, 1 },
            };
            var expected = 375;

            //Act
            var actual = PotterShoppingCart.CalculateTotalPrice(books);

            //Assert
            Assert.AreEqual(expected, actual);
        }
        public void CalculateFeeTest_Buy_One_Book1_One_Book2_One_Book3_One_book4_One_book5_Should_Get_Fee_375()
        {
            PotterShoppingCart target = new PotterShoppingCart();

            var basket = new Basket
            {
                Books = new List<Book>()
                {
                    new Book() { BookId = 1 },
                    new Book() { BookId = 2 },
                    new Book() { BookId = 3 },
                    new Book() { BookId = 4 },
                    new Book() { BookId = 5 }
                }
            };

            target.CalculateFee(basket);

            var expected = 375;
            Assert.AreEqual(expected, basket.Fee);
        }
        public void CalculateFeeTest_Buy_One_Book1_Should_Get_Fee_100()
        {
            PotterShoppingCart target = new PotterShoppingCart();

            var basket = new Basket
            {
                Books = new List<Book>() { new Book() { BookId = 1 } }
            };

            target.CalculateFee(basket);

            var expected = 100;
            Assert.AreEqual(expected, basket.Fee);
        }