Skip to content

Commit 7cd0c33

Browse files
committed
Unit test that reproduces the problem.
1 parent 1b871a0 commit 7cd0c33

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/Components/Components/test/OwningComponentBaseTest.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,33 @@ public MyService(Counter counter)
111111
void IDisposable.Dispose() => Counter.DisposedCount++;
112112
}
113113

114+
[Fact]
115+
public async Task DisposeAsync_CallsDispose_WithDisposingTrue()
116+
{
117+
var services = new ServiceCollection();
118+
services.AddTransient<MyService>();
119+
var serviceProvider = services.BuildServiceProvider();
120+
121+
var renderer = new TestRenderer(serviceProvider);
122+
var component = (ComponentWithDispose)renderer.InstantiateComponent<ComponentWithDispose>();
123+
124+
_ = component.MyService;
125+
await ((IAsyncDisposable)component).DisposeAsync();
126+
Assert.True(component.DisposingParameter);
127+
}
128+
129+
private class ComponentWithDispose : OwningComponentBase<MyService>
130+
{
131+
public MyService MyService => Service;
132+
public bool? DisposingParameter { get; private set; }
133+
134+
protected override void Dispose(bool disposing)
135+
{
136+
DisposingParameter = disposing;
137+
base.Dispose(disposing);
138+
}
139+
}
140+
114141
private class MyOwningComponent : OwningComponentBase<MyService>
115142
{
116143
public MyService MyService => Service;

0 commit comments

Comments
 (0)