Esempio n. 1
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));
        }
Esempio n. 2
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));
        }
Esempio n. 3
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));
            });
        }
Esempio n. 4
0
        public void PProxyListDefaultBehavior_can_apply_default_behavior_to_return_default_value_against_one_instance()
        {
            // Arrange
            var proxy = new PProxyList <int>();

            proxy.
            ExcludeGeneric().
            IncludeAddT().
            DefaultBehavior = IndirectionBehaviors.DefaultValue;
            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.DoesNotThrow(() => addTarget(target, 0));
            Assert.Throws <FallthroughException>(() => addTarget(new List <int>(), 0));
            Assert.Throws <FallthroughException>(() => addOther(null, 0));
        }
Esempio n. 5
0
 public TypeBehaviorSetting IncludeAddT()
 {
     Include(PList <T> .AddT());
     return(this);
 }