public async Task GetHistoryRatesForGivenPeriodsAsync_WhenModelIsValid_ShouldReturnOk() { var sut = new ExchangeRatesController( new Logger <ExchangeRatesController>(new LoggerFactory()), new ExchangeRatesManagement(new HttpClient())); var result = await sut.GetHistoryRatesForGivenPeriodsAsync(new HistoryRatesRequest(new [] { new DateTime(2018, 1, 1), DateTime.Now }, "USD", "EUR")); Assert.IsType <OkObjectResult>(result); }
public async Task GetHistoryRatesForGivenPeriodsAsync_WhenDateIsInFuture_ShouldReturnBadRequest() { var loggerMock = new Mock <ILogger <ExchangeRatesController> >(); var exchangeRatesManagement = new ExchangeRatesManagement(new Mock <HttpClient>().Object); var sut = new ExchangeRatesController(loggerMock.Object, exchangeRatesManagement); var result = await sut.GetHistoryRatesForGivenPeriodsAsync(new HistoryRatesRequest(new [] { DateTime.Now.AddDays(1) }, "EUR", "EUR")); Assert.IsType <BadRequestObjectResult>(result); }
public async Task GetHistoryRatesForGivenPeriodsAsync_WhenTargetCurrencyIsInvalid_ShouldReturnBadRequest(string targetCurrency) { var loggerMock = new Mock <ILogger <ExchangeRatesController> >(); var exchangeRatesManagement = new ExchangeRatesManagement(new Mock <HttpClient>().Object); var sut = new ExchangeRatesController(loggerMock.Object, exchangeRatesManagement); var result = await sut.GetHistoryRatesForGivenPeriodsAsync(new HistoryRatesRequest(new [] { DateTime.Now }, "EUR", targetCurrency )); Assert.IsType <BadRequestObjectResult>(result); }
public async Task GetHistoryRatesForGivenPeriodsAsync_WhenBManagementThrowsException_ShouldReturnBadRequest() { var loggerMock = new Mock <ILogger <ExchangeRatesController> >(); var exchangeRatesManagementMock = new Mock <IExchangeRatesManagement>(); exchangeRatesManagementMock .Setup(x => x.GetRatesForGivenPeriodsAsync(It.IsAny <HistoryRatesRequest>())) .Throws <Exception>(); var sut = new ExchangeRatesController(loggerMock.Object, exchangeRatesManagementMock.Object); var result = await sut.GetHistoryRatesForGivenPeriodsAsync(It.IsAny <HistoryRatesRequest>()); Assert.IsType <BadRequestObjectResult>(result); }
public async Task GetHistoryRatesForGivenPeriodsAsync_WhenArgumentIsNull_ShouldReturnBadRequest() { var result = await _sut.GetHistoryRatesForGivenPeriodsAsync(null); Assert.IsType <BadRequestObjectResult>(result); }