Esempio n. 1
0
        public IOrderProcess GetProductRuleInstance(ProductType productType)
        {
            IOrderProcess orderRule;

            switch (productType)
            {
            case ProductType.PhysicalProduct:
                orderRule = new PhysicalProductRule();
                break;

            case ProductType.Book:
                orderRule = new BookRule();
                break;

            case ProductType.Membership:
                orderRule = new MembershipRule();
                break;

            case ProductType.MembershipUpgrade:
                orderRule = new MembershipUpgradeRule();
                break;

            case ProductType.Video:
                orderRule = new VideoRule();
                break;

            default:
                orderRule = new NewProductRule();
                break;
            }
            return(orderRule);
        }
Esempio n. 2
0
        public void AddRule_Should_Add_Rule_ToEngine()
        {
            IBussinessRuleEngine ruleEngine = new BusinessRuleEngine();
            IRule rule = new PhysicalProductRule();

            ruleEngine.AddRule(rule);

            ruleEngine.Rules.Should().Contain(rule);
        }
        public void IsApplication_Should_Return_False_For_NonPhysical_Product()
        {
            var rule    = new PhysicalProductRule();
            var product = new Product {
                Attribute = ProductAttribute.NONPHYSICAL
            };

            rule.IsApplicable(product).Should().BeFalse();
        }
        static void Main(string[] args)
        {
            Order  order         = new Order();
            string returnMessage = string.Empty;

            Console.WriteLine("Enter Order Type for Which Payment Done :\n" +
                              "1 for Physical Product\n" +
                              "2 for Book\n" +
                              "3 for New Membership\n" +
                              "4 for Upgrade MemberShip\n" +
                              "5 for Membership OR Upgrade\n" +
                              "6 For VideoLearning\n" +
                              "7 for Physical Product OR Book\n");
            int orderVal = int.Parse(Console.ReadLine());

            order.OrderType = orderVal;
            switch (orderVal)
            {
            case 1:
                PhysicalProductRule phyProdRule = new PhysicalProductRule();
                returnMessage = phyProdRule.ExecuteRule(order);
                break;

            case 2:
                BookRule bookRule = new BookRule();
                returnMessage = bookRule.ExecuteRule(order);
                break;

            case 3:
                NewMembershipRule newMembership = new NewMembershipRule();
                returnMessage = newMembership.ExecuteRule(order);
                break;

            case 4:
                UpgradeMemberShipRule upgradeMember = new UpgradeMemberShipRule();
                returnMessage = upgradeMember.ExecuteRule(order);
                break;

            case 5:
                MembershipORUpgradeRule membershipORUpgrade = new MembershipORUpgradeRule();
                returnMessage = membershipORUpgrade.ExecuteRule(order);
                break;

            case 6:
                VideoLearningRule videoLearning = new VideoLearningRule();
                returnMessage = videoLearning.ExecuteRule(order);
                break;

            case 7:
                PhysicalProductORBookRule physicalProductORBookRule = new PhysicalProductORBookRule();
                returnMessage = physicalProductORBookRule.ExecuteRule(order);
                break;
            }
            Console.WriteLine("{0}", returnMessage);
            Console.Read();
        }
Esempio n. 5
0
        public void RemoveRule_Should_Remove_Rule_FromEngine()
        {
            IBussinessRuleEngine ruleEngine = new BusinessRuleEngine();
            IRule rule = new PhysicalProductRule();

            ruleEngine.AddRule(rule);
            ruleEngine.RemoveRule(rule);

            ruleEngine.Rules.Should().NotContain(rule);
        }
        public void IsApplication_Should_Return_True_For_Physical_Product()
        {
            var rule    = new PhysicalProductRule();
            var product = new Product {
                Attribute = ProductAttribute.PHYSICAL
            };

            rule.IsApplicable(product).Should().BeTrue();
            rule.Apply().Should().Be("Generating a packing slip for shipping.");
        }
        public List <TypeOfActionAgainstRule> ExcuteRule(TypeOfRuleEnum rule)
        {
            var video             = new VideoRule(null, rule);
            var newMemberShip     = new NewMemberShip(video, rule);
            var upgradeMemberShip = new UpgradeMemberShip(newMemberShip, rule);
            var book      = new BookRule(upgradeMemberShip, rule);
            var ruleChain = new PhysicalProductRule(book, rule);

            return(ruleChain.VerifyRuleAndProcess());
        }
Esempio n. 8
0
        public void SatifyIfItemTypeInOrderIsAPhysicalProduct()
        {
            var item = new Item {
                Id = 1, ItemType = ItemType.PhysicalProduct, Name = "S    ome Product"
            };

            var productRule = new PhysicalProductRule();

            var actual = productRule.IsApplicable(item);

            Assert.True(actual);
        }
Esempio n. 9
0
        public void Given_A_Product_Is_Null_When_Execute_Is_Called_Throws_ArgumentNullException()
        {
            //arrange
            var sut = new PhysicalProductRule(_mockRepository.Object);


            // Act
            Action act = () => sut.Execute(null);

            //Assert
            act.Should().ThrowExactly <ArgumentNullException>();
        }
Esempio n. 10
0
        public void BusinessRule3ShouldApplyIsTrueWhenPOContainsRule()
        {
            var ipoReader = new Mock <IPOReader>();

            ipoReader.Setup(x => x.Request).Returns(new List <string> {
                "video comprehensive first aid training"
            });
            var rule   = new PhysicalProductRule();
            var actual = rule.ShouldApply(ipoReader.Object);

            Assert.True(actual);
        }
Esempio n. 11
0
        public void GeneratesACommissionForAgent()
        {
            var item = new Item {
                Id = 1, ItemType = ItemType.PhysicalProduct, Name = "someProduct"
            };

            var productRule = new PhysicalProductRule();

            var actual = productRule.Apply(item);

            Assert.Contains("Commission payment generated for Agent", actual.Activity);
        }
Esempio n. 12
0
        public void GeneratesAPackageSlipForShipping()
        {
            var item = new Item {
                Id = 1, ItemType = ItemType.PhysicalProduct, Name = "someProduct"
            };

            var productRule = new PhysicalProductRule();

            var actual = productRule.Apply(item);

            Assert.Contains("Package Slip generated for Shipping", actual.Activity);
        }
Esempio n. 13
0
        public void ApplysForPhysicalProduct()
        {
            var item = new Item {
                Id = 1, ItemType = ItemType.PhysicalProduct, Name = "someProduct"
            };

            var productRule = new PhysicalProductRule();

            var actual = productRule.Apply(item);

            Assert.NotNull(actual);
            Assert.IsType(typeof(RuleLog), actual);
        }
Esempio n. 14
0
        public void ApplicationReturnsARuleLog()
        {
            var item = new Item {
                Id = 1, ItemType = ItemType.PhysicalProduct, Name = "someProduct"
            };

            var productRule = new PhysicalProductRule();

            var actual = productRule.Apply(item);

            Assert.IsType(typeof(RuleLog), actual);
            Assert.Equal("Physical Product Rule", actual.RuleName);
        }
Esempio n. 15
0
        public void Add_Physical_Product_Rule()
        {
            Payment payment = new Payment();

            payment.PaymentType = Enum_PaymentType.PhysicalProduct;
            payment.ProductName = "Computer";
            IRule rule = new PhysicalProductRule();

            ruleManager.AddRule(rule);
            var  ruleResult            = ruleManager.ExecuteRules(payment);
            bool isPhysicalRuleApplied = ruleResult.Contains("Generate Packing Slip");

            Assert.IsTrue(isPhysicalRuleApplied);
        }
Esempio n. 16
0
        public void Given_A_Product_When_Execute_Is_Called_Calls_PartnerServices()
        {
            //arrange
            var product = _fixture.Create <Book>();
            var sut     = new PhysicalProductRule(_mockRepository.Object);

            _mockRepository.Setup(m => m.GeneratePackingSlip()).Returns(Task.CompletedTask);
            _mockRepository.Setup(m => m.GenerateCommision()).Returns(Task.CompletedTask);

            // Act
            sut.Execute(product);

            //Assert
            _mockRepository.Verify(m => m.GeneratePackingSlip(), Times.Once);
            _mockRepository.Verify(m => m.GenerateCommision(), Times.Once);
        }
Esempio n. 17
0
        public void Given_A_Product_When_Execute_Is_Called_Adds_GST_To_Final_Price()
        {
            //arrange
            var product = _fixture.Create <PhysicalProduct>();

            product.Price = 100;
            var sut = new PhysicalProductRule(_mockRepository.Object);

            _mockRepository.Setup(m => m.GeneratePackingSlip()).Returns(Task.CompletedTask);
            _mockRepository.Setup(m => m.GenerateCommision()).Returns(Task.CompletedTask);

            // Act
            sut.Execute(product);

            //Assert
            product.FinalPrice.Should().Equals(120);
        }
        public void Given_A_Product_Is_Null_When_MakePayment_Is_Called_Then_Throws_ArgumentNullException()
        {
            //arrange
            var physicalRule   = new PhysicalProductRule(_mockRepository.Object);
            var _businessRules = new List <IProductBusinessRule>();

            _businessRules.Add(physicalRule);

            var product = _fixture.Create <Book>();

            product.ProductType = ProductType.Book;
            var sut = new PaymentStrategy(_businessRules);

            // Act
            Action act = () => sut.ProcessPayment(product);

            //Assert
            act.Should().ThrowExactly <ArgumentNullException>();
        }
        public void Given_A_Product_Is_Ordered_When_Product_Exists_Then_ProcessPayment_Successfully()
        {
            //arrange
            var physicalRule = new PhysicalProductRule(_mockRepository.Object);

            _mockRepository.Setup(m => m.GeneratePackingSlip()).Returns(Task.CompletedTask);
            _mockRepository.Setup(m => m.GenerateCommision()).Returns(Task.CompletedTask);
            var _businessRules = new List <IProductBusinessRule>();

            _businessRules.Add(physicalRule);

            var product = _fixture.Create <PhysicalProduct>();
            var sut     = new PaymentStrategy(_businessRules);

            // Act
            Action act = () => sut.ProcessPayment(product);

            //Assert
            act.Should().NotThrow();
        }
Esempio n. 20
0
        public void Add_Book_And_Physical_Rule()
        {
            Payment payment = new Payment();

            payment.PaymentType = Enum_PaymentType.PhysicalProduct;
            payment.ProductName = "Harry Potter Book";
            payment.IsBook      = true;
            IRule rule = new BookRule();

            ruleManager.AddRule(rule);
            // Both rule so that both rules will be added to rule result;
            rule = new PhysicalProductRule();
            ruleManager.AddRule(rule);
            var  ruleResult        = ruleManager.ExecuteRules(payment);
            bool isBookRuleApplied = ruleResult.Contains("Packing Slip for Royalty Department");

            Assert.IsTrue(isBookRuleApplied);
            bool isPhysicalRuleApplied = ruleResult.Contains("Generate Packing Slip");

            Assert.IsTrue(isPhysicalRuleApplied);
        }
Esempio n. 21
0
        public void Physical_Product_Rule_Test()
        {
            IBussinessRuleEngine businessEngine = new BusinessRuleEngine();
            var rule = new PhysicalProductRule();

            businessEngine.AddRule(rule);
            var agent = new Agent {
                Name = "Test"
            };
            var product = new Product
            {
                Attribute = ProductAttribute.PHYSICAL,
                Id        = 1,
                Type      = "Book",
                Name      = "Hitchhiker's Guide to the Galaxy"
            };

            var orderEngine = new OrderProcessor(businessEngine, agent);

            orderEngine.Add(new OrderLine(product, 1));
            orderEngine.Process().Single().Should().Be("Generating a packing slip for shipping.");
        }
Esempio n. 22
0
        public void Process_Should_Not_Execute_Rule()
        {
            IBussinessRuleEngine ruleEngine = new BusinessRuleEngine();
            IRule rule  = new PhysicalProductRule();
            var   order = new Order(Guid.NewGuid(), new Agent {
                Name = "Test"
            });
            var product = new Product();

            order.Add(new OrderLine(product, 1));

            var ruleMock = new Mock <IRule>();

            ruleMock.Setup(x => x.IsApplicable(product)).Returns(false);
            ruleMock.Setup(x => x.Apply()).Returns("Applied Rule");

            ruleEngine.AddRule(ruleMock.Object);
            ruleEngine.Process(order);

            ruleMock.Verify(x => x.IsApplicable(product), Times.Once);
            ruleMock.Verify(x => x.Apply(), Times.Never);
        }
Esempio n. 23
0
 public PhysicalProductRuleTest()
 {
     mockPackingSlip     = new Mock <IPackingSlip>();
     mockCommission      = new Mock <ICommission>();
     physicalProductRule = new PhysicalProductRule();
 }