예제 #1
0
        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));
        }
예제 #2
0
        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));
        }
예제 #3
0
        public void DoubleChoice()
        {
            var particle = new CompositeParticle(ParticleType.Choice, 0, 1)
            {
                new ElementParticle(typeof(T1), 0, 1),
                new ElementParticle(typeof(T2), 0, 1),
            }.Compile();
            var data = new TestOpenXmlCompositeElement();

            var t1 = new T1();
            var t2 = new T2();

            Assert.True(particle.Set(data, t1));
            Assert.True(particle.Set(data, t2));

            var single = Assert.Single(data);

            Assert.Same(t2, single);
        }
예제 #4
0
        public void TwoElementInSequenceTestBackwards()
        {
            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 t1 = new T1();
            var t2 = new T2();

            Assert.True(particle.Set(data, t2));
            Assert.True(particle.Set(data, t1));

            Assert.Collection(
                data,
                e => Assert.Same(t1, e),
                e => Assert.Same(t2, e));
        }
예제 #5
0
        public void InvalidElementInSequenceTest()
        {
            var particle = new CompositeParticle(ParticleType.Sequence, 0, 1)
            {
                new ElementParticle(typeof(T1), 0, 1),
            }.Compile();
            var data = new TestOpenXmlCompositeElement();

            Assert.False(particle.Set(data, new T2()));
            Assert.Null(particle.Get <T2>(data));
        }
예제 #6
0
        public void SequenceInChoice()
        {
            var particle = new CompositeParticle(ParticleType.Choice, 0, 1)
            {
                new ElementParticle(typeof(T1), 0, 1),
                new CompositeParticle(ParticleType.Sequence, 0, 1)
                {
                    new ElementParticle(typeof(T2), 0, 1),
                    new ElementParticle(typeof(T3), 0, 1),
                },
                new ElementParticle(typeof(T4), 0, 1),
            }.Compile();
            var data = new TestOpenXmlCompositeElement();

            var t1 = new T1();
            var t2 = new T2();
            var t3 = new T3();
            var t4 = new T4();

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

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

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

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

            Assert.True(particle.Set(data, t3));
            Assert.Equal(new object[] { t3 }, data.ToArray());
            Assert.Collection(
                data,
                e => Assert.Same(t3, e));

            Assert.True(particle.Set(data, t2));
            Assert.Collection(
                data,
                e => Assert.Same(t2, e),
                e => Assert.Same(t3, e));
        }
예제 #7
0
        public void TwoSequencesInChoice()
        {
            var particle = new CompositeParticle(ParticleType.Choice, 0, 1)
            {
                new ElementParticle(typeof(T1), 0, 1),
                new CompositeParticle(ParticleType.Sequence, 0, 1)
                {
                    new ElementParticle(typeof(T2), 0, 1),
                    new ElementParticle(typeof(T3), 0, 1),
                },
                new ElementParticle(typeof(T4), 0, 1),
                new CompositeParticle(ParticleType.Sequence, 0, 1)
                {
                    new ElementParticle(typeof(T5), 0, 1),
                    new ElementParticle(typeof(T6), 0, 1),
                },
            }.Compile();
            var data = new TestOpenXmlCompositeElement();

            var t1 = new T1();
            var t2 = new T2();
            var t3 = new T3();
            var t4 = new T4();
            var t5 = new T5();
            var t6 = new T6();

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

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

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

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

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

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

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

            Assert.True(particle.Set(data, t2));
            Assert.Collection(
                data,
                e => Assert.Same(t2, e),
                e => Assert.Same(t3, e));
        }