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

A substitute on Type instance not recognized in a method call setup #859

Open
Prologh opened this issue Jan 18, 2025 · 0 comments
Open

A substitute on Type instance not recognized in a method call setup #859

Prologh opened this issue Jan 18, 2025 · 0 comments

Comments

@Prologh
Copy link

Prologh commented Jan 18, 2025

Describe the bug
A substitute on Type instance seems to be not recognized properly when used to setup method call.

To Reproduce

Interface:

public interface ITypeFormatter
{
    string GetPrettyTypeName(Type type);
}

Test code:

var typeMock = Substitute.For<Type>();
var typeFormatterMock = Substitute.For<ITypeFormatter>();
typeFormatterMock
    .GetPrettyTypeName(typeMock)
    .Returns("pretty name");
var result = typeFormatterMock.GetPrettyTypeName(typeMock);

Debug.Assert(!string.IsNullOrEmpty(result), "Result should not be null or empty.");

Expected behaviour
I would expect for result variable to not be empty and it's value be exactly pretty name just the way I configured the call.

When I use Arg.Any<Type>() instead of typeMock in call setup, it works.

Using Arg.Is(typeMock) does not help.

Environment:

  • NSubstitute version: 5.3.0
  • Platform: .NET 8.0 project on Windows
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

1 participant