Esempio n. 1
0
        public void BuildsReport()
        {
            MockZipFactory.Setup(x => x.ZipArchiveFromStream(It.IsAny <Stream>(), ZipArchiveMode.Update))
            .Returns(_mockZipArchive.Object);

            MockTemplateService.Setup(x => x.Run(It.IsAny <string>(), It.IsAny <object>(), null))
            .Returns("hello, this is a test string");

            _mockZipArchive.Setup(x => x.CreateEntry("content.xml")).Returns(_mockZipEntry.Object);

            _mockZipEntry.Setup(x => x.Open()).Returns(new MemoryStream());

            _mockZipArchive.Setup(x => x.GetEntry("content.xml")).Returns(_mockZipEntry.Object);

            _sut.BuildReport(_mockTemplate.Object, typeof(TestModel), _testStream);
        }
Esempio n. 2
0
        //[Test]
        public void IntegrationTest()
        {
            const string templatePath            = @"..\..\Test Templates\Modeled Basic Template.odt";
            const string reportPath              = @"..\..\Generated Reports\Very Basic Report.odt";
            const string expectedReportPath      = @"..\..\Expected Report Outputs\Very Basic Report.odt";
            var          templateFactory         = new TemplateFactory();
            var          zipFactory              = new ZipFactory();
            var          readerFactory           = new StreamReaderWrapperFactory();
            var          zipHandlerService       = new ZipHandlerService(readerFactory);
            var          buildOdfMetadataService = new BuildOdfMetadataService();
            var          xmlNamespaceService     = new XmlNamespaceService();
            var          xDocumentParserService  = new XDocumentParserService();
            var          odfHandlerService       = new OdfHandlerService(zipFactory, zipHandlerService, buildOdfMetadataService,
                                                                         xmlNamespaceService, xDocumentParserService);

            var templateService = new TemplateBuilderService(templateFactory, odfHandlerService,
                                                             xmlNamespaceService, xDocumentParserService);
            var document = File.ReadAllBytes(templatePath);

            var template             = templateService.BuildTemplate(document);
            var razorTemplateService = new TemplateService();
            var compileService       = new CompileService(razorTemplateService);

            compileService.Compile(template, "Template 1");

            var reportService = new ReportGeneratorService(new ZipFactory(), razorTemplateService);

            using (var report = new FileStream(reportPath, FileMode.Create))
            {
                reportService.BuildReport(template, new BasicModel {
                    Name = "Fancypants McSnooterson"
                }, report);
            }
            var diffs = GetDifferences(expectedReportPath, reportPath);
            var thereAreDifferences = diffs.HasDifferences();

            Assert.That(!thereAreDifferences);
        }