コード例 #1
0
ファイル: TypeExtensionTests.cs プロジェクト: toby2nice/lib12
        public void CallGenericMethodByName_is_correct()
        {
            var          obj  = new TypeWithMethod();
            var          type = obj.GetType();
            const string text = "test";

            type.CallGenericMethodByName(obj, nameof(TypeWithMethod.GenericCast), typeof(string).PackIntoArray(), text);
        }
コード例 #2
0
ファイル: TypeExtensionTests.cs プロジェクト: toby2nice/lib12
        public void CallMethodByName_throws_exception_for_generic_method()
        {
            var          obj  = new TypeWithMethod();
            var          type = obj.GetType();
            const string text = "test";

            Assert.Throws <lib12Exception>(() => type.CallMethodByName(obj, nameof(TypeWithMethod.GenericCast), text));
        }
コード例 #3
0
ファイル: TypeExtensionTests.cs プロジェクト: toby2nice/lib12
        public void CallMethodByName_is_correct_for_method_without_result()
        {
            var obj  = new TypeWithMethod();
            var type = obj.GetType();

            var result = type.CallMethodByName(obj, nameof(TypeWithMethod.Empty));

            result.ShouldBe(null);
        }
コード例 #4
0
ファイル: TypeExtensionTests.cs プロジェクト: toby2nice/lib12
        public void CallGenericMethodByName_throws_exception_when_incorrect_number_of_type_arguments_is_provided()
        {
            var          obj  = new TypeWithMethod();
            var          type = obj.GetType();
            const string text = "test";

            var typeArgs = Pack.IntoArray(typeof(string), typeof(int));

            Assert.Throws <ArgumentException>(() => type.CallGenericMethodByName(obj, nameof(TypeWithMethod.GenericCast), typeArgs, text));
        }
コード例 #5
0
ファイル: TypeExtensionTests.cs プロジェクト: toby2nice/lib12
        public void CallMethodByName_is_correct_for_private_static_method()
        {
            var obj  = new TypeWithMethod();
            var type = obj.GetType();

            var result = type.CallMethodByName(obj, "PrivateStatic");

            result.ShouldBeOfType <int>();
            result.ShouldBe(12);
        }
コード例 #6
0
        public void ResolveMethodTest()
        {
            Container c = new Container();

            c.AddSingleton(() => new TypeWithMethod());
            c.AddSingleton(() => new GuessableType());
            TypeWithMethod t = c.GetInstance <TypeWithMethod>();

            Assert.True(t.gotCalled);
        }
コード例 #7
0
ファイル: TypeExtensionTests.cs プロジェクト: toby2nice/lib12
        public void CallMethodByName_is_correct_for_method_with_result()
        {
            const int number1 = 5;
            const int number2 = 7;
            var       obj     = new TypeWithMethod();
            var       type    = obj.GetType();

            var result = type.CallMethodByName(obj, nameof(TypeWithMethod.Add), number1, number2);

            result.ShouldBeOfType <int>();
            result.ShouldBe(12);
        }