This class should only be used within the context of an ASP.NET web application.
public void CanBeUsedOnNonWebThread() { WebObjectFactory wof; RootWebObjectDefinition rwod; // we need to create WOF within a valid HttpContext environment 'cause we will // make use of 'request' and 'session' scope. using (new VirtualEnvironmentMock("/somedir/some.file", null, null, "/", true)) { wof = new WebObjectFactory("/somedir/", false); } rwod = new RootWebObjectDefinition(typeof(object), new ConstructorArgumentValues(), new MutablePropertyValues()); rwod.Scope = ObjectScope.Application.ToString(); wof.RegisterObjectDefinition("applicationScopedObject", rwod); rwod = new RootWebObjectDefinition(typeof(object), new ConstructorArgumentValues(), new MutablePropertyValues()); rwod.Scope = ObjectScope.Request.ToString(); wof.RegisterObjectDefinition("requestScopedObject", rwod); rwod = new RootWebObjectDefinition(typeof(object), new ConstructorArgumentValues(), new MutablePropertyValues()); rwod.Scope = ObjectScope.Session.ToString(); wof.RegisterObjectDefinition("sessionScopedObject", rwod); object o; o = wof.GetObject("applicationScopedObject"); Assert.IsNotNull(o); AssertGetObjectThrows(typeof(ObjectCreationException), wof, "requestScopedObject"); AssertGetObjectThrows(typeof(ObjectCreationException), wof, "sessionScopedObject"); }
public void ParsesPagePathIntoObjectNameIfNeitherIdNorNameAttributeSpecified() { const string CONTEXTPATH = "/ContextPath/"; const string xml = @"<?xml version='1.0' encoding='UTF-8' ?> <objects xmlns='http://www.springframework.net'> <object type='MyPage.aspx' /> <object type='~/MyControl.ascx' /> </objects>"; WebObjectFactory objectFactory = new WebObjectFactory(CONTEXTPATH, false); TestWebObjectDefinitionReader reader = new TestWebObjectDefinitionReader(objectFactory.ContextPath, objectFactory, new XmlUrlResolver()); using (VirtualEnvironmentMock env = new VirtualEnvironmentMock(CONTEXTPATH + "test.aspx", null, null, CONTEXTPATH, true)) { env.VirtualPath2ArtifactsTable[CONTEXTPATH + "MyPage.aspx"] = typeof (Spring.Web.UI.Page); env.VirtualPath2ArtifactsTable[CONTEXTPATH + "MyControl.ascx"] = typeof (Spring.Web.UI.UserControl); reader.LoadObjectDefinitions(new StringResource(xml)); } Assert.IsTrue(objectFactory.ContainsObjectDefinition("/MyPage.aspx")); Assert.AreEqual(typeof(Spring.Web.UI.Page), objectFactory.GetType("/MyPage.aspx")); Assert.IsTrue(objectFactory.ContainsObjectDefinition("Spring.Web.UI.UserControl")); }
private void AssertGetObjectThrows(Type exceptionType, WebObjectFactory wof, string objectName) { try { wof.GetObject(objectName); Assert.Fail("must not reach this line"); } catch (Exception ex) { Assert.AreEqual(exceptionType, ex.GetType()); } }
public void ControlDefinitionsGetMarkedAbstract() { const string CONTEXTPATH = "/ContextPath/"; const string xml = @"<?xml version='1.0' encoding='UTF-8' ?> <objects xmlns='http://www.springframework.net'> <object type='MyControl.ascx' /> </objects>"; WebObjectFactory objectFactory = new WebObjectFactory(CONTEXTPATH, false); TestWebObjectDefinitionReader reader = new TestWebObjectDefinitionReader(objectFactory.ContextPath, objectFactory, new XmlUrlResolver()); using (VirtualEnvironmentMock env = new VirtualEnvironmentMock(CONTEXTPATH + "test.aspx", null, null, CONTEXTPATH, true)) { env.VirtualPath2ArtifactsTable[CONTEXTPATH + "MyControl.ascx"] = typeof(Spring.Web.UI.UserControl); reader.LoadObjectDefinitions(new StringResource(xml)); } Assert.IsTrue(objectFactory.ContainsObjectDefinition("Spring.Web.UI.UserControl")); Assert.IsTrue(objectFactory.GetObjectDefinition("Spring.Web.UI.UserControl").IsAbstract); }
public void DoesNotGenerateObjectNameIfIdAndNameAttributeSpecified() { const string CONTEXTPATH = "/"; const string xml = @"<?xml version='1.0' encoding='UTF-8' ?> <objects xmlns='http://www.springframework.net'> <object id='mypage' name='mypageAlias' type='~/MyPage.aspx' /> <object id='mycontrol' name='mycontrolAlias' type='~/MyControl.ascx' /> </objects>"; WebObjectFactory objectFactory = new WebObjectFactory(CONTEXTPATH, false); TestWebObjectDefinitionReader reader = new TestWebObjectDefinitionReader(objectFactory.ContextPath, objectFactory, new XmlUrlResolver()); using (VirtualEnvironmentMock env = new VirtualEnvironmentMock(CONTEXTPATH + "test.aspx", null, null, CONTEXTPATH, true)) { env.VirtualPath2ArtifactsTable[CONTEXTPATH + "MyPage.aspx"] = typeof(Spring.Web.UI.Page); env.VirtualPath2ArtifactsTable[CONTEXTPATH + "MyControl.ascx"] = typeof(Spring.Web.UI.UserControl); reader.LoadObjectDefinitions(new StringResource(xml)); } Assert.IsTrue(objectFactory.ContainsObjectDefinition("mypage")); Assert.IsTrue(objectFactory.ContainsObject("mypageAlias")); Assert.IsTrue(objectFactory.ContainsObjectDefinition("mycontrol")); Assert.IsTrue(objectFactory.ContainsObject("mycontrolAlias")); }