public void ReplacesNamedCtorArgument() { RootObjectDefinition def = new RootObjectDefinition(); def.ObjectType = typeof(TestObject); ConstructorArgumentValues args = new ConstructorArgumentValues(); args.AddNamedArgumentValue("name", "${hope.floats}"); def.ConstructorArgumentValues = args; NameValueCollection properties = new NameValueCollection(); const string expectedName = "Rick"; properties.Add("hope.floats", expectedName); IConfigurableListableObjectFactory mock = mocks.StrictMock <IConfigurableListableObjectFactory>(); Expect.Call(mock.GetObjectDefinitionNames(false)).Return(new string[] { "foo" }); Expect.Call(mock.GetObjectDefinition(null, false)).IgnoreArguments().Return(def); Expect.Call(delegate { mock.AddEmbeddedValueResolver(null); }).IgnoreArguments(); mocks.ReplayAll(); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.Properties = properties; cfg.PostProcessObjectFactory(mock); mocks.VerifyAll(); Assert.AreEqual(expectedName, def.ConstructorArgumentValues.GetNamedArgumentValue("name").Value, "Named argument placeholder value was not replaced."); }
public void WithIgnoreUnresolvablePlaceholder() { const string defName = "foo"; const string placeholder = "${name}"; TestObject foo = new TestObject(placeholder, 30); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.Add("name", placeholder); RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), pvs); IConfigurableListableObjectFactory mock = mocks.StrictMock <IConfigurableListableObjectFactory>(); Expect.Call(mock.GetObjectDefinitionNames(false)).Return(new string [] { defName }); Expect.Call(mock.GetObjectDefinition(defName, false)).Return(def); Expect.Call(delegate { mock.AddEmbeddedValueResolver(null); }).IgnoreArguments(); mocks.ReplayAll(); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.IgnoreUnresolvablePlaceholders = true; cfg.PostProcessObjectFactory(mock); Assert.AreEqual(placeholder, foo.Name); mocks.VerifyAll(); }
public void IncludingAncestors() { const string defName = "foo"; const string placeholder = "${name}"; MutablePropertyValues pvs = new MutablePropertyValues(); const string theProperty = "name"; pvs.Add(theProperty, placeholder); RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), pvs); IConfigurableListableObjectFactory mock = mocks.StrictMock <IConfigurableListableObjectFactory>(); Expect.Call(mock.GetObjectDefinitionNames(true)).Return(new string[] { defName }); Expect.Call(mock.GetObjectDefinition(defName, true)).Return(def); Expect.Call(delegate { mock.AddEmbeddedValueResolver(null); }).IgnoreArguments(); mocks.ReplayAll(); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.IncludeAncestors = true; NameValueCollection defaultProperties = new NameValueCollection(); const string expectedName = "Rick Evans"; defaultProperties.Add(theProperty, expectedName); cfg.Properties = defaultProperties; cfg.PostProcessObjectFactory(mock); Assert.AreEqual(expectedName, def.PropertyValues.GetPropertyValue(theProperty).Value, "Property placeholder value was not replaced with the resolved value."); mocks.VerifyAll(); }
public void WithDefaultProperties() { const string defName = "foo"; const string placeholder = "${name}"; MutablePropertyValues pvs = new MutablePropertyValues(); const string theProperty = "name"; pvs.Add(theProperty, placeholder); RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), pvs); IConfigurableListableObjectFactory mock = (IConfigurableListableObjectFactory)mocks.CreateMock(typeof(IConfigurableListableObjectFactory)); Expect.Call(mock.GetObjectDefinitionNames()).Return(new string [] { defName }); Expect.Call(mock.GetObjectDefinition(defName)).Return(def); mocks.ReplayAll(); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); NameValueCollection defaultProperties = new NameValueCollection(); const string expectedName = "Rick Evans"; defaultProperties.Add(theProperty, expectedName); cfg.Properties = defaultProperties; cfg.PostProcessObjectFactory(mock); Assert.AreEqual(expectedName, def.PropertyValues.GetPropertyValue(theProperty).Value, "Property placeholder value was not replaced with the resolved value."); mocks.VerifyAll(); }
public void ChokesOnCircularReferenceToPlaceHolder() { RootObjectDefinition def = new RootObjectDefinition(); def.ObjectType = typeof(TestObject); ConstructorArgumentValues args = new ConstructorArgumentValues(); args.AddNamedArgumentValue("name", "${foo}"); def.ConstructorArgumentValues = args; NameValueCollection properties = new NameValueCollection(); const string expectedName = "ba${foo}r"; properties.Add("foo", expectedName); IConfigurableListableObjectFactory mock = (IConfigurableListableObjectFactory)mocks.CreateMock(typeof(IConfigurableListableObjectFactory)); Expect.Call(mock.GetObjectDefinitionNames()).Return(new string[] { "foo" }); Expect.Call(mock.GetObjectDefinition(null)).IgnoreArguments().Return(def); mocks.ReplayAll(); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.Properties = properties; try { cfg.PostProcessObjectFactory(mock); Assert.Fail("Should have raised an ObjectDefinitionStoreException by this point."); } catch (ObjectDefinitionStoreException) { } mocks.VerifyAll(); }
public void ChokesOnCircularReferenceToPlaceHolder() { RootObjectDefinition def = new RootObjectDefinition(); def.ObjectType = typeof(TestObject); ConstructorArgumentValues args = new ConstructorArgumentValues(); args.AddNamedArgumentValue("name", "${foo}"); def.ConstructorArgumentValues = args; NameValueCollection properties = new NameValueCollection(); const string expectedName = "ba${foo}r"; properties.Add("foo", expectedName); IConfigurableListableObjectFactory mock = A.Fake <IConfigurableListableObjectFactory>(); A.CallTo(() => mock.GetObjectDefinitionNames(false)).Returns(new string[] { "foo" }); A.CallTo(() => mock.GetObjectDefinition(null, false)).WithAnyArguments().Returns(def); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.Properties = properties; try { cfg.PostProcessObjectFactory(mock); Assert.Fail("Should have raised an ObjectDefinitionStoreException by this point."); } catch (ObjectDefinitionStoreException) { } }
public void IncludingAncestors() { const string defName = "foo"; const string placeholder = "${name}"; MutablePropertyValues pvs = new MutablePropertyValues(); const string theProperty = "name"; pvs.Add(theProperty, placeholder); RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), pvs); IConfigurableListableObjectFactory mock = A.Fake <IConfigurableListableObjectFactory>(); A.CallTo(() => mock.GetObjectDefinitionNames(true)).Returns(new string[] { defName }); A.CallTo(() => mock.GetObjectDefinition(defName, true)).Returns(def); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.IncludeAncestors = true; NameValueCollection defaultProperties = new NameValueCollection(); const string expectedName = "Rick Evans"; defaultProperties.Add(theProperty, expectedName); cfg.Properties = defaultProperties; cfg.PostProcessObjectFactory(mock); Assert.AreEqual(expectedName, def.PropertyValues.GetPropertyValue(theProperty).Value, "Property placeholder value was not replaced with the resolved value."); A.CallTo(() => mock.AddEmbeddedValueResolver(A <IStringValueResolver> ._)).MustHaveHappened(); }
public void UsingCustomMarkers() { RootObjectDefinition def = new RootObjectDefinition(); def.ObjectType = typeof(TestObject); ConstructorArgumentValues args = new ConstructorArgumentValues(); args.AddNamedArgumentValue("name", "#hope.floats#"); def.ConstructorArgumentValues = args; NameValueCollection properties = new NameValueCollection(); const string expectedName = "Rick"; properties.Add("hope.floats", expectedName); IConfigurableListableObjectFactory mock = A.Fake <IConfigurableListableObjectFactory>(); A.CallTo(() => mock.GetObjectDefinitionNames(false)).Returns(new string[] { "foo" }); A.CallTo(() => mock.GetObjectDefinition(null, false)).WithAnyArguments().Returns(def); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.PlaceholderPrefix = cfg.PlaceholderSuffix = "#"; cfg.Properties = properties; cfg.PostProcessObjectFactory(mock); A.CallTo(() => mock.AddEmbeddedValueResolver(null)).WithAnyArguments().MustHaveHappened(); Assert.AreEqual(expectedName, def.ConstructorArgumentValues.GetNamedArgumentValue("name").Value, "Named argument placeholder value was not replaced."); }
public void UsingCustomMarkers() { RootObjectDefinition def = new RootObjectDefinition(); def.ObjectType = typeof(TestObject); ConstructorArgumentValues args = new ConstructorArgumentValues(); args.AddNamedArgumentValue("name", "#hope.floats#"); def.ConstructorArgumentValues = args; NameValueCollection properties = new NameValueCollection(); const string expectedName = "Rick"; properties.Add("hope.floats", expectedName); IConfigurableListableObjectFactory mock = (IConfigurableListableObjectFactory)mocks.CreateMock(typeof(IConfigurableListableObjectFactory)); Expect.Call(mock.GetObjectDefinitionNames()).Return(new string[] { "foo" }); Expect.Call(mock.GetObjectDefinition(null)).IgnoreArguments().Return(def); mocks.ReplayAll(); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.PlaceholderPrefix = cfg.PlaceholderSuffix = "#"; cfg.Properties = properties; cfg.PostProcessObjectFactory(mock); mocks.VerifyAll(); Assert.AreEqual(expectedName, def.ConstructorArgumentValues.GetNamedArgumentValue("name").Value, "Named argument placeholder value was not replaced."); }
public void MismatchBetweenNumberOfConfigNamesAndNumberOfLocations() { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.Locations = new IResource[] { mocks.StrictMock<IResource>() }; // will never get to the point where we check the validity cfg.ConfigSections = new string[] { "", "" }; cfg.PostProcessObjectFactory((IConfigurableListableObjectFactory) mocks.DynamicMock(typeof(IConfigurableListableObjectFactory))); }
public void MismatchBetweenNumberOfConfigNamesAndNumberOfLocations() { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.Locations = new IResource[] { A.Fake <IResource>() }; // will never get to the point where we check the validity cfg.ConfigSections = new string[] { "", "" }; Assert.Throws <ObjectInitializationException>(() => cfg.PostProcessObjectFactory(A.Fake <IConfigurableListableObjectFactory>())); }
public void MismatchBetweenNumberOfConfigNamesAndNumberOfLocations() { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.Locations = new IResource[] { (IResource)mocks.CreateMock(typeof(IResource)) }; // will never get to the point where we check the validity cfg.ConfigSections = new string[] { "", "" }; cfg.PostProcessObjectFactory((IConfigurableListableObjectFactory)mocks.DynamicMock(typeof(IConfigurableListableObjectFactory))); }
public void OneConfigNameIsOKForLotsOfLocations() { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); IResource mock = mocks.StrictMock<IResource>(); Expect.Call(mock.Exists).Return(true); Expect.Call(mock.InputStream).Throw(new FileNotFoundException()); mocks.ReplayAll(); cfg.Locations = new IResource [] {mock}; cfg.ConfigSections = new string[] { "" }; cfg.PostProcessObjectFactory((IConfigurableListableObjectFactory) mocks.DynamicMock(typeof(IConfigurableListableObjectFactory))); }
public void ChokesOnBadResourceLocationIfIgnoreBadResourcesFlagNotSetToTrue() { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.IgnoreResourceNotFound = false; IResource mock = (IResource) mocks.CreateMock(typeof(IResource)); Expect.Call(mock.Exists).Return(false); mocks.ReplayAll(); cfg.Locations = new IResource [] { mock}; cfg.ConfigSections = new string[] { "" }; cfg.PostProcessObjectFactory((IConfigurableListableObjectFactory) mocks.DynamicMock(typeof(IConfigurableListableObjectFactory))); }
public void ViaXMLAndConfigSection() { IResource resource = new ReadOnlyXmlTestResource("PropertyResourceConfigurerTests.xml", GetType()); XmlObjectFactory xbf = new XmlObjectFactory(resource); PropertyPlaceholderConfigurer ppc = (PropertyPlaceholderConfigurer)xbf.GetObject("ConfigSectionPlaceholderConfigurer"); Assert.IsNotNull(ppc); ppc.PostProcessObjectFactory(xbf); Assert.AreEqual("name from section", ((TestObject)xbf.GetObject("Test3")).Name); Assert.AreEqual("name from sectiongroup/section", ((TestObject)xbf.GetObject("Test4")).Name); }
public void ChokesOnBadResourceLocationIfIgnoreBadResourcesFlagNotSetToTrue() { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.IgnoreResourceNotFound = false; IResource mock = mocks.StrictMock<IResource>(); Expect.Call(mock.Exists).Return(false); mocks.ReplayAll(); cfg.Locations = new IResource [] { mock}; cfg.ConfigSections = new string[] { "" }; Assert.Throws<ObjectInitializationException>(() => cfg.PostProcessObjectFactory((IConfigurableListableObjectFactory) mocks.DynamicMock(typeof(IConfigurableListableObjectFactory)))); }
public void OneConfigNameIsOKForLotsOfLocations() { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); IResource mock = A.Fake <IResource>(); A.CallTo(() => mock.Exists).Returns(true); A.CallTo(() => mock.InputStream).Throws(new FileNotFoundException()); cfg.Locations = new IResource [] { mock }; cfg.ConfigSections = new string[] { "" }; Assert.Throws <ObjectsException>(() => cfg.PostProcessObjectFactory(A.Fake <IConfigurableListableObjectFactory>())); }
public void ViaXML() { IResource resource = new ReadOnlyXmlTestResource("PropertyResourceConfigurerTests.xml", GetType()); XmlObjectFactory xbf = new XmlObjectFactory(resource); PropertyPlaceholderConfigurer ppc = (PropertyPlaceholderConfigurer)xbf.GetObject("PlaceholderConfigurer"); Assert.IsNotNull(ppc); ppc.PostProcessObjectFactory(xbf); TestObject to = (TestObject)xbf.GetObject("Test1"); Assert.AreEqual("A DefName", to.Name); }
public void ChokesOnBadResourceLocationIfIgnoreBadResourcesFlagNotSetToTrue() { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.IgnoreResourceNotFound = false; IResource mock = A.Fake <IResource>(); A.CallTo(() => mock.Exists).Returns(false); cfg.Locations = new IResource [] { mock }; cfg.ConfigSections = new string[] { "" }; Assert.Throws <ObjectInitializationException>(() => cfg.PostProcessObjectFactory(A.Fake <IConfigurableListableObjectFactory>())); }
public void OneConfigNameIsOKForLotsOfLocations() { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); IResource mock = (IResource)mocks.CreateMock(typeof(IResource)); Expect.Call(mock.Exists).Return(true); Expect.Call(mock.InputStream).Throw(new FileNotFoundException()); mocks.ReplayAll(); cfg.Locations = new IResource [] { mock }; cfg.ConfigSections = new string[] { "" }; cfg.PostProcessObjectFactory((IConfigurableListableObjectFactory)mocks.DynamicMock(typeof(IConfigurableListableObjectFactory))); }
public void ChokesOnBadResourceLocationIfIgnoreBadResourcesFlagNotSetToTrue() { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.IgnoreResourceNotFound = false; IResource mock = (IResource)mocks.CreateMock(typeof(IResource)); Expect.Call(mock.Exists).Return(false); mocks.ReplayAll(); cfg.Locations = new IResource [] { mock }; cfg.ConfigSections = new string[] { "" }; cfg.PostProcessObjectFactory((IConfigurableListableObjectFactory)mocks.DynamicMock(typeof(IConfigurableListableObjectFactory))); }
public void ChokesOnBadResourceLocationIfIgnoreBadResourcesFlagNotSetToTrue() { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.IgnoreResourceNotFound = false; IResource mock = mocks.StrictMock <IResource>(); Expect.Call(mock.Exists).Return(false); mocks.ReplayAll(); cfg.Locations = new IResource [] { mock }; cfg.ConfigSections = new string[] { "" }; Assert.Throws <ObjectInitializationException>(() => cfg.PostProcessObjectFactory((IConfigurableListableObjectFactory)mocks.DynamicMock(typeof(IConfigurableListableObjectFactory)))); }
public void DoesNotChokeOnBadResourceLocationIfIgnoreBadResourcesFlagSetToTrue() { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.IgnoreResourceNotFound = true; IResource mockResource = A.Fake <IResource>(); A.CallTo(() => mockResource.Exists).Returns(false); cfg.Location = mockResource; cfg.ConfigSections = new string[] { "" }; IConfigurableListableObjectFactory mockFactory = A.Fake <IConfigurableListableObjectFactory>(); A.CallTo(() => mockFactory.GetObjectDefinitionNames(false)).Returns(new string[] {}); cfg.PostProcessObjectFactory(mockFactory); }
public void DoesNotChokeOnBadResourceLocationIfIgnoreBadResourcesFlagSetToTrue() { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.IgnoreResourceNotFound = true; IResource mockResource = (IResource)mocks.CreateMock(typeof(IResource)); Expect.Call(mockResource.Exists).Return(false); cfg.Location = mockResource; cfg.ConfigSections = new string[] { "" }; IConfigurableListableObjectFactory mockFactory = (IConfigurableListableObjectFactory)mocks.DynamicMock(typeof(IConfigurableListableObjectFactory)); Expect.Call(mockFactory.GetObjectDefinitionNames()).Return(new string[] {}); mocks.ReplayAll(); cfg.PostProcessObjectFactory(mockFactory); mocks.VerifyAll(); }
public void WithIgnoreUnresolvablePlaceholder() { const string defName = "foo"; const string placeholder = "${name}"; TestObject foo = new TestObject(placeholder, 30); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.Add("name", placeholder); RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), pvs); IConfigurableListableObjectFactory mock = A.Fake <IConfigurableListableObjectFactory>(); A.CallTo(() => mock.GetObjectDefinitionNames(false)).Returns(new string [] { defName }); A.CallTo(() => mock.GetObjectDefinition(defName, false)).Returns(def); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.IgnoreUnresolvablePlaceholders = true; cfg.PostProcessObjectFactory(mock); Assert.AreEqual(placeholder, foo.Name); A.CallTo(() => mock.AddEmbeddedValueResolver(null)).WithAnyArguments().MustHaveHappened(); }
public PlaceholderResolveHandlerAdapter(PropertyPlaceholderConfigurer outerPPC, NameValueCollection props) { ppc = outerPPC; this.props = props; }
public void IncludingAncestors() { const string defName = "foo"; const string placeholder = "${name}"; MutablePropertyValues pvs = new MutablePropertyValues(); const string theProperty = "name"; pvs.Add(theProperty, placeholder); RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), pvs); IConfigurableListableObjectFactory mock = mocks.StrictMock<IConfigurableListableObjectFactory>(); Expect.Call(mock.GetObjectDefinitionNames(true)).Return(new string[] { defName }); Expect.Call(mock.GetObjectDefinition(defName, true)).Return(def); Expect.Call(() => mock.AddEmbeddedValueResolver(null)).IgnoreArguments(); mocks.ReplayAll(); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.IncludeAncestors = true; NameValueCollection defaultProperties = new NameValueCollection(); const string expectedName = "Rick Evans"; defaultProperties.Add(theProperty, expectedName); cfg.Properties = defaultProperties; cfg.PostProcessObjectFactory(mock); Assert.AreEqual(expectedName, def.PropertyValues.GetPropertyValue(theProperty).Value, "Property placeholder value was not replaced with the resolved value."); mocks.VerifyAll(); }
public void ReplacesNamedCtorArgument() { RootObjectDefinition def = new RootObjectDefinition(); def.ObjectType = typeof (TestObject); ConstructorArgumentValues args = new ConstructorArgumentValues(); args.AddNamedArgumentValue("name", "${hope.floats}"); def.ConstructorArgumentValues = args; NameValueCollection properties = new NameValueCollection(); const string expectedName = "Rick"; properties.Add("hope.floats", expectedName); IConfigurableListableObjectFactory mock = mocks.StrictMock<IConfigurableListableObjectFactory>(); Expect.Call(mock.GetObjectDefinitionNames(false)).Return(new string[] {"foo"}); Expect.Call(mock.GetObjectDefinition(null, false)).IgnoreArguments().Return(def); Expect.Call(delegate { mock.AddEmbeddedValueResolver(null); }).IgnoreArguments(); mocks.ReplayAll(); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.Properties = properties; cfg.PostProcessObjectFactory(mock); mocks.VerifyAll(); Assert.AreEqual(expectedName, def.ConstructorArgumentValues.GetNamedArgumentValue("name").Value, "Named argument placeholder value was not replaced."); }
public void DoesNotChokeOnBadResourceLocationIfIgnoreBadResourcesFlagSetToTrue() { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.IgnoreResourceNotFound = true; IResource mockResource = (IResource) mocks.CreateMock(typeof(IResource)); Expect.Call(mockResource.Exists).Return(false); cfg.Location = mockResource; cfg.ConfigSections = new string[] { "" }; IConfigurableListableObjectFactory mockFactory = (IConfigurableListableObjectFactory)mocks.DynamicMock(typeof(IConfigurableListableObjectFactory)); Expect.Call(mockFactory.GetObjectDefinitionNames()).Return(new string[] {}); mocks.ReplayAll(); cfg.PostProcessObjectFactory(mockFactory); mocks.VerifyAll(); }
public void UsingCustomMarkers() { RootObjectDefinition def = new RootObjectDefinition(); def.ObjectType = typeof (TestObject); ConstructorArgumentValues args = new ConstructorArgumentValues(); args.AddNamedArgumentValue("name", "#hope.floats#"); def.ConstructorArgumentValues = args; NameValueCollection properties = new NameValueCollection(); const string expectedName = "Rick"; properties.Add("hope.floats", expectedName); IConfigurableListableObjectFactory mock = (IConfigurableListableObjectFactory) mocks.CreateMock(typeof (IConfigurableListableObjectFactory)); Expect.Call(mock.GetObjectDefinitionNames()).Return(new string[] {"foo"}); Expect.Call(mock.GetObjectDefinition(null)).IgnoreArguments().Return(def); mocks.ReplayAll(); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.PlaceholderPrefix = cfg.PlaceholderSuffix = "#"; cfg.Properties = properties; cfg.PostProcessObjectFactory(mock); mocks.VerifyAll(); Assert.AreEqual(expectedName, def.ConstructorArgumentValues.GetNamedArgumentValue("name").Value, "Named argument placeholder value was not replaced."); }
public void WithDefaultProperties() { const string defName = "foo"; const string placeholder = "${name}"; MutablePropertyValues pvs = new MutablePropertyValues(); const string theProperty = "name"; pvs.Add(theProperty, placeholder); RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), pvs); IConfigurableListableObjectFactory mock = (IConfigurableListableObjectFactory) mocks.CreateMock(typeof(IConfigurableListableObjectFactory)); Expect.Call(mock.GetObjectDefinitionNames()).Return(new string [] {defName}); Expect.Call(mock.GetObjectDefinition(defName)).Return(def); mocks.ReplayAll(); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); NameValueCollection defaultProperties = new NameValueCollection(); const string expectedName = "Rick Evans"; defaultProperties.Add(theProperty, expectedName); cfg.Properties = defaultProperties; cfg.PostProcessObjectFactory(mock); Assert.AreEqual(expectedName, def.PropertyValues.GetPropertyValue(theProperty).Value, "Property placeholder value was not replaced with the resolved value."); mocks.VerifyAll(); }
public void WithIgnoreUnresolvablePlaceholder() { const string defName = "foo"; const string placeholder = "${name}"; TestObject foo = new TestObject(placeholder, 30); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.Add("name", placeholder); RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), pvs); IConfigurableListableObjectFactory mock = (IConfigurableListableObjectFactory) mocks.CreateMock(typeof(IConfigurableListableObjectFactory)); Expect.Call(mock.GetObjectDefinitionNames()).Return(new string [] {defName}); Expect.Call(mock.GetObjectDefinition(defName)).Return(def); mocks.ReplayAll(); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.IgnoreUnresolvablePlaceholders = true; cfg.PostProcessObjectFactory(mock); Assert.AreEqual(placeholder, foo.Name); mocks.VerifyAll(); }
public void ChokesOnCircularReferenceToPlaceHolder() { RootObjectDefinition def = new RootObjectDefinition(); def.ObjectType = typeof (TestObject); ConstructorArgumentValues args = new ConstructorArgumentValues(); args.AddNamedArgumentValue("name", "${foo}"); def.ConstructorArgumentValues = args; NameValueCollection properties = new NameValueCollection(); const string expectedName = "ba${foo}r"; properties.Add("foo", expectedName); IConfigurableListableObjectFactory mock = (IConfigurableListableObjectFactory) mocks.CreateMock(typeof (IConfigurableListableObjectFactory)); Expect.Call(mock.GetObjectDefinitionNames()).Return(new string[] {"foo"}); Expect.Call(mock.GetObjectDefinition(null)).IgnoreArguments().Return(def); mocks.ReplayAll(); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.Properties = properties; try { cfg.PostProcessObjectFactory(mock); Assert.Fail("Should have raised an ObjectDefinitionStoreException by this point."); } catch (ObjectDefinitionStoreException) { } mocks.VerifyAll(); }