我创建了一个 ViewEngine(适用于台式机、平板电脑、iPhone):
public ViewEngine()
{
Set 3 Locations
};
public override ViewEngineResult FindView(ControllerContext controllerContext,
string viewName, string masterName, bool useCache)
{
Assign view locations...
}
然后我创建了一个单元测试类:
[Test]
public void Test_IPad_UserAgent()
{
var controllerContext = new Mock<ControllerContext>();
var controller = new PaymentController();
controllerContext.SetupGet(p => p.HttpContext.Request.UserAgent).Returns("Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10");
controller.ControllerContext = controllerContext.Object;
var result = controller.Index() as ViewResult;
var viewData = result.ViewData;
}
我的问题是,我如何编写一个断言来检查我的视图引擎是否为不同的 UserAgent 字符串返回正确的视图?
如果有人愿意帮助我,我很乐意提供 ViewEngine 的完整代码。