Skip to content
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

Support services that implement IAsyncDisposable #249

Closed
jmaillet opened this issue Nov 3, 2020 · 4 comments · Fixed by #292
Closed

Support services that implement IAsyncDisposable #249

jmaillet opened this issue Nov 3, 2020 · 4 comments · Fixed by #292
Labels
enhancement New feature or request needs design More design is needed before this issue should result in a feature being implemented.

Comments

@jmaillet
Copy link

jmaillet commented Nov 3, 2020

Can TestContext and/or TestServiceProvider be made to implement IAsyncDisposable?

Is your feature request related to a problem? Please describe.
I'm getting an exception on my test TearDown method, where I'm calling _context?.Dispose()
System.InvalidOperationException : 'MyService' type only implements IAsyncDisposable. Use DisposeAsync to dispose the container.

I believe this related to #233. The MyService type uses an IJSObjectReference internally and so it implements IAsyncDisposable

@egil egil added .net5 enhancement New feature or request needs design More design is needed before this issue should result in a feature being implemented. and removed .net5 labels Nov 4, 2020
@egil
Copy link
Member

egil commented Nov 4, 2020

Yes, that should not be a problem. Thanks for bringing this to my attention.

Can you help with a test and component that causes this error?

@jmaillet
Copy link
Author

Sorry for the delayed response. Yes, I can do that. Happy to help.

Can I assume the component would go under Bunit.TestAssets.SampleComponents?
Where would you like the actual test to go, Bunit.Web.Tests or Bunit.Core.Tests?

@egil
Copy link
Member

egil commented Nov 12, 2020

Just post them here as code snippets or attach a small runnable project here that I can try locally. Then I will add the needed test cases to bUnit 🙂

@jmaillet
Copy link
Author

No problem, here you go:
Service:

public class AsyncDisposableService : IAsyncDisposable
{
  public ValueTask DisposeAsync() => ValueTask.CompletedTask;
}

Component:

<h3>ComponentWithAsyncDisposableService</h3>
@inject AsyncDisposableService Service

@code { }

Failing Test:

var context = new TestContext();
context.Services.AddScoped<AsyncDisposableService>();
var component = context.RenderComponent<ComponentWithAsyncDisposableService>();

// throwsSystem.InvalidOperationException : 'AsyncDisposableService' type only implements IAsyncDisposable. Use DisposeAsync to dispose the container.
context.Dispose();

@egil egil linked a pull request Dec 19, 2020 that will close this issue
9 tasks
@egil egil closed this as completed Dec 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs design More design is needed before this issue should result in a feature being implemented.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants