Exemplo n.º 1
0
        public void TestDynamicPanelAfterRenderEvent()
        {
            var          report = new TestReport();
            IXLWorksheet ws     = report.Workbook.AddWorksheet("Test");
            IXLRange     range  = ws.Range(2, 2, 4, 2);

            range.AddToNamed("TestRange", XLScope.Worksheet);

            ws.Cell(2, 2).Value = "{Headers}";
            ws.Cell(3, 2).Value = "{Data}";
            ws.Cell(4, 2).Value = "{Totals}";

            var panel = new ExcelDataSourceDynamicPanel("m:DataProvider:GetAllCustomersDataSet()", ws.NamedRange("TestRange"), report, report.TemplateProcessor)
            {
                AfterRenderMethodName = "TestExcelDynamicPaneAfterRender",
            };

            panel.Render();

            Assert.AreEqual(ws.Range(2, 2, 6, 7), panel.ResultRange);

            ExcelAssert.AreWorkbooksContentEquals(TestHelper.GetExpectedWorkbook(nameof(DataSourceDynamicPanelDataSetRenderTest),
                                                                                 nameof(TestDynamicPanelAfterRenderEvent)), ws.Workbook);

            //report.Workbook.SaveAs("test.xlsx");
        }
Exemplo n.º 2
0
        public void TestRenderEmptyDataReader()
        {
            var          report = new TestReport();
            IXLWorksheet ws     = report.Workbook.AddWorksheet("Test");
            IXLRange     range  = ws.Range(2, 2, 4, 2);

            range.AddToNamed("TestRange", XLScope.Worksheet);

            ws.Cell(2, 2).Value = "{Headers}";
            ws.Cell(2, 2).Style.Border.OutsideBorder      = XLBorderStyleValues.Medium;
            ws.Cell(2, 2).Style.Border.OutsideBorderColor = XLColor.Red;
            ws.Cell(2, 2).Style.Font.Bold = true;

            ws.Cell(3, 2).Value = "{Data}";
            ws.Cell(3, 2).Style.Border.OutsideBorder      = XLBorderStyleValues.Thin;
            ws.Cell(3, 2).Style.Border.OutsideBorderColor = XLColor.Black;

            ws.Cell(4, 2).Value = "{Totals}";
            ws.Cell(4, 2).Style.Border.OutsideBorder      = XLBorderStyleValues.Dotted;
            ws.Cell(4, 2).Style.Border.OutsideBorderColor = XLColor.Green;

            var panel = new ExcelDataSourceDynamicPanel("m:DataProvider:GetEmptyDataReader()", ws.NamedRange("TestRange"), report, report.TemplateProcessor);

            panel.Render();

            Assert.AreEqual(ws.Range(2, 2, 3, 7), panel.ResultRange);

            ExcelAssert.AreWorkbooksContentEquals(TestHelper.GetExpectedWorkbook(nameof(DataSourceDynamicPanelDataReaderRenderTest),
                                                                                 nameof(TestRenderEmptyDataReader)), ws.Workbook);

            //report.Workbook.SaveAs("test.xlsx");
        }
Exemplo n.º 3
0
        public void TestDynamicPanelBeforeRenderEvent()
        {
            var          report = new TestReport();
            IXLWorksheet ws     = report.Workbook.AddWorksheet("Test");
            IXLRange     range  = ws.Range(2, 2, 4, 2);

            range.AddToNamed("TestRange", XLScope.Worksheet);

            ws.Cell(2, 2).Value = "{Headers}";
            ws.Cell(3, 2).Value = "{Data}";
            ws.Cell(4, 2).Value = "{Totals}";

            var panel = new ExcelDataSourceDynamicPanel("m:DataProvider:GetAllCustomersDataSet()", ws.NamedRange("TestRange"), report, report.TemplateProcessor)
            {
                BeforeRenderMethodName = "TestExcelDynamicPaneBeforeRender",
            };

            panel.Render();

            Assert.AreEqual(range, panel.ResultRange);

            Assert.AreEqual(3, ws.CellsUsed(XLCellsUsedOptions.Contents).Count());
            Assert.AreEqual("CanceledHeaders", ws.Cell(2, 2).Value);
            Assert.AreEqual("CanceledData", ws.Cell(3, 2).Value);
            Assert.AreEqual("CanceledTotals", ws.Cell(4, 2).Value);

            //report.Workbook.SaveAs("test.xlsx");
        }
        public void TestRenderDictionaryEnumerable()
        {
            var          report = new TestReport();
            IXLWorksheet ws     = report.Workbook.AddWorksheet("Test");
            IXLRange     range1 = ws.Range(2, 2, 4, 2);

            range1.AddToNamed("TestRange1", XLScope.Worksheet);

            ws.Cell(2, 2).Value = "{Headers}";
            ws.Cell(3, 2).Value = "{Data}";
            ws.Cell(4, 2).Value = "{Totals}";

            var panel1 = new ExcelDataSourceDynamicPanel("m:DataProvider:GetDictionaryEnumerable()", ws.NamedRange("TestRange1"), report, report.TemplateProcessor);

            panel1.Render();

            Assert.AreEqual(ws.Range(2, 2, 6, 4), panel1.ResultRange);

            var dictWithDecimalValues = new List <IDictionary <string, decimal> >
            {
                new Dictionary <string, decimal> {
                    ["Value"] = 25.7m
                },
                new Dictionary <string, decimal> {
                    ["Value"] = 250.7m
                },
                new Dictionary <string, decimal> {
                    ["Value"] = 2500.7m
                },
            };

            IXLRange range2 = ws.Range(7, 2, 9, 2);

            range2.AddToNamed("TestRange2", XLScope.Worksheet);

            ws.Cell(7, 2).Value = "{Headers}";
            ws.Cell(8, 2).Value = "{Data}";
            ws.Cell(9, 2).Value = "{Totals}";

            var panel2 = new ExcelDataSourceDynamicPanel(dictWithDecimalValues, ws.NamedRange("TestRange2"), report, report.TemplateProcessor);

            panel2.Render();

            Assert.AreEqual(ws.Range(7, 2, 11, 2), panel2.ResultRange);

            ExcelAssert.AreWorkbooksContentEquals(TestHelper.GetExpectedWorkbook(nameof(DataSourceDynamicPanelDictionaryRenderTest),
                                                                                 nameof(TestRenderDictionaryEnumerable)), ws.Workbook);

            //report.Workbook.SaveAs("test.xlsx");
        }
        public void TestRenderEmptyDictionary()
        {
            var          report = new TestReport();
            IXLWorksheet ws     = report.Workbook.AddWorksheet("Test");
            IXLRange     range1 = ws.Range(2, 2, 4, 2);

            range1.AddToNamed("TestRange", XLScope.Worksheet);

            ws.Cell(2, 2).Value = "{Headers}";
            ws.Cell(3, 2).Value = "{Data}";
            ws.Cell(4, 2).Value = "{Totals}";

            IXLRange range2 = ws.Range(7, 2, 9, 2);

            range2.AddToNamed("TestRange2", XLScope.Worksheet);

            ws.Cell(7, 2).Value = "{Headers}";
            ws.Cell(8, 2).Value = "{Data}";
            ws.Cell(9, 2).Value = "{Totals}";

            IDictionary <string, object> data1 = new Dictionary <string, object>();
            var panel1 = new ExcelDataSourceDynamicPanel(data1, ws.NamedRange("TestRange"), report, report.TemplateProcessor);

            panel1.Render();

            Assert.AreEqual(ws.Range(2, 2, 3, 3), panel1.ResultRange);

            IEnumerable <KeyValuePair <string, object> > data2 = new List <KeyValuePair <string, object> >();
            var panel2 = new ExcelDataSourceDynamicPanel(data2, ws.NamedRange("TestRange2"), report, report.TemplateProcessor);

            panel2.Render();

            Assert.AreEqual(ws.Range(6, 2, 7, 3), panel2.ResultRange);

            Assert.AreEqual(4, ws.CellsUsed(XLCellsUsedOptions.Contents).Count());
            Assert.AreEqual("Key", ws.Cell(2, 2).Value);
            Assert.AreEqual("Value", ws.Cell(2, 3).Value);
            Assert.AreEqual("Key", ws.Cell(6, 2).Value);
            Assert.AreEqual("Value", ws.Cell(6, 3).Value);

            //report.Workbook.SaveAs("test.xlsx");
        }
Exemplo n.º 6
0
        public void TestRenderNullItem()
        {
            var          report = new TestReport();
            IXLWorksheet ws     = report.Workbook.AddWorksheet("Test");
            IXLRange     range1 = ws.Range(2, 2, 4, 2);

            range1.AddToNamed("TestRange", XLScope.Worksheet);

            ws.Cell(2, 2).Value = "{Headers}";
            ws.Cell(3, 2).Value = "{Data}";
            ws.Cell(4, 2).Value = "{Totals}";

            var panel = new ExcelDataSourceDynamicPanel("m:DataProvider:GetNullItem()", ws.NamedRange("TestRange"), report, report.TemplateProcessor);

            panel.Render();

            Assert.IsNull(panel.ResultRange);

            Assert.AreEqual(0, ws.CellsUsed(XLCellsUsedOptions.Contents).Count());
        }
        public void TestRenderDictionary()
        {
            var          report = new TestReport();
            IXLWorksheet ws     = report.Workbook.AddWorksheet("Test");
            IXLRange     range1 = ws.Range(2, 2, 4, 2);

            range1.AddToNamed("TestRange", XLScope.Worksheet);

            ws.Cell(2, 2).Value = "{Headers}";
            ws.Cell(3, 2).Value = "{Data}";
            ws.Cell(4, 2).Value = "{Totals}";

            IXLRange range2 = ws.Range(7, 2, 9, 2);

            range2.AddToNamed("TestRange2", XLScope.Worksheet);

            ws.Cell(7, 2).Value = "{Headers}";
            ws.Cell(8, 2).Value = "{Data}";
            ws.Cell(9, 2).Value = "{Totals}";

            IDictionary <string, object> data1 = new DataProvider().GetDictionaryEnumerable().First();
            var panel1 = new ExcelDataSourceDynamicPanel(data1, ws.NamedRange("TestRange"), report, report.TemplateProcessor);

            panel1.Render();

            Assert.AreEqual(ws.Range(2, 2, 6, 3), panel1.ResultRange);

            IEnumerable <KeyValuePair <string, object> > data2 = new DataProvider().GetDictionaryEnumerable().First()
                                                                 .Select(x => new KeyValuePair <string, object>(x.Key, x.Value));
            var panel2 = new ExcelDataSourceDynamicPanel(data2, ws.NamedRange("TestRange2"), report, report.TemplateProcessor);

            panel2.Render();

            Assert.AreEqual(ws.Range(9, 2, 13, 3), panel2.ResultRange);

            ExcelAssert.AreWorkbooksContentEquals(TestHelper.GetExpectedWorkbook(nameof(DataSourceDynamicPanelDictionaryRenderTest),
                                                                                 nameof(TestRenderDictionary)), ws.Workbook);

            //report.Workbook.SaveAs("test.xlsx");
        }
Exemplo n.º 8
0
        public void TestRenderDataSetWithEvents_HorizontalPanel()
        {
            var          report = new TestReport();
            IXLWorksheet ws     = report.Workbook.AddWorksheet("Test");
            IXLRange     range  = ws.Range(2, 2, 2, 4);

            range.AddToNamed("TestRange", XLScope.Worksheet);

            ws.Cell(2, 2).Value = "{Headers}";
            ws.Cell(2, 3).Value = "{Data}";
            ws.Cell(2, 4).Value = "{Totals}";

            var panel = new ExcelDataSourceDynamicPanel("m:DataProvider:GetAllCustomersDataSet()", ws.NamedRange("TestRange"), report, report.TemplateProcessor)
            {
                BeforeHeadersRenderMethodName         = "TestExcelDynamicPanelBeforeHeadersRender",
                AfterHeadersRenderMethodName          = "TestExcelDynamicPanelAfterHeadersRender",
                BeforeDataTemplatesRenderMethodName   = "TestExcelDynamicPanelBeforeDataTemplatesRender",
                AfterDataTemplatesRenderMethodName    = "TestExcelDynamicPanelAfterDataTemplatesRender",
                BeforeDataRenderMethodName            = "TestExcelDynamicPanelBeforeDataRender",
                AfterDataRenderMethodName             = "TestExcelDynamicPanelAfterDataRender",
                BeforeDataItemRenderMethodName        = "TestExcelDynamicPanelBeforeDataItemRender",
                AfterDataItemRenderMethodName         = "TestExcelDynamicPanelAfterDataItemRender",
                BeforeTotalsTemplatesRenderMethodName = "TestExcelDynamicPanelBeforeTotalsTemplatesRender",
                AfterTotalsTemplatesRenderMethodName  = "TestExcelDynamicPanelAfterTotalsTemplatesRender",
                BeforeTotalsRenderMethodName          = "TestExcelDynamicPanelBeforeTotalsRender",
                AfterTotalsRenderMethodName           = "TestExcelDynamicPaneAfterTotalsRender",
                Type    = PanelType.Horizontal,
                GroupBy = "4",
            };

            panel.Render();

            Assert.AreEqual(ws.Range(2, 2, 8, 6), panel.ResultRange);

            ExcelAssert.AreWorkbooksContentEquals(TestHelper.GetExpectedWorkbook(nameof(DataSourceDynamicPanelDataSetRenderTest),
                                                                                 nameof(TestRenderDataSetWithEvents_HorizontalPanel)), ws.Workbook);

            // report.Workbook.SaveAs("test.xlsx");
        }
        public void TestRenderEmptyDictionaryEnumerable()
        {
            var          report = new TestReport();
            IXLWorksheet ws     = report.Workbook.AddWorksheet("Test");
            IXLRange     range  = ws.Range(2, 2, 4, 2);

            range.AddToNamed("TestRange1", XLScope.Worksheet);

            ws.Cell(2, 2).Value = "{Headers}";
            ws.Cell(3, 2).Value = "{Data}";
            ws.Cell(4, 2).Value = "{Totals}";

            var panel = new ExcelDataSourceDynamicPanel(new List <IDictionary <string, decimal> >(), ws.NamedRange("TestRange1"), report, report.TemplateProcessor);

            panel.Render();

            Assert.IsNull(panel.ResultRange);

            Assert.AreEqual(0, ws.CellsUsed(XLCellsUsedOptions.Contents).Count());

            //report.Workbook.SaveAs("test.xlsx");
        }
        public void TestRenderEmptyEnumerable()
        {
            var          report = new TestReport();
            IXLWorksheet ws     = report.Workbook.AddWorksheet("Test");
            IXLRange     range1 = ws.Range(2, 2, 4, 2);

            range1.AddToNamed("TestRange", XLScope.Worksheet);

            ws.Cell(2, 2).Value = "{Headers}";
            ws.Cell(3, 2).Value = "{Data}";
            ws.Cell(4, 2).Value = "{Totals}";

            var panel = new ExcelDataSourceDynamicPanel("m:DataProvider:GetEmptyIEnumerable()", ws.NamedRange("TestRange"), report, report.TemplateProcessor);

            panel.Render();

            Assert.AreEqual(ws.Range(2, 2, 3, 5), panel.ResultRange);

            ExcelAssert.AreWorkbooksContentEquals(TestHelper.GetExpectedWorkbook(nameof(DataSourceDynamicPanelEnumerableRenderTest),
                                                                                 nameof(TestRenderEmptyEnumerable)), ws.Workbook);

            //report.Workbook.SaveAs("test.xlsx");
        }