Exemplo n.º 1
0
        public void GetObject_ViaObjectNameWithNullInNestedPropertyPath()
        {
            Expect.Call(mockFactory.IsSingleton("foo")).Return(true);
            Expect.Call(mockFactory.GetObject("foo")).Return(new TestObject("Fiona Apple", 28));
            mocks.ReplayAll();

            PropertyPathFactoryObject fac = new PropertyPathFactoryObject();

            fac.ObjectName = "foo.spouse.name";
            Assert.Throws <NullValueInNestedPathException>(() => fac.ObjectFactory = mockFactory);
        }
Exemplo n.º 2
0
        public void GetObject_ViaObjectNameThatStartsWithAPeriod()
        {
            Expect.Call(mockFactory.IsSingleton("foo")).Return(true);
            Expect.Call(mockFactory.GetObject("foo")).Return(new TestObject("Fiona Apple", 28));
            mocks.ReplayAll();

            PropertyPathFactoryObject fac = new PropertyPathFactoryObject();

            fac.ObjectName = ".foo.name";
            Assert.Throws <ArgumentException>(() => fac.ObjectFactory = mockFactory);
        }
Exemplo n.º 3
0
        public void GetObject_PropertyPathEvaluatesToNull()
        {
            Expect.Call(mockFactory.IsSingleton("foo")).Return(true);
            Expect.Call(mockFactory.GetObject("foo")).Return(new TestObject(null, 28));
            mocks.ReplayAll();

            PropertyPathFactoryObject fac = new PropertyPathFactoryObject();

            fac.ObjectName    = "foo.name";
            fac.ObjectFactory = mockFactory;
            Assert.Throws <FatalObjectException>(() => fac.GetObject());
        }
Exemplo n.º 4
0
        public void GetObject_ViaObjectName()
        {
            Expect.Call(mockFactory.IsSingleton("foo")).Return(true);
            Expect.Call(mockFactory.GetObject("foo")).Return(new TestObject("Fiona Apple", 28));
            mocks.ReplayAll();

            PropertyPathFactoryObject fac = new PropertyPathFactoryObject();

            fac.ObjectName    = "foo.name";
            fac.ObjectFactory = mockFactory;
            string name = (string)fac.GetObject();

            Assert.AreEqual("Fiona Apple", name);
            mocks.VerifyAll();
        }
Exemplo n.º 5
0
        public void GetObject_MakeSureLeadingAndTrailingWhitspaceIsTrimmed()
        {
            Expect.Call(mockFactory.IsSingleton("foo")).Return(true);
            Expect.Call(mockFactory.GetObject("foo")).Return(new TestObject("Fiona Apple", 28));
            mocks.ReplayAll();

            PropertyPathFactoryObject fac = new PropertyPathFactoryObject();

            fac.ObjectName    = "   \nfoo.name  ";
            fac.ObjectFactory = mockFactory;
            string name = (string)fac.GetObject();

            Assert.AreEqual("Fiona Apple", name);
            mocks.VerifyAll();
        }
Exemplo n.º 6
0
        public void GetObject_ViaObjectNameWithNestedPropertyPath()
        {
            Expect.Call(mockFactory.IsSingleton("foo")).Return(true);
            TestObject target = new TestObject("Fiona Apple", 28);

            target.Spouse = target;
            Expect.Call(mockFactory.GetObject("foo")).Return(target);
            mocks.ReplayAll();

            PropertyPathFactoryObject fac = new PropertyPathFactoryObject();

            fac.ObjectName    = "foo.spouse.name";
            fac.ObjectFactory = mockFactory;
            string name = (string)fac.GetObject();

            Assert.AreEqual("Fiona Apple", name);
            mocks.VerifyAll();
        }