public void FeeCalculator_ShouldAddMonthlyFee_WhenAtLeastOneTransaction() { // We check following requirementInvoice Fee should be included in the fee for first transaction of the month // Arrange var merchants = new Dictionary <string, Merchant>(); merchants.Add(sevenEleven, new Merchant() { DiscountPercentage = 0, Name = sevenEleven, FeeAsPercentage = 1 }); merchants.Add(circleK, new Merchant() { DiscountPercentage = 0, Name = circleK, FeeAsPercentage = 2 }); List <Transaction> transactions = new List <Transaction> { new Transaction { DoneOn = new DateTime(2018, 9, 1), Amount = 100, Owner = merchants[sevenEleven] }, new Transaction { DoneOn = new DateTime(2018, 9, 19), Amount = 100, Owner = merchants[sevenEleven] }, new Transaction { DoneOn = new DateTime(2018, 10, 19), Amount = 100, Owner = merchants[circleK] }, }; var calculator = new FeeCalculator(); // Act calculator.InitializeFeeCalculation(); var processedFirstTransaction = calculator.CalculateFee(transactions[0]); var processedSecondTransaction = calculator.CalculateFee(transactions[1]); var processedThirdTransaction = calculator.CalculateFee(transactions[2]); // Assert // Month #9 Assert.Equal(30M, processedFirstTransaction.Fee); Assert.Equal(sevenEleven, processedFirstTransaction.RelatedTransaction.Owner.Name); Assert.Equal(new DateTime(2018, 9, 1), processedFirstTransaction.RelatedTransaction.DoneOn); Assert.Equal(1M, processedSecondTransaction.Fee); Assert.Equal(sevenEleven, processedSecondTransaction.RelatedTransaction.Owner.Name); Assert.Equal(new DateTime(2018, 9, 19), processedSecondTransaction.RelatedTransaction.DoneOn); // Month #10 Assert.Equal(31M, processedThirdTransaction.Fee); Assert.Equal(circleK, processedThirdTransaction.RelatedTransaction.Owner.Name); Assert.Equal(new DateTime(2018, 10, 19), processedThirdTransaction.RelatedTransaction.DoneOn); }
public void FeeCalculator_ShouldNotAddMonthlyFee_WhenFeeIsZero() { // IWe check following requirement-If transaction fee is 0 after applying discounts, InvoiceFee should not be added // Arrange var merchants = new Dictionary <string, Merchant>(); merchants.Add(sevenEleven, new Merchant() { DiscountPercentage = 0, Name = sevenEleven, FeeAsPercentage = 0 }); List <Transaction> transactions = new List <Transaction> { new Transaction { DoneOn = new DateTime(2018, 9, 1), Amount = 100, Owner = merchants[sevenEleven] }, new Transaction { DoneOn = new DateTime(2018, 9, 19), Amount = 100, Owner = merchants[sevenEleven] }, }; var calculator = new FeeCalculator(); // Act calculator.InitializeFeeCalculation(); var processedFirstTransactions = calculator.CalculateFee(transactions[0]); var processedSecondTransaction = calculator.CalculateFee(transactions[1]); // Assert // Month #9 Assert.Equal(0, processedFirstTransactions.Fee); Assert.Equal(sevenEleven, processedFirstTransactions.RelatedTransaction.Owner.Name); Assert.Equal(new DateTime(2018, 9, 1), processedFirstTransactions.RelatedTransaction.DoneOn); Assert.Equal(0, processedSecondTransaction.Fee); Assert.Equal(sevenEleven, processedSecondTransaction.RelatedTransaction.Owner.Name); Assert.Equal(new DateTime(2018, 9, 19), processedSecondTransaction.RelatedTransaction.DoneOn); }
public void FeeCalculator_ShouldCalculateFee_WhenDiscountProvided(string merchantName, string stringifiedTransactionDate, decimal percentageFee, decimal transactionAmount, decimal discount, decimal expectedFee) { // Arrange var calculator = new FeeCalculator(); DateTime transactionDate; var transactionDateValid = DateTime.TryParseExact(stringifiedTransactionDate, "yyyy-MM-dd", null, DateTimeStyles.None, out transactionDate); var merchant = new Merchant() { Name = merchantName, FeeAsPercentage = percentageFee, DiscountPercentage = discount }; var transaction = new Transaction() { Owner = merchant, Amount = transactionAmount, DoneOn = transactionDate }; // Act calculator.InitializeFeeCalculation(); var processedTransaction = calculator.CalculateFee(transaction); // Assert Assert.True(transactionDateValid); Assert.Equal(expectedFee, processedTransaction.Fee); }