コード例 #1
0
        public void CaculateFeeTest_一二三集各買一本_價錢為270()
        {
            // arrange
            var target = new PotterShoppingCart();
            var books = new Book[]
            {
                new Book() { Id = 1, Name="哈利波特1", Amount = 1, Price = 100},
                new Book() { Id = 2, Name="哈利波特2", Amount = 1, Price = 100},
                new Book() { Id = 3, Name="哈利波特3", Amount = 1, Price = 100}
            };
            target.SetBooks(books);
            var expected = 270;

            // act
            target.CaculatePrice();
            var actual = target.Price;

            // assert
            Assert.AreEqual(expected, actual);
        }
コード例 #2
0
        public void CaculateFeeTest_計算運費後購物車內容不會消失()
        {
            // arrange
            var target = new PotterShoppingCart();
            var booksStub = new Book[]
            {
                new Book() { Id = 1, Name="哈利波特1", Amount = 1, Price = 100},
                new Book() { Id = 2, Name="哈利波特2", Amount = 2, Price = 100},
                new Book() { Id = 3, Name="哈利波特3", Amount = 2, Price = 100},
            };
            target.SetBooks(booksStub);
            var expected = 5;

            // act
            target.CaculatePrice();
            var actual = target.BookCount;

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