public void Execute_WhenValidInputTo_ShouldRespondWithPdfContentType()
        {
            //---------------Arrange-------------------
            var input = new RenderWordInput {
                JsonModel = "{}", ReportName = "Test.docx", TemplateName = "Test"
            };
            var reportResult = new RenderedDocumentOutput {
                Base64String = "", ContentType = ContentTypes.Word
            };
            var pdfResult = new RenderedDocumentOutput {
                Base64String = "", ContentType = ContentTypes.Pdf
            };

            var presenter = new PropertyPresenter <IFileOutput, ErrorOutput>();

            var reportGateway = Create_Report_Gateway(reportResult);
            var pdfGateway    = Create_Pdf_Gateway(pdfResult);

            var wordUsecase = new RenderWordUseCase(reportGateway);
            var pdfUsecase  = new RenderWordToPdfUseCase(pdfGateway);
            var sut         = new RenderAsWordThenPdfUseCase(wordUsecase, pdfUsecase);

            //---------------Act-----------------------
            sut.Execute(input, presenter);
            //---------------Assert--------------------
            Assert.Equal("application/pdf", presenter.SuccessContent.ContentType);
        }
        private void Respond_With_File(RenderWordInput inputTo,
                                       IRespondWithSuccessOrError <IFileOutput, ErrorOutput> presenter,
                                       RenderedDocumentOutput result)
        {
            var reportMessage = new WordFileOutput(inputTo.ReportName, result.FetchDocumentAsByteArray());

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

            // assert
            Assert.Equal("report.docx", actual.ReportName);
        }
Example #4
0
        private static RenderWordInput Create_Word_Input_Message(string jsonData)
        {
            var inputMessage = new RenderWordInput
            {
                TemplateName = "ReportWithImages",
                ReportName   = "ExampleReport",
                JsonModel    = jsonData
            };

            return(inputMessage);
        }
        public void Execute(RenderWordInput inputTo,
                            IRespondWithSuccessOrError <IFileOutput, ErrorOutput> presenter)
        {
            var result = _wordGateway.CreateWordReport(inputTo);

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

            Respond_With_File(inputTo, presenter, result);
        }
Example #6
0
        public IActionResult Create_Pdf()
        {
            var jsonData = Read_Report_Json();

            var inputMessage = new RenderWordInput
            {
                TemplateName = "ReportWithImages",
                ReportName   = "ExampleReport.docx",
                JsonModel    = jsonData
            };
            var presenter = new DownloadFilePresenter();

            _pdfUsecase.Execute(inputMessage, presenter);
            return(presenter.Render());
        }
        private void Render_Word_Report(string reportOutputDirectory,
                                        string reportDataFilePath)
        {
            var jsonData     = Read_Report_Data(reportDataFilePath);
            var inputMessage = new RenderWordInput
            {
                TemplateName = "ReportWithImages",
                ReportName   = "ExampleReport",
                JsonModel    = jsonData
            };

            _wordUseCase.Execute(inputMessage, _presenter);

            _presenter.Render(reportOutputDirectory, "docx");
        }
Example #8
0
        public void Execute(RenderWordInput inputTo, IRespondWithSuccessOrError <IFileOutput, ErrorOutput> presenter)
        {
            var wordPresenter = new PropertyPresenter <IFileOutput, ErrorOutput>();

            _wordUsecase.Execute(inputTo, wordPresenter);

            if (wordPresenter.IsErrorResponse())
            {
                presenter.Respond(wordPresenter.ErrorContent);
                return;
            }

            var pdfInput = Create_Pdf_Input(wordPresenter);

            _pdfUsecase.Execute(pdfInput, presenter);
        }
        public void CreateWordReport_WhenValidInput_ShouldReturnRenderedReport()
        {
            //---------------Arrange------------------
            var configuration = SetupConfiguration();
            var reportData    = File.ReadAllText("ExampleData\\WithImagesSampleData.json");
            var wordGateway   = new ReportGateway(configuration);
            var input         = new RenderWordInput {
                JsonModel = reportData, ReportName = "test.docx", TemplateName = "ReportWithImages"
            };
            //---------------Act----------------------
            var actual = wordGateway.CreateWordReport(input);
            //---------------Assert-------------------
            var expected = File.ReadAllText("Expected\\RenderedWordBase64.txt");

            Assert.Equal(expected.Substring(0, 50), actual.Base64String.Substring(0, 50));
        }
        public RenderedDocumentOutput CreateWordReport(RenderWordInput input)
        {
            Func <string, ReportGenerationArguments, NodePipeLineTask> renderFactory = (nodeAppPath, arguements) =>
            {
                return(new WordRender(nodeAppPath, arguements.TemplatePath, arguements.JsonPath));
            };

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

            var result = CreateReport(factoryArguments, renderFactory);

            result.ContentType = ContentTypes.Word;
            return(result);
        }
        public void Execute_WhenRenderErrors_ShouldRespondWithErrors()
        {
            //---------------Arrange-------------------
            var gatewayResult = new RenderedDocumentOutput {
                ErrorMessages = new List <string> {
                    "error"
                }
            };
            var gateway = Create_Report_Gateway(gatewayResult);

            var input = new RenderWordInput {
                JsonModel = "", ReportName = "Test.docx", TemplateName = "Test"
            };
            var presenter = new PropertyPresenter <IFileOutput, ErrorOutput>();

            var usecase = new RenderWordUseCase(gateway);

            //---------------Act----------------------
            usecase.Execute(input, presenter);
            //---------------Assert-----------------------
            Assert.True(presenter.IsErrorResponse());
        }
        public void Execute_WhenValidInputTo_ShouldRespondWithWordContentType()
        {
            //---------------Arrange-------------------
            var gatewayResult = new RenderedDocumentOutput {
                Base64String = "eA=="
            };
            var gateway = Create_Report_Gateway(gatewayResult);

            var input = new RenderWordInput {
                JsonModel = "", ReportName = "Test.docx", TemplateName = "Test"
            };
            var presenter = new PropertyPresenter <IFileOutput, ErrorOutput>();

            var usecase = new RenderWordUseCase(gateway);

            //---------------Act----------------------
            usecase.Execute(input, presenter);
            //---------------Assert-----------------------
            var expected = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";

            Assert.Equal(expected, presenter.SuccessContent.ContentType);
        }