-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
"Did not find a best constructor concrete type" error after updating to 2.1 #88
Comments
This ends up being because we don't include the protected constructor of Moq.AutoMocker/Moq.AutoMock/ConstructorSelector.cs Lines 11 to 18 in 3c5eea1
bindingFlags == Instance | Public .
I also found that there is still a failure to resolve in 2.0, it is just delayed. For example, public class SomeController
{
public SomeController(HttpRequest request) { }
}
// As noted, this works in 2.0, but throws a stack trace like the above in 2.1
var controllerMock = mocker.GetMock<SomeController>();
// However, this throws in 2.0 resolving Object because it can't find a valid constructor on HttpRequest
Sut(controllerMock.Object); |
Thank you for your quick reply, Adam! |
When we can expect stable version with that fix? |
Sorry, I've been in the midst of a job change and didn't mean to drop this. Testing aside, it could be as simple as changing the Moq.AutoMocker/Moq.AutoMock/AutoMocker.cs Lines 348 to 351 in 004e965
|
Thank you @adamhewitt627! Does this mean after updating AutoMocker is supposed to work as with 2.0, or is some configuration needed? |
The issue is the exclusion of non-public constructors when it attempts to create the dependency. To align with the IService service = mocker.GetMock<IService>(enablePrivate: true); |
I see, thank you! Updated and works flawlessly. |
Just stumbled upon this. I was refactoring some tests to use [Fact] // fails
public void UseAutoMocker()
{
this.AutoMocker.GetMock<HttpRequest>();
}
[Fact] // works
public void UseMock()
{
new Mock<HttpRequest>();
} Simply adding the [Fact] // works
public void UseAutoMocker()
{
this.AutoMocker.GetMock<HttpRequest>(true);
} Thanks @adamhewitt627! 🎉 |
This started happening with 2.1, the same code is fine with 2.0.1.
If a class has a constructor parameter of type
Microsoft.AspNetCore.Http.HttpRequest
orMicrosoft.AspNetCore.Routing.LinkGenerator
(note that both are concrete types) then exceptions of the following kind are thrown:I'd guess this has to do something with #86.
The text was updated successfully, but these errors were encountered: