Beispiel #1
0
        public void TestShippingByStore_Seven_1_Order_Family_2_Orders()
        {
            //arrange
            var target = new ShipService();

            var orders = new List <Order>
            {
                new Order {
                    StoreType = StoreType.Seven, Id = 1
                },
                new Order {
                    StoreType = StoreType.Family, Id = 2
                },
                new Order {
                    StoreType = StoreType.Family, Id = 3
                },
            };

            var seven  = Substitute.For <IStoreService>();
            var family = Substitute.For <IStoreService>();

            SimpleFactory.SetStoreService(seven, family);

            //act
            target.ShippingByStore(orders);

            seven.Received().Ship(Arg.Any <Order>());
            family.Received(2).Ship(Arg.Any <Order>());

            //todo, assert
            //ShipService should invoke SevenService once and FamilyService twice
        }
 public void ShippingByStore(List <Order> orders)
 {
     foreach (var order in orders)
     {
         // simple factory pattern implementation
         IStoreService storeService = SimpleFactory.GetStoreService(order);
         storeService.Ship(order);
     }
 }
Beispiel #3
0
        public void TestShippingByStore_Seven_1_Order_Family_2_Orders()
        {
            //arrange
            var target = new ShipService();

            var orders = new List <Order>
            {
                new Order {
                    StoreType = StoreType.Seven, Id = 1
                },
                new Order {
                    StoreType = StoreType.Family, Id = 2
                },
                new Order {
                    StoreType = StoreType.Family, Id = 3
                },
            };

            IStoreService sevenService  = Substitute.For <IStoreService>();
            IStoreService familyService = Substitute.For <IStoreService>();

            //var simpleFactory = new MockSimpleFactory
            //{
            //	SevenService = sevenService,
            //	FamilyService = familyService
            //};
            SimpleFactory.SetSevenService(sevenService);
            SimpleFactory.SetFamilyService(familyService);

            //act
            target.ShippingByStore(orders);

            //todo, assert
            //ShipService should invoke SevenService once and FamilyService twice
            sevenService.Received(1).Ship(Arg.Is <Order>(x => x.StoreType == StoreType.Seven));
            familyService.Received(2).Ship(Arg.Is <Order>(x => x.StoreType == StoreType.Family));
        }