rebus-org / Rebus.TestHelpers

:bus: Test helpers for Rebus (i.e. fake bus, saga fixture, etc.)
https://mookid.dk/category/rebus
Other
4 stars 2 forks source link

Use ISagaSerializer in SagaFixture (InMemorySagaStorage ) #8

Closed chklauser closed 2 years ago

chklauser commented 2 years ago

We ran into an issue using Rebus.TestHelpers.SagaFixture in combination with saga data that relies on a custom ISagaSerializer.

The Clone method of InMemorySagaStorage uses JsonConvert.SerializeObject and DeserializeObject instead of a configured ISagaSerializer.

We found this surprising for two reasons:

For our particular case, we have worked around the issue by accessing InMemorySagaStorage._serializerSettings via reflection to add JsonConverter that we need. This is obviously not a great solution because it relies on a very private implementation detail of SagaFixture :(

mookid8000 commented 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?

chklauser commented 2 years ago

Ah yes, that makes sense, sorry for the confusion 😅

A dedicated ISagaSerializer interface would definitely solve the problem we face. 👍

hdrachmann commented 2 years ago

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?