public void Test_SyncBookOrders_3_Orders_Only_2_book_order()
        {
            //arrange
            var target = new StubOrderService();

            var orders = new List <Order>
            {
                new Order {
                    Type = "Book", Price = 100, ProductName = "91's book"
                },
                new Order {
                    Type = "CD", Price = 200, ProductName = "91's CD"
                },
                new Order {
                    Type = "Book", Price = 300, ProductName = "POP book"
                },
            };

            target.SetOrders(orders);

            var stubBookDao = Substitute.For <IBookDao>();

            target.SetBookDao(stubBookDao);

            //act
            target.SyncBookOrders();

            // assert
            // there are 2 orders of Type="Book", so IBookDao.Insert() should be called 2 times
            stubBookDao.Received(2).Insert(Arg.Is <Order>(x => x.Type == "Book"));
        }
Пример #2
0
        public void Test_SyncBookOrders_3_Orders_Only_2_book_order()
        {
            // hard to isolate dependency to unit test
            var target = new StubOrderService();

            var orders = new List<Order>
            {
                new Order{ Type="Book", Price = 100, ProductName = "91's book"},
                new Order{ Type="CD", Price = 200, ProductName = "91's CD"},
                new Order{ Type="Book", Price = 300, ProductName = "POP book"},
            };

            //模擬csv內資料parse完的結果注入,當作GetOrders()的回傳內容
            target.SetOrders(orders);

            //建立mock物件,模擬與 http://api.joey.io/Order 這個 web service互動
            var mockBookDao = Substitute.For<IBookDao>();
            target.SetBookDao(mockBookDao);

            //act
            target.SyncBookOrders();

            mockBookDao.Received(2).Insert(Arg.Is<Order>(x => x.Type == "Book"));
        }
        public void Test_SyncBookOrders_3_Orders_Only_2_book_order()
        {
            //arrange
            var target = new StubOrderService();

            var orders = new List<Order>
            {
                new Order{ Type="Book", Price = 100, ProductName = "91's book"},
                new Order{ Type="CD", Price = 200, ProductName = "91's CD"},
                new Order{ Type="Book", Price = 300, ProductName = "POP book"},
            };

            target.SetOrders(orders);

            var stubBookDao = Substitute.For<IBookDao>();
            target.SetBookDao(stubBookDao);

            //act
            target.SyncBookOrders();

            // assert
            // there are 2 orders of Type="Book", so IBookDao.Insert() should be called 2 times
            stubBookDao.Received(2).Insert(Arg.Is<Order>(x => x.Type == "Book"));
        }