示例#1
0
        public void GetTradesListCorrectTest()
        {
            // Arrange.
            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                 = DateTime.Now,
                    ClientName           = "TestClient"
                });
            }
            var tradesRepository = new TradesInMemoryRepository(trades);
            var tradesService    = CreateTradesService(tradesRepository: tradesRepository);

            // Act.
            var result = tradesService.GetTradesListAsync(1, 2).Result;

            // Assert.
            Assert.AreEqual(2, result.Count);
        }
示例#2
0
        public void GetTradeCorrectTest()
        {
            // Arrange.
            var      currencyRepository   = new CurrencyInMemoryRepository();
            int      tradeId              = 1;
            Currency askCurrency          = currencyRepository.GetQueryable().First(x => x.Code == Constants.Usd);
            Currency bidCurrency          = currencyRepository.GetQueryable().First(x => x.Code == Constants.Rub);
            decimal  soldAmount           = 210m;
            decimal  boughtByClientAmount = 2m;
            decimal  boughtByUsAmount     = 3m;
            DateTime time             = new DateTime(2020, 1, 1);
            string   clientName       = "TestClient";
            var      tradesRepository = new TradesInMemoryRepository(new List <Trade>
            {
                new Trade
                {
                    Id                   = tradeId,
                    AskCurrency          = askCurrency,
                    BidCurrency          = bidCurrency,
                    SoldAmount           = soldAmount,
                    BoughtByClientAmount = boughtByClientAmount,
                    BoughtByUsAmount     = boughtByUsAmount,
                    Time                 = time,
                    ClientName           = clientName
                }
            });
            var tradesService = CreateTradesService(tradesRepository: tradesRepository);

            // Act.
            var result = tradesService.GetTradeAsync(tradeId).Result;

            // Assert.
            Assert.AreEqual(tradeId, result.Id);
            Assert.AreEqual(askCurrency.Code, result.AskCurrencyCode);
            Assert.AreEqual(bidCurrency.Code, result.BidCurrencyCode);
            Assert.AreEqual(soldAmount, result.SoldAmount);
            Assert.AreEqual(boughtByClientAmount, result.BoughtAmount);
            Assert.AreEqual(boughtByClientAmount / soldAmount, result.ClientRate);
            Assert.AreEqual(boughtByUsAmount / soldAmount, result.BrokerRate);
            Assert.AreEqual(time, result.Time);
            Assert.AreEqual(clientName, result.ClientName);
        }
示例#3
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);
        }