Ejemplo n.º 1
0
        public void ShouldReflectionOnlyGetLogicalPropertyValueTest()
        {
            ReflectionFascade reflectionFascade;
            MockObject        mockObject;
            string            propertyName;
            object            propertyValue;
            bool result;

            MockFactory      mockFactory;
            IDataTypeFascade mockDataTypeFascade;

            string _unusedString = null;

            mockFactory         = new MockFactory();
            mockDataTypeFascade = mockFactory.CreateInstance <IDataTypeFascade>();

            Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With((object)null).Will(Return.Value(true));
            Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With(string.Empty).Will(Return.Value(true));
            Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With("FirstName").Will(Return.Value(false));

            Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With("NoGetter").Will(Return.Value(false));
            Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With("NoSetter").Will(Return.Value(false));

            reflectionFascade = new ReflectionFascade(mockDataTypeFascade);

            // null, null
            mockObject   = null;
            propertyName = null;

            result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

            Assert.IsFalse(result);
            Assert.IsNull(propertyValue);

            // null, ""
            mockObject   = null;
            propertyName = string.Empty;

            result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

            Assert.IsFalse(result);
            Assert.IsNull(propertyValue);

            // null, "PropName"
            mockObject   = null;
            propertyName = "FirstName";

            result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

            Assert.IsFalse(result);
            Assert.IsNull(propertyValue);

            // !null, null
            mockObject   = new MockObject();
            propertyName = null;

            result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

            Assert.IsFalse(result);
            Assert.IsNull(propertyValue);

            // !null, ""
            mockObject   = new MockObject();
            propertyName = string.Empty;

            result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

            Assert.IsFalse(result);
            Assert.IsNull(propertyValue);

            // !null, "PropName"
            mockObject           = new MockObject();
            mockObject.FirstName = "john";
            propertyName         = "FirstName";

            result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

            Assert.IsTrue(result);
            Assert.IsNotNull(propertyValue);
            Assert.AreEqual("john", propertyValue);

            // !null, "PropName:PropName!!!getter"
            mockObject           = new MockObject();
            mockObject.FirstName = "john";
            propertyName         = "NoGetter";

            result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

            Assert.IsFalse(result);
            Assert.IsNull(propertyValue);

            // !null, "PropName:PropName!!!setter"
            mockObject           = new MockObject();
            mockObject.FirstName = "john";
            propertyName         = "NoSetter";

            result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

            Assert.IsTrue(result);
            Assert.IsNotNull(propertyValue);
            Assert.AreEqual(1, propertyValue);
        }
Ejemplo n.º 2
0
		public void ShouldReflectionOnlyGetLogicalPropertyValueTest()
		{
			ReflectionFascade reflectionFascade;
			MockObject mockObject;
			string propertyName;
			object propertyValue;
			bool result;

			MockFactory mockFactory;
			IDataTypeFascade mockDataTypeFascade;

			string _unusedString = null;

			mockFactory = new MockFactory();
			mockDataTypeFascade = mockFactory.CreateInstance<IDataTypeFascade>();

			Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With((object)null).Will(Return.Value(true));
			Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With(string.Empty).Will(Return.Value(true));
			Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With("FirstName").Will(Return.Value(false));

			Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With("NoGetter").Will(Return.Value(false));
			Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With("NoSetter").Will(Return.Value(false));

			reflectionFascade = new ReflectionFascade(mockDataTypeFascade);

			// null, null
			mockObject = null;
			propertyName = null;

			result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

			Assert.IsFalse(result);
			Assert.IsNull(propertyValue);

			// null, ""
			mockObject = null;
			propertyName = string.Empty;

			result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

			Assert.IsFalse(result);
			Assert.IsNull(propertyValue);

			// null, "PropName"
			mockObject = null;
			propertyName = "FirstName";

			result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

			Assert.IsFalse(result);
			Assert.IsNull(propertyValue);

			// !null, null
			mockObject = new MockObject();
			propertyName = null;

			result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

			Assert.IsFalse(result);
			Assert.IsNull(propertyValue);

			// !null, ""
			mockObject = new MockObject();
			propertyName = string.Empty;

			result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

			Assert.IsFalse(result);
			Assert.IsNull(propertyValue);

			// !null, "PropName"
			mockObject = new MockObject();
			mockObject.FirstName = "john";
			propertyName = "FirstName";

			result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

			Assert.IsTrue(result);
			Assert.IsNotNull(propertyValue);
			Assert.AreEqual("john", propertyValue);

			// !null, "PropName:PropName!!!getter"
			mockObject = new MockObject();
			mockObject.FirstName = "john";
			propertyName = "NoGetter";

			result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

			Assert.IsFalse(result);
			Assert.IsNull(propertyValue);

			// !null, "PropName:PropName!!!setter"
			mockObject = new MockObject();
			mockObject.FirstName = "john";
			propertyName = "NoSetter";

			result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

			Assert.IsTrue(result);
			Assert.IsNotNull(propertyValue);
			Assert.AreEqual(1, propertyValue);
		}
Ejemplo n.º 3
0
        public void ShouldAssociativeOnlyGetLogicalPropertyValueTest()
        {
            ReflectionFascade           reflectionFascade;
            Dictionary <string, object> mockObject;
            string propertyName;
            object propertyValue;
            bool   result;

            MockFactory      mockFactory;
            IDataTypeFascade mockDataTypeFascade;

            string _unusedString = null;

            mockFactory         = new MockFactory();
            mockDataTypeFascade = mockFactory.CreateInstance <IDataTypeFascade>();

            Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With((object)null).Will(Return.Value(true));
            Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With(string.Empty).Will(Return.Value(true));
            Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With("FirstName").Will(Return.Value(false));

            reflectionFascade = new ReflectionFascade(mockDataTypeFascade);

            // null, null
            mockObject   = null;
            propertyName = null;

            result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

            Assert.IsFalse(result);
            Assert.IsNull(propertyValue);

            // null, ""
            mockObject   = null;
            propertyName = string.Empty;

            result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

            Assert.IsFalse(result);
            Assert.IsNull(propertyValue);

            // null, "PropName"
            mockObject   = null;
            propertyName = "FirstName";

            result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

            Assert.IsFalse(result);
            Assert.IsNull(propertyValue);

            // !null, null
            mockObject   = new Dictionary <string, object>();
            propertyName = null;

            result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

            Assert.IsFalse(result);
            Assert.IsNull(propertyValue);

            // !null, ""
            mockObject   = new Dictionary <string, object>();
            propertyName = string.Empty;

            result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

            Assert.IsFalse(result);
            Assert.IsNull(propertyValue);

            // !null, "PropName"
            mockObject = new Dictionary <string, object>();
            mockObject["FirstName"] = "john";
            propertyName            = "FirstName";

            result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

            Assert.IsTrue(result);
            Assert.IsNotNull(propertyValue);
            Assert.AreEqual("john", propertyValue);

            mockFactory.VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 4
0
		public void ShouldAssociativeOnlyGetLogicalPropertyValueTest()
		{
			ReflectionFascade reflectionFascade;
			Dictionary<string, object> mockObject;
			string propertyName;
			object propertyValue;
			bool result;

			MockFactory mockFactory;
			IDataTypeFascade mockDataTypeFascade;

			string _unusedString = null;

			mockFactory = new MockFactory();
			mockDataTypeFascade = mockFactory.CreateInstance<IDataTypeFascade>();

			Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With((object)null).Will(Return.Value(true));
			Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With(string.Empty).Will(Return.Value(true));
			Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With("FirstName").Will(Return.Value(false));

			reflectionFascade = new ReflectionFascade(mockDataTypeFascade);

			// null, null
			mockObject = null;
			propertyName = null;

			result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

			Assert.IsFalse(result);
			Assert.IsNull(propertyValue);

			// null, ""
			mockObject = null;
			propertyName = string.Empty;

			result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

			Assert.IsFalse(result);
			Assert.IsNull(propertyValue);

			// null, "PropName"
			mockObject = null;
			propertyName = "FirstName";

			result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

			Assert.IsFalse(result);
			Assert.IsNull(propertyValue);

			// !null, null
			mockObject = new Dictionary<string, object>();
			propertyName = null;

			result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

			Assert.IsFalse(result);
			Assert.IsNull(propertyValue);

			// !null, ""
			mockObject = new Dictionary<string, object>();
			propertyName = string.Empty;

			result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

			Assert.IsFalse(result);
			Assert.IsNull(propertyValue);

			// !null, "PropName"
			mockObject = new Dictionary<string, object>();
			mockObject["FirstName"] = "john";
			propertyName = "FirstName";

			result = reflectionFascade.GetLogicalPropertyValue(mockObject, propertyName, out propertyValue);

			Assert.IsTrue(result);
			Assert.IsNotNull(propertyValue);
			Assert.AreEqual("john", propertyValue);

			mockFactory.VerifyAllExpectationsHaveBeenMet();
		}