Skip to content

How to test Publish() method on sagas #1118

@thaifurforo

Description

@thaifurforo

I am using the Publish() method on sagas, but I am not sure how to write a unit test that verifies the method is being called. My goal is to ensure that if someone removes it from the code, the unit test will fail.

My suggestion is to expose the _unpublishedCommands list in AggregateSaga through a public property, similar to how the _uncommittedEvents field is exposed in AggregateRoot.

For example:

public IEnumerable<IUncommittedEvent> UnpublishedCommands => _unpublishedCommands;

Would this be a good solution, or is there a specific reason why this property should remain private?
If keeping it private is intentional, is there another recommended way to unit test that Publish() is being called?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions