New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async methods missing for FakeContext? #673
Comments
In the generated code, change one function within public TResult ExecuteAsync<TResult>(Expression expression, CancellationToken cancellationToken = new CancellationToken())
{
var expectedResultType = typeof(TResult).GetGenericArguments()[0];
var executionResult = typeof(IQueryProvider)
.GetMethod(
name: nameof(IQueryProvider.Execute),
genericParameterCount: 1,
types: new[] { typeof(Expression) })
.MakeGenericMethod(expectedResultType)
.Invoke(this, new[] { expression });
return (TResult) typeof(Task).GetMethod(nameof(Task.FromResult))
?.MakeGenericMethod(expectedResultType)
.Invoke(null, new[] { executionResult });
} Let me know if that works for you. In the mean time I will implement this in the generator. |
See changeset f0a8589 Grab the latest code for EF.Reverse.POCO.v3.ttinclude and update your project. |
Let me know if this does not work, and I will re-open this case. |
Simon - thanks for such a quick response! Your fix took care of 3 of my test cases, but one still fails - AddRangeAsync(). FirstOrDefaultAsync(), ToArrayAsync() and ToListAsync() all now work as expected. Here's the code for the failing AddRangeAsync() test: [Fact]
public async void FakeContextFactory_AddFourContactsWithAddRangeAsync_EnsureTheyWereAdded()
{
var list1 = new List<Contact>
{
new Contact { FirstName = "TestOne", LastName = "Test", ContactId = 1},
new Contact { FirstName = "TestTwo", LastName = "Test", ContactId = 2}
};
var list2 = new List<Contact>
{
new Contact { FirstName = "TestThree", LastName = "Test", ContactId = 3},
new Contact { FirstName = "TestFour", LastName = "Test", ContactId = 4}
};
var factory = new Project.Data.V5.Context.FakeProjectContextFactory();
var context = factory.CreateDbContext();
context.Contacts.AddRange(list1); // This works fine
await context.Contacts.AddRangeAsync(list2); // Crashes - exception below...
Assert.Equal(4, context.Contacts.Count());
} Exception:
|
@slee-accesso This is now fixed and will be in the next release. |
Released in v3.4.1 |
I've been trying to use the FakeDbContext, and it fails anytime I try to run async methods. The synchronous methods work - and the async methods do work against the "real" context, just not against the fake one.
Is there a setting I'm missing? Or is the generation code skipping the async methods? Here's the sample code I'm using in a unit test:
Exception:
This occurs for every async method I've tried (AddRangeAsync, query.ToArrayAsync(), query.ToListAsync(), etc.)
And help would be much appreciated! Thanks!
The text was updated successfully, but these errors were encountered: