public void SelectControllerIsCaseInsensitive(string controllerTypeName) { const string expectedNamespace = "ExpectedNamespace"; var configuration = new HttpConfiguration(); var controllerTypeResolver = new Mock<IHttpControllerTypeResolver>(); configuration.Services.Replace(typeof(IHttpControllerTypeResolver), controllerTypeResolver.Object); Type controllerType = GetMockControllerType("Sample", expectedNamespace); controllerTypeResolver .Setup(c => c.GetControllerTypes(It.IsAny<IAssembliesResolver>())) .Returns(new Collection<Type> { controllerType }); var request = new HttpRequestMessage(); IHttpRouteData routeData = GetRouteData(); routeData.Values["controller"] = controllerTypeName; routeData.Route.SetNameSpaces(new[] {expectedNamespace}); request.Properties[HttpPropertyKeys.HttpRouteDataKey] = routeData; var selector = new DnnHttpControllerSelector(configuration); // Act HttpControllerDescriptor descriptor = selector.SelectController(request); // Assert Assert.AreEqual(controllerType, descriptor.ControllerType); }
public void SelectControllerIgnoresControllersInUnexpectedNamespaces() { const string expectedNamespace = "ExpectedNamespace"; const string unexpectedNamespace = "UnexpectedNamespace"; const string controllerName = "Sample"; var configuration = new HttpConfiguration(); var controllerTypeResolver = new Mock<IHttpControllerTypeResolver>(); configuration.Services.Replace(typeof(IHttpControllerTypeResolver), controllerTypeResolver.Object); Type controllerType = GetMockControllerType(controllerName, unexpectedNamespace); controllerTypeResolver .Setup(c => c.GetControllerTypes(It.IsAny<IAssembliesResolver>())) .Returns(new Collection<Type> { controllerType }); var request = new HttpRequestMessage(); IHttpRouteData routeData = GetRouteData(); routeData.Values["controller"] = controllerName; routeData.Route.SetNameSpaces(new[] { expectedNamespace }); request.Properties[HttpPropertyKeys.HttpRouteDataKey] = routeData; var selector = new DnnHttpControllerSelector(configuration); // Act selector.SelectController(request); }