'EF Core with xunit, Function behaviour different than in controller
I have set up a little test with xunit to test if a certain row in my test database is not there when I query for it. Here is the test:
[Fact]
public async Task GetApplication_ResultEmpty()
{
Application application = await _applicationFunctions.GetApplicationByIdAsync(1010);
Console.WriteLine("Application:" + application);
Console.WriteLine("ApplicationID: " + application.Id);
Assert.Null(application);
}
The GetApplicationById function returns null if it doesnt find anything in the database. Here is a short version of it:
public async Task<Application> GetApplicationByIdAsync(int id)
{
using(var dbContext = _dbContextFactory.CreateDbContext())
{
List<Application> ApplicationList = await dbContext.Applications.FromSqlRaw("Exec dbo.GetApplication {0}", id).ToListAsync();
if (ApplicationList.Any())
{
//call some stored procedures...
return Application;
}
}
return null;
}
I return null if the result is empty. When I debug the Object of type Application inside my controller is set to null correctly. In my test the Assert.Null fails and says that the actual value is this:
Actual:
Application
{
Applicants = null,
ApplicationComments = null,
ApplicationNumber = null,
ApplicationRelStates = null,
ApplicationUuid = null, ...
}
What am I doing wrong here? Sepcifically I want to test if the Object itself is null.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
