Mock —— .Protected() .Setup
原文: https://riptutorial.com/moq/example/27613/mocking-protected-members
To mock a protected member you must first include the following at the top of your test fixture:
using Moq.Protected;
You then call Protected()
on your mock, after which you can use the generic Setup<>
with the return type of your method.
var mock = new Mock<MyClass>();
mock.Protected()
.Setup<int>("MyProtectedGetIntMethod")
.Returns(1);
If the method returns void then use the non-generic Setup()
.