Example #1
0
 public void TestMethod2()
 {
     var cart = new Cart();
     cart.AddItem("FR1");
     cart.AddItem("FR1");
     Assert.AreEqual(cart.GetTotal(), 3.11, 0.001, "Test 2 (FR1, FR1) Failed");
 }
Example #2
0
        private static void TestExamples()
        {
            var cart = new Cart();
            cart.AddItem("Cart 1");
            cart.AddItem("FR1");
            cart.AddItem("SR1");
            cart.AddItem("FR1");
            cart.AddItem("FR1");
            cart.AddItem("CF1");
            Console.WriteLine("Expected : \u00A322.45");
            Console.WriteLine(cart.ToString());

            cart = new Cart();
            cart.AddItem("Cart 2");
            cart.AddItem("FR1");
            cart.AddItem("FR1");
            Console.WriteLine("Expected : \u00A33.11");
            Console.WriteLine(cart.ToString());

            cart = new Cart();
            cart.AddItem("Cart 3");
            cart.AddItem("SR1");
            cart.AddItem("SR1");
            cart.AddItem("FR1");
            cart.AddItem("SR1");
            Console.WriteLine("Expected : \u00A316.61");
            Console.WriteLine(cart.ToString());
        }
Example #3
0
 public void TestMethod3()
 {
     var cart = new Cart();
     cart.AddItem("SR1");
     cart.AddItem("SR1");
     cart.AddItem("FR1");
     cart.AddItem("SR1");
     Assert.AreEqual(cart.GetTotal(), 16.61, 0.001, "Test 3 (SR1, SR1, FR1, SR1) Failed");
 }
Example #4
0
 public static void Main()
 {
     Console.WriteLine("What would you like to buy?");
     var items = Console.ReadLine() ?? "";
     var cart = new Cart { Items = items.Split(',') };
     var priceCalculator = new PriceCalculator(cart);
     var price = priceCalculator.CalculatePrice();
     Console.WriteLine("That will cost you {0}.", price);
 }
Example #5
0
 public void TestMethod1()
 {
     var cart = new Cart();
     cart.AddItem("FR1");
     cart.AddItem("SR1");
     cart.AddItem("FR1");
     cart.AddItem("FR1");
     cart.AddItem("CF1");
     Assert.AreEqual(cart.GetTotal(), 22.45, 0.001, "Test 1 (FR1, SR1, FR1, FR1, CF1) Failed");
 }
Example #6
0
 private static void TestInputString(string input)
 {
     var cart = new Cart();
     var inputList = input.Split(',');
     foreach (var inputItem in inputList.Where(inputItem => cart.AddItem(inputItem) != 0))
     {
         Console.WriteLine("There was an error trying to find the product :" + inputItem);
     }
     Console.Write(cart.ToString());
 }
Example #7
0
 public void 第1集買了_1_本_其他都沒買_價格應為_100元()
 {
     //arrange
     var cart = new Cart();
     cart.AddBook(new Book() { bookName = "哈利波特第1集" });
     var expected = 100;
     //act
     var actual = cart.CalPrice();
     //assert
     Assert.AreEqual(expected,actual);
 }
Example #8
0
 public void 一二集各買了1本_第三集買了2本_價格應為_370元()
 {
     //arrange
     var cart = new Cart();
     cart.AddBook(new Book() { bookName = "哈利波特第1集" });
     cart.AddBook(new Book() { bookName = "哈利波特第2集" });
     cart.AddBook(new Book() { bookName = "哈利波特第3集" });
     cart.AddBook(new Book() { bookName = "哈利波特第3集" });
     var expected = 370;
     //act
     var actual = cart.CalPrice();
     //assert
     Assert.AreEqual(expected, actual);
 }
Example #9
0
        public void 第1集買了_1_本_第2集買了_1_本_第3集買了_1_本_價格應為_270元()
        {
            //arrange
            var cart = new Cart();
            cart.AddBook(new Book() { bookName = "哈利波特第1集" });
            cart.AddBook(new Book() { bookName = "哈利波特第2集" });
            cart.AddBook(new Book() { bookName = "哈利波特第3集" });
            var expected = 270;
            //act
            var actual = cart.CalPrice();

            Console.WriteLine("ClassCleanup");
            //assert
            Assert.AreEqual(expected, actual);
        }
Example #10
0
        public void Test_add_1_book_to_cart_then_checkout_total_should_be_equal_sell_price()
        {
            // Arrange
            var book = new Book { Id = 1, Name = "Harry Potter and the Philosopher's Stone", SellPrice = 100 };
            var expected = 100;

            var target = new Cart();
            target.Add(book);
            target.Checkout();

            // Act
            var actual = target.Total;

            // Assert
            Assert.AreEqual(expected, actual);
        }
Example #11
0
        public void Test_add_2_different_books_to_cart_then_checkout_total_should_be_equal_sell_price_5_percent_save_off()
        {
            // Arrange
            var book_1 = new Book { Id = 1, Name = "Harry Potter and the Philosopher's Stone", SellPrice = 100 };
            var book_2 = new Book { Id = 2, Name = "Harry Potter and the Chamber of Secrets", SellPrice = 100 };
            var expected = 190;

            var target = new Cart();
            target.Add(book_1);
            target.Add(book_2);
            target.Checkout();

            // Act
            var actual = target.Total;

            // Assert
            Assert.AreEqual(expected, actual);
        }
Example #12
0
 public void SetUp()
 {
     _cart = new Cart();
     _cartItem = new CartItem(2, "Test", 1.00m); // 2.00m
     _cartItem2 = new CartItem(3, "Test2", 2.00m); //6.00m
 }
Example #13
0
 public IEnumerable<ShippingCost> Calculate(Cart shoppingCart, string postcode)
 {
     return GetDefaultShippingCosts();
 }
Example #14
0
 public static void ApplyRules(Cart cart)
 {
     cart.Rule1();
     cart.Rule2();
     //Execute new Rules
 }
Example #15
0
        public void Test_add_5_different_books_to_cart_then_checkout_total_should_be_equal_sell_price_25_percent_save_off()
        {
            // Arrange
            var book_1 = new Book { Id = 1, Name = "Harry Potter and the Philosopher's Stone", SellPrice = 100 };
            var book_2 = new Book { Id = 2, Name = "Harry Potter and the Chamber of Secrets", SellPrice = 100 };
            var book_3 = new Book { Id = 3, Name = "Harry Potter and the Prisoner of Azkaban", SellPrice = 100 };
            var book_4 = new Book { Id = 4, Name = "Harry Potter and the Goblet of Fire", SellPrice = 100 };
            var book_5 = new Book { Id = 5, Name = "Harry Potter and the Order of the Phoenix", SellPrice = 100 };
            var expected = 375;

            var target = new Cart();
            target.Add(book_1);
            target.Add(book_2);
            target.Add(book_3);
            target.Add(book_4);
            target.Add(book_5);
            target.Checkout();

            // Act
            var actual = target.Total;

            // Assert
            Assert.AreEqual(expected, actual);
        }
Example #16
0
 public void 買了整套_價格應為_375元()
 {
     //arrange
     var cart = new Cart();
     cart.AddBook(new Book() { bookName = "哈利波特第1集" });
     cart.AddBook(new Book() { bookName = "哈利波特第2集" });
     cart.AddBook(new Book() { bookName = "哈利波特第3集" });
     cart.AddBook(new Book() { bookName = "哈利波特第4集" });
     cart.AddBook(new Book() { bookName = "哈利波特第5集" });
     var expected = 375;
     //act
     var actual = cart.CalPrice();
     //assert
     Assert.AreEqual(expected, actual);
 }
Example #17
0
        public void Test_add_3_diff_1_same_books_to_cart_then_checkout_total_should_be_equal_370()
        {
            // Arrange
            var book_1 = new Book { Id = 1, Name = "Harry Potter and the Philosopher's Stone", SellPrice = 100 };
            var book_2 = new Book { Id = 2, Name = "Harry Potter and the Chamber of Secrets", SellPrice = 100 };
            var book_3 = new Book { Id = 3, Name = "Harry Potter and the Prisoner of Azkaban", SellPrice = 100 };
            var book_4 = new Book { Id = 3, Name = "Harry Potter and the Prisoner of Azkaban", SellPrice = 100 };
            var expected = 370;

            var target = new Cart();
            target.Add(book_1);
            target.Add(book_2);
            target.Add(book_3);
            target.Add(book_4);
            target.Checkout();

            // Act
            var actual = target.Total;

            // Assert
            Assert.AreEqual(expected, actual);
        }
Example #18
0
 static void Main(string[] args)
 {
     var cart = new Cart();
     cart.AddBook(new Book() { bookName = "哈利波特第1集" });
     cart.AddBook(new Book() { bookName = "哈利波特第2集" });
     cart.AddBook(new Book() { bookName = "哈利波特第3集" });
     cart.AddBook(new Book() { bookName = "哈利波特第3集" });
     //act
     var actual = cart.CalPrice();
     Console.WriteLine(actual);
     Console.ReadLine();
 }