如何在RhinoMock中模擬RouteData?我不得不嘲笑這個。在RhinoMocks-MVC3中模擬RouteData
(RouteData.Values["id"].Tostring()!=null)
謝謝
如何在RhinoMock中模擬RouteData?我不得不嘲笑這個。在RhinoMocks-MVC3中模擬RouteData
(RouteData.Values["id"].Tostring()!=null)
謝謝
假設的RouteData的類型是IRouteData你可以這樣嘲笑它:
[Test]
public void TestMockingConcreteClass()
{
MockRepository mockRepository = new MockRepository();
RouteData routeData = mockRepository.Stub<RouteData>();
routeData.Stub(r => r.Values["id"]).Return("XXX");
mockRepository.ReplayAll();
Assert.That(routeData.Values["id"].ToString(), Is.EqualTo("XXX"));
}
感謝Morten。我已經使用了另一種方法,稍有不同。我現在會發布。 –
經過大量谷歌上搜索我的得到了這: 在類中聲明等級
HttpContextBase httpContextMock;
ControllerBase controllerMock;
In the Constructor
mockRepository = new MockRepository();
httpContextMock = mockRepository.DynamicMock<HttpContextBase>();
controllerMock = mockRepository.DynamicMock<ControllerBase>();
In The Test Method:
var routeData = new RouteData();
routeData.Values.Add("id", "Value");
absenceController.ControllerContext = new ControllerContext(httpContextMock, routeData, controllerMock);
`
RouteData是什麼類型? – Morten