Closed chklauser closed 2 years ago
This is because ISagaSerializer
is not a part of Rebus, it's Rebus.SqlServer's ability to customize how the saga data is serialized - and so, if Rebus.TestHelpers should use ISagaSerializer
it would have to depend on Rebus.SqlServer (which it shouldn't).
I do think there is a nice solution though: By having Rebus.TestHelpers define its own ISagaSerializer
(and use it 🙂 ) then it would be possible for you to customize it however you want.
How does that sound?
Ah yes, that makes sense, sorry for the confusion 😅
A dedicated ISagaSerializer
interface would definitely solve the problem we face. 👍
I've tried a simple version. Just specifying a serializer factory within the test like this:
using var fixture = SagaFixture.For<MySaga>(() => new MicrosoftSagaSerializer());
@mookid8000 Is this what you had in mind?
We ran into an issue using
Rebus.TestHelpers.SagaFixture
in combination with saga data that relies on a customISagaSerializer
.The
Clone
method ofInMemorySagaStorage
usesJsonConvert.SerializeObject
andDeserializeObject
instead of a configuredISagaSerializer
.We found this surprising for two reasons:
Newtonsoft.Json.JsonConverter
configured in theJsonSerializerSettings
). From the perspective of our tests, the saga store would silently revert to default values for the fields that it couldn't deserialize.SagaFixture
can succeed while the real application fails with subtle and hard to track down serialization-deserialization round-tripping issues.For our particular case, we have worked around the issue by accessing
InMemorySagaStorage._serializerSettings
via reflection to addJsonConverter
that we need. This is obviously not a great solution because it relies on a very private implementation detail ofSagaFixture
:(