public void Not_an_IEnum()
        {
            var sut = new Flatten_IEnumerables_all_alike();
            var passedOn = 0;
            sut.PassOn += _ => passedOn = (int)_;

            sut.Process(42);
            Assert.AreEqual(42, passedOn);

            sut.Configure("True");

            sut.Process(99);
            Assert.AreEqual(99, passedOn);
        }
        public void MetaObjects_and_elements_for_IEnum()
        {
            var sut = new Flatten_IEnumerables_all_alike();
            sut.Configure("True");

            var fragments = new List<object>();
            sut.MetaObject += fragments.Add;
            sut.Element += fragments.Add;

            sut.Process(new[] { 42 });

            Assert.AreEqual(3, fragments.Count);
            Assert.IsInstanceOf<OpeningFragment>(fragments[0]);
            Assert.AreEqual(42, fragments[1]);
            Assert.IsInstanceOf<ClosingFragment>(fragments[2]);
        }
        public void An_IEnum()
        {
            var sut = new Flatten_IEnumerables_all_alike();
            var passedOn = new int[0];
            sut.PassOn += _ => passedOn = (int[])_;

            sut.Process(new[]{42});
            Assert.AreEqual(new[]{42}, passedOn);

            passedOn = null;
            sut.MetaObject += delegate { };
            sut.Element += delegate { };
            sut.Configure("True");

            sut.Process(new[]{99});
            Assert.IsNull(passedOn);
        }
Ejemplo n.º 4
0
        public Flatten(bool treatAllIEnumerablesAlike)
        {
            // Build
            var handleNull = new Flatten_null();
            var scalar     = new Flatten_scalar();
            var cache      = new Cache();
            var ienum      = new Flatten_IEnumerables_all_alike();
            var array      = new Flatten_array();
            var nonScalar  = new Flatten_non_scalar_field_by_field();
            var collect    = new Collect();

            // Bind
            _process = handleNull.Process;

            handleNull.Null   += collect.Process;
            handleNull.PassOn += scalar.Process;

            scalar.Scalar += collect.Process;
            scalar.PassOn += cache.Process;

            cache.CacheHit  += collect.Process;
            cache.CacheMiss += ienum.Process;

            ienum.MetaObject += collect.Process;
            ienum.Element    += handleNull.Process; // recursion for IEnum elements
            ienum.PassOn     += array.Process;

            array.MetaObject += collect.Process;
            array.Element    += handleNull.Process; // recursion for array elements
            array.PassOn     += nonScalar.Process;

            nonScalar.MetaObject += collect.Process;
            nonScalar.FieldValue += _process; // recursion for field values

            collect.Result += _ => this.Result(_);

            // Config
            ienum.Configure(treatAllIEnumerablesAlike.ToString());
        }
Ejemplo n.º 5
0
        public Flatten(bool treatAllIEnumerablesAlike)
        {
            // Build
            var handleNull = new Flatten_null();
            var scalar = new Flatten_scalar();
            var cache = new Cache();
            var ienum = new Flatten_IEnumerables_all_alike();
            var array = new Flatten_array();
            var nonScalar = new Flatten_non_scalar_field_by_field();
            var collect = new Collect();

            // Bind
            _process = handleNull.Process;

            handleNull.Null += collect.Process;
            handleNull.PassOn += scalar.Process;

            scalar.Scalar += collect.Process;
            scalar.PassOn += cache.Process;

            cache.CacheHit += collect.Process;
            cache.CacheMiss += ienum.Process;

            ienum.MetaObject += collect.Process;
            ienum.Element += handleNull.Process; // recursion for IEnum elements
            ienum.PassOn += array.Process;

            array.MetaObject += collect.Process;
            array.Element += handleNull.Process; // recursion for array elements
            array.PassOn += nonScalar.Process;

            nonScalar.MetaObject += collect.Process;
            nonScalar.FieldValue += _process; // recursion for field values

            collect.Result += _ => this.Result(_);

            // Config
            ienum.Configure(treatAllIEnumerablesAlike.ToString());
        }