public static ICommand Build <TCommand>(MpConfig config, params object[] dependencies) where TCommand : ICommand { var requestedCommandType = typeof(TCommand).FullName; if (!string.Equals(requestedCommandType, typeof(FeeCalculationCommand).FullName, StringComparison.Ordinal)) { throw new NotSupportedException(requestedCommandType); } return(BuildFeeCalculationCommand(config, dependencies)); }
private static FeeCalculationCommand BuildFeeCalculationCommand(MpConfig config, params object[] dependencies) { var defaultFee = new PercentageFee( config.Fees.PercentageFee, config.Fees.MinAllowedFeeAmount); var feeDiscount = new DiscountedFee( config.Fees.DiscountedFees, config.Fees.MinAllowedFeeAmount); var fixedFee = new InvoiceFixedFee( config.Fees.InvoiceFixedFee, config.Fees.MinAllowedFeeAmount); var extraFees = new IExtraFee[] { feeDiscount, fixedFee }; ITransactionRepository transactionRepository = dependencies .OfType <ITransactionRepository>() .FirstOrDefault() ?? new TransactionRepository( config.Input.TransactionsFilePath, new FileReader(), new TransactionParser( config.Input.Separator, config.Input.DateFormat)); IFeeCalculationService feeCalculationService = dependencies .OfType <IFeeCalculationService>() .FirstOrDefault() ?? new FeeCalculationService( new BaseFeeCalculator(defaultFee, new Dictionary <string, ITransactionFee>()), extraFees, new Mapper()); IOutputWriter outputWriter = dependencies .OfType <IOutputWriter>() .FirstOrDefault() ?? new OutputWriter( config.Output.DateFormat, config.Output.AmountFormat, config.Output.MerchantNameMinimalWidth); var command = new FeeCalculationCommand( transactionRepository, feeCalculationService, outputWriter); return(command); }