Beispiel #1
0
        private IReportTable <ReportCell> BuildReport()
        {
            ReportCellProperty  centerAlignment = new AlignmentProperty(Alignment.Center);
            BoldProperty        bold            = new BoldProperty();
            IndentationProperty indentation     = new IndentationProperty();

            HorizontalReportSchemaBuilder <Entity> reportBuilder = new HorizontalReportSchemaBuilder <Entity>();

            reportBuilder.AddGlobalProperties(centerAlignment);

            reportBuilder
            .AddHeaderRow(string.Empty, e => e.Name)
            .AddProperties(centerAlignment);
            reportBuilder.AddRow("Age", e => e.Age)
            .AddHeaderProperties(bold);
            reportBuilder.AddRow(new EmptyCellsProvider <Entity>("Score"))
            .AddHeaderProperties(bold);
            reportBuilder.AddRow("Min. Score", e => e.MinScore)
            .AddHeaderProperties(indentation);
            reportBuilder.AddRow("Max. Score", e => e.MaxScore)
            .AddHeaderProperties(indentation);
            reportBuilder.AddRow("Avg. Score", e => e.AverageScore)
            .AddHeaderProperties(indentation)
            .AddProperties(new DecimalPrecisionProperty(2));

            return(reportBuilder.BuildSchema().BuildReportTable(this.GetData()));
        }
        public void Build_WithHeader_CorrectValues()
        {
            HorizontalReportSchemaBuilder <string> reportBuilder = new HorizontalReportSchemaBuilder <string>();

            reportBuilder.AddRow("Value", s => s);
            reportBuilder.AddHeaderRow(string.Empty, s => s.Length);

            IReportTable <ReportCell> table = reportBuilder.BuildSchema().BuildReportTable(new[]
            {
                "Test",
            });

            ReportCell[][] headerCells = this.GetCellsAsArray(table.HeaderRows);
            headerCells.Should().HaveCount(1);
            headerCells[0][0].GetValue <string>().Should().Be(string.Empty);
            headerCells[0][1].GetValue <int>().Should().Be(4);
        }
        public void Build_WithCustomHeaderProperty_CorrectProperties()
        {
            HorizontalReportSchemaBuilder <string> reportBuilder = new HorizontalReportSchemaBuilder <string>();

            reportBuilder.AddRow("Value", s => s)
            .AddHeaderProperties(new CustomTitleProperty());

            IReportTable <ReportCell> table = reportBuilder.BuildSchema().BuildReportTable(new[]
            {
                "Test",
            });

            ReportCell[][] cells = this.GetCellsAsArray(table.Rows);
            cells.Should().HaveCount(1);
            cells[0][0].Properties.Should()
            .HaveCount(1).And
            .ContainItemsAssignableTo <CustomTitleProperty>();
        }
        public void Build_SequentialNumberValueProviderWithNonDefaultStartValue_CorrectValues()
        {
            HorizontalReportSchemaBuilder <string> reportBuilder = new HorizontalReportSchemaBuilder <string>();

            reportBuilder.AddRow("#", new SequentialNumberValueProvider(50));

            IReportTable <ReportCell> table = reportBuilder.BuildSchema().BuildReportTable(new[]
            {
                "John Doe",
                "Jane Doe",
            });

            ReportCell[][] cells = this.GetCellsAsArray(table.Rows);
            cells.Should().HaveCount(1);
            cells[0][0].GetValue <string>().Should().Be("#");
            cells[0][1].GetValue <int>().Should().Be(50);
            cells[0][2].GetValue <int>().Should().Be(51);
        }
Beispiel #5
0
        public void Build_CustomPropertyWithoutProcessor_CorrectProperties()
        {
            HorizontalReportSchemaBuilder <string> reportBuilder = new HorizontalReportSchemaBuilder <string>();

            reportBuilder.AddRow("Value", s => s)
            .AddProperties(new CustomProperty());

            IReportTable <ReportCell> table = reportBuilder.BuildSchema().BuildReportTable(new[]
            {
                "Test",
            });

            ReportCell[][] cells = this.GetCellsAsArray(table.Rows);
            cells.Should().HaveCount(1);
            cells[0][0].Properties.Should().BeEmpty();
            cells[0][1].Properties.Should()
            .HaveCount(1).And
            .AllBeOfType <CustomProperty>();
        }
Beispiel #6
0
        public void Build_WithCustomProperty_CorrectProperties()
        {
            HorizontalReportSchemaBuilder <string> reportBuilder = new HorizontalReportSchemaBuilder <string>();

            reportBuilder.AddRow("Value", s => s)
            .AddProcessors(new CustomPropertyProcessor());

            IReportTable <ReportCell> table = reportBuilder.BuildSchema().BuildReportTable(new[]
            {
                "Test",
            });

            ReportCell[][] cells = this.GetCellsAsArray(table.Rows);
            cells.Should().HaveCount(1);
            cells[0][0].Properties.Should().BeEmpty();
            cells[0][1].Properties.Should()
            .HaveCount(1).And
            .ContainSingle(p => p is CustomProperty && ((CustomProperty)p).Assigned);
        }
        public void Build_DecimalRowWithRounding_CorrectDisplayValue()
        {
            HorizontalReportSchemaBuilder <decimal> reportBuilder = new HorizontalReportSchemaBuilder <decimal>();

            reportBuilder.AddRow("Score", d => d);

            IReportTable <ReportCell> table = reportBuilder.BuildSchema().BuildReportTable(new[]
            {
                3m,
                6.5m,
            });

            ReportCell[][] cells = this.GetCellsAsArray(table.Rows);
            cells.Should().HaveCount(1);
            cells[0][0].ValueType.Should().Be(typeof(string));
            cells[0][0].GetValue <string>().Should().Be("Score");
            cells[0][1].ValueType.Should().Be(typeof(decimal));
            cells[0][1].GetValue <decimal>().Should().Be(3m);
            cells[0][2].ValueType.Should().Be(typeof(decimal));
            cells[0][2].GetValue <decimal>().Should().Be(7m);
        }
        public void Build_DateTimeRowWithFormat_CorrectDisplayValue()
        {
            HorizontalReportSchemaBuilder <DateTime> reportBuilder = new HorizontalReportSchemaBuilder <DateTime>();

            reportBuilder.AddRow("The Date", d => d);            // .SetValueFormatter(new DateTimeValueFormatter("MM/dd/yyyy"));
            reportBuilder.AddRow("Next Day", d => d.AddDays(1)); // .SetValueFormatter(new DateTimeValueFormatter("MM/dd/yyyy"));

            IReportTable <ReportCell> table = reportBuilder.BuildSchema().BuildReportTable(new[]
            {
                new DateTime(2020, 10, 24, 20, 25, 00),
            });

            ReportCell[][] cells = this.GetCellsAsArray(table.Rows);
            cells.Should().HaveCount(2);
            cells[0][0].Value.Should().Be("The Date");
            cells[0][0].ValueType.Should().Be(typeof(string));
            cells[0][1].Value.Should().Be("10/24/2020");
            cells[0][1].ValueType.Should().Be(typeof(DateTime));
            cells[1][0].Value.Should().Be("Next Day");
            cells[1][0].ValueType.Should().Be(typeof(string));
            cells[1][1].Value.Should().Be("10/25/2020");
            cells[1][1].ValueType.Should().Be(typeof(DateTime));
        }
        private IReportTable <ReportCell> BuildReport()
        {
            ReportCellProperty centerAlignment = new AlignmentProperty(Alignment.Center);
            BoldProperty       bold            = new BoldProperty();

            HorizontalReportSchemaBuilder <Entity> reportBuilder = new HorizontalReportSchemaBuilder <Entity>();

            reportBuilder.AddGlobalProperties(centerAlignment);
            reportBuilder
            .AddHeaderRow("Metrics", e => e.Name)
            .AddProperties(centerAlignment)
            .AddHeaderProperties(centerAlignment);
            reportBuilder.AddRow("Age", e => e.Age)
            .AddHeaderProperties(bold);
            reportBuilder.AddRow("Min. Score", e => e.MinScore);
            reportBuilder.AddRow("Max. Score", e => e.MaxScore);
            reportBuilder.AddRow("Avg. Score", e => e.AverageScore)
            .AddProperties(new DecimalPrecisionProperty(2));

            reportBuilder.AddComplexHeader(0, "Score", "Min. Score", "Avg. Score");
            reportBuilder.AddComplexHeaderProperties("Score", new ColorProperty(Color.Blue));

            return(reportBuilder.BuildSchema().BuildReportTable(this.GetData()));
        }
        public void Build_IntegerRow_CorrectValue()
        {
            HorizontalReportSchemaBuilder <int> reportBuilder = new HorizontalReportSchemaBuilder <int>();

            reportBuilder.AddRow("#", i => i);

            IReportTable <ReportCell> table = reportBuilder.BuildSchema().BuildReportTable(new[]
            {
                3,
                6,
            });

            ReportCell[][] headerCells = this.GetCellsAsArray(table.HeaderRows);
            headerCells.Should().BeEmpty();

            ReportCell[][] cells = this.GetCellsAsArray(table.Rows);
            cells.Should().HaveCount(1);
            cells[0][0].ValueType.Should().Be(typeof(string));
            cells[0][0].GetValue <string>().Should().Be("#");
            cells[0][1].ValueType.Should().Be(typeof(int));
            cells[0][1].GetValue <int>().Should().Be(3);
            cells[0][2].ValueType.Should().Be(typeof(int));
            cells[0][2].GetValue <int>().Should().Be(6);
        }