Esempio n. 1
0
        public void GetProficInGbpCorrect()
        {
            // Arrange.
            var currencyRatesProvider = new MockCurrencyRatesProvider();

            currencyRatesProvider.Rates.Add(new Tuple <string, string>(Constants.Usd, Constants.Gbp), 0.6m);
            var      currencyRepository = new CurrencyInMemoryRepository();
            Currency usd    = currencyRepository.GetQueryable().First(x => x.Code == Constants.Usd);
            Currency rub    = currencyRepository.GetQueryable().First(x => x.Code == Constants.Rub);
            var      trades = new List <Trade>();

            for (var i = 0; i < 4; i++)
            {
                trades.Add(new Trade
                {
                    Id                   = i,
                    AskCurrency          = usd,
                    BidCurrency          = rub,
                    SoldAmount           = 210m,
                    BoughtByClientAmount = 2m,
                    BoughtByUsAmount     = 3m,
                    Time                 = new DateTime(2020, 1, 1 + i),
                    ClientName           = "TestClient"
                });
            }
            var tradesRepository = new TradesInMemoryRepository(trades);
            var tradesService    = CreateTradesService(
                tradesRepository: tradesRepository,
                currencyRatesProvider: currencyRatesProvider);
            var startDate = new DateTime(2020, 1, 2);
            var endDate   = new DateTime(2020, 1, 5);

            // Act.
            var result = tradesService.GetProfitInGbpAsync(startDate, endDate).Result;

            // Assert.
            Assert.AreEqual(4, result.Count);
            Assert.AreEqual(new DateTime(2020, 1, 2), result[0].Date);
            Assert.AreEqual(0.6m, result[0].Sum);
            Assert.AreEqual(new DateTime(2020, 1, 5), result[3].Date);
            Assert.AreEqual(0m, result[3].Sum);
        }
Esempio n. 2
0
        public void AddTradeCorrectTest()
        {
            // Arrange.
            var currencyRatesProvider = new MockCurrencyRatesProvider();
            var configurationService  = new MockConfigurationService();
            var tradesRepository      = new TradesInMemoryRepository();

            currencyRatesProvider.Rates.Add(new Tuple <string, string>(Constants.Rub, Constants.Usd), 1m / 70m);
            configurationService.TotalEnrichmentPercent = 50m;
            var tradesService = CreateTradesService(
                tradesRepository: tradesRepository,
                currencyRatesProvider: currencyRatesProvider,
                configurationService: configurationService);
            string clientName = "TestClient";

            // Act.
            var parameters = new AddTradeParameters
            {
                AskCurrencyCode = Constants.Usd,
                BidCurrencyCode = Constants.Rub,
                SoldAmount      = 210,
                Time            = DateTime.Now,
                ClientName      = clientName
            };

            tradesService.AddTradeAsync(parameters).Wait();

            // Assert.
            Assert.AreEqual(1, tradesRepository.GetQueryable().Count());
            var trade = tradesRepository.GetAllAsync().Result.First();

            Assert.AreEqual(Constants.Usd, trade.AskCurrency.Code);
            Assert.AreEqual(Constants.Rub, trade.BidCurrency.Code);
            Assert.AreEqual(2m, trade.BoughtByClientAmount);
            Assert.AreEqual(3m, trade.BoughtByUsAmount);
            Assert.AreEqual(clientName, trade.ClientName);
        }