コード例 #1
0
        private void AssertThrowsPoeTradeApiCommunicationExceptionIfHttpResponseDoesNotReturnSuccessStatusCode(AsyncTestDelegate asyncTestDelegate, string endpoint, string jsonContent = "")
        {
            HttpStatusCode httpStatusCode = HttpStatusCode.BadRequest;

            HttpResponseMessage httpResponse = new HttpResponseMessage
            {
                Content    = new StringContent(""),
                StatusCode = httpStatusCode
            };

            this.poeTradeApiJsonSerializerMock.Setup(x => x.Serialize(It.IsAny <SearchQueryRequest>()))
            .Returns(jsonContent);
            this.httpClientWrapperMock.Setup(x => x.GetAsync(It.Is <string>(s => s.Contains(endpoint)), It.IsAny <CancellationToken>()))
            .ReturnsAsync(httpResponse);
            this.httpClientWrapperMock.Setup(x => x.PostAsync(It.Is <string>(s => s.Contains(endpoint)), It.IsAny <HttpContent>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(httpResponse);

            PoeTradeApiCommunicationException exception = Assert.CatchAsync <PoeTradeApiCommunicationException>(asyncTestDelegate);

            Assert.That(exception.Message, Contains.Substring(httpStatusCode.ToString()));
            Assert.That(exception.Message, Contains.Substring(endpoint));

            if (!string.IsNullOrEmpty(jsonContent))
            {
                Assert.That(exception.Message, Contains.Substring(jsonContent));
            }
        }
コード例 #2
0
        private void GetListingsAsyncShouldThrowPoeTradeApiCommunicationExceptionIfAnyExceptionOccurs(AsyncTestDelegate asyncTestDelegate)
        {
            Exception expectedInnerException = new Exception();

            this.poeTradeApiJsonSerializerMock.Setup(x => x.Deserialize <SearchQueryResult>(It.IsAny <string>()))
            .Throws(expectedInnerException);

            PoeTradeApiCommunicationException exception = Assert.CatchAsync <PoeTradeApiCommunicationException>(asyncTestDelegate);

            Assert.That(exception.InnerException, Is.EqualTo(expectedInnerException));
        }