コード例 #1
0
        public void InvokeMethodWithDerivedParametersTest()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);
            var value    = (string)accessor.GetObjectString(12345);

            Assert.AreEqual("12345", value);
        }
コード例 #2
0
        public void InvokeMethodWithGenericsTest()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);
            var value    = (int)accessor.GenericMethod <int>(1);

            Assert.AreEqual(1, value);
        }
コード例 #3
0
        public void InvokePrivateMethodTest()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);
            var value    = (string)accessor.PrivateMethod();

            Assert.AreEqual(DefaultMethodStringValue, value);
        }
コード例 #4
0
        public void InvokeMethodWithParametersTest()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);
            var value    = (int)accessor.AddMethod(1, 2);

            Assert.AreEqual(3, value);
        }
コード例 #5
0
        public void GetThenInvokePublicMethodTest()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);
            var method   = accessor.PublicMethod;
            var value    = (string)method();

            Assert.AreEqual(DefaultMethodStringValue, value);
        }
コード例 #6
0
        public void InvokeHiddenMethodTest()
        {
            // This should only invoke the first method going down the types
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);
            var value    = (string)accessor.HiddenMethod();

            Assert.AreEqual(DefaultMethodStringValue, value);
        }
コード例 #7
0
        public void CastReturnToConvertableTypeTest()
        {
            var accessor         = DynamicObjectAccessor.Create(new TestClass(), true);
            var publicField      = accessor.PublicTestInt;
            var publicFieldValue = (long)publicField;

            Assert.IsNotNull(publicFieldValue);
        }
コード例 #8
0
        public void AccessPrivateFieldTest()
        {
            var accessor          = DynamicObjectAccessor.Create(new TestClass(), true);
            var privateField      = accessor.PrivateField;
            var privateFieldValue = (string)privateField;

            Assert.IsNotNull(privateField);
            Assert.AreEqual(PrivateFieldStringValue, privateFieldValue);
        }
コード例 #9
0
        public void GetByMultiIndexTest()
        {
            var accessor               = DynamicObjectAccessor.Create(new TestClass(), true);
            var privateClassField      = accessor["PublicTestObject", "PrivateClassString"];
            var privateClassFieldValue = (string)privateClassField;

            Assert.IsNotNull(privateClassField);
            Assert.AreEqual(PrivateFieldStringValue, privateClassFieldValue);
        }
コード例 #10
0
        public void GetByIndexTest()
        {
            var accessor         = DynamicObjectAccessor.Create(new TestClass(), true);
            var publicField      = accessor["PublicTestObject"];
            var publicFieldValue = (AccessorMemberTests.A)publicField;

            Assert.IsNotNull(publicFieldValue);
            Assert.IsTrue(publicFieldValue is AccessorMemberTests.A);
        }
コード例 #11
0
        public void CastReturnToBaseTypeTest()
        {
            var accessor         = DynamicObjectAccessor.Create(new TestClass(), true);
            var publicField      = accessor.PublicTestObject;
            var publicFieldValue = (AccessorMemberTests.A)publicField;

            Assert.IsNotNull(publicFieldValue);
            Assert.IsTrue(publicFieldValue is AccessorMemberTests.A);
        }
コード例 #12
0
        public void AccessPublicPropertyTest()
        {
            var accessor            = DynamicObjectAccessor.Create(new TestClass(), true);
            var publicProperty      = accessor.PublicProperty;
            var publicPropertyValue = (string)publicProperty;

            Assert.IsNotNull(publicProperty);
            Assert.AreEqual(PublicPropertyStringValue, publicPropertyValue);
        }
コード例 #13
0
        public void AccessPrivateFieldOnBaseClassTest()
        {
            var accessor = DynamicObjectAccessor.Create(new B(), true);
            var privateBaseClassProperty      = accessor.PrivateBaseClassString;
            var privateBaseClassPropertyValue = (string)privateBaseClassProperty;

            Assert.IsNotNull(privateBaseClassProperty);
            Assert.AreEqual(PrivateFieldStringValue, privateBaseClassPropertyValue);
        }
コード例 #14
0
        public void TestPropertyNullAssigning()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            accessor.TestProperty = null;
            var newPropertyValue = (string)accessor.TestProperty;

            Assert.AreEqual(null, newPropertyValue);
        }
コード例 #15
0
        public void TestFieldNullAssigning()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            accessor.TestField = null;
            var newFieldValue = (string)accessor.TestField;

            Assert.AreEqual(null, newFieldValue);
        }
コード例 #16
0
        public void SetByMultiIndexTest()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            accessor["Child", "PublicStringField"] = TestStringValue;
            var newFieldValue = (string)accessor.Child.PublicStringField;

            Assert.AreEqual(TestStringValue, newFieldValue);
        }
コード例 #17
0
        public void AccessHiddenFieldTest()
        {
            var accessor       = DynamicObjectAccessor.Create(new B(), true);
            var accessorHidden = DynamicObjectAccessor.Create(new B(), true, typeof(A));

            var privateFieldValue       = (string)accessor.HiddenStringField;
            var hiddenPrivateFieldValue = (string)accessorHidden.HiddenStringField;

            Assert.AreEqual(privateFieldValue, string.Empty);
            Assert.AreEqual(hiddenPrivateFieldValue, PrivateFieldStringValue);
        }
コード例 #18
0
        public void TestThrowOnInvalidTypeAssign()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            Assert.ThrowsException <RuntimeBinderException>(() => accessor.TestField = 42);
        }
コード例 #19
0
        public void CastReturnToInvalidTypeTest()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            Assert.ThrowsException <RuntimeBinderException>(() => (int)accessor.PublicField);
        }
コード例 #20
0
        public void AccessInvalidIndexTest()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            Assert.ThrowsException <RuntimeBinderException>(() => accessor["PropertyThatDoesNotExist"]);
        }
コード例 #21
0
        public void AccessUsingInvalidIndexType()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            Assert.ThrowsException <RuntimeBinderException>(() => accessor[42]);
        }
コード例 #22
0
        public void InvokeMethodWithInvalidParametersTest()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            Assert.ThrowsException <RuntimeBinderException>(() => accessor.AddMethod("1", "2"));
        }
コード例 #23
0
        public void AccessStaticFieldTest()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            Assert.ThrowsException <RuntimeBinderException>(() => accessor.StaticField);
        }
コード例 #24
0
        public void TestThrowOnGetProperty()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            Assert.ThrowsException <RuntimeBinderException>(() => accessor.TestGetOnlyProperty = TestStringValue);
        }
コード例 #25
0
        public void TestThrowOnNullAssignOnvalueType()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            Assert.ThrowsException <RuntimeBinderException>(() => accessor.TestValueField = null);
        }
コード例 #26
0
        public void AccessNonExistentMemberTest()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            Assert.ThrowsException <RuntimeBinderException>(() => accessor.SomeMemebrThatDoesNotExist);
        }