public void TestTransactionFeesFromFile(string transactionFilePath, string assertResultsFilePath, string implementerAssemblyName) { var assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var factory = DynamicLoader.LoadModuleType <IMerchantFeesCalculatorFactory>(Path.Combine(assemblyPath, implementerAssemblyName)); var context = DynamicLoader.LoadModuleType <ITransactionContext>(Path.Combine(assemblyPath, implementerAssemblyName)); var source = factory.CreateTextBasedTransactionSource(transactionFilePath); var sourceFormat = factory.CreateTransactionInputFormat(); var feeCalculator = factory.CreateTransactionFeeCalculator(29); var outputFormatter = factory.CreateOutputFormatter(); context.ApplyDiscount("TELIA", factory.CreatePercentageDiscount(10)); context.ApplyDiscount("CIRCLE_K", factory.CreatePercentageDiscount(20)); using (var outputWriter = new TestOutputWriter(assertResultsFilePath)) // use custom test writer { foreach (var transaction in source.FetchTransactions(sourceFormat, context)) { context.LogTransaction(transaction); var fee = feeCalculator.Compute(transaction, context); outputWriter.Write(fee, outputFormatter); } } }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Incorrect syntax. Provide file for transactions."); return; } // read input file name var transactionFilePath = args[0]; // retrieve root factory and context objects from implementing assembly // note that "MobilePay.MerchantFeesCalculator.BasicImplementation.dll" is implemented all internal so that // client applications would use API to access the transaction fee computation objects var factory = DynamicLoader.LoadModuleType <IMerchantFeesCalculatorFactory>( "MobilePay.MerchantFeesCalculator.BasicImplementation.dll"); var context = DynamicLoader.LoadModuleType <ITransactionContext>( "MobilePay.MerchantFeesCalculator.BasicImplementation.dll"); // generate application objects from implementing assembly var source = factory.CreateTextBasedTransactionSource(transactionFilePath); var sourceFormat = factory.CreateTransactionInputFormat(); var outputWriter = factory.CreateOutputWriter(); var outputFormatter = factory.CreateOutputFormatter(); // TODO: the fixed 29DKK fee could be refactored into separate object to and implemented // TODO: in more elegant fashion as discounts below var feeCalculator = factory.CreateTransactionFeeCalculator(29); // apply discounts to major companies context.ApplyDiscount("TELIA", factory.CreatePercentageDiscount(10)); context.ApplyDiscount("CIRCLE_K", factory.CreatePercentageDiscount(20)); // fetch transactions - lazy load foreach (var transaction in source.FetchTransactions(sourceFormat, context)) { // log transaction into the system context.LogTransaction(transaction); // compute the fee var fee = feeCalculator.Compute(transaction, context); // output outputWriter.Write(fee, outputFormatter); } Console.ReadKey(); }
public void TestSimpleFormatter() { var factory = DynamicLoader.LoadModuleType <IMerchantFeesCalculatorFactory>( "MobilePay.MerchantFeesCalculator.BasicImplementation.dll"); var formatter = factory.CreateOutputFormatter(); var transactionMock = new Moq.Mock <ITransaction>(); transactionMock.SetupGet(m => m.Amount).Returns(100m); var transactionFeeMock = new Moq.Mock <ITransactionFee>(); transactionFeeMock.SetupGet(m => m.Transaction.Date).Returns(DateTime.Parse("2001-02-03")); transactionFeeMock.SetupGet(m => m.Transaction.Merchant.Name).Returns("NORFA"); transactionFeeMock.SetupGet(m => m.Value).Returns(20); var line = formatter.Format(transactionFeeMock.Object); Assert.AreEqual("2001-02-03 NORFA $20.00", line); }
public void TestCase1(string implementerAssemblyName) { var assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var factory = DynamicLoader.LoadModuleType <IMerchantFeesCalculatorFactory>(Path.Combine(assemblyPath, implementerAssemblyName)); var context = DynamicLoader.LoadModuleType <ITransactionContext>(Path.Combine(assemblyPath, implementerAssemblyName)); var source = new TestHelper(); var outputWriter = source; var sourceFormat = factory.CreateTransactionInputFormat(); var feeCalculator = factory.CreateTransactionFeeCalculator(0); var outputFormatter = factory.CreateOutputFormatter(); foreach (var transaction in source.FetchTransactions(sourceFormat, context)) { context.LogTransaction(transaction); var fee = feeCalculator.Compute(transaction, context); outputWriter.Write(fee, outputFormatter); } }