示例#1
0
        public async Task <PoePricesInfoPrediction> GetPricePredictionAsync(string league, string itemText, CancellationToken cancellationToken = default)
        {
            PoePricesInfoPrediction result = null;

            if (string.IsNullOrEmpty(league) || string.IsNullOrEmpty(itemText))
            {
                return(result);
            }

            try
            {
                var url = GetUrl(league, itemText);
                System.Net.Http.HttpResponseMessage httpResponse = await this.httpClient.GetAsync(url, cancellationToken).ConfigureAwait(false);

                if (httpResponse.IsSuccessStatusCode)
                {
                    string jsonResult = await httpResponse.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);

                    result = this.jsonSerializer.Deserialize <PoePricesInfoPrediction>(jsonResult, new JsonSerializerOptions {
                        PropertyNamingPolicy = new JsonSnakeCaseNamingPolicy()
                    });
                }
                else
                {
                    this.logger.LogError("Poeprices.info api returned non success status code for league {@league} and item text {@itemText}. Response: {@response}", league, itemText, httpResponse);
                }
            }
            catch (Exception exception) when(exception is not OperationCanceledException)
            {
                this.logger.LogError(exception, "Failed to get price prediction in league {@league} with item text {@itemText}.", league, itemText);
            }

            return(result);
        }
        public async Task GetPricePredictionAsyncShouldReturnNullIf(string league, string itemText)
        {
            // act
            PoePricesInfoPrediction result = await this.poePricesInfoClient.GetPricePredictionAsync(league, itemText);

            // assert
            Assert.IsNull(result);
        }
示例#3
0
        private PoePricesInfoPrediction MockPoePricesInfoClient()
        {
            PoePricesInfoPrediction poePricesInfoPrediction = GetPoePricesInfoItem();

            this.poePricesInfoClientMock.Setup(x => x.GetPricePredictionAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(poePricesInfoPrediction);

            return(poePricesInfoPrediction);
        }
示例#4
0
        public async Task HandleShouldSetValueOnCacheEntry()
        {
            // arrange
            PoePricesInfoPrediction poePricesInfoPrediction = this.MockPoePricesInfoClient();

            // act
            await this.handler.Handle(this.validRequest, default);

            // assert
            this.cacheEntryMock.VerifySet(x => x.Value = poePricesInfoPrediction);
        }
        public async Task GetPricePredictionAsyncShouldReturnNullIfExceptionIsThrown()
        {
            // arrange
            this.httpClientMock
            .Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Throws <Exception>();

            // act
            PoePricesInfoPrediction result = await this.poePricesInfoClient.GetPricePredictionAsync("Heist", "Scroll of Wisdom");

            // assert
            Assert.IsNull(result);
        }
        public async Task GetPricePredictionAsyncShouldReturnResultFromJsonSerializer()
        {
            // arrange
            var expected = new PoePricesInfoPrediction
            {
                Min             = 0.15m,
                Max             = 0.25m,
                Currency        = "chaos",
                ConfidenceScore = 0.89744m
            };

            this.jsonSerializerMock.Setup(x => x.Deserialize <PoePricesInfoPrediction>(It.IsAny <string>(), It.IsAny <JsonSerializerOptions>()))
            .Returns(expected);

            // act
            PoePricesInfoPrediction result = await this.poePricesInfoClient.GetPricePredictionAsync("Heist", "Scroll of Wisdom");

            // assert
            Assert.That(result, Is.EqualTo(expected));
        }