Answer the question
In order to leave comments, you need to log in
How to fix an integration test error?
I am writing an integration test, but I get an error 500. Even if I change the URL to another one. I think I did the wrong setting. if I write the test in a different way, then the
setting reacts to a different URL.
public UnitTest1()
{
var server = new TestServer(new WebHostBuilder()
.UseEnvironment("Development")
.UseStartup<Startup>());
_client = server.CreateClient();
}
[Theory]
[InlineData("Get")]
public async Task Test1(string method)
{
_client.BaseAddress = new Uri("https://localhost:44320");
//Arrange
var request = new HttpRequestMessage(HttpMethod.Get, "/");
//Act
var response = await _client.SendAsync(request);
//Assert
response.EnsureSuccessStatusCode();// status code 500
Assert.Equal(HttpStatusCode.OK,response.StatusCode);
}
HttpWebRequest requestSecond = (HttpWebRequest)WebRequest.Create("https://localhost:44320");
HttpWebResponse responseSecond = (HttpWebResponse)requestSecond.GetResponse();
var statusCodeSecond = responseSecond.StatusCode; // код 200 если проект запущен
Answer the question
In order to leave comments, you need to log in
Well the problem is 100% somewhere in the code.
500 code is an internal server error, which means that an exception is falling somewhere, you need to debug and read the logs.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question