Beispiel #1
0
        public void GenerateTextTest()
        {
            var rnd = new Random();

            var model = new TestReportModel
                {
                    Items = Enumerable.Range(0, 50).Select(id => new TestReportItemModel
                        {
                            Id = id,
                            Name = Guid.NewGuid().ToString(),
                            Value = rnd.Next(1000000, 10000000) / 1000.0
                        })
                };

            var generator = new RazorTextGenerator();

            var content = generator.Generate(@"Content\SimpleReport.cshtml", model);

            var document = XDocument.Parse("<body>" + content + "</body>");

            // ReSharper disable PossibleNullReferenceException
            var style = document.Root.Element("style");
            var table = document.Root.Element("table");
            // ReSharper restore PossibleNullReferenceException

            Assert.IsFalse(string.IsNullOrEmpty(content), "Content is null or empty");
            Assert.IsNotNull(style, "Cant find 'style' tag");
            Assert.IsNotNull(table, "Cant find 'table' tag");
        }
Beispiel #2
0
        public void GenerateTextTest()
        {
            var rnd = new Random();

            var model = new TestReportModel
            {
                Items = Enumerable.Range(0, 50).Select(id => new TestReportItemModel
                {
                    Id    = id,
                    Name  = Guid.NewGuid().ToString(),
                    Value = rnd.Next(1000000, 10000000) / 1000.0
                })
            };

            var generator = new RazorTextGenerator();

            var content = generator.Generate(@"Content\SimpleReport.cshtml", model);

            var document = XDocument.Parse("<body>" + content + "</body>");

            // ReSharper disable PossibleNullReferenceException
            var style = document.Root.Element("style");
            var table = document.Root.Element("table");

            // ReSharper restore PossibleNullReferenceException

            Assert.IsFalse(string.IsNullOrEmpty(content), "Content is null or empty");
            Assert.IsNotNull(style, "Cant find 'style' tag");
            Assert.IsNotNull(table, "Cant find 'table' tag");
        }
Beispiel #3
0
        public IEnumerable <Table> CreateTables <TModel>(string filePath, TModel model)
        {
            var generator = new RazorTextGenerator();

            var content = generator.Generate(filePath, model);

            var document = XDocument.Parse(string.Concat("<body>", content, "</body>"));

            // ReSharper disable PossibleNullReferenceException

            var tableTags = document.Root.Elements("table");

            var styleTag = document.Root.Elements("style").FirstOrDefault();

            // ReSharper restore PossibleNullReferenceException

            IDictionary <string, BaseStyle> classes;

            if (styleTag != null)
            {
                var parser = new CssParser();
                classes = CssParser.ParceCss(styleTag.Value);
            }
            else
            {
                classes = new Dictionary <string, BaseStyle>();
            }

            var tables = ParseTables(tableTags, classes).ToArray();

            var imagesTags = document.Root.Elements("img");

            var images = ParseImages(imagesTags);

            var table = tables.First();

            table.Images = images;

            return(tables);
        }