public async Task UpdatedPairByIdAsync_CorrectId_UpdatesPair() { var testData = await FormDataAsync(); var expectedCurrencyData = new CreateOrUpdateCurrencyData { PairName = "XRP-USD", BuyPrice = 258.0m, SellPrice = 259.0m, LastTradePrice = 260.0m, HighPrice = 261.0m, LowPrice = 262.0m, Volume = 1234568, Updated = DateTime.Now }; var actualBefore = testData.First(); actualBefore.Should().NotBeEquivalentTo(expectedCurrencyData); var id = actualBefore.PairId; await _bittrexService.UpdatedPairByIdAsync(id, expectedCurrencyData); var actualAfter = await TestApiDbContext.Pairs.SingleAsync(x => x.PairId == id); actualAfter.Should().BeEquivalentTo(expectedCurrencyData); }
/// <summary> /// Обновляет информацию о валютной паре. /// </summary> /// <param name="id">Идентификатор записи.</param> /// <param name="data">Информация о валютной паре.</param> /// <returns>Обновленная информация о валютной паре.</returns> public async Task <PairData> UpdatedPairByIdAsync(long id, CreateOrUpdateCurrencyData data) { var pairToModify = await _apiDbContext.Pairs.SingleOrDefaultAsync(x => x.PairId == id); if (pairToModify == null) { throw new DataBaseException("Could not update"); } _apiDbContext.Entry(pairToModify).CurrentValues.SetValues(data); _apiDbContext.SaveChanges(); return(await _apiDbContext.Pairs.SingleAsync(x => x.PairId == id)); }
/// <summary> /// Добавляет информацию о валютной паре. /// </summary> /// <param name="data">Информация о валютной паре.</param> /// <returns>Идентификатор созданной записи.</returns> public async Task <long> AddPairDataAsync(CreateOrUpdateCurrencyData data) { var pairToAdd = new PairData { PairName = data.PairName, BuyPrice = data.BuyPrice, SellPrice = data.SellPrice, LastTradePrice = data.LastTradePrice, HighPrice = data.HighPrice, LowPrice = data.LowPrice, Volume = data.Volume, Updated = data.Updated }; await _apiDbContext.Pairs.AddAsync(pairToAdd); await _apiDbContext.SaveChangesAsync(); return(pairToAdd.PairId); }
public async Task AddPairDataAsync_CorrectData_AddsEntry() { var testDate = new DateTime(2020, 9, 9); var expectedCurrencyData = new CreateOrUpdateCurrencyData { PairName = "XRP-USD", BuyPrice = 254.0m, SellPrice = 254.0m, LastTradePrice = 254.0m, HighPrice = 254.0m, LowPrice = 254.0m, Volume = 1234567, Updated = testDate }; var actualBefore = await TestApiDbContext.Pairs.ToListAsync(); var actualId = await _bittrexService.AddPairDataAsync(expectedCurrencyData); var actualAfter = await TestApiDbContext.Pairs.SingleAsync(); actualBefore.Should().BeEmpty(); actualAfter.PairId.Should().Be(actualId); actualAfter.Should().BeEquivalentTo(expectedCurrencyData); }
public Task <PairData> UpdatedPairById(long id, CreateOrUpdateCurrencyData data) { return(_bittrexService.UpdatedPairByIdAsync(id, data)); }
public Task <long> AddPairData(CreateOrUpdateCurrencyData data) { return(_bittrexService.AddPairDataAsync(data)); }