public void SetUp() { HttpApplicationConfigurer h1 = new HttpApplicationConfigurer(); h1.ApplicationTemplate = null; h1.ModuleTemplates.Clear(); }
public void ConfigureUsingXmlApplicationContext_CanMergePropertyValues() { XmlApplicationContext appContext = new XmlApplicationContext(false, ReadOnlyXmlTestResource.GetFilePath("HttpApplicationConfigurerMergablePropertiesTests.xml", typeof(HttpApplicationConfigurerTests))); ParentHttpModule module = new ParentHttpModule(); TestApplication appObject = new TestApplication(new ModuleEntry[] { new ModuleEntry("DirectoryServicesAuthentication", module) }); HttpApplicationConfigurer.Configure(appContext, appObject); //base class property has carried through successfully Assert.Contains("GrandParentValue1", module.GrandParentProperty); //parent property values remain in the final instance Assert.Contains("ParentValue1", module.ParentProperty); Assert.Contains("ParentValue2", module.ParentProperty); Assert.Contains("ParentValue3", module.ParentProperty); Assert.Contains("ParentValue4", module.ParentProperty); //the new additional value has been merged into the property Assert.Contains("MergedValueToFind", module.ParentProperty); }
public void ConfiguresApplicationAndModulesFromTemplate() { StaticApplicationContext appContext = CreateTestContext(); HttpApplicationConfigurer h; RootObjectDefinition rod; h = new HttpApplicationConfigurer(); rod = new RootObjectDefinition(); rod.PropertyValues.Add("TestObject", new RuntimeObjectReference("testObject")); h.ApplicationTemplate = rod; rod = new RootObjectDefinition(); rod.PropertyValues.Add("TestObject", new RuntimeObjectReference("testObject1")); h.ModuleTemplates.Add("TestModule1", rod); rod = new RootObjectDefinition(); rod.PropertyValues.Add("TestObject", new RuntimeObjectReference("testObject2")); h.ModuleTemplates.Add("TestModule2", rod); TestModule m1 = new TestModule(); TestModule m2 = new TestModule(); TestApplication appObject = new TestApplication(new ModuleEntry[] { new ModuleEntry("TestModule1", m1) , new ModuleEntry("TestModule2", m2), }); HttpApplicationConfigurer.Configure(appContext, appObject); // app configured Assert.AreEqual(appContext.GetObject("testObject"), appObject.TestObject); // modules configured Assert.AreEqual(appContext.GetObject("testObject1"), m1.TestObject); Assert.AreEqual(appContext.GetObject("testObject2"), m2.TestObject); }
/// <summary> /// Registers this module for all events required by the Spring.Web framework /// </summary> public virtual void Init(HttpApplication app) { lock (typeof(WebSupportModule)) { s_log.Debug("Initializing Application instance"); if (!s_isInitialized) { HttpModuleCollection modules = app.Modules; foreach (string moduleKey in modules.AllKeys) { if (modules[moduleKey] is SessionStateModule) { HookSessionEvent((SessionStateModule)modules[moduleKey]); } } } s_isInitialized = true; // signal, that VirtualEnvironment is ready to accept // handler registrations for EndRequest and EndSession events VirtualEnvironment.SetInitialized(); } app.PreRequestHandlerExecute += new EventHandler(OnConfigureHandler); app.EndRequest += new EventHandler(VirtualEnvironment.RaiseEndRequest); #if NET_2_0 // TODO: this is only a workaround to get us up & running in IIS7/integrated mode // We must review all code for relative virtual paths - they must be resolved to application-relative paths // during parsing of the object definitions bool hideRequestResponse = false; if (ContextHideRequestResponse != null) { hideRequestResponse = (bool)ContextHideRequestResponse.GetValue(app.Context); ContextHideRequestResponse.SetValue(app.Context, false); } #endif try { // ensure context is instantiated IConfigurableApplicationContext appContext = WebApplicationContext.GetRootContext() as IConfigurableApplicationContext; // configure this app + it's module instances if (appContext == null) { throw new InvalidOperationException("Implementations of IApplicationContext must also implement IConfigurableApplicationContext"); } HttpApplicationConfigurer.Configure(appContext, app); } finally { #if NET_2_0 if (ContextHideRequestResponse != null) { ContextHideRequestResponse.SetValue(app.Context, hideRequestResponse); } #endif } }
public void ThrowsOnUnapplicableModuleTemplate() { StaticApplicationContext appContext = CreateTestContext(); HttpApplicationConfigurer h; RootObjectDefinition rod; h = new HttpApplicationConfigurer(); rod = new RootObjectDefinition(); rod.PropertyValues.Add("TestObject", new RuntimeObjectReference("testObject1")); h.ModuleTemplates.Add("TestModule1", rod); TestApplication appObject = new TestApplication(null); HttpApplicationConfigurer.Configure(appContext, appObject); }
public void ShareApplicationTemplate() { RootObjectDefinition rod = new RootObjectDefinition(); HttpApplicationConfigurer h1 = new HttpApplicationConfigurer(); h1.ApplicationTemplate = rod; Assert.AreEqual(rod, h1.ApplicationTemplate); // h2 returns same template as h1 HttpApplicationConfigurer h2 = new HttpApplicationConfigurer(); Assert.AreEqual(rod, h2.ApplicationTemplate); Assert.AreEqual(h2.ApplicationTemplate, h1.ApplicationTemplate); // allows overriding rod = new RootObjectDefinition(); h2.ApplicationTemplate = rod; Assert.AreEqual(rod, h1.ApplicationTemplate); }
public void ConfigureUsingXmlApplicationContext() { XmlApplicationContext appContext = new XmlApplicationContext(false, ReadOnlyXmlTestResource.GetFilePath("HttpApplicationConfigurerTests.xml", typeof(HttpApplicationConfigurerTests))); TestModule m1 = new TestModule(); TestModule m2 = new TestModule(); TestApplication appObject = new TestApplication(new ModuleEntry[] { new ModuleEntry("TestModule1", m1) , new ModuleEntry("TestModule2", m2), }); HttpApplicationConfigurer.Configure(appContext, appObject); // app configured Assert.AreEqual(appContext.GetObject("testObject"), appObject.TestObject); // modules configured Assert.AreEqual(appContext.GetObject("testObject1"), m1.TestObject); Assert.AreEqual(null, m2.TestObject); }
public void ShareModuleTemplates() { // is never null HttpApplicationConfigurer h1; HttpApplicationConfigurer h2; RootObjectDefinition rod; // is shared h1 = new HttpApplicationConfigurer(); Assert.IsNotNull(h1.ModuleTemplates); h2 = new HttpApplicationConfigurer(); Assert.AreEqual(h1.ModuleTemplates, h2.ModuleTemplates); // allows overriding rod = new RootObjectDefinition(); h1.ModuleTemplates.Add("test", rod); Assert.AreEqual(rod, h1.ModuleTemplates["test"]); h2.ModuleTemplates.Add("test", rod); Assert.AreEqual(1, h2.ModuleTemplates.Count); Assert.AreEqual(rod, h2.ModuleTemplates["test"]); }