Faking/mocking an interface gives "no default constructor" error, how can that be?
You're correct in that the exception message does not make any sense, this is a bug. It would be great if you could supply a VS-solution that reproduces the bug and file an issue here: https://github.com/patrik-hagne/FakeItEasy/
The bug is in that the wrong exception message is used, however there must be something wrong that makes the fake creation go wrong. Is the "UserDocument"-type public? If it is internal and you have given your test-project access to it through the use of InternalsVisibleToAttribute you must give the proxy generating library access to it as well: https://fakeiteasy.readthedocs.io/en/stable/how-to-fake-internal-types/#how-to-fake-internal-friend-in-vb-types.
Does the IRavenQueryable<T>
interface have a where T : new()
type constraint?
If so, and UserDocument
does not provide a parameter-less ctor, this might be causing your problem.
I just ran into this, but my issue wasn't around internal types. My issue was with the assembly containing the type not being in the bin folder of the unit test project.
It seems like FakeItEasy throws this error when it can't resolve a type that it needs to fake. (This makes sense why an internal type in another assembly would cause the same error.)
So, I had Project Foo, which is referenced by Project Bar. Project Bar had a public interface referencing a public type from Project Foo. Project Bar.Tests has a reference to Project Bar, but not Project Foo. When I build Bar.Tests, Bar.dll gets put in the bin folder but Foo.dll does not. When FakeItEasy tries to fake out my interface, it can't resolve the type which resides in Foo.dll.
Adding a reference to Project Foo in my Bar.Tests project ensured that Foo.dll makes its way over and is there for FakeItEasy and made this error disappear.
So...
In your case, it could be that your RavenDB assembly (which I assume contains UserDocument
) is only referenced by your actual project and is not getting copied to your unit test build output.