コード例 #1
0
        public void Test_CanAddOrRemovePricingRule()
        {
            productService.AddPricingRule(new PricingRule()
            {
                Id            = 5,
                Quantity      = 1,
                Price         = 1.35m,
                MeasureUnit   = MeasureUnit.KILOGRAM,
                Description   = "new pricing rule",
                BonusQuantity = 0
            });

            productService.RemovePricingRule(5);
        }
コード例 #2
0
        public void Setup()
        {
            // we can use Mocking framework like Moq or NSubstitute
            orderService   = new OrderService();
            productService = new ProductService();

            // init new list of pricing rules
            productService.AddPricingRule(new PricingRule()
            {
                Id            = 1,
                Quantity      = 3,
                Price         = 1m,
                MeasureUnit   = MeasureUnit.PIECE,
                Description   = "Buy Three for a Dollar",
                BonusQuantity = 0
            });
            productService.AddPricingRule(new PricingRule()
            {
                Id            = 2,
                Quantity      = 1,
                Price         = 1.99m,
                MeasureUnit   = MeasureUnit.POUND,
                Description   = "Buy one pound for 2 Dollars",
                BonusQuantity = 0
            });
            productService.AddPricingRule(new PricingRule()
            {
                Id            = 3,
                Quantity      = 2,
                Price         = 1.5m,
                MeasureUnit   = MeasureUnit.PIECE,
                Description   = "Buy two, get one free",
                BonusQuantity = 1
            });
            productService.AddPricingRule(new PricingRule()
            {
                Id            = 4,
                Quantity      = 1,
                Price         = 0.65m,
                MeasureUnit   = MeasureUnit.PIECE,
                Description   = "standard pricing",
                BonusQuantity = 0
            });

            // init new list of products
            productService.AddProduct(new Product()
            {
                Id          = 1,
                Name        = "A1",
                Sku         = "A0001",
                UnitPrice   = 0.5m,
                MeasureUnit = MeasureUnit.PIECE,
                PricingRule = productService.GetPricingRule(1)
            });
            productService.AddProduct(new Product()
            {
                Id          = 2,
                Name        = "B1",
                Sku         = "B0001",
                UnitPrice   = 4.75m,
                MeasureUnit = MeasureUnit.POUND,
                PricingRule = productService.GetPricingRule(2)
            });
            productService.AddProduct(new Product()
            {
                Id          = 3,
                Name        = "C1",
                Sku         = "C0001",
                UnitPrice   = 1.75m,
                MeasureUnit = MeasureUnit.PIECE,
                PricingRule = productService.GetPricingRule(3)
            });
            productService.AddProduct(new Product()
            {
                Id          = 4,
                Name        = "D1",
                Sku         = "D0001",
                UnitPrice   = 5.25m,
                MeasureUnit = MeasureUnit.PIECE,
                PricingRule = productService.GetPricingRule(4)
            });

            productService.AddProduct(new Product()
            {
                Id          = 5,
                Name        = "E1",
                Sku         = "E0001",
                UnitPrice   = 5.25m,
                MeasureUnit = MeasureUnit.GALLON
            });
            productService.AddProduct(new Product()
            {
                Id          = 7,
                Name        = "B2",
                Sku         = "B0002",
                UnitPrice   = 0.55m,
                MeasureUnit = MeasureUnit.OUNCE,
                PricingRule = productService.GetPricingRule(2)
            });
            productService.AddProduct(new Product()
            {
                Id          = 8,
                Name        = "D2",
                Sku         = "D0002",
                UnitPrice   = 5.25m,
                MeasureUnit = MeasureUnit.GALLON,
                PricingRule = productService.GetPricingRule(4)
            });

            // init new order object with zero items
            orderService.AddOrder(new Order()
            {
                Id = 1, ProductOrderList = new List <ProductOrder>()
            });
            orderService.AddOrder(new Order()
            {
                Id = 2, ProductOrderList = new List <ProductOrder>()
            });
            orderService.AddOrder(new Order()
            {
                Id = 3, ProductOrderList = new List <ProductOrder>()
            });
        }