Giter Club home page Giter Club logo

rebus.testhelpers's Introduction

Rebus.TestHelpers

install from nuget

Provides testing helpers for Rebus.


rebus.testhelpers's People

Contributors

fishie avatar hdrachmann avatar mclausen avatar mookid8000 avatar rsivanov avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

rebus.testhelpers's Issues

Bump Rebus.TestHelpers to include Rebus 7

Howdy there and congrats on the new Major of Rebus 7 🫢🏽

I was looking into upgrading our solution to the shiny new version, and I got stuck when updating my tests. It seems like the Rebus.TestHelper package does not target Rebus 7 yet.

Screenshot 2022-12-23 at 12 56 59

Do you need some help? 🀠

Use ISagaSerializer in SagaFixture (InMemorySagaStorage )

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:

  • Our saga data requires a custom serializer (or rather: having a custom Newtonsoft.Json.JsonConverter configured in the JsonSerializerSettings). From the perspective of our tests, the saga store would silently revert to default values for the fields that it couldn't deserialize.
  • Not using the custom serializer also means that tests using 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 add JsonConverter that we need. This is obviously not a great solution because it relies on a very private implementation detail of SagaFixture :(

Is it possible to use Newtonsoft.Json with FakeBus?

Hi there πŸ‘‹πŸ½ it's my first time writing an issue on GitHub! Thanks for the open space and I hope I'm doing it right πŸ˜…

So some of my DTOs have looping references and it's not a problem as I configured Rebus to use NewtonSoft.Json.
I have upgraded to Rebus 7.0 and, therefore to Rebus.TextHelpers 8.0. I've read that Rebus now uses System.Text.Json as default Json serializer, therefore FakeBus as well. The problem I have now is that System.Text.Json can't handle my DTOs. I looked on the Wiki but I could not find a way to set the JsonSerializer of FakeBus.

I just want to restate that the application is running fine with the new Rebus, my only problem is with Unit Tests.

Do you have any suggestion?

Here I've pasted some code snippets.

public class ChangeParentCommand {
    public ChangeParentCommand(Guid processingId) {
        ProcessingId = processingId;
    }

    public Guid ProcessingId { get; set; }

    [JsonProperty(IsReference = true,
        ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
        ItemReferenceLoopHandling = ReferenceLoopHandling.Serialize,
        TypeNameHandling = TypeNameHandling.All
    )]
    public ICollection<ParentDto> Parents { get; set; } = new List<ParentDto>();
}

[JsonObject(IsReference = true, ItemTypeNameHandling = TypeNameHandling.All)]
public class Parent {
    [JsonProperty(IsReference = true,
        ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
        ItemReferenceLoopHandling = ReferenceLoopHandling.Serialize,
        TypeNameHandling = TypeNameHandling.All
    )]
    public ICollection<ChildDto> Children { get; set; } = new List<ChildDto>();
}

[JsonObject(IsReference = true, ItemTypeNameHandling = TypeNameHandling.All)]
public class Child {
    [JsonProperty(IsReference = true,
        ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
        ItemReferenceLoopHandling = ReferenceLoopHandling.Serialize,
        TypeNameHandling = TypeNameHandling.All
    )]
    public ICollection<ParentDto> Parents { get; set; } = new List<ParentDto>();
}

// on my unit tests:
    [Fact]
    public void HandleChangeParentCommand() {
        var message = new ChangeParentCommand(Guid.NewGuid()) {
            Parents = someData.ToList(),
        };

        var fakeBus = new FakeBus();
        using var fixture = SagaFixture.For(() => new ChangeParentSaga(fakeBus));

        fixture.Add(new ChangeParentSagaData {
                ProcessingStepTrackingId = message.SagaCorrelationId,
                Step = "Some Step",
            }
        );

        fixture.Deliver(message); // error on sending

        var data = fixture.Data.OfType<ChangeParentSagaData>();

        data.Should().NotBeEmpty();
    }
# error thrown
System.Text.Json.JsonException
A possible object cycle was detected. This can either be due to a cycle or
if the object depth is larger than the maximum allowed depth of 64. Consider 
using ReferenceHandler.Preserve on JsonSerializerOptions to support cycles.

A bug in FakeRoutingApi.Defer method

Hi

It seems that you have an error in FakeRoutingApi.Defer method.
The current code:
var messageSentToDestination = _factory.CreateEventGeneric(
typeof(MessageSentToDestination<>),
explicitlyRoutedMessage.GetType(),
destinationAddress,
delay,
explicitlyRoutedMessage,
optionalHeaders
);

There should be typeof(MessageDeferredToDestination<>) instead of typeof(MessageSentToDestination<>).

Rebus 8 update broke saga test

I noticed that my shiny saga test broke while updating to Rebus 8. I have a saga test where i test an Ifailed handler (the regular handler is not part of the saga) and i see an handler not found exception :(

Testing an ifailed where the regular handler is part of the saga does work tho. With testing i mean using the deliverFailed method.

This worked with Rebus 7.

Possible issue with the 'PrepareConflict'

Hello,
while trying to unit test the saga conflict resolution I encountered a strange behavior. Could you please help me to clarify?
This behavior is also reproducible with the unit test provided in this repository, therefore no custom code is needed.

TestSagaFixture_ResolveConflicts.CanSimulateConflict()

The saga ConflictSagaHandler provides a ResolveConflict method but this method is never called when calling the mentioned test.
Saga flow is undisturbed and all the assertions pass.

From what I gather the ResolveConflict method should be called, or am I missing something?

FakeMessageContext doesn't support cancellation token

I can understand why the FakeMessageContext doesn't contain a valid IncomingStepContext, but that unfortunately means that MessageContextExtensions.GetCancellationToken() doesn't work with the fake context. Because that's an extension method, it's also kind of difficult to get around this by mocking the message context.

Do you have any suggestions for testing handlers that use the cancellation token?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.