I'm trying to use Ninject.MockingKernel.Moq. I have 2 problems:
- I have to register all kinds of types, which I want to fake. If I do not do this, then the parasailable constructor of my class is called and it is not the object of an automaker
- It seems that even though the fake is called, verification fails. See the following sample
Sample code:
// Organize var kernel = New Ninject.MockingKernel.Moq.MoqMockingKernel (); Kernel.Bind & LT; ClassUnderTest & gt; () ToSelf () .; Kernel.Bind & LT; ILogger & gt; () ToMock () .; Kernel.GetBindings (typeof (ILogger)); // Act var sut = kernel.Get & lt; ClassUnderTest & gt; (); Sut.DoSomething (); // Logger.Log is said within that method / var mok = kernel. Getmock & lt; ILogger & gt; (); fake. Verify (x = & gt; x.log (this. Any such & lt; string & gt; ()), times actually (1));
for self-propelled type such as an example of non-abstract class class By default it is. The purpose behind it is to make matters of the most common use easy, where the resolution of a class is an object in the examination and all the dependencies are defined as the interface.
It is unusual to use classes as dependency because it only allows fun of virtual methods, as above this unusual scenario it has been said that more complex to make as easy as possible is.
On the other hand there is no compulsive requirement for interfaces.
If you want to copy the classes, then you have to define
// Note that you can access it again later in the kernel. & Lt; Foo & gt; (). ToMock () InSingletonScope (); Var Mock = Col. Gatemock & lt; Foo & gt; ()
Comments
Post a Comment