Example #1
0
        public void NothingSet()
        {
            FieldRetrievingFactoryObject fac = new FieldRetrievingFactoryObject();

            fac.ObjectName = "foo";
            Assert.Throws <ArgumentException>(() => fac.AfterPropertiesSet());
        }
Example #2
0
        public void BailsWhenBothTargetTypeAndTargetObjectPropsAreSet()
        {
            FieldRetrievingFactoryObject fac = new FieldRetrievingFactoryObject();

            fac.TargetObject = this;
            fac.TargetType   = GetType();
            Assert.Throws <ArgumentException>(() => fac.AfterPropertiesSet());
        }
Example #3
0
        public void BailsOnNonExistantField()
        {
            FieldRetrievingFactoryObject fac = new FieldRetrievingFactoryObject();

            fac.StaticField = "Oragon.Spring.Objects.Factory.Config.FinalFielder.Rubbish, Oragon.Spring.Core.Tests";
            fac.ObjectName  = "foo";
            Assert.Throws <ObjectDefinitionStoreException>(() => fac.AfterPropertiesSet());
        }
Example #4
0
        public void BailsWhenStaticFieldPassedGumpfh()
        {
            FieldRetrievingFactoryObject fac = new FieldRetrievingFactoryObject();

            fac.StaticField = "Goob"; // no field specified
            fac.ObjectName  = "foo";
            Assert.Throws <ArgumentException>(() => fac.AfterPropertiesSet());
        }
Example #5
0
        public void JustTargetField()
        {
            FieldRetrievingFactoryObject fac = new FieldRetrievingFactoryObject();

            fac.TargetField = "Space";
            fac.ObjectName  = "foo";
            Assert.Throws <ArgumentException>(() => fac.AfterPropertiesSet());
        }
Example #6
0
        public void UsesObjectNameForStaticField()
        {
            FieldRetrievingFactoryObject fac = new FieldRetrievingFactoryObject();

            fac.ObjectName = "System.Type.Delimiter";
            fac.AfterPropertiesSet();
            Assert.AreEqual(typeof(char), fac.ObjectType);
            object actual = fac.GetObject();

            Assert.AreEqual(Type.Delimiter, actual);
        }
Example #7
0
        public void StaticFieldSystemClass()
        {
            FieldRetrievingFactoryObject fac = new FieldRetrievingFactoryObject();

            fac.StaticField = "System.DBNull.Value";
            fac.ObjectName  = "foo";
            fac.AfterPropertiesSet();
            Assert.AreEqual(typeof(DBNull), fac.ObjectType);
            object actual = fac.GetObject();

            Assert.AreEqual(DBNull.Value, actual);
        }
Example #8
0
        public void StaticFieldThatAintAssemblyQualifiedShouldStillBeResolved()
        {
            FieldRetrievingFactoryObject fac = new FieldRetrievingFactoryObject();

            fac.StaticField = "Oragon.Spring.Objects.Factory.Config.FinalFielder.Name";
            fac.ObjectName  = "foo";
            fac.AfterPropertiesSet();
            Assert.AreEqual(typeof(string), fac.ObjectType);
            object actual = fac.GetObject();

            Assert.AreEqual(FinalFielder.Name, actual);
        }
Example #9
0
        public void StaticFieldWithWhitespace()
        {
            FieldRetrievingFactoryObject fac = new FieldRetrievingFactoryObject();

            fac.StaticField = "\tOragon.Spring.Objects.Factory.Config.FinalFielder.Name, Oragon.Spring.Core.Tests        ";
            fac.ObjectName  = "foo";
            fac.AfterPropertiesSet();
            Assert.AreEqual(typeof(string), fac.ObjectType);
            object actual = fac.GetObject();

            Assert.AreEqual(FinalFielder.Name, actual);
        }
Example #10
0
        public void StaticFieldIsCaseINsenSiTiVE()
        {
            FieldRetrievingFactoryObject fac = new FieldRetrievingFactoryObject();

            fac.StaticField = "System.Type.emptytyPES, Mscorlib";
            fac.ObjectName  = "foo";
            fac.AfterPropertiesSet();
            Assert.AreEqual(typeof(Type[]), fac.ObjectType);
            Type[] actual = fac.GetObject() as Type[];
            Assert.IsNotNull(actual);
            Assert.AreEqual(Type.EmptyTypes.Length, actual.Length);
        }
Example #11
0
        public void StaticFieldViaClassAndFieldName()
        {
            FieldRetrievingFactoryObject fac = new FieldRetrievingFactoryObject();

            fac.TargetField = "Name";
            fac.TargetType  = typeof(FinalFielder);
            fac.ObjectName  = "foo";
            fac.AfterPropertiesSet();
            object actual = fac.GetObject();

            Assert.AreEqual(FinalFielder.Name, actual);
        }
Example #12
0
        public void OnlyUsesObjectNameForStaticFieldIfTheStaticFieldHasNotBeenSet()
        {
            FieldRetrievingFactoryObject fac = new FieldRetrievingFactoryObject();

            fac.ObjectName  = "System.DBNull.Value";
            fac.StaticField = "Oragon.Spring.Objects.Factory.Config.FinalFielder.Name";
            fac.AfterPropertiesSet();
            Assert.AreEqual(typeof(string), fac.ObjectType);
            object actual = fac.GetObject();

            Assert.AreEqual(FinalFielder.Name, actual);
        }
Example #13
0
        public void InstanceField()
        {
            FinalFielder expected = new FinalFielder();

            expected.Age = 56;
            FieldRetrievingFactoryObject fac = new FieldRetrievingFactoryObject();

            fac.TargetObject = expected;
            fac.TargetField  = "Age";
            fac.ObjectName   = "foo";
            fac.AfterPropertiesSet();
            object actual = fac.GetObject();

            Assert.AreEqual(expected.Age, actual);
        }