ninject / Ninject.MockingKernel

Extension for Ninject aiding testability in Moq, NSubstitute, and FakeItEasy
http://ninject.org/
Other
62 stars 25 forks source link

GetMock() - Object instance was not created by Moq. #29

Closed Nikita-Tut closed 6 years ago

Nikita-Tut commented 8 years ago

In my project when I call this method - I get exception, that object instance was not created by Moq. I follow by your description and example, but even in your example on github - (https://github.com/ninject/Ninject.MockingKernel/wiki/Examples) the same issue.

kevinkuszyk commented 8 years ago

What versions of the NuGet packages are you using?

I just tried it with the latest (Ninject 3.2.2 and Moq 4.5.21) and the sample works.

Nikita-Tut commented 8 years ago

Sorry, it was my mistake. The sample works, if you have di like parameters in constructor. In this case all good. But in my proj - I take implementation of interface from kernel in parameterless constructor.. And in UT I want to get from kernel mocks which I put there. I've already found another solution (bind<>().ToConstant())

juanjoseluisgarcia commented 7 years ago

Is any way to make the MockingKernel inject dependencies in a constructor?

scott-xu commented 6 years ago

@juanjoseluisgarcia Yes, that’s the current behavior.