I am trying to test some application logic that depends on the Values ββproperty in ControllerContext.RouteData.
I still have
// Arrange var httpContextMock = new Mock<HttpContextBase>(MockBehavior.Loose); var controllerMock = new Mock<ControllerBase>(MockBehavior.Loose); var routeDataMock = new Mock<RouteData>(); var wantedRouteValues = new Dictionary<string, string>(); wantedRouteValues.Add("key1", "value1"); var routeValues = new RouteValueDictionary(wantedRouteValues); routeDataMock.SetupGet(r => r.Values).Returns(routeValues); <=== Fails here var controllerContext = new ControllerContext(httpContextMock.Object, routeDataMock.Object, controllerMock.Object);
Failure unit test: System.ArgumentException: Invalid setting to not override member: r => r.Values
Creating a fake RouteData does not work either as a RouteData constructor (RouteBase, IRouteHandler).
The important class here is the abstract RouteBase class, which has a GetRouteData (HttpContextBase) method that returns an instance of RouteData, the class I'm trying to fake. Taking me in circles!
Any help on this would be appreciated.
c # asp.net-mvc moq
Magpie Jun 12 '09 at 11:30 a.m. 2009-06-12 11:30
source share