public async Task Return_CustomResponseObject_WhenCallIsFailed() { HttpResponseMessage httpResponseMessage = new HttpResponseMessage() { StatusCode = HttpStatusCode.BadRequest, }; Example example = new Example(); HandlerMock .Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(httpResponseMessage); DilibHttpClientResponse <Example> result = await DiLibHttpClient.DeleteAsync <Example>( AbsoluteUri, example) .ConfigureAwait(false); result.Should().BeOfType <DilibHttpClientResponse <Example> >(); result.IsSuccess.Should().BeFalse(); result.HttpStatusCode.Should().Be((int)HttpStatusCode.BadRequest); result.Exception.Should().BeOfType <HttpRequestException>(); }
public async Task Return_CustomResponseObject_WhenCallIsSuccessful() { HttpResponseMessage httpResponseMessage = new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent(@"{ ""result"":""success""}"), }; HandlerMock .Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(httpResponseMessage); DilibHttpClientResponse <ExampleResult> exampleResult = await DiLibHttpClient.GetAsync <ExampleResult>( AbsoluteUri) .ConfigureAwait(false); exampleResult.Should().BeOfType <DilibHttpClientResponse <ExampleResult> >(); exampleResult.IsSuccess.Should().BeTrue(); exampleResult.HttpStatusCode.Should().Be((int)HttpStatusCode.OK); exampleResult.Result.Should().BeOfType <ExampleResult>(); exampleResult.Result.Result.Should().Be("success"); }