Example #1
0
        public void CalculateFee_WhenInputIsCorrect_ShouldReturnCorrectValue(float rate, float transactionAmount, float expectedFee)
        {
            // Arrange
            var transaction = new Transaction("X", DateTime.Now, (decimal)transactionAmount);
            var fee         = new PercentageFee((decimal)rate);

            // Act
            var result = fee.CalculateFee(transaction);

            // Assert
            Assert.NotNull(result);
            Assert.Equal((decimal)expectedFee, result.Amount);
        }
Example #2
0
        public void CalculateFee_ShouldCopyMerchantNameAndDateToFee()
        {
            // Arrange
            var transaction = new Transaction("X", DateTime.Now, 100M);
            var fee         = new PercentageFee(0.5M);

            // Act
            var result = fee.CalculateFee(transaction);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(transaction.MerchantName, result.MerchantName, StringComparer.Ordinal);
            Assert.Equal(transaction.Date, result.Date);
        }
Example #3
0
        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);
        }
Example #4
0
 public string FeesToString()
 {
     return(MoneyFee.ToString() + " + " + PercentageFee.ToShortClearString() + "%");
 }