public void CreateExcelReport_When_Multiple_Sheets_Expect_Both_Populated()
        {
            //---------------Arrange------------------
            var configuration = SetupConfiguration();
            var reportData    = File.ReadAllText("ExampleData\\CampaignDetailedReport.json");
            var wordGateway   = new ReportGateway(configuration);

            var input = new RenderExcelInput
            {
                JsonModel    = reportData,
                ReportName   = "test.xslx",
                TemplateName = "CampaignDetailedReport",
                SheetNumbers = new List <int> {
                    1, 2
                }
            };
            //---------------Act----------------------
            var actual = wordGateway.CreateExcelReport(input);

            //---------------Assert-------------------
            File.WriteAllBytes("c:\\tmp\\two-tab.xlsx", actual.FetchDocumentAsByteArray());
            var expected = File.ReadAllText("Expected\\RenderedCampaignDetailedReportBase64.txt");

            Assert.Equal(expected.Substring(0, 50), actual.Base64String.Substring(0, 50));
        }
        private static void Respond_With_File(RenderExcelInput input,
                                              IRespondWithSuccessOrError <IFileOutput, ErrorOutput> presenter,
                                              RenderedDocumentOutput result)
        {
            var reportMessage = new WordFileOutput(input.ReportName, result.FetchDocumentAsByteArray());

            presenter.Respond(reportMessage);
        }
Example #3
0
        public void Ctor_ShouldSetFileNamePropertyToDefault()
        {
            // arrange
            // act
            var actual = new RenderExcelInput();

            // assert
            Assert.Equal("report.xlsx", actual.ReportName);
        }
Example #4
0
        public void Ctor_ShouldSetSheetNumberToOne()
        {
            // arrange
            // act
            var actual = new RenderExcelInput();

            // assert
            Assert.Equal(1, actual.SheetNumber);
        }
        public void Execute(RenderExcelInput inputInput,
                            IRespondWithSuccessOrError <IFileOutput, ErrorOutput> presenter)
        {
            var result = _reportGateway.CreateExcelReport(inputInput);

            if (result.HasErrors())
            {
                Respond_With_Errors(presenter, result);
                return;
            }

            Respond_With_File(inputInput, presenter, result);
        }
Example #6
0
        public void When_Setting_Sheet_Number_Should_Convert_To_Sheet_Numbers()
        {
            // arrange
            // act
            var actual = new RenderExcelInput
            {
                SheetNumber = 9
            };

            // assert
            Assert.Equal(new List <int> {
                9
            }, actual.SheetNumbers);
        }
        public void CreateExcelReport_GivenTemplate_Has_Dynamic_Chart_ShouldReturnRenderedReport()
        {
            //---------------Arrange------------------
            var configuration = SetupConfiguration();
            var reportData    = File.ReadAllText("ExampleData\\dynamic-chart-range.json");
            var wordGateway   = new ReportGateway(configuration);
            var input         = new RenderExcelInput {
                JsonModel = reportData, ReportName = "test.xslx", TemplateName = "dynamic-chart", SheetNumber = 1
            };
            //---------------Act----------------------
            var actual = wordGateway.CreateExcelReport(input);
            //---------------Assert-------------------
            var expected = File.ReadAllText("Expected\\RenderedDynamicChartExcelBase64.txt");

            Assert.Equal(expected.Substring(0, 50), actual.Base64String.Substring(0, 50));
        }
        public void CreateExcelReport_WhenInvalidTemplateName_ShouldReturnTemplateNameError()
        {
            //---------------Arrange------------------
            var configuration = SetupConfiguration();
            var reportGateway = new ReportGateway(configuration);
            var input         = new RenderExcelInput {
                JsonModel = "", ReportName = "test.xslx", TemplateName = "INVALID_NAME"
            };
            //---------------Act----------------------
            var actual = reportGateway.CreateExcelReport(input);

            //---------------Assert-------------------
            Assert.True(actual.HasErrors());
            Assert.Contains("Invalid Report Template", actual.ErrorMessages[0]);
            Assert.Contains("INVALID_NAME.xlsx", actual.ErrorMessages[0]);
        }
        public void CreateExcelReport_WhenValidInput_ShouldReturnRenderedReport()
        {
            //---------------Arrange------------------
            var configuration = SetupConfiguration();
            var reportData    = File.ReadAllText("ExampleData\\ExcelSampleData.json");
            var wordGateway   = new ReportGateway(configuration);
            var input         = new RenderExcelInput {
                JsonModel = reportData, ReportName = "test.xslx", TemplateName = "SimpleReport"
            };
            //---------------Act----------------------
            var actual = wordGateway.CreateExcelReport(input);
            //---------------Assert-------------------
            var expected = File.ReadAllText("Expected\\RenderedExcelBase64.txt");

            Assert.Equal(expected.Substring(0, 50), actual.Base64String.Substring(0, 50));
        }
        public RenderedDocumentOutput CreateExcelReport(RenderExcelInput input)
        {
            Func <string, ReportGenerationArguments, NodePipeLineTask> renderFactory = (nodeAppPath, arguments) =>
            {
                return(new ExcelRender(nodeAppPath, arguments.TemplatePath, arguments.JsonPath, arguments.SheetNumber));
            };

            var factoryArguments = new ReportFactoryArguments
            {
                ReportJson   = input.JsonModel.ToString(),
                TemplateName = input.TemplateName,
                Extension    = "xlsx",
                SheetNumber  = input.SheetNumber
            };

            var result = CreateReport(factoryArguments, renderFactory);

            result.ContentType = ContentTypes.Excel;
            return(result);
        }