Centralised resource getter for loading all of those XML object definition files used in the XML based object factory tests.
Наследование: IResource
Пример #1
0
        public void RefSubelementsBuildCollectionWithPrototypes()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);

            TestObject jen     = (TestObject)xof.GetObject("pJenny");
            TestObject dave    = (TestObject)xof.GetObject("pDavid");
            TestObject rod     = (TestObject)xof.GetObject("pRod");
            IList      friends = (IList)rod.Friends;

            Assert.IsTrue(friends.Count == 2);
            Assert.IsTrue(friends[0].ToString().Equals(jen.ToString()), "First friend must be jen, not " + friends[0]);
            Assert.IsTrue(friends[0] != jen, "Jen not same instance");
            Assert.IsTrue(friends[1].ToString().Equals(dave.ToString()));
            Assert.IsTrue(friends[1] != dave, "Dave not same instance");

            TestObject rod2     = (TestObject)xof.GetObject("pRod");
            IList      friends2 = (IList)rod2.Friends;

            Assert.IsTrue(friends2.Count == 2);
            Assert.IsTrue(friends2[0].ToString().Equals(jen.ToString()), "First friend must be jen, not " + friends2[0]);
            Assert.IsTrue(friends2[0] != friends[0], "Jen not same instance");
            Assert.IsTrue(friends2[1].ToString().Equals(dave.ToString()));
            Assert.IsTrue(friends2[1] != friends[1], "Dave not same instance");
        }
Пример #2
0
        /// <summary>
        /// Test that we can add elements to an ISet that is exposed as a
        /// read-only property
        /// </summary>
        public void AddElementsToReadOnlySet()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);

            TestObject to        = (TestObject)xof.GetObject("readOnlySet");
            ISet       computers = to.Computers;

            Assert.IsTrue(computers.Count == 2);
            bool foundDell = false;
            bool foundIbm  = false;

            foreach (string name in computers)
            {
                if (name.Equals("Dell"))
                {
                    foundDell = true;
                }
                if (name.Equals("IBM T41"))
                {
                    foundIbm = true;
                }
            }
            Assert.IsTrue(foundDell, "Dell string not found in ISet");
            Assert.IsTrue(foundIbm, "IBM T41 not found in ISet");
        }
Пример #3
0
        public void EmptyValue()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("emptyValue");

            Assert.AreEqual("", hasMap.Props.Get("foo"), "Expected empty string");
        }
Пример #4
0
        public void EmptyProps()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("emptyProps");

            Assert.IsTrue(hasMap.Props.Count == 0);
        }
Пример #5
0
        public void ObjectWithIndexerProperty()
        {
            IResource        resource   = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof        = new XmlObjectFactory(resource);
            TestObject       testObject = (TestObject)xof.GetObject("objectWithIndexer");

            Assert.IsNotNull(testObject);
            Assert.AreEqual("my string value", testObject[0]);
        }
Пример #6
0
        public void CustomListCollection()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            TestObject       objectWithTypedFriends = (TestObject)xof.GetObject("objectWithTypedFriends");
            TestObjectList   tol = objectWithTypedFriends.TypedFriends;

            Assert.AreEqual(1, tol.Count);
            Assert.IsTrue(tol[0].Equals(xof.GetObject("david")));
        }
Пример #7
0
        public void ClassArray()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("classArray");

            Assert.IsTrue(hasMap.ClassArray.Length == 2);
            Assert.IsTrue(hasMap.ClassArray[0].Equals(typeof(String)));
            Assert.IsTrue(hasMap.ClassArray[1].Equals(typeof(Exception)));
        }
Пример #8
0
        public void PrototypeDictionaryFactory()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            IDictionary      map      = (IDictionary)xof.GetObject("pMapFactory");

            Assert.IsTrue(map.Count == 2);
            Assert.AreEqual("bar", map["foo"]);
            Assert.AreEqual("jenny", map["jen"]);
        }
Пример #9
0
        public void ObjectArray()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("objectArray");

            Assert.IsTrue(hasMap.ObjectArray.Length == 2);
            Assert.IsTrue(hasMap.ObjectArray[0].Equals("one"));
            Assert.IsTrue(hasMap.ObjectArray[1].Equals(xof.GetObject("jenny")));
        }
Пример #10
0
        public void PopulatedProps()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("props");

            Assert.AreEqual(2, hasMap.Props.Count);
            Assert.AreEqual("bar", hasMap.Props["foo"]);
            Assert.AreEqual("TWO", hasMap.Props["2"]);
        }
Пример #11
0
        public void AutoAliasing()
        {
            IResource        resource    = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof         = new XmlObjectFactory(resource);
            IList <string>   objectNames = xof.GetObjectDefinitionNames();
            TestObject       tb1         = (TestObject)xof.GetObject("aliased");
            TestObject       alias1      = (TestObject)xof.GetObject("myalias");

            Assert.IsTrue(tb1 == alias1);

            IList <string> tb1Aliases = xof.GetAliases("aliased");

            Assert.AreEqual(1, tb1Aliases.Count);
            Assert.IsTrue(tb1Aliases.Contains("myalias"));
            Assert.IsTrue(objectNames.Contains("aliased"));
            Assert.IsFalse(objectNames.Contains("myalias"));

            TestObject tb2    = (TestObject)xof.GetObject("multiAliased");
            TestObject alias2 = (TestObject)xof.GetObject("alias1");
            TestObject alias3 = (TestObject)xof.GetObject("alias2");

            Assert.IsTrue(tb2 == alias2);
            Assert.IsTrue(tb2 == alias3);
            IList <string> tb2Aliases = xof.GetAliases("multiAliased");

            Assert.AreEqual(2, tb2Aliases.Count);
            Assert.IsTrue(tb2Aliases.Contains("alias1"));
            Assert.IsTrue(tb2Aliases.Contains("alias2"));
            Assert.IsTrue(objectNames.Contains("multiAliased"));
            Assert.IsFalse(objectNames.Contains("alias1"));
            Assert.IsFalse(objectNames.Contains("alias2"));

            TestObject tb3    = (TestObject)xof.GetObject("aliasWithoutId1");
            TestObject alias4 = (TestObject)xof.GetObject("aliasWithoutId2");
            TestObject alias5 = (TestObject)xof.GetObject("aliasWithoutId3");

            Assert.IsTrue(tb3 == alias4);
            Assert.IsTrue(tb3 == alias5);

            IList <string> tb3Aliases = xof.GetAliases("aliasWithoutId1");

            Assert.AreEqual(2, tb2Aliases.Count);
            Assert.IsTrue(tb3Aliases.Contains("aliasWithoutId2"));
            Assert.IsTrue(tb3Aliases.Contains("aliasWithoutId3"));
            Assert.IsTrue(objectNames.Contains("aliasWithoutId1"));
            Assert.IsFalse(objectNames.Contains("aliasWithoutId2"));
            Assert.IsFalse(objectNames.Contains("aliasWithoutId3"));

            string className  = typeof(TestObject).FullName;
            string targetName = className + ObjectDefinitionReaderUtils.GENERATED_OBJECT_NAME_SEPARATOR + "0";

            TestObject tb4 = (TestObject)xof.GetObject(targetName);

            Assert.AreEqual(null, tb4.Name);
        }
Пример #12
0
        public void MapWithLiteralsOnly()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("literalMap");

            Assert.IsTrue(hasMap.Map.Count == 3);
            Assert.IsTrue(hasMap.Map["foo"].Equals("bar"));
            Assert.IsTrue(hasMap.Map["fi"].Equals("fum"));
            Assert.IsTrue(hasMap.Map["fa"] == null);
        }
Пример #13
0
        public void PrototypeSetFactory()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            Set mySet = (Set)xof.GetObject("pSetFactory");

            Assert.IsTrue(mySet is HybridSet);
            Assert.IsTrue(mySet.Count == 2);
            Assert.IsTrue(mySet.Contains("bar"));
            Assert.IsTrue(mySet.Contains("jenny"));
        }
Пример #14
0
        public void DelimitedProps()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("delimitedProps");

            Assert.AreEqual(2, hasMap.Props.Count);
            Assert.AreEqual(3, hasMap.Props.GetValues("foo").Length);
            Assert.AreEqual(7, hasMap.Props.GetValues("days").Length);
            Assert.AreEqual("wednesday", hasMap.Props.GetValues("days")[2]);
        }
Пример #15
0
        public void PrototypeListFactory()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            IList            list     = (IList)xof.GetObject("pListFactory");

            Assert.IsTrue(list is LinkedList);
            Assert.IsTrue(list.Count == 2);
            Assert.AreEqual("bar", list[0]);
            Assert.AreEqual("jenny", list[1]);
        }
Пример #16
0
        /// <summary>
        /// Test that we can add elements to an IDictionary that is exposed as a
        /// read-only property.
        /// </summary>
        public void AddElementsToReadOnlyDictionary()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);

            TestObject  to    = (TestObject)xof.GetObject("readOnlyDictionary");
            IDictionary table = to.PeriodicTable;

            Assert.IsTrue(table.Count == 2);
            Assert.AreEqual("1", table["hydrogen"], "Dictionary Value incorrect");
            Assert.AreEqual("12", table["carbon"], "Dictionary value incorrect");
        }
Пример #17
0
        public void AddElementsToReadOnlyList()
        {
            IResource resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            //Stream stream = new FileSystemResource("file:///w:/collections.xml").InputStream;
            XmlObjectFactory xof = new XmlObjectFactory(resource);

            TestObject aleks = (TestObject)xof.GetObject("aleks");
            IList      pets  = (IList)aleks.Pets;

            Assert.IsTrue(pets.Count == 1);
            Assert.IsTrue(pets[0].Equals("Nadja"));
        }
Пример #18
0
        public void PopulatedPropsWithSameKey()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("propsWithSameKey");

            Assert.AreEqual(2, hasMap.Props.Count);
            Assert.AreEqual("OnE,tWo", hasMap.Props["foo"]);
            Assert.AreEqual(2, hasMap.Props.GetValues("bar").Length);
            Assert.AreEqual("OnE", hasMap.Props.GetValues("bar")[0]);
            Assert.AreEqual("tWo", hasMap.Props.GetValues("bar")[1]);
        }
Пример #19
0
        public void MapWithLiteralsAndReferences()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("mixedMap");

            Assert.IsTrue(hasMap.Map.Count == 3);
            Assert.IsTrue(hasMap.Map["foo"].Equals("bar"));
            TestObject jenny = (TestObject)xof.GetObject("jenny");

            Assert.IsTrue(hasMap.Map["jenny"] == jenny);
            Assert.IsTrue(hasMap.Map["david"].Equals("david"));
        }
Пример #20
0
        public void PopulatedSet()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("set");

            Assert.IsTrue(hasMap.Set.Count == 3);
            Assert.IsTrue(hasMap.Set.Contains("bar"));
            TestObject jenny = (TestObject)xof.GetObject("jenny");

            Assert.IsTrue(hasMap.Set.Contains(jenny));
            Assert.IsTrue(hasMap.Set.Contains(null));
        }
Пример #21
0
        public void BuildCollectionFromMixtureOfReferencesAndValues()
        {
            MixedCollectionObject.ResetStaticState();
            IResource             resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory      xof      = new XmlObjectFactory(resource);
            MixedCollectionObject jumble   = (MixedCollectionObject)xof.GetObject("jumble");

            Assert.AreEqual(1, MixedCollectionObject.nrOfInstances);
            xof.GetObject("david", typeof(TestObject));
            Assert.IsTrue(jumble.Jumble.Count == 4, "Expected 3 elements, not " + jumble.Jumble.Count);
            IList l = (IList)jumble.Jumble;

            Assert.IsTrue(l[0].Equals(xof.GetObject("david")));
            Assert.IsTrue(l[1].Equals("literal"));
            Assert.IsTrue(l[2].Equals(xof.GetObject("jenny")));
            Assert.IsTrue(l[3].Equals("rod"));
        }
Пример #22
0
        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
        }
Пример #23
0
        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
        }
Пример #24
0
        public void MapWithLiteralsReferencesAndList()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            HasMap           hasMap   = (HasMap)xof.GetObject("mixedMapWithList");

            Assert.IsTrue(hasMap.Map.Count == 4);
            Assert.IsTrue(hasMap.Map["foo"].Equals("bar"));
            TestObject jenny = (TestObject)xof.GetObject("jenny");

            Assert.IsTrue(hasMap.Map["jenny"].Equals(jenny));

            // Check list
            IList l = (IList)hasMap.Map["list"];

            Assert.IsNotNull(l);
            Assert.IsTrue(l.Count == 4);
            Assert.IsTrue(l[0].Equals("zero"));
            Assert.IsTrue(l[3] == null);

            // Check nested map in list
            IDictionary m = (IDictionary)l[1];

            Assert.IsNotNull(m);
            Assert.IsTrue(m.Count == 2);
            Assert.IsTrue(m["fo"].Equals("bar"));
            Assert.IsTrue(m["jen"].Equals(jenny), "Map element 'jenny' should be equal to jenny object, not " + m["jen"]);

            // Check nested list in list
            l = (IList)l[2];
            Assert.IsNotNull(l);
            Assert.IsTrue(l.Count == 2);
            Assert.IsTrue(l[0].Equals(jenny));
            Assert.IsTrue(l[1].Equals("ba"));

            // Check nested map
            m = (IDictionary)hasMap.Map["map"];
            Assert.IsNotNull(m);
            Assert.IsTrue(m.Count == 2);
            Assert.IsTrue(m["foo"].Equals("bar"));
            Assert.IsTrue(m["jenny"].Equals(jenny),
                          "Map element 'jenny' should be equal to jenny object, not " + m["jenny"]);
        }
Пример #25
0
        public void MapWithLiteralsAndPrototypeReferences()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);

            TestObject jenny  = (TestObject)xof.GetObject("pJenny");
            HasMap     hasMap = (HasMap)xof.GetObject("pMixedMap");

            Assert.IsTrue(hasMap.Map.Count == 2);
            Assert.IsTrue(hasMap.Map["foo"].Equals("bar"));
            Assert.IsTrue(hasMap.Map["jenny"].ToString().Equals(jenny.ToString()));
            Assert.IsTrue(hasMap.Map["jenny"] != jenny, "Not same instance");

            HasMap hasMap2 = (HasMap)xof.GetObject("pMixedMap");

            Assert.IsTrue(hasMap2.Map.Count == 2);
            Assert.IsTrue(hasMap2.Map["foo"].Equals("bar"));
            Assert.IsTrue(hasMap2.Map["jenny"].ToString().Equals(jenny.ToString()));
            Assert.IsTrue(hasMap2.Map["jenny"] != hasMap.Map["jenny"], "Not same instance");
        }
Пример #26
0
        public void RefSubelementsBuildCollectionFromSingleElement()
        {
            IResource        resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            TestObject       loner    = (TestObject)xof.GetObject("loner");
            TestObject       dave     = (TestObject)xof.GetObject("david");

            Assert.IsTrue(loner.Friends.Count == 1);
            bool contains = false;

            foreach (object friend in loner.Friends)
            {
                if (friend == dave)
                {
                    contains = true;
                    break;
                }
            }
            Assert.IsTrue(contains);
        }
Пример #27
0
        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;
            }
        }
        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);
        }
Пример #29
0
        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;
            }
        }
Пример #30
0
        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);
        }
Пример #31
0
 public void AnObjectsFileWithNoObjectsIsOk()
 {
     // test just makes sure that no exception is thrown and that
     // said container doesn't complain about having no objects.
     IResource resource = new ReadOnlyXmlTestResource("no-objects.xml", GetType());
     new XmlObjectFactory(resource);
 }
Пример #32
0
        public void BadParentReference()
        {
            IResource resource = new ReadOnlyXmlTestResource("wellformed-but-bad.xml", GetType());
            XmlObjectFactory xof = new XmlObjectFactory(resource);

            xof.GetObject("no.parent.factory");
        }
Пример #33
0
        public void TestExpressionElement()
        {
            TypeRegistry.RegisterType("WebMethod", typeof(WebMethodAttribute));

            IResource resource = new ReadOnlyXmlTestResource("expressions.xml", GetType());
            XmlObjectFactory xof = new XmlObjectFactory(resource);

            ExpressionTestObject eto = (ExpressionTestObject)xof.GetObject("to2");
            Assert.AreEqual(new DateTime(1974, 8, 24).ToString("m"), eto.SomeString);
            Assert.AreEqual(new DateTime(2004, 8, 14), eto.SomeDate);
            Assert.IsInstanceOf(typeof(IExpression), eto.ExpressionOne);
            Assert.IsInstanceOf(typeof(IExpression), eto.ExpressionTwo);
            Assert.AreEqual(DateTime.Today, eto.ExpressionOne.GetValue());
            Assert.AreEqual(String.Empty, eto.ExpressionTwo.GetValue());
            Assert.IsInstanceOf(typeof(WebMethodAttribute), eto.SomeDictionary["method1"]);
            Assert.IsInstanceOf(typeof(WebMethodAttribute), eto.SomeDictionary["method2"]);
            Assert.AreEqual("My First Web Method", ((WebMethodAttribute)eto.SomeDictionary["method1"]).Description);
            Assert.AreEqual("My Second Web Method", ((WebMethodAttribute)eto.SomeDictionary["method2"]).Description);
        }
        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);
        }
Пример #35
0
 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);
 }
Пример #36
0
 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"));
 }
Пример #37
0
 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);
 }
Пример #38
0
 /// <summary>
 /// Creates a new instance of the
 /// <see cref="Spring.Objects.Factory.Xml.ReadOnlyXmlTestResource"/> class.
 /// </summary>
 /// <param name="fileName">
 /// The filename/resourcename (e.g. foo.txt) of the XML file containing the object
 /// definitions.
 /// </param>
 /// <param name="associatedTestType">
 /// The <see cref="System.Type"/> of the test class utilising said file.
 /// </param>
 public ReadOnlyXmlTestResource(string fileName, Type associatedTestType)
     : this(ReadOnlyXmlTestResource.GetFilePath(fileName, associatedTestType))
 {
 }
 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);
 }
 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 NoSuchInitMethod()
 {
     IResource resource = new ReadOnlyXmlTestResource("initializers.xml", GetType());
     XmlObjectFactory xof = new XmlObjectFactory(resource);
     Assert.Throws<ObjectCreationException>(() => xof.GetObject("init-method3"));
 }
 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"));
 }
Пример #43
0
 public void ImportsExternalResourcesCorrectly()
 {
     IResource resource = new ReadOnlyXmlTestResource("external-resources.xml", GetType());
     XmlObjectFactory xof = new XmlObjectFactory(resource);
     // object comes from imported file...
     ITestObject rick = xof["rick"] as ITestObject;
     Assert.IsNotNull(rick);
     Assert.AreEqual("Rick", rick.Name);
     // object comes from base file...
     ITestObject jenny = xof["jenny"] as ITestObject;
     Assert.IsNotNull(jenny);
     Assert.AreEqual("Jenny", jenny.Name);
 }
Пример #44
0
 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);
     }
 }
Пример #45
0
 public void ImportsExternalResourcesBailsOnNonExistentResource()
 {
     IResource resource = new ReadOnlyXmlTestResource("bad-external-resources.xml", GetType());
     new XmlObjectFactory(resource);
 }
Пример #46
0
 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);
 }
Пример #47
0
 public void DependenciesMaterializeThis()
 {
     IResource resource = new ReadOnlyXmlTestResource("dependenciesMaterializeThis.xml", GetType());
     XmlObjectFactory bf = new XmlObjectFactory(resource);
     DummyBo bos = (DummyBo) bf.GetObject("boSingleton");
     DummyBo bop = (DummyBo) bf.GetObject("boPrototype");
     Assert.IsFalse(bos == bop);
     Assert.AreEqual(bos.dao, bop.dao);
 }
Пример #48
0
 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);
 }
Пример #49
0
 public void RefSubelement()
 {
     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");
     Assert.IsTrue(jen.Spouse == dave);
 }
 public void ImportsExternalResourcesBailsOnNonExistentResource()
 {
     IResource resource = new ReadOnlyXmlTestResource("bad-external-resources.xml", GetType());
     Assert.Throws<ObjectDefinitionStoreException>(() => new XmlObjectFactory(resource));
 }
Пример #51
0
 public void DefaultInitMethodDisabled()
 {
     IResource resource = new ReadOnlyXmlTestResource("default-initializers.xml", GetType());
     XmlObjectFactory xof = new XmlObjectFactory(resource);
     DoubleInitializer in_Renamed = (DoubleInitializer)xof.GetObject("init-method2");
     // Initializer should have doubled value
     Assert.AreEqual(7, in_Renamed.Num);
 }
Пример #52
0
 public void DefaultLazyInitNoInObjectDef()
 {
     InitAndIB.constructed = false;
     IResource resource = new ReadOnlyXmlTestResource("default-lazy-init.xml", GetType());
     XmlObjectFactory xof = new XmlObjectFactory(resource);
     Assert.IsFalse(InitAndIB.constructed);
     xof.PreInstantiateSingletons();
     Assert.IsTrue(InitAndIB.constructed);
     try
     {
         xof.GetObject("init-and-ib-no-init-in-local-object-def");
     }
     catch (ObjectCreationException ex)
     {
         Assert.IsTrue(ex.InnerException is FormatException);
     }
 }
Пример #53
0
 public void NoSuchInitMethod()
 {
     IResource resource = new ReadOnlyXmlTestResource("initializers.xml", GetType());
     XmlObjectFactory xof = new XmlObjectFactory(resource);
     xof.GetObject("init-method3");
     Assert.Fail();
 }
Пример #54
0
 public void DependsOn()
 {
     PreparingObject1.prepared = false;
     PreparingObject1.destroyed = false;
     PreparingObject2.prepared = false;
     PreparingObject2.destroyed = false;
     DependingObject.destroyed = false;
     IResource resource = new ReadOnlyXmlTestResource("initializers.xml", GetType());
     XmlObjectFactory xof = new XmlObjectFactory(resource);
     xof.PreInstantiateSingletons();
     xof.Dispose();
     Assert.IsTrue(PreparingObject1.prepared);
     Assert.IsTrue(PreparingObject1.destroyed);
     Assert.IsTrue(PreparingObject2.prepared);
     Assert.IsTrue(PreparingObject2.destroyed);
     Assert.IsTrue(DependingObject.destroyed);
 }
Пример #55
0
 public void DefaultDestroyMethodDisabled()
 {
     IResource resource = new ReadOnlyXmlTestResource("default-destroy-methods.xml", GetType());
     XmlObjectFactory xof = new XmlObjectFactory(resource);
     xof.PreInstantiateSingletons();
     DefaultDestroyer dd = (DefaultDestroyer)xof.GetObject("destroy-method2");
     Assert.IsTrue(!dd.customDestroyed);
     xof.Dispose();
     Assert.IsTrue(!dd.customDestroyed);
 }
Пример #56
0
 public void AnObjectCanBeIstantiatedWithANotFullySpecifiedAssemblyName()
 {
     IResource resource = new ReadOnlyXmlTestResource("notfullyspecified.xml", GetType());
     XmlObjectFactory xof = new XmlObjectFactory(resource);
     IDbConnection connection = (IDbConnection) xof.GetObject("connectionNotFullySpecified");
     Assert.IsNotNull(connection);
 }
 public void SetUp()
 {
     IResource resource = new ReadOnlyXmlTestResource("concurrent.xml", GetType());
     factory = new XmlObjectFactory(resource);
 }
Пример #58
0
        public void ResourceAndInputStream()
        {
            //string filename = @"C:\temp\spring-test.properties";
            string filename = @"/temp/spring-test.properties";
            FileInfo file = new FileInfo(filename);
            bool tempDirWasCreated = false;
            try
            {
                if (file.Exists)
                {
                    file.Delete();
                }
                if (!file.Directory.Exists)
                {
                    file.Directory.Create();
                    tempDirWasCreated = true;
                }
                StreamWriter sw = file.CreateText();
                sw.WriteLine("test");
                sw.Close();

                IResource resource = new ReadOnlyXmlTestResource("resource.xml", GetType());
                XmlObjectFactory xof = new XmlObjectFactory(resource);

                ResourceTestObject resource1 = (ResourceTestObject) xof.GetObject("resource1");
                Assert.IsTrue(resource1.Resource is FileSystemResource);
                using (StreamReader reader = new StreamReader(resource1.Resource.InputStream))
                {
                    string fileText = reader.ReadLine();
                    Assert.AreEqual("test", fileText, "error using IResource to read file contents");
                }
                using (StreamReader reader = new StreamReader(resource1.InputStream))
                {
                    string fileText = reader.ReadLine();
                    Assert.AreEqual("test", fileText, "error using Stream to read file contents");
                }
            }
            finally
            {
                if (tempDirWasCreated)
                {
                    file.Delete();
                    // sure hope another process hasn't created the directory
                    file.Directory.Delete();
                }
            }
        }