public void CrossAllRates() { // Arrange const string ratesEndpoint = "https://www.jefrijmartinez.com/rates.json"; var mockRateService = new Mock <IRateService>(); var rateCrossersService = new RateCrosserService(); mockRateService.Setup(r => r.GetAllAsync(ratesEndpoint)) .Returns(() => Task.FromResult <IList <Rate> >(new List <Rate>() { new Rate() { From = "EUR", To = "USD", ConversionRate = 1.359m }, new Rate() { From = "CAD", To = "EUR", ConversionRate = 0.732m }, new Rate() { From = "USD", To = "EUR", ConversionRate = 0.736m }, new Rate() { From = "EUR", To = "CAD", ConversionRate = 1.366m } })); // Act var rateService = mockRateService.Object; var rateCrossService = new RateCrosserService(); var rates = rateService.GetAllAsync(ratesEndpoint).Result; var originalSize = rates.Count; rateCrossersService.CrossRates(ref rates); var ratesNewSize = rates.Count; // Assert Assert.True(ratesNewSize > originalSize); }
public void Total_Sum_Of_Transactions_For_T2006_Should_Be_Expected_Result() { // Arrange const string ratesEndpoint = "https://www.jefrijmartinez.com/rates.json"; const string transactionsEndpoint = "https://www.jefrijmartinez.com/transactions.json"; const string defaultCurrency = "EUR"; var mockRateService = new Mock <IRateService>(); var mockTransactionService = new Mock <ITransactionService>(); mockRateService.Setup(r => r.GetAllAsync(ratesEndpoint)) .Returns(() => Task.FromResult <IList <Rate> >(new List <Rate>() { new Rate() { From = "EUR", To = "USD", ConversionRate = 1.359m }, new Rate() { From = "CAD", To = "EUR", ConversionRate = 0.732m }, new Rate() { From = "USD", To = "EUR", ConversionRate = 0.736m }, new Rate() { From = "EUR", To = "CAD", ConversionRate = 1.366m } })); mockTransactionService.Setup(r => r.GetAllAsync(transactionsEndpoint)) .Returns(() => Task.FromResult <IList <Transaction> >(new List <Transaction>() { new Transaction() { Sku = "T2006", Amount = 10.00m, Currency = "USD" }, new Transaction() { Sku = "M2007", Amount = 34.57m, Currency = "CAD" }, new Transaction() { Sku = "R2008", Amount = 17.95m, Currency = "USD" }, new Transaction() { Sku = "T2006", Amount = 7.63m, Currency = "EUR" }, new Transaction() { Sku = "B2009", Amount = 21.23m, Currency = "USD" } })); // Act var rateService = mockRateService.Object; var transactionService = mockTransactionService.Object; var _rateCrosserService = new RateCrosserService(); var _transactionUpdaterService = new TransactionUpdaterService(); var rates = rateService.GetAllAsync(ratesEndpoint).Result; var transactions = transactionService.GetAllAsync(transactionsEndpoint).Result.ToList(); _rateCrosserService.CrossRates(ref rates); // Cross all rates to get the ones that does not exist. transactions.ForEach(transaction => // Updates transactions amount. _transactionUpdaterService.UpdateAmount(ref transaction, defaultCurrency, rates) ); var totalAmount = transactions.Where(x => x.Sku == "T2006").Sum(x => x.Amount); // Assert Assert.Equal(14.99m, totalAmount); }