Example #1
0
        public void GetPropertyValue()
        {
            var propertyOrFieldReflection = new ClassToAnalyze(1, 1, 1).Reflection().GetPropertyOrField("PrivateProperty");
            var value = propertyOrFieldReflection.GetValue <string>();

            value.Should().Be("PrivateProperty");
        }
Example #2
0
        public void InvokeGeneric()
        {
            var methodReflection = new ClassToAnalyze(1, 1, 1).Reflection().GetMethod("GenericMethod");
            var returnValue      = methodReflection.InvokeGeneric(new Type[] { typeof(object) });

            returnValue.Should().BeNull();
        }
Example #3
0
        public void GetEnclosingType()
        {
            var propertyOrFieldReflection = new ClassToAnalyze(1, 1, 1).Reflection().GetPropertyOrField("_privateField");
            var result = propertyOrFieldReflection.GetEnclosingType <ClassToAnalyze>();

            result.Should().NotBeNull();
        }
Example #4
0
        public void InvokeMethod()
        {
            var methodReflection = new ClassToAnalyze(1, 1, 1).Reflection().GetMethod("PrivateMethod");
            var returnValue      = methodReflection.Invoke(1);

            returnValue.Should().BeNull();
        }
Example #5
0
        public void SetFieldValue()
        {
            var propertyOrFieldReflection = new ClassToAnalyze(1, 1, 1).Reflection().GetPropertyOrField("_privateField");

            propertyOrFieldReflection.SetValue("test");
            var value = propertyOrFieldReflection.GetValue <string>();

            value.Should().Be("test");
        }
Example #6
0
        public void InvokeGenericOnNonGenericMethod()
        {
            var methodReflection = new ClassToAnalyze(1, 1, 1).Reflection().GetMethod("PrivateMethod");

            methodReflection
            .Invoking(x => x.InvokeGeneric(new Type[] { typeof(object) }))
            .Should()
            .Throw <InvalidOperationException>();
        }
Example #7
0
        public void InvokeOnGenericMethodThrowsException()
        {
            var methodReflection = new ClassToAnalyze(1, 1, 1).Reflection().GetMethod("GenericMethod");

            methodReflection
            .Invoking(x => x.Invoke())
            .Should()
            .Throw <InvalidOperationException>();
        }
        public void SetPropertyOrField()
        {
            var methodReflection = new ClassToAnalyze(1, 1, 1).Reflection();

            methodReflection.SetPropertyOrField("_privateField", "test");
            var newValue = methodReflection.GetPropertyOrField("_privateField").GetValue <string>();

            newValue.Should().Be("test");
        }