Exemplo n.º 1
0
        public void IndirectionDelegate_should_get_the_delegate_type_that_indicates_the_method_that_has_a_type_as_same_as_declaring_type_variation()
        {
            // Arrange
            var name   = "FugaIndirectionStubTestDOfBarRef";
            var alias  = "FugaIndirectionStubTestDOfBarRef";
            var xml    = string.Empty;
            var target = typeof(D <>).GetMethods().First();
            var stub   = new IndirectionStub(name, alias, xml, target);


            // Act
            var indDlgt = stub.IndirectionDelegate;


            // Assert
            var invokeMeth = indDlgt.GetMethod("Invoke");
            {
                var genericType = invokeMeth.GetParameters()[1].ParameterType.GetElementType().GetElementType().GetGenericArguments()[0].GetElementType();
                Assert.AreEqual(typeof(D <>).ToString(), genericType.ToString());
                Assert.AreNotEqual(typeof(D <>), genericType);
            }
            {
                var genericType = invokeMeth.ReturnType.GetElementType().GetGenericArguments()[0].GetElementType();
                Assert.AreEqual(typeof(D <>).ToString(), genericType.ToString());
                Assert.AreNotEqual(typeof(D <>), genericType);
            }
        }
Exemplo n.º 2
0
        public void IndirectionDelegate_should_get_the_delegate_type_that_indicates_the_getter_of_static_class()
        {
            // Arrange
            var name   = "NowGet";
            var alias  = "NowGet";
            var xml    = string.Empty;
            var target = typeof(DateTime).GetProperty("Now").GetGetMethod();
            var stub   = new IndirectionStub(name, alias, xml, target);


            // Act
            var indDlgt = stub.IndirectionDelegate;


            // Assert
            Assert.AreEqual("Urasandesu.Prig.Delegates.IndirectionFunc`1[System.DateTime]", indDlgt.ToString());
        }
Exemplo n.º 3
0
        public void IndirectionDelegate_should_get_the_delegate_type_that_indicates_the_pinvoke_method_of_a_class()
        {
            // Arrange
            var name   = "IsWow64ProcessIntPtrBooleanRef";
            var alias  = "IsWow64ProcessIntPtrBooleanRef";
            var xml    = string.Empty;
            var target = typeof(Foo).GetMethods(BindingFlags.NonPublic | BindingFlags.Static).First();
            var stub   = new IndirectionStub(name, alias, xml, target);


            // Act
            var indDlgt = stub.IndirectionDelegate;


            // Assert
            Assert.AreEqual("Urasandesu.Prig.Delegates.IndirectionOutFunc`3[System.IntPtr,System.Boolean,System.Boolean]", indDlgt.ToString());
        }
Exemplo n.º 4
0
        public void IndirectionDelegate_should_get_the_delegate_type_that_indicates_the_generic_method_of_a_class()
        {
            // Arrange
            var name   = "GetPropertyOfTStringT";
            var alias  = "GetPropertyOfTStringT";
            var xml    = string.Empty;
            var target = typeof(ULConfigurationManager).GetMethods().First();
            var stub   = new IndirectionStub(name, alias, xml, target);


            // Act
            var indDlgt = stub.IndirectionDelegate;


            // Assert
            Assert.AreEqual("Urasandesu.Prig.Delegates.IndirectionFunc`3[System.String,T,T]", indDlgt.ToString());
        }
Exemplo n.º 5
0
        public void CreateDelegateOfDefaultBehavior_should_return_the_default_behavior_that_indicates_the_generic_method_of_a_class()
        {
            // Arrange
            var name   = "GetPropertyOfTStringT";
            var alias  = "GetPropertyOfTStringT";
            var xml    = string.Empty;
            var target = typeof(ULConfigurationManager).GetMethods().First();
            var stub   = new IndirectionStub(name, alias, xml, target);


            // Act
            var defaultBehavior = stub.CreateDelegateOfDefaultBehavior(IndirectionBehaviors.DefaultValue, new Type[] { }, new Type[] { typeof(DayOfWeek) });


            // Assert
            var getProperty = defaultBehavior.Cast <IndirectionFunc <string, DayOfWeek, DayOfWeek> >(GetType().Module);
            var value       = getProperty("aiueo", DayOfWeek.Wednesday);

            Assert.AreEqual(default(DayOfWeek), value);
        }
Exemplo n.º 6
0
        public void CreateDelegateOfDefaultBehavior_should_return_the_default_behavior_that_indicates_the_getter_of_static_class()
        {
            // Arrange
            var name   = "NowGet";
            var alias  = "NowGet";
            var xml    = string.Empty;
            var target = typeof(DateTime).GetProperty("Now").GetGetMethod();
            var stub   = new IndirectionStub(name, alias, xml, target);


            // Act
            var defaultBehavior = stub.CreateDelegateOfDefaultBehavior(IndirectionBehaviors.DefaultValue, new Type[] { }, new Type[] { });


            // Assert
            var get_Now = defaultBehavior.Cast <IndirectionFunc <DateTime> >(GetType().Module);
            var value   = get_Now();

            Assert.AreEqual(default(DateTime), value);
        }
Exemplo n.º 7
0
        public void IndirectionDelegate_should_get_the_delegate_type_that_indicates_the_ctor_of_generic_struct()
        {
            // Arrange
            var name   = "ConstructorT";
            var alias  = "ConstructorT";
            var xml    = string.Empty;
            var target = typeof(Nullable <>).GetConstructors().First();
            var stub   = new IndirectionStub(name, alias, xml, target);


            // Act
            var indDlgt = stub.IndirectionDelegate;


            // Assert
            Assert.AreEqual("Urasandesu.Prig.Delegates.IndirectionRefThisAction`2[System.Nullable`1[T],T]", indDlgt.ToString());
            var genericType = indDlgt.GetMethod("Invoke").GetParameters()[0].ParameterType.GetElementType();

            Assert.AreEqual(typeof(Nullable <>).ToString(), genericType.ToString());
            Assert.AreNotEqual(typeof(Nullable <>), genericType);
        }
Exemplo n.º 8
0
        public void CreateDelegateOfDefaultBehavior_should_return_the_default_behavior_that_indicates_the_ctor_of_generic_struct()
        {
            // Arrange
            var name   = "ConstructorT";
            var alias  = "ConstructorT";
            var xml    = string.Empty;
            var target = typeof(Nullable <>).GetConstructors().First();
            var stub   = new IndirectionStub(name, alias, xml, target);


            // Act
            var defaultBehavior = stub.CreateDelegateOfDefaultBehavior(IndirectionBehaviors.DefaultValue, new Type[] { typeof(int) }, new Type[] { });


            // Assert
            var ctor  = defaultBehavior.Cast <IndirectionRefThisAction <Nullable <int>, int> >(GetType().Module);
            var value = new int?(42);

            ctor(ref value, 42);
            Assert.AreEqual(default(int?), value);
        }
Exemplo n.º 9
0
        public void IndirectionsContextDefaultBehavior_can_apply_default_behavior_to_return_default_value_globally()
        {
            // Arrange
            IndirectionsContext.
            ExcludeGeneric().
            Include(PList <int> .AddT()).
            Include(PArray.ExistsOfTTArrayPredicateOfT <int>()).
            DefaultBehavior = IndirectionBehaviors.DefaultValue;


            // Act
            var get_now = PDateTime.NowGet().Body;
            var add     = PList <int> .AddT().Body;

            var exists = PArray.ExistsOfTTArrayPredicateOfT <int>().Body;


            // Assert
            Assert.AreEqual(default(DateTime), get_now());
            Assert.DoesNotThrow(() => add(null, 10));
            Assert.IsFalse(exists(null, null));
        }
Exemplo n.º 10
0
        public void IndirectionHolder_can_transport_delegates_to_different_AppDomain()
        {
            // Arrange
            PDateTime.NowGet().Body = () => new DateTime(2014, 1, 1);
            PList <int> .AddT().Body = (@this, item) => { @this.Add(item); @this.Add(item); };
            PArray.ExistsOfTTArrayPredicateOfT <int>().Body = (array, match) => match(array[0]);

            AppDomain.CurrentDomain.RunAtIsolatedDomain(() =>
            {
                // Act
                var get_now    = PDateTime.NowGet().Body;
                var add        = PList <int> .AddT().Body;
                var addResults = new List <int>();
                add(addResults, 10);
                var exists = PArray.ExistsOfTTArrayPredicateOfT <int>().Body;


                // Assert
                Assert.AreEqual(new DateTime(2014, 1, 1), get_now());
                CollectionAssert.AreEqual(new int[] { 10, 10 }, addResults);
                Assert.IsFalse(exists(new int[] { 10, 42 }, _ => _ == 42));
            });
        }
Exemplo n.º 11
0
        public void IndirectionDelegate_should_get_the_delegate_type_that_indicates_the_method_that_has_a_type_as_same_as_declaring_type_excluding_this()
        {
            // Arrange
            var name   = "FugaIndirectionStubTestCOfBar";
            var alias  = "FugaIndirectionStubTestCOfBar";
            var xml    = string.Empty;
            var target = typeof(C <>).GetMethods().First();
            var stub   = new IndirectionStub(name, alias, xml, target);


            // Act
            var indDlgt = stub.IndirectionDelegate;


            // Assert
            Assert.AreEqual("Urasandesu.Prig.Delegates.IndirectionFunc`3[Test.Urasandesu.Prig.Framework.PilotStubberConfiguration.IndirectionStubTest+C`1[Bar]," +
                            "Test.Urasandesu.Prig.Framework.PilotStubberConfiguration.IndirectionStubTest+C`1[Bar]," +
                            "Test.Urasandesu.Prig.Framework.PilotStubberConfiguration.IndirectionStubTest+C`1[Bar]]", indDlgt.ToString());
            var invokeMeth = indDlgt.GetMethod("Invoke");
            {
                var genericType = invokeMeth.GetParameters()[0].ParameterType;

                Assert.AreEqual(typeof(C <>).ToString(), genericType.ToString());
                Assert.AreNotEqual(typeof(C <>), genericType);
            }
            {
                var genericType = invokeMeth.GetParameters()[1].ParameterType;
                Assert.AreEqual(typeof(C <>).ToString(), genericType.ToString());
                Assert.AreNotEqual(typeof(C <>), genericType);
            }
            {
                var genericType = invokeMeth.ReturnType;
                Assert.AreEqual(typeof(C <>).ToString(), genericType.ToString());
                Assert.AreNotEqual(typeof(C <>), genericType);
            }
        }