Ejemplo n.º 1
0
        protected void Application_Start()
        {
            // Get the settings from the web.config
            ConfigReaderWriter  configReader        = new FullTrustConfigReaderWriter("");
            ApplicationSettings applicationSettings = configReader.GetApplicationSettings();

            // Configure StructureMap dependencies
            DependencyManager iocSetup = new DependencyManager(applicationSettings);

            iocSetup.Configure();
            iocSetup.ConfigureMvc();

            // Logging
            Log.ConfigureLogging(applicationSettings);

            // Filters
            GlobalFilters.Filters.Add(new HandleErrorAttribute());

            // Areas are used for:
            // - Site settings (for a cleaner view structure)
            // - Webapi help.
            // This should be called before the other routes, for some reason.
            AreaRegistration.RegisterAllAreas();

            // Register routes and JS/CSS bundles
            Routing.RegisterApi(GlobalConfiguration.Configuration);
            Routing.Register(RouteTable.Routes);
            Bundles.Register();

            // Custom view engine registration (to add new search paths)
            ExtendedRazorViewEngine.Register();

            Log.Information("Application started");
        }
        public void RegisterMvcFactoriesAndRouteHandlers_Requires_Run_First()
        {
            // Arrange
            DependencyManager container = new DependencyManager(new ApplicationSettings());

            // Act
            container.ConfigureMvc();

            // Assert
        }
        public void RegisterMvcFactoriesAndRouteHandlers_Should_Register_Instances()
        {
            // Arrange
            RouteTable.Routes.Clear();
            DependencyManager iocSetup = new DependencyManager(new ApplicationSettings());

            // Act
            iocSetup.Configure();
            iocSetup.ConfigureMvc();

            // Assert
            Assert.That(RouteTable.Routes.Count, Is.EqualTo(1));
            Assert.That(((Route)RouteTable.Routes[0]).RouteHandler, Is.TypeOf <AttachmentRouteHandler>());
            Assert.True(ModelBinders.Binders.ContainsKey(typeof(SettingsViewModel)));
            Assert.True(ModelBinders.Binders.ContainsKey(typeof(UserViewModel)));
        }