public void TwoElementOneCollectionInSequenceTest()
        {
            var particle = new CompositeParticle(ParticleType.Sequence, 0, 1)
            {
                new ElementParticle(typeof(T1), 0, 1),
                new ElementParticle(typeof(T2), 1, 10),
                new ElementParticle(typeof(T3), 0, 1),
            }.Compile();
            var data = new TestOpenXmlCompositeElement();

            var t1  = new T1();
            var t2a = new T2();
            var t2b = new T2();
            var t3  = new T3();

            Assert.True(particle.Set(data, t3));
            Assert.True(particle.GetCollection <T2>(data).Add(t2a));
            Assert.True(particle.Set(data, t1));
            Assert.True(particle.GetCollection <T2>(data).Add(t2b));

            Assert.Collection(
                data,
                e => Assert.Same(t1, e),
                e => Assert.Same(t2a, e),
                e => Assert.Same(t2b, e),
                e => Assert.Same(t3, e));
        }
        public void ElementCollectionTest()
        {
            var particle = new CompositeParticle(ParticleType.Sequence, 0, 1)
            {
                new ElementParticle(typeof(T1), 0, 10),
            }.Compile();
            var data     = new TestOpenXmlCompositeElement();
            var instance = new T1();

            Assert.True(particle.GetCollection <T1>(data).Add(instance));
            var single = Assert.Single(particle.GetCollection <T1>(data));

            Assert.Equal(instance, single);
        }
        public void ElementInAllList()
        {
            var particle = new CompositeParticle(ParticleType.All, 0, 1)
            {
                new ElementParticle(typeof(T1), 0, 1),
                new ElementParticle(typeof(T2), 0, 1),
            }.Compile();
            var data = new TestOpenXmlCompositeElement();

            var t1a = new T1();
            var t1b = new T1();
            var t1c = new T1();
            var t2  = new T2();

            data.PrependChild(t1a);
            data.PrependChild(t1b);
            data.PrependChild(t2);
            data.PrependChild(t1c);

            Assert.Collection(
                particle.GetCollection <T1>(data),
                e => Assert.Same(t1c, e),
                e => Assert.Same(t1b, e),
                e => Assert.Same(t1a, e));
        }
        public void SequenceAdd()
        {
            var particle = new CompositeParticle(ParticleType.Sequence, 0, 1)
            {
                new ElementParticle(typeof(T1), 0, 1),
                new ElementParticle(typeof(T2), 0, 1),
                new ElementParticle(typeof(T3), 0, 1),
                new ElementParticle(typeof(T4), 0, 1),
                new ElementParticle(typeof(T5), 0, 1),
                new ElementParticle(typeof(T6), 0, 1),
            }.Compile();

            var data = new TestOpenXmlCompositeElement();
            var t1   = new T1();
            var t3   = new T3();
            var t5   = new T5();

            Assert.Empty(data);

            particle.GetCollection <T1>(data).Add(t1);
            Assert.Collection(
                data,
                e => Assert.Same(e, t1));

            particle.GetCollection <T3>(data).Add(t3);
            Assert.Collection(
                data,
                e => Assert.Same(e, t1),
                e => Assert.Same(e, t3));

            particle.GetCollection <T5>(data).Add(t5);
            Assert.Collection(
                data,
                e => Assert.Same(e, t1),
                e => Assert.Same(e, t3),
                e => Assert.Same(e, t5));
        }
        public void CollectionInAll()
        {
            var particle = new CompositeParticle(ParticleType.All, 0, 1)
            {
                new ElementParticle(typeof(T1), 0, 1),
                new ElementParticle(typeof(T2), 0, 10),
                new ElementParticle(typeof(T3), 0, 1),
            }.Compile();
            var data = new TestOpenXmlCompositeElement();

            var t1  = new T1();
            var t2a = new T2();
            var t2b = new T2();
            var t2c = new T2();

            Assert.True(particle.Set(data, t1));
            Assert.Collection(
                data,
                e => Assert.Same(t1, e));

            Assert.True(particle.Set(data, t2a));
            Assert.Collection(
                data,
                e => Assert.Same(t1, e),
                e => Assert.Same(t2a, e));

            Assert.True(particle.Set(data, t2b));
            Assert.Collection(
                data,
                e => Assert.Same(t1, e),
                e => Assert.Same(t2b, e));

            Assert.True(particle.GetCollection <T2>(data).Add(t2c));
            Assert.Collection(
                data,
                e => Assert.Same(t1, e),
                e => Assert.Same(t2b, e),
                e => Assert.Same(t2c, e));

            Assert.True(particle.Set(data, t2a));
            Assert.Collection(
                data,
                e => Assert.Same(t1, e),
                e => Assert.Same(t2a, e));
        }
        public void AllElements()
        {
            var particle = new CompositeParticle(ParticleType.Sequence, 0, 1)
            {
                new ElementParticle(typeof(T1), 0, 1),
                new ElementParticle(typeof(T2), 0, 1),
            }.Compile();
            var data = new TestOpenXmlCompositeElement();
            var t1a  = new T1();
            var t1b  = new T1();
            var t2a  = new T2();

            data.AppendChild(t1a);
            data.AppendChild(t2a);
            data.AppendChild(t1b);

            Assert.Collection(
                particle.GetCollection <T1>(data),
                e => Assert.Same(t1a, e),
                e => Assert.Same(t1b, e));
        }