private IOrderProcess GetHandlerByPaymentType(PaymentType options) { IOrderProcess handler; handler = PaymentFactory.GetOrderProcessor(options); return(handler); }
public void ProcessOrder_BookName_Empty_Test() { //arrange var book = GetProducts().Where(x => x.ProductType == Models.Constants.ProductTypes.BOOKORPHYSICAL).FirstOrDefault(); book.AgentName = string.Empty; OrderProcessHandler = PaymentFactory.GetOrderProcessor(Models.Constants.PaymentType.BOOKORPHYSICAL); //assert var ex = Assert.Throws <InvalidOperationException>(() => OrderProcessHandler.ProcessOrder(book)); Assert.That(ex.Message, Is.EqualTo("Agent Name is missing")); }
public void ProcessOrder_PhysicalProduct_Name_Empty_Test() { //arrange var product = GetProducts().Where(x => x.ProductType == Models.Constants.ProductTypes.PRODUCT_PHYSICAL).FirstOrDefault(); product.Name = string.Empty; OrderProcessHandler = PaymentFactory.GetOrderProcessor(Models.Constants.PaymentType.PHYSICAL_PRODUCT); //assert var ex = Assert.Throws <InvalidOperationException>(() => OrderProcessHandler.ProcessOrder(product)); Assert.That(ex.Message, Is.EqualTo("Product Name is missing")); }
public void ProcessOrder_BookName_Empty_Test() { //arrange var video = GetProducts().Where(x => x.ProductType == Models.Constants.ProductTypes.VIDEO).FirstOrDefault(); OrderProcessHandler = PaymentFactory.GetOrderProcessor(Models.Constants.PaymentType.VIDEO); video.Description = string.Empty; OrderProcessHandler = PaymentFactory.GetOrderProcessor(Models.Constants.PaymentType.VIDEO); var ex = Assert.Throws <InvalidOperationException>(() => OrderProcessHandler.ProcessOrder(video)); Assert.That(ex.Message, Is.EqualTo("Video Descrption is missing")); }
public void When_I_Pass_Valid_PhysicalProduct_Order_it_should_process() { //arrange var physcialProduct = GetProducts().Where(x => x.ProductType == Models.Constants.ProductTypes.PRODUCT_PHYSICAL).FirstOrDefault(); OrderProcessHandler = PaymentFactory.GetOrderProcessor(Models.Constants.PaymentType.PHYSICAL_PRODUCT); //act var result = OrderProcessHandler.ProcessOrder(physcialProduct); //assert Assert.IsTrue(result.IsSuccess); Assert.AreEqual("Packing slip created for physical product", result.Message); }
public void ProcessOrder_BookName_Empty_Test() { //arrange var book = GetProducts().Where(x => x.ProductType == Models.Constants.ProductTypes.BOOK).FirstOrDefault(); book.Name = string.Empty; OrderProcessHandler = PaymentFactory.GetOrderProcessor(Models.Constants.PaymentType.BOOK); double royaltyAmount = book.Price * book.Quantity * book.Commission; //assert var ex = Assert.Throws <InvalidOperationException>(() => OrderProcessHandler.ProcessOrder(book)); Assert.That(ex.Message, Is.EqualTo("Book Name is missing")); }
public void When_I_Pass_Valid_BookOrder_it_should_process() { //arrange var book = GetProducts().Where(x => x.ProductType == Models.Constants.ProductTypes.BOOKORPHYSICAL).FirstOrDefault(); OrderProcessHandler = PaymentFactory.GetOrderProcessor(Models.Constants.PaymentType.BOOKORPHYSICAL); double Commission = (book.Price * book.Quantity) / 0.10; string message = "Commision paid to agent -" + Commission; //act var result = OrderProcessHandler.ProcessOrder(book); //assert Assert.IsTrue(result.IsSuccess); Assert.AreEqual(message, result.Message); }
public void When_I_Pass_Valid_VideoOrder_it_should_process() { //arrange var video = GetProducts().Where(x => x.ProductType == Models.Constants.ProductTypes.VIDEO).FirstOrDefault(); OrderProcessHandler = PaymentFactory.GetOrderProcessor(Models.Constants.PaymentType.VIDEO); video.Description = "TestVideos"; video.PackingDate = DateTime.Today; //act var result = OrderProcessHandler.ProcessOrder(video); //assert Assert.IsTrue(result.IsSuccess); Assert.AreEqual("Generated Packing slip", result.Message); }
public void When_I_Pass_Valid_BookOrder_it_should_process() { //arrange var book = GetProducts().Where(x => x.ProductType == Models.Constants.ProductTypes.BOOK).FirstOrDefault(); OrderProcessHandler = PaymentFactory.GetOrderProcessor(Models.Constants.PaymentType.BOOK); double royaltyAmount = book.Price * book.Quantity * book.Commission; string message = "Royalty slip created with Amount - " + royaltyAmount; //act var result = OrderProcessHandler.ProcessOrder(book); //assert Assert.IsTrue(result.IsSuccess); Assert.AreEqual(message, result.Message); }
private static void ProcessPaymentOrder(int options) { int subscription = 0; var paymentType = (PaymentType)Enum.Parse(typeof(PaymentType), options.ToString()); if (options == 5 || options == 6) { paymentType = (PaymentType)Enum.Parse(typeof(PaymentType), "5".ToString()); subscription = options == 5 ? 1 : 2; // assign Subscription type } IOrderProcess processor = PaymentFactory.GetOrderProcessor(paymentType); var data = SampleData.GetSampleDataForOrder(paymentType, subscription); if (processor != null) { var result = processor.ProcessOrder(data); Console.WriteLine($"Hanlded Order of {paymentType.ToString()} and Result is {result.Message}\n"); } else { Console.WriteLine("Invalid operation"); } }