简体   繁体   中英

How to fake arg constructor JustMock

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM