public async Task Should_Return_Exception_When_Symbol_Not_Exists_In_Exchange_Async() { TickerPrice ticker = null; var symbol = "nuncaterajsdhjkdhsajkdh"; var cacheMock = new Mock <IExchangeIntegrationCache>(MockBehavior.Strict); cacheMock.Setup(repo => repo.GetAsync <TickerPrice>(ExchangesIntegratedType.Binance, symbol)) .ReturnsAsync(ticker); cacheMock.Setup(c => c.AddAsync(It.IsAny <IEnumerable <TickerPrice> >(), ExchangesIntegratedType.Binance, It.IsAny <Func <TickerPrice, string> >())) .Returns(Task.CompletedTask); var clientMock = new Mock <IBinanceIntegrationClient>(MockBehavior.Strict); clientMock.Setup(c => c.GetTickerPricesAsync()) .ReturnsAsync(new[] { new TickerPrice { Price = "1", Symbol = "LTCBTC" } }); var strategy = new BinanceIntegrationStrategy(cacheMock.Object, clientMock.Object); var ex = await Assert.ThrowsAsync <InvalidOperationException>(async() => await strategy.GetCurrentPriceAsync("nuncatera", "jsdhjkdhsajkdh")); Assert.Equal($"symbol {symbol} not exists in Binance", ex.Message); }
public async Task Should_Return_Price_Async() { TickerPrice ticker = null; var symbol = "LTCBTC"; var cacheMock = new Mock <IExchangeIntegrationCache>(MockBehavior.Strict); cacheMock.Setup(repo => repo.GetAsync <TickerPrice>(ExchangesIntegratedType.Binance, symbol)) .ReturnsAsync(ticker); cacheMock.Setup(c => c.AddAsync(It.IsAny <IEnumerable <TickerPrice> >(), ExchangesIntegratedType.Binance, It.IsAny <Func <TickerPrice, string> >())) .Returns(Task.CompletedTask); var clientMock = new Mock <IBinanceIntegrationClient>(MockBehavior.Strict); clientMock.Setup(c => c.GetTickerPricesAsync()) .ReturnsAsync(new[] { new TickerPrice { Price = "1", Symbol = symbol } }); var strategy = new BinanceIntegrationStrategy(cacheMock.Object, clientMock.Object); var price = await strategy.GetCurrentPriceAsync("LTC", "BTC"); Assert.True(price > 0); }