Reputation: 33
I am getting below errors while executing my integration test for one of method to post the data in the dynamics crm. This is the first time i am writing integration test where my project is web api using to swagger and some of the azure resources like key vault, active directory.
While executing the Get call it seems to run fine all the steps are performed and getting results as well. But for Post call i can see the call is successful and database is inserted record for the latest call but while returning execustion point back to my integration test from my PostAsync method it fails in between.
Below is the error:
Message:
System.IO.IOException : The request was aborted or the pipeline has finished
Stack Trace:
ResponseStream.CheckNotComplete()
ResponseStream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
ErrorHandller.InvokeAsync(HttpContext context)
AuthenticationMiddleware.Invoke(HttpContext context)
StaticFileMiddleware.Invoke(HttpContext context)
SwaggerUIMiddleware.Invoke(HttpContext httpContext)
SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
CorrelationIdMiddleware.Invoke(HttpContext context, ICorrelationContextFactory correlationContextFactory)
<<SendAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
ClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
GeoIntegrationTest.Test_AddState() line 72
--- End of stack trace from previous location where exception was thrown ---
and the code is as below
public async Task Test_AddState()
{
try
{
var data = new StateRequestModel
{
StateCode = "AL",
Name ="Alabama",
}
};
ByteArrayContent byteContent = BuildRequestObject(data);
var response = await httpClient.PostAsync("api/Geo/AddState", byteContent);
var result = response?.Content.ReadAsStringAsync().Result;
var addStateReposne = (ResponseModel<List<string>>) JsonConvert.DeserializeObject(result);
Assert.NotNull(result);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
catch (Exception ex)
{
throw;
}
}
Please help me to fix this issue and advice me if i can improve the code quality.
Upvotes: 2
Views: 871
Reputation: 33
So, I got it resolved myself only. The problem was with the Timeout due to some long running process which was running more than default timeout of the HttpClient object.
client.Timeout = System.TimeSpan.FromMinutes(5);
Thanks everyone!!!
Upvotes: 1