コード例 #1
0
        public void BailsWhenJustTargetTypeIsSet()
        {
            PropertyRetrievingFactoryObject fac = new PropertyRetrievingFactoryObject();

            fac.TargetType = GetType();
            Assert.Throws <ArgumentException>(() => fac.AfterPropertiesSet());
        }
コード例 #2
0
        public void BailsWhenJustTargetObjectIsSet()
        {
            PropertyRetrievingFactoryObject fac = new PropertyRetrievingFactoryObject();

            fac.TargetObject = this;
            Assert.Throws <ArgumentException>(() => fac.AfterPropertiesSet(), "The TargetProperty property is required.");
        }
コード例 #3
0
        public void ResistsSettingTheArgumentsToNull()
        {
            PropertyRetrievingFactoryObject fac = new PropertyRetrievingFactoryObject();

            fac.Arguments = null;
            Assert.IsNotNull(fac.Arguments);
        }
コード例 #4
0
        public void BailsOnNonExistantProperty()
        {
            PropertyObject expected             = new PropertyObject();
            PropertyRetrievingFactoryObject fac = new PropertyRetrievingFactoryObject();

            fac.TargetObject   = expected;
            fac.TargetProperty = "Blister";
            Assert.Throws <InvalidPropertyException>(() => fac.AfterPropertiesSet());
        }
コード例 #5
0
        public void BailsOnWriteOnlyProperty()
        {
            PropertyObject expected             = new PropertyObject();
            PropertyRetrievingFactoryObject fac = new PropertyRetrievingFactoryObject();

            fac.TargetObject   = expected;
            fac.TargetProperty = "Greenness";
            Assert.Throws <NotWritablePropertyException>(() => fac.AfterPropertiesSet());
        }
コード例 #6
0
        public void BailsWhenReadingIndexedPropertyWithNoArguments()
        {
            PropertyObject expected             = new PropertyObject();
            PropertyRetrievingFactoryObject fac = new PropertyRetrievingFactoryObject();

            fac.TargetObject   = expected;
            fac.TargetProperty = "Item";
            Assert.Throws <FatalObjectException>(() => fac.AfterPropertiesSet());
        }
コード例 #7
0
        public void NestedStaticProperty()
        {
            PropertyRetrievingFactoryObject fac = new PropertyRetrievingFactoryObject();

            fac.StaticProperty = "Oragon.Spring.Objects.Factory.Config.PropertyObject.StaticProperty.Age, Oragon.Spring.Core.Tests";
            fac.AfterPropertiesSet();
            Assert.AreEqual(typeof(int), fac.ObjectType);
            object actual = fac.GetObject();

            Assert.AreEqual(PropertyObject.Age, actual);
        }
コード例 #8
0
        public void StaticPropertyViaClassAndFieldName()
        {
            PropertyRetrievingFactoryObject fac = new PropertyRetrievingFactoryObject();

            fac.TargetProperty = "Age";
            fac.TargetType     = typeof(PropertyObject);
            fac.AfterPropertiesSet();
            object actual = fac.GetObject();

            Assert.AreEqual(PropertyObject.Age, actual);
        }
コード例 #9
0
        public void StaticPropertyThatAintAssemblyQualifiedShouldStillBeResolved()
        {
            PropertyRetrievingFactoryObject fac = new PropertyRetrievingFactoryObject();

            fac.StaticProperty = "Oragon.Spring.Objects.Factory.Config.PropertyObject.Age";
            fac.AfterPropertiesSet();
            Assert.AreEqual(typeof(int), fac.ObjectType);
            object actual = fac.GetObject();

            Assert.AreEqual(PropertyObject.Age, actual);
        }
コード例 #10
0
        public void SuperMixOfNestedIndexedStaticAndInstanceProperty()
        {
            PropertyRetrievingFactoryObject fac = new PropertyRetrievingFactoryObject();

            fac.StaticProperty = "Oragon.Spring.Objects.Factory.Config.PropertyObject.StaticProperty.StaticProperty.Item, Oragon.Spring.Core.Tests";
            fac.Arguments      = new object[] { 0 };
            fac.AfterPropertiesSet();
            Assert.AreEqual(typeof(int), fac.ObjectType);
            object actual = fac.GetObject();

            Assert.AreEqual(PropertyObject.StaticProperty[0], actual);
        }
コード例 #11
0
        public void StaticPropertyCaseINsenSiTiVE()
        {
            PropertyRetrievingFactoryObject fac = new PropertyRetrievingFactoryObject();

            fac.StaticProperty = "System.Globalization.CultureInfo.CURRENtUiCultURE, Mscorlib";
            fac.AfterPropertiesSet();
            Assert.AreEqual(typeof(CultureInfo), fac.ObjectType);
            CultureInfo actual = fac.GetObject() as CultureInfo;

            Assert.IsNotNull(actual);
            Assert.AreEqual(CultureInfo.CurrentUICulture, actual);
        }
コード例 #12
0
        public void IndexedProperty()
        {
            PropertyObject expected             = new PropertyObject();
            PropertyRetrievingFactoryObject fac = new PropertyRetrievingFactoryObject();

            fac.TargetObject   = expected;
            fac.TargetProperty = "Item";
            fac.Arguments      = new object[] { 2 };
            fac.AfterPropertiesSet();
            object actual = fac.GetObject();

            Assert.AreEqual(expected[2], actual);
        }
コード例 #13
0
        public void InstanceProperty()
        {
            PropertyObject expected = new PropertyObject();

            expected.Name = "Haruki Murakami";
            PropertyRetrievingFactoryObject fac = new PropertyRetrievingFactoryObject();

            fac.TargetObject   = expected;
            fac.TargetProperty = "Name";
            fac.AfterPropertiesSet();
            object actual = fac.GetObject();

            Assert.AreEqual(expected.Name, actual);
        }
コード例 #14
0
        public void GetDateTimeDotNowToTestHandlingOfPrototypesIsCorrect()
        {
            PropertyRetrievingFactoryObject fac = new PropertyRetrievingFactoryObject();

            fac.TargetType     = typeof(DateTime);
            fac.TargetProperty = "Now";
            fac.IsSingleton    = false;
            fac.AfterPropertiesSet();
            DateTime then = (DateTime)fac.GetObject();

            Assert.IsNotNull(then);
            DateTime now = (DateTime)fac.GetObject();

            Assert.IsNotNull(now);
            Assert.IsFalse(ReferenceEquals(then, now));
        }
コード例 #15
0
        public void IsSingleton()
        {
            PropertyRetrievingFactoryObject fac = new PropertyRetrievingFactoryObject();

            fac.IsSingleton    = false;
            fac.TargetProperty = "Age";
            fac.TargetType     = typeof(PropertyObject);
            fac.AfterPropertiesSet();
            object actual = fac.GetObject();

            Assert.AreEqual(PropertyObject.Age, actual);

            PropertyObject.Age = 94;
            object tryTwo = fac.GetObject();

            Assert.AreEqual(PropertyObject.Age, tryTwo);
        }
コード例 #16
0
        public void NestedInstanceProperty()
        {
            TestObject person = new TestObject();

            person.Age = 20;
            TestObject spouse = new TestObject();

            spouse.Age    = 21;
            person.Spouse = spouse;
            PropertyRetrievingFactoryObject fac = new PropertyRetrievingFactoryObject();

            fac.TargetObject   = person;
            fac.TargetProperty = "spouse.age";
            fac.AfterPropertiesSet();
            object actual      = fac.GetObject();
            int    expectedAge = 21;

            Assert.AreEqual(expectedAge, actual);
        }
コード例 #17
0
        public void BailsWhenNotConfigured()
        {
            PropertyRetrievingFactoryObject fac = new PropertyRetrievingFactoryObject();

            Assert.Throws <ArgumentException>(() => fac.AfterPropertiesSet(), "One of the TargetType or TargetObject properties must be set.");
        }
コード例 #18
0
        public void BailsWhenStaticPropertyIsSetToNull()
        {
            PropertyRetrievingFactoryObject fac = new PropertyRetrievingFactoryObject();

            Assert.Throws <ArgumentNullException>(() => fac.StaticProperty = null);
        }
コード例 #19
0
        public void Instantiation()
        {
            PropertyRetrievingFactoryObject fac = new PropertyRetrievingFactoryObject();

            Assert.IsNotNull(fac.Arguments);
        }
コード例 #20
0
        public void BailsWhenStaticPropertyPassedGumpfh()
        {
            PropertyRetrievingFactoryObject fac = new PropertyRetrievingFactoryObject();

            Assert.Throws <ArgumentException>(() => fac.StaticProperty = "Boog"); // no field specified
        }