Constructor layout with MOQ

I have a class B with a constructor parameter of type A.

I want class A to make fun of me when I create a layout for class B.

How can i do this? I tried MockBehavior Loose / Strict but that didn't help!

+8
c # moq
source share
1 answer

If you mock classes, you can pass constructor arguments when calling new Mock<T> :

So, if you have classes:

 public class A {} public class B { private readonly A a; public B(A a) { this.a = a; } } 

The following code creates layout B with layout A:

 var mockA = new Mock<A>(); var mockB = new Mock<B>(mockA.Object); 
+16
source share

All Articles