1

I don't know how to fake constructor has arg

Mock.SetupStatic(typeof(A), StaticConstructor.Mocked);

with Class A has Constructor arg s:

public A(string s)
{}

Please help me! Thanks.

Nhat Duy
  • 198
  • 1
  • 2
  • 11

1 Answers1

1

SetupStatic is meant to be used with static constructors. In order to mock an instance constructor with arguments you can use Mock.Arrange like this:

        var expected = "StringArg";
        string arg = null;
        Mock.Arrange(() => new A(Arg.AnyString)).DoInstead<string>(x => arg = x);

        new A(expected);

        Assert.Equal(expected, arg);