Skip to content

Commit

Permalink
Use saga data type to save and update sagas (#488)
Browse files Browse the repository at this point in the history
* Switch persister to use explicit type

# Conflicts:
#	src/NServiceBus.Storage.MongoDB.AcceptanceTests/NServiceBus.Storage.MongoDB.AcceptanceTests.csproj
#	src/NServiceBus.Storage.MongoDB.NoTx.AcceptanceTests/NServiceBus.Storage.MongoDB.NoTx.AcceptanceTests.csproj
#	src/NServiceBus.Storage.MongoDB.PersistenceTests/NServiceBus.Storage.MongoDB.PersistenceTests.csproj
#	src/NServiceBus.Storage.MongoDB.Tests/NServiceBus.Storage.MongoDB.Tests.csproj
#	src/NServiceBus.Storage.MongoDB/NServiceBus.Storage.MongoDB.csproj
  • Loading branch information
danielmarbach authored Mar 31, 2023
1 parent 3146e69 commit d5f2cee
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net462;net6.0;net7.0</TargetFrameworks>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<NoWarn>$(NoWarn);SYSLIB0021</NoWarn>
</PropertyGroup>
Expand All @@ -11,11 +11,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="NServiceBus.AcceptanceTests.Sources" Version="7.8.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="GitHubActionsTestLogger" Version="1.2.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="MongoDB.Driver" Version="2.19.1" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net462;net6.0;net7.0</TargetFrameworks>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<NoWarn>$(NoWarn);SYSLIB0021</NoWarn>
</PropertyGroup>
Expand All @@ -11,11 +11,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="NServiceBus.AcceptanceTests.Sources" Version="7.8.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="GitHubActionsTestLogger" Version="1.2.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="MongoDB.Driver" Version="2.19.1" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net462;net6.0;net7.0</TargetFrameworks>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

Expand All @@ -10,13 +10,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="MongoDB.Driver" Version="2.19.1" />
<PackageReference Include="NServiceBus" Version="7.8.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Particular.Approvals" Version="0.2.0" />
<PackageReference Include="PublicApiGenerator" Version="10.2.0" />
<PackageReference Include="GitHubActionsTestLogger" Version="1.2.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="Particular.Approvals" Version="0.4.1" />
<PackageReference Include="PublicApiGenerator" Version="11.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net462;net6.0;net7.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<!-- We want the root namespace to match the transactional session one -->
<RootNamespace>NServiceBus.TransactionalSession.AcceptanceTests</RootNamespace>
Expand All @@ -14,6 +14,7 @@
<PackageReference Include="NServiceBus.TransactionalSession" Version="1.0.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="MongoDB.Driver" Version="2.19.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net462;net6.0;net7.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
</PropertyGroup>

Expand All @@ -23,4 +23,4 @@
<ProjectReference Include="..\NServiceBus.Storage.MongoDB.TransactionalSession\NServiceBus.Storage.MongoDB.TransactionalSession.csproj" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageReference Include="MongoDB.Driver" Version="[2.9.2, 3.0.0)" />
<PackageReference Include="NServiceBus" Version="[7.8.0, 8.0.0)" />
<PackageReference Include="Particular.CodeRules" Version="0.2.1" PrivateAssets="All" />
<PackageReference Include="Particular.Packaging" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Particular.Packaging" Version="2.3.0" PrivateAssets="All" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/NServiceBus.Storage.MongoDB/Sagas/SagaPersister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task Save(IContainSagaData sagaData, SagaCorrelationProperty correl
var storageSession = (StorageSession)session;
var sagaDataType = sagaData.GetType();

var document = sagaData.ToBsonDocument();
var document = sagaData.ToBsonDocument(sagaDataType);
document.Add(versionElementName, 0);

await storageSession.InsertOneAsync(sagaDataType, document).ConfigureAwait(false);
Expand All @@ -33,7 +33,7 @@ public async Task Update(IContainSagaData sagaData, SynchronizedStorageSession s
var sagaDataType = sagaData.GetType();

var version = storageSession.RetrieveVersion(sagaDataType);
var document = sagaData.ToBsonDocument().SetElement(new BsonElement(versionElementName, version + 1));
var document = sagaData.ToBsonDocument(sagaDataType).SetElement(new BsonElement(versionElementName, version + 1));

var result = await storageSession.ReplaceOneAsync(sagaDataType, filterBuilder.Eq(idElementName, sagaData.Id) & filterBuilder.Eq(versionElementName, version), document).ConfigureAwait(false);

Expand Down

0 comments on commit d5f2cee

Please sign in to comment.