D
D
DD-var2021-07-03 23:38:12
ASP.NET
DD-var, 2021-07-03 23:38:12

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();
        }

Test:

[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);

        }

Test 2:
HttpWebRequest requestSecond = (HttpWebRequest)WebRequest.Create("https://localhost:44320"); 
            HttpWebResponse responseSecond = (HttpWebResponse)requestSecond.GetResponse(); 
              var statusCodeSecond = responseSecond.StatusCode; // код 200 если проект запущен

here is the screenshot:60e0caaeab43e068063861.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-07-04
@vabka

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 question

Ask a Question

731 491 924 answers to any question