Esempio n. 1
0
        public async Task GetCurrency_ShouldBeReturnCotizationAvailableFalseAndOk_WhenTrmDoesNotHaveInformation()
        {
            var dateTime = new DateTime(2020, 02, 05);

            _httpMessageHandlerMock.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent("[]")
            });

            _httpClientFactoryMock.Setup(_ => _.CreateClient(It.IsAny <string>()))
            .Returns(_httpClient);

            var slackHookServiceMock = new Mock <ISlackHooksService>();
            var trmHandler           = new TrmHandler(
                _httpClientFactoryMock.Object,
                new HttpClientPoliciesSettings
            {
                ClientName = "test"
            },
                _mockUsdCurrencySettings.Object,
                slackHookServiceMock.Object,
                Mock.Of <ILogger <CurrencyHandler> >());

            var result = await trmHandler.Handle(dateTime);

            Assert.True(result.Success);
            Assert.False(result.Entity.CotizationAvailable);
        }
Esempio n. 2
0
        public async Task GetCurrency_ShouldBeReturnCurrencyOk_WhenTrmHasInformation()
        {
            var dateTime = new DateTime(2020, 02, 05);

            _httpMessageHandlerMock.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent("[{\"valor\":\"3783.15\",\"vigenciadesde\":\"2020-02-05T00: 00:00.000\",\"vigenciahasta\":\"2020-02-05T00: 00:00.000\"}]")
            });

            _httpClientFactoryMock.Setup(_ => _.CreateClient(It.IsAny <string>()))
            .Returns(_httpClient);

            var trmHandler = new TrmHandler(
                _httpClientFactoryMock.Object,
                new HttpClientPoliciesSettings
            {
                ClientName = "test"
            },
                _mockUsdCurrencySettings.Object,
                Mock.Of <ISlackHooksService>(),
                Mock.Of <ILogger <CurrencyHandler> >());

            var result = await trmHandler.Handle(dateTime);

            Assert.True(result.Success);
            Assert.True(result.Entity.CotizationAvailable);
            Assert.Equal("2020-02-05", result.Entity.Date);
            Assert.Equal("Peso Colombiano", result.Entity.CurrencyName);
            Assert.Equal("COP", result.Entity.CurrencyCode);
        }