예제 #1
0
        public void Bug448241()
        {
            this.MyTestInitialize(TestContext.GetCurrentMethod());
            DocumentFormat.OpenXml.Wordprocessing.TableCellMarginDefault tablecellmar = new DocumentFormat.OpenXml.Wordprocessing.TableCellMarginDefault();
            var wrongChild = tablecellmar.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.LeftMargin());
            var leftmar    = tablecellmar.TableCellLeftMargin;

            // should be null, as the correct child should be TableCellLeftMargin
            Assert.Null(leftmar);

            tablecellmar.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.BottomMargin());
            Assert.Null(leftmar);

            // **** Set a correct left.
            var correctChild = tablecellmar.TableCellLeftMargin = new TableCellLeftMargin();

            Assert.NotNull(tablecellmar.TableCellLeftMargin);
            Assert.Same(tablecellmar.LastChild, tablecellmar.BottomMargin);

            // the wrong child should still be there.
            Assert.Same(wrongChild, tablecellmar.FirstChild);

            // **** Top, wrong, correctLeft, Bottom
            tablecellmar.TopMargin = new TopMargin();
            Assert.NotNull(tablecellmar.TableCellLeftMargin);
            Assert.Same(tablecellmar.LastChild, tablecellmar.BottomMargin);
            Assert.Same(tablecellmar.FirstChild, tablecellmar.TopMargin);

            // the wrong child should still be there.
            Assert.Same(wrongChild, tablecellmar.FirstChild.NextSibling());

            // **** Top, wrong, Bottom
            tablecellmar.RemoveChild(correctChild);
            Assert.Null(tablecellmar.TableCellLeftMargin);
            Assert.Same(tablecellmar.LastChild, tablecellmar.BottomMargin);
            Assert.Same(tablecellmar.FirstChild, tablecellmar.TopMargin);

            // the wrong child should still be there.
            Assert.Same(wrongChild, tablecellmar.FirstChild.NextSibling());


            // =========== case for xsd:choice ==============
            var shapeTaget = new DocumentFormat.OpenXml.Presentation.ShapeTarget();
            var wrongBg    = shapeTaget.AppendChild(new DocumentFormat.OpenXml.Presentation.Background());

            Assert.Null(shapeTaget.BackgroundAnimation);

            // **** set a correct one.
            var correctBg = shapeTaget.BackgroundAnimation = new DocumentFormat.OpenXml.Presentation.BackgroundAnimation();

            Assert.Equal(1, shapeTaget.ChildElements.Count);
            Assert.Same(correctBg, shapeTaget.BackgroundAnimation);
        }
예제 #2
0
        public void Bug448241()
        {
            DocumentFormat.OpenXml.Wordprocessing.TableCellMarginDefault tablecellmar = new DocumentFormat.OpenXml.Wordprocessing.TableCellMarginDefault();
            var wrongChild = tablecellmar.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.LeftMargin());
            var leftmar = tablecellmar.TableCellLeftMargin;

            // should be null, as the correct child should be TableCellLeftMargin
            Assert.Null(leftmar);

            tablecellmar.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.BottomMargin());
            Assert.Null(leftmar);

            // **** Set a correct left.
            var correctChild = tablecellmar.TableCellLeftMargin = new TableCellLeftMargin();
            Assert.NotNull(tablecellmar.TableCellLeftMargin);
            Assert.Same(tablecellmar.LastChild, tablecellmar.BottomMargin);

            // the wrong child should still be there.
            Assert.Same(wrongChild, tablecellmar.FirstChild);

            // **** Top, wrong, correctLeft, Bottom
            tablecellmar.TopMargin = new TopMargin();
            Assert.NotNull(tablecellmar.TableCellLeftMargin);
            Assert.Same(tablecellmar.LastChild, tablecellmar.BottomMargin);
            Assert.Same(tablecellmar.FirstChild, tablecellmar.TopMargin);

            // the wrong child should still be there.
            Assert.Same(wrongChild, tablecellmar.FirstChild.NextSibling());

            // **** Top, wrong, Bottom
            tablecellmar.RemoveChild(correctChild);
            Assert.Null(tablecellmar.TableCellLeftMargin);
            Assert.Same(tablecellmar.LastChild, tablecellmar.BottomMargin);
            Assert.Same(tablecellmar.FirstChild, tablecellmar.TopMargin);

            // the wrong child should still be there.
            Assert.Same(wrongChild, tablecellmar.FirstChild.NextSibling());


            // =========== case for xsd:choice ==============
            var shapeTaget = new DocumentFormat.OpenXml.Presentation.ShapeTarget();
            var wrongBg = shapeTaget.AppendChild(new DocumentFormat.OpenXml.Presentation.Background());

            Assert.Null(shapeTaget.BackgroundAnimation);

            // **** set a correct one.
            var correctBg = shapeTaget.BackgroundAnimation = new DocumentFormat.OpenXml.Presentation.BackgroundAnimation();

            Assert.Equal(1, shapeTaget.ChildElements.Count);
            Assert.Same(correctBg, shapeTaget.BackgroundAnimation);
        }