public void AggregateAmountData_OverallMaximumAmount_Calculates() { // Arrange TransactionGrouper grouper = TransactionGrouper.Overall; TransactionAggregator aggregator = TransactionAggregator.MaximumAmount; TransactionData[] transactions = { new TransactionData() { Amount = 1 }, new TransactionData() { Amount = 2 }, new TransactionData() { Amount = 3 }, new TransactionData() { Amount = 4 }, new TransactionData() { Amount = 5 }, new TransactionData() { Amount = 6 }, new TransactionData() { Amount = 7 }, new TransactionData() { Amount = 8 }, new TransactionData() { Amount = 9 } }; IEnumerable <TransactionData> expectedData = new TransactionData[] { new TransactionData() { Amount = 9 } }; // Act IEnumerable <TransactionData> actualData = Program.AggregateAmountData(transactions, grouper, aggregator); // Assert Assert.AreEqual(expectedData, actualData); }
public static void OutputTransactionStats(TransactionGrouper grouper, TransactionAggregator aggregator) { IEnumerable <TransactionData> amountStats = AggregateAmountData(Transactions, grouper, aggregator); foreach (TransactionData stats in amountStats) { Console.WriteLine($"- {grouper} {aggregator} {stats}"); } }
public static IEnumerable <TransactionData> AggregateAmountData(IEnumerable <TransactionData> transactionData, TransactionGrouper grouper, TransactionAggregator aggregator) { return(transactionData .GroupBy(grouper.KeyFunction, aggregator.AggregateFunction)); }
public void AggregateAmountData_YearlyTotalAmount_Calculates() { // Arrange TransactionGrouper grouper = TransactionGrouper.Yearly; TransactionAggregator aggregator = TransactionAggregator.TotalAmount; TransactionData[] transactions = { new TransactionData() { Year = 2000, Amount = 1 }, new TransactionData() { Year = 2000, Amount = 2 }, new TransactionData() { Year = 2000, Amount = 3 }, new TransactionData() { Year = 2001, Amount = 4 }, new TransactionData() { Year = 2001, Amount = 5 }, new TransactionData() { Year = 2001, Amount = 6 }, new TransactionData() { Year = 2002, Amount = 7 }, new TransactionData() { Year = 2002, Amount = 8 }, new TransactionData() { Year = 2002, Amount = 9 } }; IEnumerable <TransactionData> expectedData = new TransactionData[] { new TransactionData() { Year = 2000, Amount = 6 }, new TransactionData() { Year = 2001, Amount = 15 }, new TransactionData() { Year = 2002, Amount = 24 } }; // Act IEnumerable <TransactionData> actualData = Program.AggregateAmountData(transactions, grouper, aggregator); // Assert Assert.AreEqual(expectedData, actualData); }