Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Running tests results in failure #1

Open
shahabganji opened this issue May 31, 2020 · 5 comments
Open

Question: Running tests results in failure #1

shahabganji opened this issue May 31, 2020 · 5 comments

Comments

@shahabganji
Copy link

shahabganji commented May 31, 2020

Dear @phatboyg

Thanks for such an amazing content around MassTransit. I am trying to write the code as you teach on MassTransit concepts here.

I run dotnet test on this repository and it results in failing tests:

  • Should_publish_order_submitted_event
  • Should_respond_with_acceptance_if_ok

That being said, I am trying to write the sample hand-in-hand with your education stuff, hence created a repository, however the above-mentioned tests do not fail on my repository while they are almost identical to those in Sample-Twitch repo, but another test fails!! ( Should_cancel_order_when_account_closed ).

That repository is almost identical to the one here, and I am wondering why those tests are failing? is there something missed in between about the InMemoryHarness?

BTW, when I remove the .Activity(x => x.OfType<CustomerAccountClosedActivity>()) from here in the OrderStateMachine state definitions the test pass!!

I will be grateful and highly appreciate if you could invest some time to answer my question 🙏

Again, many thanks for sharing your valuable knowledge with all of us.

@shahabganji shahabganji changed the title Question: Running results in failure Question: Running tests results in failure May 31, 2020
@phatboyg
Copy link
Member

Do you have the CustomerAccountClosedActivity registered in your container, so that the state machine can resolve it?

@shahabganji
Copy link
Author

@phatboyg Yes, the app works fine when dotnet run.

I think if the saga activities NOT being registered we will get a DI error indicating it cannot resolve type T, for instance, CustomerAccountClosedActivity .

here I've registered both activities used in the saga. However, I don't know how does that relates to InMemoryTestHarness does it also use DI?

@phatboyg
Copy link
Member

The in-memory test harness doesn't have any magic behind it, and state machines where the activities are specifying using that style need to have some type of factory that can create them. I'm not sure there is a testing harness provision for that, since there isn't a way to specify the factory beyond adding it to the consume context during the saga execution.

I'd have to think about it. It's definitely a limitation of the test harness.

@shahabganji
Copy link
Author

shahabganji commented Jun 1, 2020

state machines where the activities are specifying using that style need to have some type of factory that can create them.

That looks rational. however, In this case, even when the activities have no deps, with default ctor, the test is still failing.


Anyway, thanks for the time and support; still don't know why tests fail in one project and not in the other?! And there is also a situation in which a test fails when run with all the others but when runs alone, it's green. The behavior sounds strange to me. 😩

@phatboyg
Copy link
Member

phatboyg commented Jun 1, 2020

So, it does use the default constructor activity factory if there isn't on available on the payload context.

https://github.com/MassTransit/MassTransit/blob/develop/src/MassTransit/Automatonymous/Activities/StateMachineActivityFactoryPayloadExtensions.cs#L10

So if your activity has a public default constructor, it should be created as part of the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants