I got an dotnet project and i was building an implementation test routine
Here is my code:
Base->BaseProject->Controllers->SensorController
[Route("[controller]")]
[ApiController]
public class SensorController : Controller
{
private readonly SensorContext _context;
public SensorController(SensorContext context)
{
_context = context;
}
[HttpGet("api/")]
public async Task<ActionResult<IEnumerable<Sensor>>> GetTodoItems()
{
return await _context.Sensor.ToListAsync();
}
}
And in my TestProject, I got this:
Base->TestProject->Fixtures->TestContext
public class TestContext
{
public HttpClient Client { get; private set; }
private TestServer _server;
public TestContext()
{
SetupClient();
}
private void SetupClient()
{
_server = new TestServer(new WebHostBuilder().UseStartup<Startup>());
Client = _server.CreateClient();
}
}
Base->TestProject->SensorApiTest.cs
public class SensorApiTest
{
private readonly TestContext _testContext;
public SensorApiTest()
{
_testContext = new TestContext();
}
[Fact]
public async Task Values_Get_ReturnsOkResponse()
{
var response = await _testContext.Client.GetAsync("/Sensor/api");
response.EnsureSuccessStatusCode();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
}
If i run the base project and send requests using insominia, i got the responses just fine. But running the TestProject with dotnet test return an 404 error. The dependencies off the project are working fine, i dont know why this do not run.
Can anyone help me? Thanks