public void ConfigureMvc() { if (_hasRunInitialization) { // // * **All** Roadkill MVC controllers are new'd up by MvcDependencyResolver so dependencies are injected into them // * Some view models are new'd up by custom MvcModelBinders so dependencies are injected into them // * MVC Attributes are injected using setter injection // * All views use RoadkillViewPage which is setter injected. // * All layout views use RoadkillLayoutPage which uses bastard injection (as master pages are part of ASP.NET and not MVC) // MvcDependencyResolver mvcResolver = new MvcDependencyResolver(); GlobalConfiguration.Configuration.DependencyResolver = mvcResolver; // web api GlobalConfiguration.Configuration.Services.Add(typeof(System.Web.Http.Filters.IFilterProvider), new MvcAttributeProvider(GlobalConfiguration.Configuration.Services.GetFilterProviders())); // web api DependencyResolver.SetResolver(mvcResolver); // views and controllers FilterProviders.Providers.Add(new MvcAttributeProvider()); // attributes ModelBinders.Binders.Add(typeof(UserViewModel), new UserViewModelModelBinder()); // models needing DI ModelBinders.Binders.Add(typeof(SettingsViewModel), new SettingsViewModelBinder()); // Attachments path AttachmentRouteHandler.RegisterRoute(_applicationSettings, RouteTable.Routes); } else { throw new IoCException("Please call Run() to perform IoC initialization before performing MVC setup.", null); } }
// See LocatorStartup for lots of pre-startup IoC setup that's performed. public void Configuration(IAppBuilder app) { var appSettings = LocatorStartup.Locator.GetInstance <ApplicationSettings>(); app.Use <InstallCheckMiddleware>(appSettings); // Register the "/Attachments/" route handler. This needs to be called before the other routing setup. if (appSettings.Installed) { // InstallService.Install also performs this var fileService = LocatorStartup.Locator.GetInstance <IFileService>(); AttachmentRouteHandler.RegisterRoute(appSettings, RouteTable.Routes, fileService); } // Filters GlobalFilters.Filters.Add(new HandleErrorAttribute()); // Areas are used for Site settings (for a cleaner view structure) // This should be called before the other routes, for some reason. AreaRegistration.RegisterAllAreas(); // Register routes Routing.RegisterApi(GlobalConfiguration.Configuration); Routing.Register(RouteTable.Routes); // Custom view engine registration (to add directory search paths for Theme views) ExtendedRazorViewEngine.Register(); app.UseWebApi(new HttpConfiguration()); Log.Information("Application started"); }
public void should_register_default_MVC_models() { // Arrange IContainer container = CreateContainer(); // Act UserViewModel userModel = container.GetInstance <UserViewModel>(); SettingsViewModel settingsModel = container.GetInstance <SettingsViewModel>(); AttachmentRouteHandler routerHandler = container.GetInstance <AttachmentRouteHandler>(); // Assert Assert.That(userModel, Is.TypeOf <UserViewModel>()); Assert.That(settingsModel, Is.TypeOf <SettingsViewModel>()); Assert.That(routerHandler, Is.TypeOf <AttachmentRouteHandler>()); }
public void AttachmentsRoute_Using_Files_Route_Should_Throw_Exception() { // Arrange ApplicationSettings settings = new ApplicationSettings(); settings.AttachmentsRoutePath = "Files"; string filename = "somefile.png"; string url = string.Format("~/{0}/{1}", settings.AttachmentsRoutePath, filename); var mockContext = new StubHttpContextForRouting("", url); RouteTable.Routes.Clear(); RouteCollection routes = new RouteCollection(); // Act Routing.Register(RouteTable.Routes); AttachmentRouteHandler.RegisterRoute(settings, routes, new FileServiceMock()); // Assert }
public void attachments_in_standard_controller_path_should_not_map_to_attachments_handler() { // Arrange ApplicationSettings settings = new ApplicationSettings(); string url = "/pages/6/attachments-are-us"; var mockContext = new StubHttpContextForRouting("", url); RouteTable.Routes.Clear(); RouteCollection routes = new RouteCollection(); AttachmentRouteHandler.RegisterRoute(settings, routes, new FileServiceMock()); Routing.Register(routes); // Act RouteData routeData = routes.GetRouteData(mockContext); // Assert Assert.IsNotNull(routeData); Assert.That(routeData.RouteHandler, Is.Not.TypeOf <AttachmentRouteHandler>()); }
public void Attachments_In_Standard_Controller_Path_Should_Not_Map_To_Attachments_Handler() { // Arrange ApplicationSettings settings = new ApplicationSettings(); string url = "/pages/6/attachments-are-us"; var mockContext = new StubHttpContextForRouting("", url); RouteTable.Routes.Clear(); RouteCollection routes = new RouteCollection(); AttachmentRouteHandler.RegisterRoute(settings, routes); Routing.Register(routes); // Act RouteData routeData = routes.GetRouteData(mockContext); // Assert Assert.IsNotNull(routeData); Assert.That(routeData.RouteHandler, Is.Not.TypeOf <AttachmentRouteHandler>()); }
public void Single_Constructor_Argument_Should_Register_Default_Instances() { // Arrange DependencyManager container = new DependencyManager(new ApplicationSettings()); // Act container.Configure(); ApplicationSettings settings = ObjectFactory.TryGetInstance <ApplicationSettings>(); IRepository repository = ObjectFactory.GetInstance <IRepository>(); IUserContext context = ObjectFactory.GetInstance <IUserContext>(); IPageService pageService = ObjectFactory.GetInstance <IPageService>(); MarkupConverter markupConverter = ObjectFactory.GetInstance <MarkupConverter>(); CustomTokenParser tokenParser = ObjectFactory.GetInstance <CustomTokenParser>(); UserViewModel userModel = ObjectFactory.GetInstance <UserViewModel>(); SettingsViewModel settingsModel = ObjectFactory.GetInstance <SettingsViewModel>(); AttachmentRouteHandler routerHandler = ObjectFactory.GetInstance <AttachmentRouteHandler>(); UserServiceBase userManager = ObjectFactory.GetInstance <UserServiceBase>(); IPluginFactory pluginFactory = ObjectFactory.GetInstance <IPluginFactory>(); IWikiImporter wikiImporter = ObjectFactory.GetInstance <IWikiImporter>(); IAuthorizationProvider authProvider = ObjectFactory.GetInstance <IAuthorizationProvider>(); IActiveDirectoryProvider adProvider = ObjectFactory.GetInstance <IActiveDirectoryProvider>(); // Assert Assert.That(settings, Is.Not.Null); Assert.That(repository, Is.TypeOf <LightSpeedRepository>()); Assert.That(context, Is.TypeOf <UserContext>()); Assert.That(pageService, Is.TypeOf <PageService>()); Assert.That(markupConverter, Is.TypeOf <MarkupConverter>()); Assert.That(tokenParser, Is.TypeOf <CustomTokenParser>()); Assert.That(userModel, Is.TypeOf <UserViewModel>()); Assert.That(settingsModel, Is.TypeOf <SettingsViewModel>()); Assert.That(userManager, Is.TypeOf <FormsAuthUserService>()); Assert.That(pluginFactory, Is.TypeOf <PluginFactory>()); Assert.That(wikiImporter, Is.TypeOf <ScrewTurnImporter>()); Assert.That(authProvider, Is.TypeOf <AuthorizationProvider>()); #if !MONO Assert.That(adProvider, Is.TypeOf <ActiveDirectoryProvider>()); #endif }
public void attachments_should_have_correct_handler_and_contain_route_values() { // Arrange ApplicationSettings settings = new ApplicationSettings(); string filename = "somefile.png"; string url = string.Format("~/{0}/{1}", settings.AttachmentsRoutePath, filename); var mockContext = new StubHttpContextForRouting("", url); RouteTable.Routes.Clear(); RouteCollection routes = new RouteCollection(); AttachmentRouteHandler.RegisterRoute(settings, routes, new FileServiceMock()); // has to be registered first Routing.Register(routes); // Act RouteData routeData = routes.GetRouteData(mockContext); // Assert Assert.IsNotNull(routeData); Assert.That(routeData.RouteHandler, Is.TypeOf <AttachmentRouteHandler>()); Assert.That(routeData.Values["filename"].ToString(), Is.EqualTo(filename)); }
public void Install(SettingsViewModel model) { try { IInstallerRepository installerRepository = _getRepositoryFunc(model.DatabaseName, model.ConnectionString); installerRepository.CreateSchema(); if (model.UseWindowsAuth == false) { installerRepository.AddAdminUser(model.AdminEmail, "admin", model.AdminPassword); } SiteSettings siteSettings = new SiteSettings(); siteSettings.AllowedFileTypes = model.AllowedFileTypes; siteSettings.AllowUserSignup = model.AllowUserSignup; siteSettings.IsRecaptchaEnabled = model.IsRecaptchaEnabled; siteSettings.MarkupType = model.MarkupType; siteSettings.RecaptchaPrivateKey = model.RecaptchaPrivateKey; siteSettings.RecaptchaPublicKey = model.RecaptchaPublicKey; siteSettings.SiteUrl = model.SiteUrl; siteSettings.SiteName = model.SiteName; siteSettings.Theme = model.Theme; // v2.0 siteSettings.OverwriteExistingFiles = model.OverwriteExistingFiles; siteSettings.HeadContent = model.HeadContent; siteSettings.MenuMarkup = model.MenuMarkup; installerRepository.SaveSettings(siteSettings); // Attachments handler needs re-registering var appSettings = Locator.GetInstance <ApplicationSettings>(); var fileService = Locator.GetInstance <IFileService>(); AttachmentRouteHandler.RegisterRoute(appSettings, RouteTable.Routes, fileService); } catch (DatabaseException ex) { throw new DatabaseException(ex, "An exception occurred while saving the site configuration."); } }
public void Attachments_With_SubApplication_Should_Have_Correct_Handler_And_Contain_Route_Values() { // Arrange ApplicationSettings settings = new ApplicationSettings(); settings.AttachmentsRoutePath = "Attachments"; string filename = "somefile.png"; string url = string.Format("~/{0}/{1}", settings.AttachmentsRoutePath, filename); // doesn't work without the ~ var mockContext = new StubHttpContextForRouting("/mywiki/", url); RouteTable.Routes.Clear(); RouteCollection routes = new RouteCollection(); AttachmentRouteHandler.RegisterRoute(settings, routes, new FileServiceMock()); // Act RouteData routeData = routes.GetRouteData(mockContext); // Assert Assert.IsNotNull(routeData); Assert.That(routeData.RouteHandler, Is.TypeOf <AttachmentRouteHandler>()); Assert.That(routeData.Values["filename"].ToString(), Is.EqualTo(filename)); }
public void Setup() { RouteTable.Routes.Clear(); AttachmentRouteHandler.RegisterRoute(new ApplicationSettings(), RouteTable.Routes, new FileServiceMock()); Routing.Register(RouteTable.Routes); }