Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
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 旨在与静态构造函数一起使用。为了模拟带有参数的实例构造函数,您可以像这样使用 Mock.Arrange :
var expected = "StringArg"; string arg = null; Mock.Arrange(() => new A(Arg.AnyString)).DoInstead<string>(x => arg = x); new A(expected); Assert.Equal(expected, arg);