Skip to content

Commit

Permalink
Use await in the Disposer Tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
alistairjevans authored and alexmg committed Oct 20, 2019
1 parent a40320c commit 9eee0ea
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions test/Autofac.Test/Core/DisposerTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Autofac.Core;
using Autofac.Test.Util;
using Xunit;
Expand Down Expand Up @@ -59,7 +59,7 @@ public void CannotAddObjectsToDisposerAfterSyncDispose()
}

[Fact]
public void DisposerDisposesOfObjectsAsyncIfIAsyncDisposableDeclared()
public async ValueTask DisposerDisposesOfObjectsAsyncIfIAsyncDisposableDeclared()
{
var instance = new AsyncDisposeTracker();

Expand All @@ -74,21 +74,21 @@ public void DisposerDisposesOfObjectsAsyncIfIAsyncDisposableDeclared()
Assert.False(instance.IsAsyncDisposed);

// Now we wait.
result.GetAwaiter().GetResult();
await result;

Assert.False(instance.IsSyncDisposed);
Assert.True(instance.IsAsyncDisposed);
}

[Fact]
public void DisposerDisposesOfObjectsSyncIfIDisposableOnly()
public async ValueTask DisposerDisposesOfObjectsSyncIfIDisposableOnly()
{
var instance = new DisposeTracker();

var disposer = new Disposer();
disposer.AddInstanceForDisposal(instance);
Assert.False(instance.IsDisposed);
disposer.DisposeAsync().GetAwaiter().GetResult();
await disposer.DisposeAsync();
Assert.True(instance.IsDisposed);
}

Expand All @@ -107,15 +107,15 @@ public void DisposerDisposesOfObjectsSyncIfIAsyncDisposableDeclaredButSyncDispos
}

[Fact]
public void CannotAddObjectsToDisposerAfterAsyncDispose()
public async ValueTask CannotAddObjectsToDisposerAfterAsyncDispose()
{
var instance = new AsyncDisposeTracker();

var disposer = new Disposer();
disposer.AddInstanceForDisposal(instance);
Assert.False(instance.IsSyncDisposed);
Assert.False(instance.IsAsyncDisposed);
disposer.DisposeAsync().GetAwaiter().GetResult();
await disposer.DisposeAsync();
Assert.False(instance.IsSyncDisposed);
Assert.True(instance.IsAsyncDisposed);

Expand All @@ -140,7 +140,7 @@ public void SyncDisposalOnObjectWithNoIDisposableThrows()
}

[Fact]
public void DisposerAsyncDisposesContainedInstances_InReverseOfOrderAdded()
public async ValueTask DisposerAsyncDisposesContainedInstances_InReverseOfOrderAdded()
{
var disposeOrder = new List<object>();

Expand All @@ -160,7 +160,7 @@ public void DisposerAsyncDisposesContainedInstances_InReverseOfOrderAdded()
disposer.AddInstanceForDisposal(syncInstance4);
disposer.AddInstanceForAsyncDisposal(asyncOnlyInstance2);

disposer.DisposeAsync().GetAwaiter().GetResult();
await disposer.DisposeAsync();

Assert.Collection(
disposeOrder,
Expand Down

0 comments on commit 9eee0ea

Please sign in to comment.