如何使用Moq创建纯存根?使用Rhino Mocks,我是这样做的:
[TestFixture]
public class UrlHelperAssetExtensionsTests
{
private HttpContextBase httpContextBaseStub;
private RequestContext requestContext;
private UrlHelper urlHelper;
private string stylesheetPath = "/Assets/Stylesheets/{0}";
[SetUp]
public void SetUp()
{
httpContextBaseStub = MockRepository.GenerateStub<HttpContextBase>();
requestContext = new RequestContext(httpContextBaseStub, new RouteData());
urlHelper = new UrlHelper(requestContext);
}
[Test]
public void PbeStylesheet_should_return_correct_path_of_stylesheet()
{
// Arrange
string expected = stylesheetPath.FormatWith("stylesheet.css");
// Act
string actual = urlHelper.PbeStylesheet();
// Assert
Assert.AreEqual(expected, actual);
}
}
如何使用Moq为
MockRepository.GenerateStub<HttpContextBase>();
创建存根?还是我应该只留在犀牛Mo? 最佳答案
这是我对您的建议:
Mock<HttpContextBase> mock = new Mock<HttpContextBase>();
mock.SetupAllProperties();
然后,您必须进行设置。
有关更多信息,请参见homepage of the MOQ project.。
关于c# - 如何用Moq创建 stub ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8241887/