コード例 #1
0
        public void TestForRestrictiveGetter()
        {
            Something something = new Something();

            IDynamicProperty third = Create(typeof(Something).GetProperty("Third"));
            //this should be ok, because both get and set of the "Third" property are public
            third.SetValue(something, 456);
            Assert.AreEqual(456, third.GetValue(something));

            IDynamicProperty first = Create(typeof(Something).GetProperty("First"));
            first.SetValue(something, 123);
            //this should cause MethodAccessException, because get is private
            Assert.Throws<MethodAccessException>(() => first.GetValue(something));
        }
コード例 #2
0
        public void TestForRestrictiveGetterWithSafeWrapper()
        {
            Something something = new Something();
            //new SafeProperty()
            IDynamicProperty third = Create(typeof(Something).GetProperty("Third"));

            //this should be ok, because both get and set of the "Third" property are public
            third.SetValue(something, 456);
            Assert.AreEqual(456, third.GetValue(something));

            IDynamicProperty first = Create(typeof(Something).GetProperty("First"));

            first.SetValue(something, 123);
            //this should not cause MethodAccessException, "first" is createtd using "CreateSafe"
            Assert.AreEqual(123, first.GetValue(something));
        }
コード例 #3
0
        public void TestForRestrictiveSetter()
        {
            Something something = new Something();

            IDynamicProperty third = Create(typeof(Something).GetProperty("Third"));
            third.SetValue(something, 456);
            //this should be ok, because both get and set of the "Third" property are public
            Assert.AreEqual(456, third.GetValue(something));

            IDynamicProperty second = Create(typeof(Something).GetProperty("Second"));
            Assert.AreEqual(2, second.GetValue(something));
            //this should cause MethodAccessException, because set is private in "Second" property
            second.SetValue(something, 123);

            //this should never execute
            Assert.Throws<MethodAccessException>(() => second.GetValue(something));
        }
コード例 #4
0
        public void TestForRestrictiveSetterWithSafeWrapper()
        {
            Something something = new Something();

            IDynamicProperty third = Create(typeof(Something).GetProperty("Third"));

            third.SetValue(something, 456);
            //this should be ok, because both get and set of the "Third" property are public
            Assert.AreEqual(456, third.GetValue(something));

            IDynamicProperty second = Create(typeof(Something).GetProperty("Second"));

            Assert.AreEqual(2, second.GetValue(something));
            //this should not cause MethodAccessException because "second" is created using "CreateSafe"
            second.SetValue(something, 123);

            Assert.AreEqual(123, second.GetValue(something));
        }
コード例 #5
0
ファイル: BasePropertyTests.cs プロジェクト: fuadm/spring-net
        public void TestForRestrictiveSetter()
        {
            Something something = new Something();

            IDynamicProperty third = Create(typeof(Something).GetProperty("Third"));
            third.SetValue(something, 456);
            //this should be ok, because both get and set of the "Third" property are public
            Assert.AreEqual(456, third.GetValue(something));

            IDynamicProperty second = Create(typeof(Something).GetProperty("Second"));
            Assert.AreEqual(2, second.GetValue(something));
            //this should cause MethodAccessException, because set is private in "Second" property
            second.SetValue(something, 123);

            //this should never execute
            Assert.AreEqual(123, second.GetValue(something));
        }
コード例 #6
0
ファイル: BasePropertyTests.cs プロジェクト: fuadm/spring-net
        public void TestForRestrictiveGetter()
        {
            Something something = new Something();

            IDynamicProperty third = Create(typeof(Something).GetProperty("Third"));
            //this should be ok, because both get and set of the "Third" property are public
            third.SetValue(something, 456);
            Assert.AreEqual(456, third.GetValue(something));

            IDynamicProperty first = Create(typeof(Something).GetProperty("First"));
            first.SetValue(something, 123);
            //this should cause MethodAccessException, because get is private
            Assert.AreEqual(123, first.GetValue(something));
        }
コード例 #7
0
 public void TestForRestrictiveGetterWithSafeWrapper()
 {
     Something something = new Something();
     //new SafeProperty()
     IDynamicProperty third = Create(typeof(Something).GetProperty("Third"));
     //this should be ok, because both get and set of the "Third" property are public
     third.SetValue(something, 456);
     Assert.AreEqual(456, third.GetValue(something));
     
     IDynamicProperty first = Create(typeof(Something).GetProperty("First"));
     first.SetValue(something, 123);
     //this should not cause MethodAccessException, "first" is createtd using "CreateSafe"
     Assert.AreEqual(123, first.GetValue(something));
 }	
コード例 #8
0
        public void TestForRestrictiveSetterWithSafeWrapper()
        {
            Something something = new Something();

            IDynamicProperty third = Create(typeof(Something).GetProperty("Third"));
            third.SetValue(something, 456);
            //this should be ok, because both get and set of the "Third" property are public
            Assert.AreEqual(456, third.GetValue(something));

            IDynamicProperty second = Create(typeof(Something).GetProperty("Second"));
            Assert.AreEqual(2, second.GetValue(something));
            //this should not cause MethodAccessException because "second" is created using "CreateSafe"
            second.SetValue(something, 123);
            
            Assert.AreEqual(123, second.GetValue(something));
        }