public void RecalculateHeightValueWhen([Random(10, 100, 1)] int initialHeight)
        {
            PrintDimension pd = new PrintDimension
            {
                InternalPrintDefinition = new PrintDefinition()
            };

            pd.InternalPrintDefinition.SetPrintAttribute(new PrintOnAllPagesAttribute(PrintAppendixes.All));

            Mock <IPrintProcessor> printProcessor = new Mock <IPrintProcessor>();

            printProcessor.Setup(i => i.GetSummary()).Returns(() => new Grid()
            {
                Height = initialHeight
            });
            pd.PrintProcessor = printProcessor.Object;

            Assert.That(pd.GetHeightFor(PrintAppendixes.Summary, 1, false), Is.EqualTo(initialHeight));
            pd.SetHeightValue(PrintAppendixes.Summary, 5);

            pd.RecalculateHeightValueWhen(() => false, PrintAppendixes.Summary);

            Assert.That(pd.GetHeightFor(PrintAppendixes.Summary, 1, false), Is.EqualTo(5));

            pd.RecalculateHeightValueWhen(() => true, PrintAppendixes.Summary);

            Assert.That(pd.GetHeightFor(PrintAppendixes.Summary, 1, false), Is.EqualTo(initialHeight));

            Assert.That(() => pd.RecalculateHeightValueWhen(null, PrintAppendixes.Summary), Throws.ArgumentNullException);
        }
        public void GetHeightFor()
        {
            Mock <IPrintProcessor> mock = new Mock <IPrintProcessor>();

            mock.Setup(i => i.GetHeader()).Returns(new Grid {
                Height = 1
            });
            mock.Setup(i => i.GetFooter()).Returns(new Grid {
                Height = 2
            });
            mock.Setup(i => i.GetHeaderDescription()).Returns(new Grid {
                Height = 3
            });

            PrintDimension pd = new PrintDimension
            {
                PrintProcessor          = mock.Object,
                InternalPrintDefinition = new PrintDefinition()
            };

            pd.InternalPrintDefinition.SetPrintAttribute(new PrintOnAllPagesAttribute(PrintAppendixes.Header | PrintAppendixes.Footer | PrintAppendixes.Summary));

            Assert.That(pd.GetHeightFor(PrintAppendixes.Header, 1, false), Is.EqualTo(1));
            Assert.That(pd.GetHeightFor(PrintAppendixes.Footer, 1, false), Is.EqualTo(2));

            Assert.That(pd.GetHeightFor(PrintAppendixes.HeaderDescription, 1, false), Is.EqualTo(0));

            Assert.That(() => pd.GetHeightFor(PrintAppendixes.Summary, 1, false), Throws.ArgumentNullException);

            pd.InternalPrintDefinition.SetPrintAttribute(new PrintOnAllPagesAttribute(PrintAppendixes.HeaderDescription));
            Assert.That(pd.GetHeightFor(PrintAppendixes.HeaderDescription, 1, false), Is.EqualTo(3));
        }
Пример #3
0
        public void GetRangeFor()
        {
            Mock <IPrintProcessor> mock = new Mock <IPrintProcessor>();

            mock.Setup(i => i.GetHeader()).Returns(new Grid {
                Height = 10
            });
            mock.Setup(i => i.GetFooter()).Returns(new Grid {
                Height = 20
            });
            mock.Setup(i => i.GetHeaderDescription()).Returns(new Grid {
                Height = 30
            });
            mock.Setup(i => i.GetSummary()).Returns(new Grid {
                Height = 40
            });

            PrintDimension pd = new PrintDimension();

            pd.PrintProcessor          = mock.Object;
            pd.Margin                  = new Thickness(10);
            pd.PageSize                = new Size(100, 1000);
            pd.InternalPrintDefinition = new PrintDefinition();
            pd.InternalPrintDefinition.SetPrintAttribute(new PrintOnAllPagesAttribute(PrintAppendixes.All));

            Assert.That(pd.GetRangeFor(PrintAppendixes.Header, 1, false), Is.EqualTo(new Range <double>(10, 20)));
            Assert.That(pd.GetRangeFor(PrintAppendixes.HeaderDescription, 1, false), Is.EqualTo(new Range <double>(20, 50)));
            Assert.That(pd.GetRangeForBodyGrid(1, false), Is.EqualTo(new Range <double>(50, 905)));
            Assert.That(pd.GetRangeFor(PrintAppendixes.Summary, 1, false), Is.EqualTo(new Range <double>(905, 945)));
            Assert.That(pd.GetRangeFor(PrintAppendixes.Footer, 1, false), Is.EqualTo(new Range <double>(945, 965)));
            Assert.That(pd.GetRangeFor(PrintAppendixes.PageNumbers, 1, false), Is.EqualTo(new Range <double>(965, 990)));
        }
        public void GetHeightForBody_IsTotalPageHeightMinusPrintParts()
        {
            Mock <IPrintProcessor> mock = new Mock <IPrintProcessor>();

            mock.Setup(i => i.GetHeader()).Returns(new Grid {
                Height = 10
            });
            mock.Setup(i => i.GetFooter()).Returns(new Grid {
                Height = 20
            });
            mock.Setup(i => i.GetHeaderDescription()).Returns(new Grid {
                Height = 30
            });
            mock.Setup(i => i.GetSummary()).Returns(new Grid {
                Height = 40
            });
            mock.Setup(i => i.GetPageNumbers(It.IsAny <int>(), It.IsAny <int>())).Returns(new Grid {
                Height = 25
            });

            PrintDimension pd = new PrintDimension
            {
                PrintProcessor          = mock.Object,
                InternalPrintDefinition = new PrintDefinition()
            };

            pd.InternalPrintDefinition.SetPrintAttribute(new PrintOnAllPagesAttribute(PrintAppendixes.All));

            pd.PageSize = new Size(100, 300);

            // 300 - Header - Footer - HeaderDescritpion - Summary - PageNumbers
            Assert.That(pd.GetHeightForBodyGrid(1, false), Is.EqualTo(175));
        }
        public void PrintDimension()
        {
            var pp = new PrintProcessorWithPrintOnAttribute();
            var pd = new PrintDimension();

            pp.PrintDimension = pd;
            Assert.That(pp.PrintDimension, Is.EqualTo(pd));
        }
Пример #6
0
        public PageHelper(ItemsControl bodyGrid, Brush borderBrush, PageContent pageContent, PrintDimension printingDimension, double usedSpace)
        {
            BodyGrid          = bodyGrid;
            BorderBrush       = borderBrush;
            PageContent       = pageContent;
            PrintingDimension = printingDimension;

            BodyGrid.Measure(new Size(double.MaxValue, double.MaxValue));
            RemoveRemainingSpace(usedSpace);
        }
        public void PageSize_Test()
        {
            Thickness margin             = new Thickness(10, 20, 30, 40);
            var       printingDimensions = new PrintDimension(margin);

            Size pageSize = new Size(500, 1000);

            SetPageSizeToPrintDimension(printingDimensions, pageSize);

            Assert.AreEqual(pageSize, printingDimensions.PageSize);
        }
Пример #8
0
        private static void SetPageSizeToPrintDimension(PrintDimension printingDimension, Size pageSize)
        {
            Type t = printingDimension.GetType();
            var  v = t.GetProperty("PageSize");

            v.SetValue(printingDimension, pageSize, null);

            var m = t.GetMethod("PositionizeRelative", BindingFlags.NonPublic | BindingFlags.Instance);

            Assert.That(m, Is.Not.Null);
            m.Invoke(printingDimension, null);
        }
Пример #9
0
        public void SetHeightValue()
        {
            PrintDimension pd = new PrintDimension();

            pd.InternalPrintDefinition = new PrintDefinition();
            pd.InternalPrintDefinition.SetPrintAttribute(new PrintOnAllPagesAttribute(PrintAppendixes.All));

            pd.SetHeightValue(PrintAppendixes.Summary, 5);
            Assert.That(pd.GetHeightFor(PrintAppendixes.Summary, 1, false), Is.EqualTo(5));
            pd.SetHeightValue(PrintAppendixes.Summary, 6);
            Assert.That(pd.GetHeightFor(PrintAppendixes.Summary, 1, false), Is.EqualTo(6));
        }
        public void GetHeightForBody_IsTotalPageHeight_IfNoAdditionalPrintParts()
        {
            PrintDimension pd = new PrintDimension();
            pd.InternalPrintDefinition = new PrintDefinition();

            Assert.That(pd.GetHeightForBodyGrid(1, false), Is.EqualTo(0));

            pd.PageSize = new Size(100, 300);

            Assert.That(pd.GetHeightForBodyGrid(1, false), Is.EqualTo(300));

            pd.Margin = new Thickness(10);

            Assert.That(pd.GetHeightForBodyGrid(1, false), Is.EqualTo(280));
        }
        public void GetHeightForBody_IsTotalPageHeight_IfNoAdditionalPrintParts()
        {
            PrintDimension pd = new PrintDimension {
                InternalPrintDefinition = new PrintDefinition()
            };

            Assert.That(pd.GetHeightForBodyGrid(1, false), Is.EqualTo(0));

            pd.PageSize = new Size(100, 300);

            Assert.That(pd.GetHeightForBodyGrid(1, false), Is.EqualTo(300));

            pd.Margin = new Thickness(10);

            Assert.That(pd.GetHeightForBodyGrid(1, false), Is.EqualTo(280));
        }
        public void SetHeightValue()
        {
            PrintDimension pd = new PrintDimension
            {
                InternalPrintDefinition = new PrintDefinition()
            };

            pd.InternalPrintDefinition.SetPrintAttribute(new PrintOnAllPagesAttribute(PrintAppendixes.All));

            pd.SetHeightValue(PrintAppendixes.Summary, 5);
            Assert.That(pd.GetHeightFor(PrintAppendixes.Summary, 1, false), Is.EqualTo(5));
            pd.SetHeightValue(PrintAppendixes.Summary, 6);
            Assert.That(pd.GetHeightFor(PrintAppendixes.Summary, 1, false), Is.EqualTo(6));

            Assert.That(() => pd.SetHeightValue(PrintAppendixes.Summary, -1), Throws.TypeOf <ArgumentOutOfRangeException>());
        }
        public void PrintablePageSize_Test(
            [Values(1, 2)] double left,
            [Values(4, 5)] double top,
            [Values(7, 8)] double right,
            [Values(10, 11)] double bottom)
        {
            Thickness margin             = new Thickness(left, top, right, bottom);
            var       printingDimensions = new PrintDimension(margin);

            Size pageSize = new Size(500, 1000);

            SetPageSizeToPrintDimension(printingDimensions, pageSize);

            Size expected = new Size(pageSize.Width - margin.Left - margin.Right, pageSize.Height - margin.Top - margin.Bottom);

            Assert.AreEqual(expected, printingDimensions.PrintablePageSize);
        }
        public void GetHeightForBody_IsTotalPageHeightMinusPrintParts()
        {
            Mock<IPrintProcessor> mock = new Mock<IPrintProcessor>();
            mock.Setup(i => i.GetHeader()).Returns(new Grid { Height = 10 });
            mock.Setup(i => i.GetFooter()).Returns(new Grid { Height = 20 });
            mock.Setup(i => i.GetHeaderDescription()).Returns(new Grid { Height = 30 });
            mock.Setup(i => i.GetSummary()).Returns(new Grid { Height = 40 });

            PrintDimension pd = new PrintDimension();
            pd.PrintProcessor = mock.Object;
            pd.InternalPrintDefinition = new PrintDefinition();
            pd.InternalPrintDefinition.SetPrintAttribute(new PrintOnAllPagesAttribute(PrintAppendixes.All));

            pd.PageSize = new Size(100, 300);

            // 300 - Header - Footer - HeaderDescritpion - Summary - PageNumbers
            Assert.That(pd.GetHeightForBodyGrid(1, false), Is.EqualTo(175));
        }
        public void GetHeightFor()
        {
            Mock<IPrintProcessor> mock = new Mock<IPrintProcessor>();
            mock.Setup(i => i.GetHeader()).Returns(new Grid { Height = 1 });
            mock.Setup(i => i.GetFooter()).Returns(new Grid { Height = 2 });
            mock.Setup(i => i.GetHeaderDescription()).Returns(new Grid { Height = 3 });

            PrintDimension pd = new PrintDimension();
            pd.PrintProcessor = mock.Object;
            pd.InternalPrintDefinition = new PrintDefinition();
            pd.InternalPrintDefinition.SetPrintAttribute(new PrintOnAllPagesAttribute(PrintAppendixes.Header | PrintAppendixes.Footer | PrintAppendixes.Summary));

            Assert.That(pd.GetHeightFor(PrintAppendixes.Header, 1, false), Is.EqualTo(1));
            Assert.That(pd.GetHeightFor(PrintAppendixes.Footer, 1, false), Is.EqualTo(2));

            Assert.That(pd.GetHeightFor(PrintAppendixes.HeaderDescription, 1, false), Is.EqualTo(0));

            Assert.That(() => pd.GetHeightFor(PrintAppendixes.Summary, 1, false), Throws.ArgumentNullException);

            pd.InternalPrintDefinition.SetPrintAttribute(new PrintOnAllPagesAttribute(PrintAppendixes.HeaderDescription));
            Assert.That(pd.GetHeightFor(PrintAppendixes.HeaderDescription, 1, false), Is.EqualTo(3));
        }
        public void GetRangeFor()
        {
            Mock<IPrintProcessor> mock = new Mock<IPrintProcessor>();
            mock.Setup(i => i.GetHeader()).Returns(new Grid { Height = 10 });
            mock.Setup(i => i.GetFooter()).Returns(new Grid { Height = 20 });
            mock.Setup(i => i.GetHeaderDescription()).Returns(new Grid { Height = 30 });
            mock.Setup(i => i.GetSummary()).Returns(new Grid { Height = 40 });

            PrintDimension pd = new PrintDimension();
            pd.PrintProcessor = mock.Object;
            pd.Margin = new Thickness(10);
            pd.PageSize = new Size(100, 1000);
            pd.InternalPrintDefinition = new PrintDefinition();
            pd.InternalPrintDefinition.SetPrintAttribute(new PrintOnAllPagesAttribute(PrintAppendixes.All));

            Assert.That(pd.GetRangeFor(PrintAppendixes.Header, 1, false), Is.EqualTo(new Range<double>(10, 20)));
            Assert.That(pd.GetRangeFor(PrintAppendixes.HeaderDescription, 1, false), Is.EqualTo(new Range<double>(20, 50)));
            Assert.That(pd.GetRangeForBodyGrid(1, false), Is.EqualTo(new Range<double>(50, 905)));
            Assert.That(pd.GetRangeFor(PrintAppendixes.Summary, 1, false), Is.EqualTo(new Range<double>(905, 945)));
            Assert.That(pd.GetRangeFor(PrintAppendixes.Footer, 1, false), Is.EqualTo(new Range<double>(945, 965)));
            Assert.That(pd.GetRangeFor(PrintAppendixes.PageNumbers, 1, false), Is.EqualTo(new Range<double>(965, 990)));
        }
 private static void SetPageSizeToPrintDimension(PrintDimension printingDimension, Size pageSize)
 {
     printingDimension.PageSize = pageSize;
     printingDimension.PositionRelative();
 }
        public void PrintablePageSize_Test(
            [Values(1, 2)] double left,
            [Values(4, 5)] double top,
            [Values(7, 8)] double right,
            [Values(10, 11)] double bottom)
        {
            Thickness margin = new Thickness(left, top, right, bottom);
            var printingDimensions = new PrintDimension(margin);

            Size pageSize = new Size(500, 1000);
            SetPageSizeToPrintDimension(printingDimensions, pageSize);

            Size expected = new Size(pageSize.Width - margin.Left - margin.Right, pageSize.Height - margin.Top - margin.Bottom);

            Assert.AreEqual(expected, printingDimensions.PrintablePageSize);
        }
        public void SetHeightValue()
        {
            PrintDimension pd = new PrintDimension();

            pd.InternalPrintDefinition = new PrintDefinition();
            pd.InternalPrintDefinition.SetPrintAttribute(new PrintOnAllPagesAttribute(PrintAppendixes.All));

            pd.SetHeightValue(PrintAppendixes.Summary, 5);
            Assert.That(pd.GetHeightFor(PrintAppendixes.Summary, 1, false), Is.EqualTo(5));
            pd.SetHeightValue(PrintAppendixes.Summary, 6);
            Assert.That(pd.GetHeightFor(PrintAppendixes.Summary, 1, false), Is.EqualTo(6));
        }
        public void GetRangeFor_InvalidPrintAppendix()
        {
            PrintDimension pd = new PrintDimension();

            Assert.That(() => pd.GetRangeFor(PrintAppendixes.All, 1, false), Throws.ArgumentException);
        }
        public void PageSize_Test()
        {
            Thickness margin = new Thickness(10, 20, 30, 40);
            var printingDimensions = new PrintDimension(margin);

            Size pageSize = new Size(500, 1000);
            SetPageSizeToPrintDimension(printingDimensions, pageSize);

            Assert.AreEqual(pageSize, printingDimensions.PageSize);
        }
 public void PrintDimension()
 {
     var pp = new PrintProcessorWithPrintOnAttribute();
     var pd = new PrintDimension();
     pp.PrintDimension = pd;
     Assert.That(pp.PrintDimension, Is.EqualTo(pd));
 }
        private static void SetPageSizeToPrintDimension(PrintDimension printingDimension, Size pageSize)
        {
            Type t = printingDimension.GetType();
            var v = t.GetProperty("PageSize");

            v.SetValue(printingDimension, pageSize, null);

            var m = t.GetMethod("PositionizeRelative", BindingFlags.NonPublic | BindingFlags.Instance);
            Assert.That(m, Is.Not.Null);
            m.Invoke(printingDimension, null);
        }
        public void RecalculateHeightValueWhen([Random(10, 100, 1)] int initialHeight)
        {
            PrintDimension pd = new PrintDimension();
            pd.InternalPrintDefinition = new PrintDefinition();
            pd.InternalPrintDefinition.SetPrintAttribute(new PrintOnAllPagesAttribute(PrintAppendixes.All));

            Mock<IPrintProcessor> printProcessor = new Mock<IPrintProcessor>();
            printProcessor.Setup(i => i.GetSummary()).Returns(() => new Grid() { Height = initialHeight });
            pd.PrintProcessor = printProcessor.Object;

            Assert.That(pd.GetHeightFor(PrintAppendixes.Summary, 1, false), Is.EqualTo(initialHeight));
            pd.SetHeightValue(PrintAppendixes.Summary, 5);

            pd.RecalculateHeightValueWhen(() => false, PrintAppendixes.Summary);

            Assert.That(pd.GetHeightFor(PrintAppendixes.Summary, 1, false), Is.EqualTo(5));

            pd.RecalculateHeightValueWhen(() => true, PrintAppendixes.Summary);

            Assert.That(pd.GetHeightFor(PrintAppendixes.Summary, 1, false), Is.EqualTo(initialHeight));
        }
 private void Prepare(Size pageSize)
 {
     PrintDimension.PageSize = pageSize;
     PreparePrint();
     PrintDimension.PositionizeRelative();
 }
 public void GetRangeFor_InvalidPrintAppendix()
 {
     PrintDimension pd = new PrintDimension();
     Assert.That(() => pd.GetRangeFor(PrintAppendixes.All, 1, false), Throws.ArgumentException);
 }