本文整理汇总了C#中Spring.Objects.Factory.Xml.ReadOnlyXmlTestResource类的典型用法代码示例。如果您正苦于以下问题:C# ReadOnlyXmlTestResource类的具体用法?C# ReadOnlyXmlTestResource怎么用?C# ReadOnlyXmlTestResource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReadOnlyXmlTestResource类属于Spring.Objects.Factory.Xml命名空间,在下文中一共展示了ReadOnlyXmlTestResource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RefSubelementsBuildCollection
public void RefSubelementsBuildCollection()
{
IResource resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
XmlObjectFactory xof = new XmlObjectFactory(resource);
//Assert.IsTrue ("5 objects in reftypes, not " + xof.GetObjectDefinitionCount(), xof.GetObjectDefinitionCount() == 5);
TestObject jen = (TestObject) xof.GetObject("jenny");
TestObject dave = (TestObject) xof.GetObject("david");
TestObject rod = (TestObject) xof.GetObject("rod");
// Must be a list to support ordering
// Our object doesn't modify the collection:
// of course it could be a different copy in a real object
IList friends = (IList) rod.Friends;
Assert.IsTrue(friends.Count == 2);
Assert.IsTrue(friends[0] == jen, "First friend must be jen, not " + friends[0]);
Assert.IsTrue(friends[1] == dave);
// Should be ordered
}
示例2: CanApplyConstructorArgsToAbstractType
public void CanApplyConstructorArgsToAbstractType()
{
IResource resource = new ReadOnlyXmlTestResource("ctor-args.xml", GetType());
XmlObjectFactory xof = new XmlObjectFactory(resource);
TestObject rod = (TestObject)xof.GetObject("rod");
Assert.AreEqual(1, rod.Age);
RootObjectDefinition def = (RootObjectDefinition) xof.GetObjectDefinition("rod");
ConstructorResolver resolver = new ConstructorResolver(xof, xof, new SimpleInstantiationStrategy(),
new ObjectDefinitionValueResolver(xof));
ConstructorInstantiationInfo ci = resolver.GetConstructorInstantiationInfo("rod", def, null, null);
AbstractObjectDefinition objDef = (AbstractObjectDefinition)xof.GetObjectDefinition("foo");
objDef.IsAbstract = false;
TestObject foo = (TestObject) xof.GetObject("foo");
Assert.AreEqual(2, foo.Age);
}
示例3: LocaleTest
public void LocaleTest()
{
CultureInfo oldCulture = Thread.CurrentThread.CurrentCulture;
try
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
IResource resource = new ReadOnlyXmlTestResource("locale.xml", GetType());
XmlObjectFactory xof = new XmlObjectFactory(resource);
TestObject to = xof.GetObject("jenny") as TestObject;
Assert.IsNotNull(to);
DateTime d = new DateTime(2007, 10, 30);
Assert.AreEqual(d, to.Date);
Assert.AreEqual(30, to.Size.Height);
Assert.AreEqual(30, to.Size.Width);
}
finally
{
Thread.CurrentThread.CurrentCulture = oldCulture;
}
}
示例4: MultiThreadedLazyInit
public void MultiThreadedLazyInit()
{
IResource resource = new ReadOnlyXmlTestResource("lazy-init-multithreaded.xml", GetType());
XmlObjectFactory xof = new XmlObjectFactory(resource);
LazyWorker lw1 = new LazyWorker(xof);
LazyWorker lw2 = new LazyWorker(xof);
Thread thread1 = new Thread(new ThreadStart(lw1.DoWork));
Thread thread2 = new Thread(new ThreadStart(lw2.DoWork));
thread1.Start();
Thread.Sleep(1000);
thread2.Start();
thread1.Join();
thread2.Join();
Assert.AreEqual(typeof(LazyTestObject), lw1.ObjectFromContext.GetType());
Assert.AreEqual(typeof(LazyTestObject), lw2.ObjectFromContext.GetType());
Assert.AreEqual(1, LazyTestObject.Count);
}
示例5: InitializingObjectAndInitMethod
public void InitializingObjectAndInitMethod()
{
InitAndIB.constructed = false;
IResource resource = new ReadOnlyXmlTestResource("initializers.xml", GetType());
XmlObjectFactory xof = new XmlObjectFactory(resource);
Assert.IsFalse(InitAndIB.constructed);
xof.PreInstantiateSingletons();
Assert.IsFalse(InitAndIB.constructed);
InitAndIB iib = (InitAndIB) xof.GetObject("init-and-ib");
Assert.IsTrue(InitAndIB.constructed);
Assert.IsTrue(iib.afterPropertiesSetInvoked && iib.initMethodInvoked);
Assert.IsTrue(!iib.destroyed && !iib.customDestroyed);
xof.Dispose();
Assert.IsTrue(iib.destroyed && iib.customDestroyed);
xof.Dispose();
Assert.IsTrue(iib.destroyed && iib.customDestroyed);
}
示例6: InitMethodThrowsException
public void InitMethodThrowsException()
{
IResource resource = new ReadOnlyXmlTestResource("initializers.xml", GetType());
XmlObjectFactory xof = new XmlObjectFactory(resource);
try
{
xof.GetObject("init-method2");
Assert.Fail();
}
catch (ObjectCreationException ex)
{
Assert.IsTrue(ex.InnerException is FormatException);
}
}
示例7: PropertyWithIdRefObjectAttrSubelement
public void PropertyWithIdRefObjectAttrSubelement()
{
IResource resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
XmlObjectFactory xof = new XmlObjectFactory(resource);
TestObject verbose = (TestObject) xof.GetObject("verbose3");
Assert.IsTrue(verbose.Name.Equals("verbose"));
}
示例8: FactoryReferenceCircle
public void FactoryReferenceCircle()
{
IResource resource = new ReadOnlyXmlTestResource("factoryCircle.xml", GetType());
XmlObjectFactory xof = new XmlObjectFactory(resource);
TestObject tb = (TestObject) xof.GetObject("singletonFactory");
DummyFactory db = (DummyFactory) xof.GetObject("&singletonFactory");
Assert.IsTrue(tb == db.OtherTestObject);
}
示例9: PropertyInvokingFactoryObjectIsWiredCorrectly
public void PropertyInvokingFactoryObjectIsWiredCorrectly()
{
IResource resource = new ReadOnlyXmlTestResource("invoke-factory.xml", GetType());
XmlObjectFactory xof = new XmlObjectFactory(resource);
TestObject actual = xof["culturalObject"] as TestObject;
object expected = CultureInfo.InstalledUICulture;
Assert.AreEqual(expected, actual.MyCulture);
}
示例10: ViaXML
public void ViaXML()
{
IResource resource = new ReadOnlyXmlTestResource("PropertyResourceConfigurerTests.xml", GetType());
XmlObjectFactory xbf = new XmlObjectFactory(resource);
PropertyOverrideConfigurer poc = (PropertyOverrideConfigurer) xbf.GetObject("OverrideConfigurer");
Assert.IsNotNull(poc);
poc.PostProcessObjectFactory(xbf);
TestObject to = (TestObject) xbf.GetObject("Test2");
Assert.AreEqual("Overriden Name", to.Name);
}
示例11: ViaXMLAndConfigSection
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);
}
示例12: ViaXML
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);
}
示例13: NoSuchInitMethod
public void NoSuchInitMethod()
{
IResource resource = new ReadOnlyXmlTestResource("initializers.xml", GetType());
XmlObjectFactory xof = new XmlObjectFactory(resource);
Assert.Throws<ObjectCreationException>(() => xof.GetObject("init-method3"));
}
示例14: ImportsExternalResourcesBailsOnNonExistentResource
public void ImportsExternalResourcesBailsOnNonExistentResource()
{
IResource resource = new ReadOnlyXmlTestResource("bad-external-resources.xml", GetType());
Assert.Throws<ObjectDefinitionStoreException>(() => new XmlObjectFactory(resource));
}
示例15: BadParentReference
public void BadParentReference()
{
IResource resource = new ReadOnlyXmlTestResource("wellformed-but-bad.xml", GetType());
XmlObjectFactory xof = new XmlObjectFactory(resource);
Assert.Throws<ObjectCreationException>(() => xof.GetObject("no.parent.factory"));
}