-
Notifications
You must be signed in to change notification settings - Fork 648
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* resolve storage session per call * only dispose session once * approve scope change in test * change registration back to same scope as the referenced type
- Loading branch information
1 parent
a35bc1d
commit b693bac
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...ests/Reliability/SynchronizedStorage/CompletableSynchronizedStorageSessionAdapterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
namespace NServiceBus.Core.Tests.Reliability | ||
{ | ||
using System.Threading.Tasks; | ||
using Extensibility; | ||
using NServiceBus.Outbox; | ||
using NServiceBus.Persistence; | ||
using NUnit.Framework; | ||
using Transport; | ||
|
||
[TestFixture] | ||
public class CompletableSynchronizedStorageSessionAdapterTests | ||
{ | ||
[Test] | ||
public async Task Should_dispose_adapted_session_only_once() | ||
{ | ||
var storageAdapter = new FakeStorageAdapter(); | ||
var sessionAdapter = new CompletableSynchronizedStorageSessionAdapter(storageAdapter, null); | ||
await sessionAdapter.TryOpen(new TransportTransaction(), new ContextBag()); | ||
|
||
sessionAdapter.Dispose(); | ||
sessionAdapter.Dispose(); | ||
|
||
Assert.AreEqual(1, storageAdapter.StorageSession.DisposeCounter); | ||
} | ||
} | ||
|
||
public class FakeStorageAdapter : ISynchronizedStorageAdapter | ||
{ | ||
public FakeStorageSession StorageSession { get; } = new FakeStorageSession(); | ||
|
||
public Task<CompletableSynchronizedStorageSession> TryAdapt(OutboxTransaction transaction, ContextBag context) => Task.FromResult<CompletableSynchronizedStorageSession>(StorageSession); | ||
|
||
public Task<CompletableSynchronizedStorageSession> TryAdapt(TransportTransaction transportTransaction, ContextBag context) => Task.FromResult<CompletableSynchronizedStorageSession>(StorageSession); | ||
} | ||
|
||
public class FakeStorageSession : CompletableSynchronizedStorageSession | ||
{ | ||
public int DisposeCounter { get; private set; } | ||
|
||
public void Dispose() => DisposeCounter++; | ||
|
||
public Task CompleteAsync() => Task.FromResult(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters