Skip to content

Commit

Permalink
Merge pull request #24 from Particular/testablestoragesession
Browse files Browse the repository at this point in the history
Introduce TestableSynchronizedStorageSession
  • Loading branch information
boblangley authored Sep 24, 2019
2 parents 38a301a + 8da8019 commit 95df43a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ namespace NServiceBus
{
public static MongoDB.Driver.IClientSessionHandle GetClientSession(this NServiceBus.Persistence.SynchronizedStorageSession session) { }
}
}
namespace NServiceBus.Testing
{
public class TestableMongoSynchronizedStorageSession : NServiceBus.Persistence.SynchronizedStorageSession
{
public TestableMongoSynchronizedStorageSession(MongoDB.Driver.IClientSessionHandle clientSessionHandle) { }
public MongoDB.Driver.IClientSessionHandle MongoSession { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace NServiceBus.Storage.MongoDB
{
using global::MongoDB.Driver;

interface IMongoSessionProvider
{
IClientSessionHandle MongoSession { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Logging;
using Persistence;

class StorageSession : CompletableSynchronizedStorageSession
class StorageSession : CompletableSynchronizedStorageSession, IMongoSessionProvider
{
public StorageSession(IClientSessionHandle mongoSession, string databaseName, ContextBag contextBag, Func<Type, string> collectionNamingConvention, bool ownsMongoSession)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static IClientSessionHandle GetClientSession(this SynchronizedStorageSess
{
Guard.AgainstNull(nameof(session), session);

if (session is StorageSession storageSession)
if (session is IMongoSessionProvider storageSession)
{
return storageSession.MongoSession;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace NServiceBus.Testing
{
using MongoDB.Driver;
using Persistence;
using Storage.MongoDB;

/// <summary>
/// A fake implementation for <see cref="SynchronizedStorageSession"/> for testing purposes.
/// </summary>
public class TestableMongoSynchronizedStorageSession : SynchronizedStorageSession, IMongoSessionProvider
{
/// <summary>
/// Creates a new instance of <see cref="TestableMongoSynchronizedStorageSession"/> using the provided <see cref="IClientSessionHandle"/>.
/// </summary>
/// <param name="clientSessionHandle"></param>
public TestableMongoSynchronizedStorageSession(IClientSessionHandle clientSessionHandle)
{
MongoSession = clientSessionHandle;
}

/// <summary>
/// The client session handle which is retrieved by calling <see cref="SynchronizedStorageSessionExtensions.GetClientSession"/>.
/// </summary>
public IClientSessionHandle MongoSession { get; }
}
}

0 comments on commit 95df43a

Please sign in to comment.