From d84e8696afc1b434b5fcd895f3c847dd91b4ec5b Mon Sep 17 00:00:00 2001 From: Bob Langley Date: Fri, 20 Sep 2019 11:38:39 +0200 Subject: [PATCH 1/5] Introduce TestableSynchronizedStorageSession --- .../APIApprovals.Approve.approved.txt | 8 ++++++ .../IExposeAMongoSession.cs | 7 ++++++ .../SynchronizedStorage/StorageSession.cs | 2 +- .../SynchronizedStorageSessionExtensions.cs | 2 +- .../TestableSynchronizedStorageSession.cs | 25 +++++++++++++++++++ 5 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 src/NServiceBus.Storage.MongoDB/SynchronizedStorage/IExposeAMongoSession.cs create mode 100644 src/NServiceBus.Storage.MongoDB/Testing/TestableSynchronizedStorageSession.cs diff --git a/src/NServiceBus.Storage.MongoDB.Tests/ApprovalFiles/APIApprovals.Approve.approved.txt b/src/NServiceBus.Storage.MongoDB.Tests/ApprovalFiles/APIApprovals.Approve.approved.txt index c9b12791..4870e382 100644 --- a/src/NServiceBus.Storage.MongoDB.Tests/ApprovalFiles/APIApprovals.Approve.approved.txt +++ b/src/NServiceBus.Storage.MongoDB.Tests/ApprovalFiles/APIApprovals.Approve.approved.txt @@ -22,4 +22,12 @@ namespace NServiceBus { public static MongoDB.Driver.IClientSessionHandle GetClientSession(this NServiceBus.Persistence.SynchronizedStorageSession session) { } } +} +namespace NServiceBus.Storage.MongoDB.Testing +{ + public class TestableSynchronizedStorageSession : NServiceBus.Persistence.SynchronizedStorageSession + { + public TestableSynchronizedStorageSession(MongoDB.Driver.IClientSessionHandle clientSessionHandle) { } + public MongoDB.Driver.IClientSessionHandle MongoSession { get; } + } } \ No newline at end of file diff --git a/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/IExposeAMongoSession.cs b/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/IExposeAMongoSession.cs new file mode 100644 index 00000000..66a38f23 --- /dev/null +++ b/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/IExposeAMongoSession.cs @@ -0,0 +1,7 @@ +namespace NServiceBus.Storage.MongoDB +{ + interface IExposeAMongoSession + { + global::MongoDB.Driver.IClientSessionHandle MongoSession { get; } + } +} diff --git a/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/StorageSession.cs b/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/StorageSession.cs index fcd90761..1e6b3254 100644 --- a/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/StorageSession.cs +++ b/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/StorageSession.cs @@ -8,7 +8,7 @@ using Logging; using Persistence; - class StorageSession : CompletableSynchronizedStorageSession + class StorageSession : CompletableSynchronizedStorageSession, IExposeAMongoSession { public StorageSession(IClientSessionHandle mongoSession, string databaseName, ContextBag contextBag, Func collectionNamingConvention, bool ownsMongoSession) { diff --git a/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/SynchronizedStorageSessionExtensions.cs b/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/SynchronizedStorageSessionExtensions.cs index 2e62e2cc..0bb83d35 100644 --- a/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/SynchronizedStorageSessionExtensions.cs +++ b/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/SynchronizedStorageSessionExtensions.cs @@ -17,7 +17,7 @@ public static IClientSessionHandle GetClientSession(this SynchronizedStorageSess { Guard.AgainstNull(nameof(session), session); - if (session is StorageSession storageSession) + if (session is IExposeAMongoSession storageSession) { return storageSession.MongoSession; } diff --git a/src/NServiceBus.Storage.MongoDB/Testing/TestableSynchronizedStorageSession.cs b/src/NServiceBus.Storage.MongoDB/Testing/TestableSynchronizedStorageSession.cs new file mode 100644 index 00000000..0ff406ba --- /dev/null +++ b/src/NServiceBus.Storage.MongoDB/Testing/TestableSynchronizedStorageSession.cs @@ -0,0 +1,25 @@ +namespace NServiceBus.Storage.MongoDB.Testing +{ + using global::MongoDB.Driver; + using NServiceBus.Persistence; + + /// + /// A fake implementation for for testing purposes. + /// + public class TestableSynchronizedStorageSession : SynchronizedStorageSession, IExposeAMongoSession + { + /// + /// Creates a new instance of using the provided . + /// + /// + public TestableSynchronizedStorageSession(IClientSessionHandle clientSessionHandle) + { + MongoSession = clientSessionHandle; + } + + /// + /// The client session handle which is retrieved by calling . + /// + public IClientSessionHandle MongoSession { get; } + } +} From 0d772cb272a9a327919ece83e14c298827c13762 Mon Sep 17 00:00:00 2001 From: Bob Langley Date: Fri, 20 Sep 2019 14:51:59 +0200 Subject: [PATCH 2/5] Fix the namespace for TestableSynchronizedStorageSession --- .../ApprovalFiles/APIApprovals.Approve.approved.txt | 2 +- .../Testing/TestableSynchronizedStorageSession.cs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/NServiceBus.Storage.MongoDB.Tests/ApprovalFiles/APIApprovals.Approve.approved.txt b/src/NServiceBus.Storage.MongoDB.Tests/ApprovalFiles/APIApprovals.Approve.approved.txt index 4870e382..1c2fbe65 100644 --- a/src/NServiceBus.Storage.MongoDB.Tests/ApprovalFiles/APIApprovals.Approve.approved.txt +++ b/src/NServiceBus.Storage.MongoDB.Tests/ApprovalFiles/APIApprovals.Approve.approved.txt @@ -23,7 +23,7 @@ namespace NServiceBus public static MongoDB.Driver.IClientSessionHandle GetClientSession(this NServiceBus.Persistence.SynchronizedStorageSession session) { } } } -namespace NServiceBus.Storage.MongoDB.Testing +namespace NServiceBus.Testing { public class TestableSynchronizedStorageSession : NServiceBus.Persistence.SynchronizedStorageSession { diff --git a/src/NServiceBus.Storage.MongoDB/Testing/TestableSynchronizedStorageSession.cs b/src/NServiceBus.Storage.MongoDB/Testing/TestableSynchronizedStorageSession.cs index 0ff406ba..0e404286 100644 --- a/src/NServiceBus.Storage.MongoDB/Testing/TestableSynchronizedStorageSession.cs +++ b/src/NServiceBus.Storage.MongoDB/Testing/TestableSynchronizedStorageSession.cs @@ -1,7 +1,8 @@ -namespace NServiceBus.Storage.MongoDB.Testing +namespace NServiceBus.Testing { - using global::MongoDB.Driver; - using NServiceBus.Persistence; + using MongoDB.Driver; + using Persistence; + using Storage.MongoDB; /// /// A fake implementation for for testing purposes. From e55086b2af7ce0b6ba5a8da80bfd4ee1e3c18b7a Mon Sep 17 00:00:00 2001 From: Bob Langley Date: Tue, 24 Sep 2019 09:16:29 -0700 Subject: [PATCH 3/5] Rename test classes/interfaces --- .../{IExposeAMongoSession.cs => IMongoSessionProvider.cs} | 2 +- .../SynchronizedStorage/StorageSession.cs | 2 +- .../SynchronizedStorageSessionExtensions.cs | 2 +- ...ession.cs => TestableMongoSynchronizedStorageSession.cs} | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) rename src/NServiceBus.Storage.MongoDB/SynchronizedStorage/{IExposeAMongoSession.cs => IMongoSessionProvider.cs} (78%) rename src/NServiceBus.Storage.MongoDB/Testing/{TestableSynchronizedStorageSession.cs => TestableMongoSynchronizedStorageSession.cs} (65%) diff --git a/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/IExposeAMongoSession.cs b/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/IMongoSessionProvider.cs similarity index 78% rename from src/NServiceBus.Storage.MongoDB/SynchronizedStorage/IExposeAMongoSession.cs rename to src/NServiceBus.Storage.MongoDB/SynchronizedStorage/IMongoSessionProvider.cs index 66a38f23..ab918885 100644 --- a/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/IExposeAMongoSession.cs +++ b/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/IMongoSessionProvider.cs @@ -1,6 +1,6 @@ namespace NServiceBus.Storage.MongoDB { - interface IExposeAMongoSession + interface IMongoSessionProvider { global::MongoDB.Driver.IClientSessionHandle MongoSession { get; } } diff --git a/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/StorageSession.cs b/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/StorageSession.cs index 1e6b3254..2cca2e9a 100644 --- a/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/StorageSession.cs +++ b/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/StorageSession.cs @@ -8,7 +8,7 @@ using Logging; using Persistence; - class StorageSession : CompletableSynchronizedStorageSession, IExposeAMongoSession + class StorageSession : CompletableSynchronizedStorageSession, IMongoSessionProvider { public StorageSession(IClientSessionHandle mongoSession, string databaseName, ContextBag contextBag, Func collectionNamingConvention, bool ownsMongoSession) { diff --git a/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/SynchronizedStorageSessionExtensions.cs b/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/SynchronizedStorageSessionExtensions.cs index 0bb83d35..f74573c0 100644 --- a/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/SynchronizedStorageSessionExtensions.cs +++ b/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/SynchronizedStorageSessionExtensions.cs @@ -17,7 +17,7 @@ public static IClientSessionHandle GetClientSession(this SynchronizedStorageSess { Guard.AgainstNull(nameof(session), session); - if (session is IExposeAMongoSession storageSession) + if (session is IMongoSessionProvider storageSession) { return storageSession.MongoSession; } diff --git a/src/NServiceBus.Storage.MongoDB/Testing/TestableSynchronizedStorageSession.cs b/src/NServiceBus.Storage.MongoDB/Testing/TestableMongoSynchronizedStorageSession.cs similarity index 65% rename from src/NServiceBus.Storage.MongoDB/Testing/TestableSynchronizedStorageSession.cs rename to src/NServiceBus.Storage.MongoDB/Testing/TestableMongoSynchronizedStorageSession.cs index 0e404286..268500b4 100644 --- a/src/NServiceBus.Storage.MongoDB/Testing/TestableSynchronizedStorageSession.cs +++ b/src/NServiceBus.Storage.MongoDB/Testing/TestableMongoSynchronizedStorageSession.cs @@ -7,13 +7,13 @@ /// /// A fake implementation for for testing purposes. /// - public class TestableSynchronizedStorageSession : SynchronizedStorageSession, IExposeAMongoSession + public class TestableMongoSynchronizedStorageSession : SynchronizedStorageSession, IMongoSessionProvider { /// - /// Creates a new instance of using the provided . + /// Creates a new instance of using the provided . /// /// - public TestableSynchronizedStorageSession(IClientSessionHandle clientSessionHandle) + public TestableMongoSynchronizedStorageSession(IClientSessionHandle clientSessionHandle) { MongoSession = clientSessionHandle; } From 17afb7710993817ec67a1cf81610d8d51d942829 Mon Sep 17 00:00:00 2001 From: danielmarbach Date: Tue, 24 Sep 2019 20:46:19 +0200 Subject: [PATCH 4/5] Approve api --- .../ApprovalFiles/APIApprovals.Approve.approved.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NServiceBus.Storage.MongoDB.Tests/ApprovalFiles/APIApprovals.Approve.approved.txt b/src/NServiceBus.Storage.MongoDB.Tests/ApprovalFiles/APIApprovals.Approve.approved.txt index 1c2fbe65..ca66fe9a 100644 --- a/src/NServiceBus.Storage.MongoDB.Tests/ApprovalFiles/APIApprovals.Approve.approved.txt +++ b/src/NServiceBus.Storage.MongoDB.Tests/ApprovalFiles/APIApprovals.Approve.approved.txt @@ -25,9 +25,9 @@ namespace NServiceBus } namespace NServiceBus.Testing { - public class TestableSynchronizedStorageSession : NServiceBus.Persistence.SynchronizedStorageSession + public class TestableMongoSynchronizedStorageSession : NServiceBus.Persistence.SynchronizedStorageSession { - public TestableSynchronizedStorageSession(MongoDB.Driver.IClientSessionHandle clientSessionHandle) { } + public TestableMongoSynchronizedStorageSession(MongoDB.Driver.IClientSessionHandle clientSessionHandle) { } public MongoDB.Driver.IClientSessionHandle MongoSession { get; } } } \ No newline at end of file From 8da8019bef4359df746a5d68209203a268868830 Mon Sep 17 00:00:00 2001 From: danielmarbach Date: Tue, 24 Sep 2019 20:46:29 +0200 Subject: [PATCH 5/5] Using --- .../SynchronizedStorage/IMongoSessionProvider.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/IMongoSessionProvider.cs b/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/IMongoSessionProvider.cs index ab918885..6178dbc6 100644 --- a/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/IMongoSessionProvider.cs +++ b/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/IMongoSessionProvider.cs @@ -1,7 +1,9 @@ namespace NServiceBus.Storage.MongoDB { + using global::MongoDB.Driver; + interface IMongoSessionProvider { - global::MongoDB.Driver.IClientSessionHandle MongoSession { get; } + IClientSessionHandle MongoSession { get; } } }