In my test method, I want to test context.T.AddAsync
method and Its output.
Below is the code for the method.
var addRequest = await _context.AddAsync<Request>(requestEntity, cancellationToken);
if (addRequest.State == Microsoft.EntityFrameworkCore.EntityState.Added)
{
Console.WriteLine("Added: " + user.Requests.Count);
saveChanges = await _context.SaveChangesAsync(cancellationToken);
}
else
{
//handle failed AddAsync of the requestEntity
}
Since the result of AddAsync
method is being used after that, I have to define a response for that in my test method. Type of addRequest
is
Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<Request>
For that, I use A.CallTo
, and below is the test method
A.CallTo(() => _request.AddAsync(A<Request>.Ignored, new CancellationToken())).Returns(_addAsyncResponse);
The problem is, I can't figure out how to create the _addAsyncResponse
object. I tried with
_addAsyncResponse = new EntityEntry<Request>() { };
and it's not working.