public void Process_Should_Process_Order() { var businessEngineMock = new Mock <IBussinessRuleEngine>(); var agent = new Agent { Name = "Test" }; var book = new Product { Attribute = Domain.ProductAttribute.PHYSICAL, Id = 1, Type = "Book", Name = "Hitchhiker's Guide to the Galaxy" }; var orderEngine = new OrderProcessor(businessEngineMock.Object, agent); orderEngine.Add(new OrderLine(book, 1)); orderEngine.Add(new OrderLine(book, 1)); var order = orderEngine.Order; var expected = new List <string> { "Applied" }; businessEngineMock.Setup(x => x.Process(order)).Returns(expected); orderEngine.Process().Should().BeEquivalentTo(expected); businessEngineMock.Verify(x => x.Process(order), Times.Once); }
public void Add_Should_Add_To_Quantity_For_The_Same_Product() { var businessEngineMock = new Mock <IBussinessRuleEngine>(); var agent = new Agent { Name = "Test" }; var orderEngine = new OrderProcessor(businessEngineMock.Object, agent); var book = new Product { Attribute = Domain.ProductAttribute.PHYSICAL, Id = 1, Type = "Book", Name = "Hitchhiker's Guide to the Galaxy" }; orderEngine.Add(new OrderLine(book, 1)); orderEngine.Add(new OrderLine(book, 1)); var order = orderEngine.Order; var orderLine = order.OrderLines.Single(); order.OrderId.Should().NotBe(Guid.Empty); orderLine.Product.Should().Be(book); orderLine.Quantity.Should().Be(2); }
public void Upgrade_Product_Rule_Test() { IBussinessRuleEngine businessEngine = new BusinessRuleEngine(); var rule = new UpgradeProductRule(); businessEngine.AddRule(rule); var agent = new Agent { Name = "Test" }; var product = new Product { Attribute = ProductAttribute.NONPHYSICAL, Id = 1, Type = ProductType.Upgrade, Name = "Upgrade to Premium" }; var orderEngine = new OrderProcessor(businessEngine, agent); orderEngine.Add(new OrderLine(product, 1)); orderEngine.Process().Single().Should().Be("Applying the upgrade"); }
public void Book_Product_Rule_Test() { IBussinessRuleEngine businessEngine = new BusinessRuleEngine(); var rule = new BookProductRule(); businessEngine.AddRule(rule); var agent = new Agent { Name = "Test" }; var product = new Product { Attribute = ProductAttribute.PHYSICAL, Id = 1, Type = ProductType.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("Creating a duplicate packing slip for the royalty department"); }
public void Membership_Product_Rule_Test() { IBussinessRuleEngine businessEngine = new BusinessRuleEngine(); var rule = new MembershipProductRule(); businessEngine.AddRule(rule); var agent = new Agent { Name = "Test" }; var product = new Product { Attribute = ProductAttribute.NONPHYSICAL, Id = 1, Type = ProductType.Membership, Name = "5 months subscription" }; var orderEngine = new OrderProcessor(businessEngine, agent); orderEngine.Add(new OrderLine(product, 1)); orderEngine.Process().Single().Should().Be("Activating membership"); }
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."); }
public void Commision_Rule_Test() { IBussinessRuleEngine businessEngine = new BusinessRuleEngine(); var rule = new CommissionRule(); businessEngine.AddRule(rule); var agent = new Agent { Name = "Test" }; var product = new Product { Attribute = ProductAttribute.PHYSICAL, Id = 1, Type = ProductType.Book, Name = "Learning Python" }; var orderEngine = new OrderProcessor(businessEngine, agent); orderEngine.Add(new OrderLine(product, 1)); orderEngine.Process().Single().Should().Be("Generating commision payment to the agent"); }
public void VideoProduct_Rule_Test() { IBussinessRuleEngine businessEngine = new BusinessRuleEngine(); var rule = new VideoProductRule(); businessEngine.AddRule(rule); var agent = new Agent { Name = "Test" }; var product = new Product { Attribute = ProductAttribute.NONPHYSICAL, Id = 1, Type = ProductType.Video, Name = "Learning to Ski" }; var orderEngine = new OrderProcessor(businessEngine, agent); orderEngine.Add(new OrderLine(product, 1)); orderEngine.Process().Single().Should().Be("Adding a free \"First Aid\" video to the packing slip (the result of a court decision in 1997)"); }
public void Email_Rule_Test() { IBussinessRuleEngine businessEngine = new BusinessRuleEngine(); var rule = new EmailRule(); businessEngine.AddRule(rule); var agent = new Agent { Name = "Test" }; var product = new Product { Attribute = ProductAttribute.NONPHYSICAL, Id = 1, Type = ProductType.Upgrade, Name = "Upgrade to Premium" }; var orderEngine = new OrderProcessor(businessEngine, agent); orderEngine.Add(new OrderLine(product, 1)); orderEngine.Process().Single().Should().Be("Sending email to the owner for activation/upgrade"); }
public static void Main() { var ruleEngine = SetUpBusinessRuleEngine(); var orderProcessor = new OrderProcessor(ruleEngine, new Agent { Name = "Real Agent" }); var results = orderProcessor .Add(new OrderLine(book, 1)) .Add(new OrderLine(membership, 1)) .Add(new OrderLine(upgrade, 1)) .Add(new OrderLine(video, 1)) .Process(); Console.WriteLine(); Console.WriteLine("Final Result"); foreach (var x in results) { Console.WriteLine(x); } ; }