Exemplo n.º 1
0
        public void PProxyJapaneseLunisolarCalendarDefaultBehavior_can_apply_default_behavior_to_throw_NotImplementedException_against_one_instance()
        {
            // Arrange
            var proxy = new PProxyJapaneseLunisolarCalendar();

            proxy.
            ExcludeGeneric().
            DefaultBehavior = IndirectionBehaviors.NotImplemented;

            {
                var bag = TaggedBagFactory <OfPJapaneseLunisolarCalendar.GetYearInfoInt32Int32Impl> .Make(proxy.GetYearInfoInt32Int32().Body);

                LooseCrossDomainAccessor.GetOrRegister <GenericHolder <TaggedBag <OfPJapaneseLunisolarCalendar.GetYearInfoInt32Int32Impl, IndirectionFunc <JapaneseLunisolarCalendar, int, int, int> > > >().Source = bag;
            }
            {
                var bag = TaggedBagFactory <OfPJapaneseLunisolarCalendar.GetGregorianYearInt32Int32Impl> .Make(proxy.GetGregorianYearInt32Int32().Body);

                LooseCrossDomainAccessor.GetOrRegister <GenericHolder <TaggedBag <OfPJapaneseLunisolarCalendar.GetGregorianYearInt32Int32Impl, IndirectionFunc <JapaneseLunisolarCalendar, int, int, int> > > >().Source = bag;
            }
            LooseCrossDomainAccessor.GetOrRegister <GenericHolder <JapaneseLunisolarCalendar> >().Source = (JapaneseLunisolarCalendar)proxy;


            // Act
            var getYearInfoTarget      = LooseCrossDomainAccessor.GetOrRegister <GenericHolder <TaggedBag <OfPJapaneseLunisolarCalendar.GetYearInfoInt32Int32Impl, IndirectionFunc <JapaneseLunisolarCalendar, int, int, int> > > >().Source.Value;
            var getGregorianYearTarget = LooseCrossDomainAccessor.GetOrRegister <GenericHolder <TaggedBag <OfPJapaneseLunisolarCalendar.GetGregorianYearInt32Int32Impl, IndirectionFunc <JapaneseLunisolarCalendar, int, int, int> > > >().Source.Value;
            var target = LooseCrossDomainAccessor.GetOrRegister <GenericHolder <JapaneseLunisolarCalendar> >().Source;


            // Assert
            Assert.Throws <NotImplementedException>(() => getGregorianYearTarget(target, 0, 0));
            Assert.Throws <FallthroughException>(() => getGregorianYearTarget(new JapaneseLunisolarCalendar(), 0, 0));
            Assert.Throws <NotImplementedException>(() => getYearInfoTarget(target, 0, 0));
            Assert.Throws <FallthroughException>(() => getYearInfoTarget(new JapaneseLunisolarCalendar(), 0, 0));
        }
Exemplo n.º 2
0
        public void PProxyListDefaultBehavior_can_apply_default_behavior_to_throw_FallthroughException_against_one_instance()
        {
            // Arrange
            IndirectionsContext.
            ExcludeGeneric().
            Include(PList <int> .AddT()).
            DefaultBehavior = IndirectionBehaviors.NotImplemented;

            var proxy = new PProxyList <int>();

            proxy.
            ExcludeGeneric().
            IncludeAddT().
            DefaultBehavior = IndirectionBehaviors.Fallthrough;
            LooseCrossDomainAccessor.GetOrRegister <GenericHolder <IndirectionAction <List <int>, int> > >().Source = proxy.AddT().Body;
            LooseCrossDomainAccessor.GetOrRegister <GenericHolder <List <int> > >().Source = (List <int>)proxy;


            // Act
            var addTarget = LooseCrossDomainAccessor.GetOrRegister <GenericHolder <IndirectionAction <List <int>, int> > >().Source;
            var target    = LooseCrossDomainAccessor.GetOrRegister <GenericHolder <List <int> > >().Source;
            var addOther  = PList <int> .AddT().Body;


            // Assert
            Assert.Throws <FallthroughException>(() => addTarget(target, 0));
            Assert.Throws <NotImplementedException>(() => addTarget(new List <int>(), 0));
            Assert.Throws <NotImplementedException>(() => addOther(null, 0));
        }
Exemplo n.º 3
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.º 4
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.º 5
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.º 6
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.º 7
0
        public void IndirectionDelegate_should_return_null_if_same_signature_delegate_is_not_found()
        {
            // Arrange
            var name   = "GetContractDetailsStringBooleanRefDecimalRefDecimalRef";
            var alias  = "GetContractDetailsStringBooleanRefDecimalRefDecimalRef";
            var xml    = string.Empty;
            var target = typeof(ULHelpers).GetMethods().First();
            var stub   = new IndirectionStub(name, alias, xml, target);


            // Act
            var indDlgt = stub.IndirectionDelegate;


            // Assert
            Assert.IsNull(indDlgt);
        }
Exemplo n.º 8
0
        public void PArrayDefaultBehavior_can_apply_default_behavior_to_return_default_value_against_one_type()
        {
            // Arrange
            PArray.
            ExcludeGeneric().
            IncludeExistsOfTTArrayPredicateOfT <int>().
            DefaultBehavior = IndirectionBehaviors.DefaultValue;


            // Act
            var get_now = PDateTime.NowGet().Body;
            var exists  = PArray.ExistsOfTTArrayPredicateOfT <int>().Body;


            // Assert
            Assert.IsNull(get_now);
            Assert.IsFalse(exists(null, null));
        }
Exemplo n.º 9
0
        public void PArrayDefaultBehavior_can_apply_default_behavior_to_throw_NotImplementedException_against_one_type()
        {
            // Arrange
            PArray.
            ExcludeGeneric().
            IncludeExistsOfTTArrayPredicateOfT <int>().
            DefaultBehavior = IndirectionBehaviors.NotImplemented;


            // Act
            var get_now = PDateTime.NowGet().Body;
            var exists  = PArray.ExistsOfTTArrayPredicateOfT <int>().Body;


            // Assert
            Assert.IsNull(get_now);
            Assert.Throws <NotImplementedException>(() => exists(null, null));
        }
Exemplo n.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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.º 15
0
        public void IndirectionsContextDefaultBehavior_can_apply_default_behavior_to_throw_FallthroughException_globally()
        {
            // Arrange
            IndirectionsContext.
            ExcludeGeneric().
            Include(PList <int> .AddT()).
            Include(PArray.ExistsOfTTArrayPredicateOfT <int>()).
            DefaultBehavior = IndirectionBehaviors.Fallthrough;


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

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


            // Assert
            Assert.Throws <FallthroughException>(() => get_now());
            Assert.Throws <FallthroughException>(() => add(null, 0));
            Assert.Throws <FallthroughException>(() => exists(null, null));
        }
Exemplo n.º 16
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.º 17
0
        public void IndirectionHolder_can_transport_untyped_delegates_to_different_AppDomain()
        {
            // Arrange
            {
                PULColumns.ValidateStateULTableStatus().Body = args => { throw new NotSupportedException(); };
                #region Prepare JIT. This simulates the behavior during profiling. Actually, it is unnecessary to go that far with that.
                var validateStateULTableStatus = PULColumns.ValidateStateULTableStatus().Body;
                Assert.Throws <NotSupportedException>(() => validateStateULTableStatus(new object[] { new ULTableStatus() }));
                #endregion
            }

            AppDomain.CurrentDomain.RunAtIsolatedDomain(() =>
            {
                InstanceGetters.NewAdditionalDelegatesAssemblyRepository = () => new MockAdditionalDelegatesAssemblyRepository();

                // Act
                var validateStateULTableStatus = PULColumns.ValidateStateULTableStatus().Body;


                // Assert
                Assert.Throws <NotSupportedException>(() => validateStateULTableStatus(new object[] { new ULTableStatus() }));
            });
        }
Exemplo n.º 18
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);
            }
        }