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

Improved message when [ScenarioDependencies] can't be found or has an incorrect return type (Reqnroll.Microsoft.Extensions.DependencyInjection) #494

Merged
merged 6 commits into from
Feb 25, 2025

Conversation

304NotModified
Copy link
Contributor

@304NotModified 304NotModified commented Feb 24, 2025

🤔 What's changed?

For Reqnroll.Microsoft.Extensions.DependencyInjection improved the message when [ScenarioDependencies] can't be found

  • Tell it should be static (and could be non-public)
  • Tell the scanned assemblies
  • Don't give a "System.ArgumentNullException : Value cannot be null" when returning the wrong type / void methods

The new messages are (see also unit tests)

  • [ScenarioDependencies] should return IServiceCollection but the method doesn't return a value.
  • [ScenarioDependencies] should return IServiceCollection but returned null.
  • [ScenarioDependencies] should return IServiceCollection but returned System.Collections.Generic.List`1[System.String].
  • No method marked with [ScenarioDependencies] attribute found. It should be a (public or non-public) static method. Scanned assemblies: Reqnroll.PluginTests.

Nothing has been changed with the behavior of the code in the happy path. I have considered scanned non-static methods, but because the current code scans all types and all static (public and private methodes) in the assembly until one is found, I don't think that is a good idea for the performance.

I also fixed the Virtual call in ctor for MissingScenarioDependenciesException.
image

⚡️ What's your motivation?

Fixes #474

🏷️ What kind of change is this?

  • 🏦 Refactoring/debt/DX (improvement to code design, tooling, etc. without changing behaviour)

♻️ Anything particular you want feedback on?

  • Do you also think the change to prevent the virtual call in the ctor is the best option?
  • Are the messages clear?

📋 Checklist:

  • I've changed the behaviour of the code
    • I have added/updated tests to cover my changes.
    • I have added an entry to the "[vNext]" section of the CHANGELOG, linking to this pull request & included my GitHub handle to the release contributors list.

This text was originally taken from the template of the Cucumber project, then edited by hand. You can modify the template here.

@304NotModified 304NotModified marked this pull request as ready for review February 24, 2025 18:17
@304NotModified 304NotModified changed the title Improved message when [ScenarioDependencies] can't be found (Reqnroll.Microsoft.Extensions.DependencyInjection) Improved message when [ScenarioDependencies] can't be found or has an incorrect return type (Reqnroll.Microsoft.Extensions.DependencyInjection) Feb 24, 2025
Copy link
Contributor

@gasparnagy gasparnagy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@gasparnagy gasparnagy merged commit ddd25c5 into reqnroll:main Feb 25, 2025
6 checks passed
@304NotModified 304NotModified deleted the issue-474 branch February 25, 2025 13:35
@gasparnagy
Copy link
Contributor

Released in 2.4.0: https://github.com/orgs/reqnroll/discussions/515

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