private static MessageContent GetMessageContent(CustomerInvestmentInfo info) { return(new MessageContent() { Title = $"You've earned £{Math.Round(info.InterestEarned, 3).ToString("N3", CultureInfo.InvariantCulture)} interest so far", Body = info.AmountNPV + info.InterestEarned >= 1000 ? "Invite your friends to earn together" : "Deposit more to earn more" }); }
public async Task Calling_GetInvestmentInfos_returns_correct_Collection() { //converting decimal Convert(decimal value, decimal?rate) { if (!rate.HasValue) { return(value); } return(Math.Floor(rate.Value * value * 100) / 100); } // Arrange var investmentDuration = 10; var customerId = 1; var interestRate = 0.06M; var amount = 100.0; var customer = new Customer() { Id = customerId, DeviceToken = "token", DeviceType = "android" }; var orders = new List <InvestmentOrderModel> { new InvestmentOrderModel() { CreatedUtc = DateTime.UtcNow.AddDays(-investmentDuration), Status = "Complete", CustomerId = customerId, Customer = customer, Amount = (decimal)amount, IsDeposit = true, InterestRate = interestRate, CurrencyId = 1 } }; double npv = amount * Math.Pow((1 + (double)interestRate), (double)investmentDuration / 365); decimal interestEarned = (decimal)Math.Round((npv - amount), 6); var repository = new Mock <IRepository <WeeklyNotification.App.DAL.Entities.CryptoExchangeRate> >(); var expected = new CustomerInvestmentInfo() { AmountNPV = Convert((decimal)npv, 2), Customer = customer, InterestEarned = Convert((decimal)interestEarned, 2) }; var mock = new List <WeeklyNotification.App.DAL.Entities.CryptoExchangeRate>() { new WeeklyNotification.App.DAL.Entities.CryptoExchangeRate() { FromCurrencyId = 1, Rate = 2 } }.AsQueryable().BuildMock(); repository.Setup(r => r.GetAll()).Returns(mock.Object); var service = new CustomerInvestmentCalculationCalculationService(repository.Object); // Act var result = await service.GetInvestmentInfos(orders); // Assert Assert.True(result.Any()); Assert.Equal(expected.AmountNPV, result.First().AmountNPV); Assert.Equal(expected.InterestEarned, result.First().InterestEarned); }