Ejemplo n.º 1
0
        public void BaseStyle()
        {
            var model   = ModelOf("<style name='style1'/><style name='style2' base-style='style1'/>");
            var actions = Creator.Compile(model);

            const string style1Builder = "style1_styleBuilder";
            const string style2Builder = "style2_styleBuilder";

            actions.Should()
            .HaveAction(action => action.Should()
                        .CallStatic <StyleBuilder>(nameof(StyleBuilder.New))
                        .And
                        .HaveNullParameter()
                        .And
                        .SaveTo(style1Builder))
            .And.Then
            .HaveAction(action => action.Should()
                        .CallStatic <StyleBuilder>(nameof(StyleBuilder.New))
                        .And
                        .HaveVariableParameter <StyleBuilder>(style1Builder)
                        .And
                        .SaveTo(style2Builder));

            actions.Should()
            .HaveNoActions(action => action.Should().CallAnyOf(style1Builder));

            actions.Should()
            .HaveNoActions(action => action.Should().CallAnyOf(style2Builder));
        }
Ejemplo n.º 2
0
        public void AreaDefinedByPosition(string areaSpec, string position, string method, string left, string top, string width, string height)
        {
            var model   = ModelOf($"<layout><page size='A4' /><area {areaSpec}><location {position} /></area></layout>");
            var actions = Creator.Compile(model);

            XUnit _left, _top, _height, _width;

            _left   = Creator.ParseUnit(left);
            _top    = Creator.ParseUnit(top);
            _height = Creator.ParseUnit(height);
            _width  = Creator.ParseUnit(width);

            actions.Should()
            .HaveAction(action => action.Should()
                        .CallInstance(SECTIONBUILDER, method)
                        .And
                        .HaveParameterN <float>(0, v =>
                                                v.IsWithinMMFrom(_left.Point))
                        .And
                        .HaveParameterN <float>(1, v =>
                                                v.IsWithinMMFrom(_top.Point))
                        .And
                        .HaveParameterN <float>(2, v =>
                                                v.IsWithinMMFrom(_width.Point))
                        .And
                        .HaveParameterN <float>(3, v =>
                                                v.IsWithinMMFrom(_height.Point))
                        );
        }
Ejemplo n.º 3
0
        public void ApplyStyle(string target, string methodName, string styleName)
        {
            var model   = ModelOf($"<apply-style name='{styleName}' target='{target}' /><layout><page size='letter' /><area type='header' height='1in'/></layout>");
            var actions = Creator.Compile(model);

            actions.Should()
            .HaveAction(action => action.Should()
                        .CallInstance(SECTIONBUILDER, methodName)
                        .And
                        .HaveVariableParameterN <StyleBuilder>(0, $"{styleName}_styleBuilder"));
        }
Ejemplo n.º 4
0
        public void CreateAreaBuilder()
        {
            var model   = ModelOf("<layout><page size='letter' /><area type='header' height='1in'/></layout>");
            var actions = Creator.Compile(model);

            actions.Should()
            .HaveAction(action => action.Should()
                        .CallAnyOf(SECTIONBUILDER)
                        .And
                        .SaveTo(AREABUILDER));
        }
Ejemplo n.º 5
0
        public void KeepWithNext(bool value)
        {
            var          model         = ModelOf($"<style name='style1' keep-with-next='{ (value ? "true" : "false") }'/>");
            var          actions       = Creator.Compile(model);
            const string style1Builder = "style1_styleBuilder";

            actions.Should()
            .HaveAction(action => action.Should()
                        .CallInstance(style1Builder, nameof(StyleBuilder.SetKeepWithNext))
                        .And
                        .HaveParameter(value));
        }
Ejemplo n.º 6
0
        public void VerticalAlighment(string alignment, VerticalAlignment alignment1)
        {
            var          model         = ModelOf($"<style name='style1' vertical-alignment='{alignment}'/>");
            var          actions       = Creator.Compile(model);
            const string style1Builder = "style1_styleBuilder";

            actions.Should()
            .HaveAction(action => action.Should()
                        .CallInstance(style1Builder, nameof(StyleBuilder.SetVerticalAlignment))
                        .And
                        .HaveParameter(alignment1));
        }
Ejemplo n.º 7
0
        public void MinCellHeight()
        {
            var          model         = ModelOf("<style name='style1' min-cell-height='3.45mm'/>");
            var          actions       = Creator.Compile(model);
            const string style1Builder = "style1_styleBuilder";

            actions.Should()
            .HaveAction(action => action.Should()
                        .CallInstance(style1Builder, nameof(StyleBuilder.SetTableCellMinHeight))
                        .And
                        .HaveParameter <XUnit>(mu => Math.Abs(mu.Value - 3.45) < 1e-5 && mu.Type == MeasurementUnit.Millimeter));
        }
Ejemplo n.º 8
0
        public void Padding(string side, string method, float u, MeasurementUnit t)
        {
            var          model         = ModelOf($"<style name='style1'><padding {side} /></style>");
            var          actions       = Creator.Compile(model);
            const string style1Builder = "style1_styleBuilder";

            actions.Should()
            .HaveAction(action => action.Should()
                        .CallInstance(style1Builder, method)
                        .And
                        .HaveParameter <XUnit>(mu => Math.Abs(mu.Value - u) < 1e-5 && mu.Type == t));
        }
Ejemplo n.º 9
0
        public void OverflowAction(string mode1, TextOverflowAction mode2)
        {
            var          model         = ModelOf($"<style name='style1' overflow-action='{ mode1 }'/>");
            var          actions       = Creator.Compile(model);
            const string style1Builder = "style1_styleBuilder";

            actions.Should()
            .HaveAction(action => action.Should()
                        .CallInstance(style1Builder, nameof(StyleBuilder.SetParagraphTextOverflowAction))
                        .And
                        .HaveParameter(mode2));
        }
Ejemplo n.º 10
0
        public void LineSpacing()
        {
            var          model         = ModelOf("<style name='style1' line-spacing='5.5'/>");
            var          actions       = Creator.Compile(model);
            const string style1Builder = "style1_styleBuilder";

            actions.Should()
            .HaveAction(action => action.Should()
                        .CallInstance(style1Builder, nameof(StyleBuilder.SetLineSpacing))
                        .And
                        .HaveParameter(5.5f));
        }
Ejemplo n.º 11
0
        public void NewPage(string mode1, PageBreak mode2)
        {
            var          model         = ModelOf($"<style name='style1' page-break='{ mode1 }'/>");
            var          actions       = Creator.Compile(model);
            const string style1Builder = "style1_styleBuilder";

            actions.Should()
            .HaveAction(action => action.Should()
                        .CallInstance(style1Builder, nameof(StyleBuilder.SetPageBreak))
                        .And
                        .HaveParameter(mode2));
        }
Ejemplo n.º 12
0
        public void BackgrounColor(string color, byte r, byte g, byte b)
        {
            var          model         = ModelOf($"<style name='style1' background-color='{color}'/>");
            var          actions       = Creator.Compile(model);
            const string style1Builder = "style1_styleBuilder";

            actions.Should()
            .HaveAction(action => action.Should()
                        .CallInstance(style1Builder, nameof(StyleBuilder.SetBackColor))
                        .And
                        .HaveParameter <Color>(color => color.R == r && color.G == g && color.B == b));
        }
Ejemplo n.º 13
0
        public void AreaDefinedByHeight(string areaSpec, string method, string height)
        {
            var model   = ModelOf($"<layout><page size='A4' /><area {areaSpec}/></layout>");
            var actions = Creator.Compile(model);

            XUnit _height = Creator.ParseUnit(height);

            actions.Should()
            .HaveAction(action => action.Should()
                        .CallInstance(SECTIONBUILDER, method)
                        .And
                        .HaveParameterN <float>(0, v =>
                                                v.IsWithinMMFrom(_height.Point)));
        }
Ejemplo n.º 14
0
        public void PageSize(string pageSpec, string width, string height)
        {
            var model   = ModelOf($"<layout><page {pageSpec} /><area type='header' height='1in'/></layout>");
            var actions = Creator.Compile(model);

            actions.Should()
            .HaveAction(action => action.Should()
                        .CallInstance(SECTIONBUILDER, nameof(SectionBuilder.SetSize))
                        .And
                        .HaveParameter <XSize>(param =>
                                               param.Width.IsWithinMMFrom(Creator.ParseUnit(width)) &&
                                               param.Height.IsWithinMMFrom(Creator.ParseUnit(height)))
                        );
        }
Ejemplo n.º 15
0
        public void Font(string font, string methodName, object value, Type valueType)
        {
            if (value is string s && valueType != typeof(string))
            {
                if (valueType == typeof(XUnit))
                {
                    value = Creator.ParseUnit(s);
                }
                else if (valueType == typeof(Color))
                {
                    value = Creator.ParseColor(s);
                }
            }

            var          model         = ModelOf($"<style name='style1'><font {font}/></style>");
            var          actions       = Creator.Compile(model);
            const string style1Builder = "style1_styleBuilder";
            const string fontBuilder   = style1Builder + "_font";

            actions.Should()
            .HaveAction(action => action.Should().SaveTo(fontBuilder)
                        .And
                        .CallStatic <FontBuilder>(nameof(FontBuilder.New)))
            .And.Then
            .HaveAction(action =>
            {
                action.Should().CallInstance(fontBuilder, methodName)
                .And
                .HaveParameterN <object>(0, obj =>
                {
                    if (value is null)
                    {
                        return(obj is Null);
                    }
                    if (value is Color s && obj is Color d)
                    {
                        return(s.R == d.R && s.G == d.G && s.B == d.B);
                    }
                    if (value is XUnit s1 && obj is XUnit d1)
                    {
                        return(Math.Abs(s1.Value - d1.Value) < 1e-5 && s1.Type == d1.Type);
                    }
                    if (value is XUnit s2 && obj is float d2)
                    {
                        return(Math.Abs(s2.Point - d2) < 1e-5);
                    }
                    return(value.Equals(obj));
                });
            })
Ejemplo n.º 16
0
        public void CreateSectionBuilder()
        {
            var model   = ModelOf("<layout><page size='letter' /><area type='header' height='1in'/></layout>");
            var actions = Creator.Compile(model);

            actions.Should()
            .HaveAction(action => action.Should()
                        .CallStatic <SectionBuilder>(nameof(SectionBuilder.New))
                        .And
                        .HaveVariableParameter <DocumentBuilder>("documentBuilder")
                        .And
                        .SaveTo(SECTIONBUILDER))
            .And.Then
            .HaveAction(action => action.Should().CallAnyOf(SECTIONBUILDER));
        }
Ejemplo n.º 17
0
        public void Margins(string marginSpec, string left, string top, string right, string bottom)
        {
            var model   = ModelOf($"<layout><page size='A4' /><margins {marginSpec} /><area type='header' height='1in'/></layout>");
            var actions = Creator.Compile(model);

            XUnit _left, _top, _bottom, _right;

            _left   = Creator.ParseUnit(left);
            _top    = Creator.ParseUnit(top);
            _right  = Creator.ParseUnit(right);
            _bottom = Creator.ParseUnit(bottom);

            actions.Should()
            .HaveAction(action => action.Should()
                        .CallInstance(SECTIONBUILDER, nameof(SectionBuilder.SetMargins))
                        .And
                        .HaveParameterN <Box>(0, box =>
                                              box.Left.IsWithinMMFrom(_left) &&
                                              box.Right.IsWithinMMFrom(_right) &&
                                              box.Top.IsWithinMMFrom(_top) &&
                                              box.Bottom.IsWithinMMFrom(_bottom)));
        }
Ejemplo n.º 18
0
        public void Border(string side, string method, float?u, MeasurementUnit?t, Stroke?s, byte?r, byte?g, byte?b)
        {
            var          model         = ModelOf($"<style name='style1'><border><{side}/></border></style>");
            var          actions       = Creator.Compile(model);
            const string style1Builder = "style1_styleBuilder";

            actions.Should()
            .HaveAction(action =>
            {
                action.Should().CallInstance(style1Builder, method);

                if (u != null && t != null)
                {
                    action.Should().HaveParameterN <XUnit>(0, xu => Math.Abs(xu.Value - u.Value) < 1e-5 && xu.Type == t.Value);
                }
                else
                {
                    action.Should().HaveNullParameterN(0);
                }

                if (s != null)
                {
                    action.Should().HaveParameterN(1, s.Value);
                }
                else
                {
                    action.Should().HaveNullParameterN(1);
                }

                if (r != null && g != null && b != null)
                {
                    action.Should().HaveParameterN <Color>(2, c => c.R == r.Value && c.G == g.Value && c.B == b.Value);
                }
                else
                {
                    action.Should().HaveNullParameterN(2);
                }
            });
        }
Ejemplo n.º 19
0
        public void Numeration(string numerationSpec, int?startNumber, NumerationStyle?numerationStyle)
        {
            var model   = ModelOf($"<layout><page size='A4' /><page-numeration {numerationSpec} /><area type='header' height='1in'/></layout>");
            var actions = Creator.Compile(model);

            if (startNumber != null)
            {
                actions.Should()
                .HaveAction(action => action.Should()
                            .CallInstance(SECTIONBUILDER, nameof(SectionBuilder.SetPageNumberStart))
                            .And
                            .HaveParameterN(0, (uint)startNumber.Value));
            }

            if (numerationStyle != null)
            {
                actions.Should()
                .HaveAction(action => action.Should()
                            .CallInstance(SECTIONBUILDER, nameof(SectionBuilder.SetNumerationStyle))
                            .And
                            .HaveParameterN(0, numerationStyle.Value));
            }
        }