Ejemplo n.º 1
0
        public void ConstructorTableTest()
        {
            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 constructor = new RazorGridConstructor();
            var tables = constructor.CreateTables(@"Content\SimpleReport.cshtml", model);
            var table = tables.First();

            Assert.IsNotNull(table.Head);
            Assert.IsNotNull(table.Body);

            Assert.IsTrue(table.Head.Rows.Any());
            Assert.IsTrue(table.Body.Rows.Any());

            Assert.IsTrue(table.Head.Rows.First().Cells.Any());
            Assert.IsTrue(table.Body.Rows.First().Cells.Any());

            Assert.IsNotNull(table.Head.Rows.First().Cells.First().Style);
            Assert.IsNotNull(table.Body.Rows.First().Cells.First().Style);
        }
Ejemplo n.º 2
0
        public void ConstructorImagesTest()
        {
            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
                })
            };

            Func<string, string> pathConverter = s => s.Replace("/", "\\");

            var constructor = new RazorGridConstructor();
            constructor.Init(new Dictionary<string, object> { { "RESOLVE_PATH_ACTION", pathConverter } });
            var tables = constructor.CreateTables(@"Content\SimpleReport.cshtml", model);
            var table = tables.First();

            Assert.IsNotNull(table.Images);
            Assert.IsTrue(table.Images.Count() == 3);

            Assert.IsTrue(table.Images.All(image => image.ImagePath.EndsWith(".png")));
            Assert.IsTrue(table.Images.All(image => image.Width == 160 && image.Height == 70));
            Assert.IsTrue(table.Images.All(image => image.Left >= 1 && image.Top >= 1));
        }
Ejemplo n.º 3
0
        public void ConstructorImagesTest()
        {
            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
                })
            };

            Func <string, string> pathConverter = s => s.Replace("/", "\\");

            var constructor = new RazorGridConstructor();

            constructor.Init(new Dictionary <string, object> {
                { "RESOLVE_PATH_ACTION", pathConverter }
            });
            var tables = constructor.CreateTables(@"Content\SimpleReport.cshtml", model);
            var table  = tables.First();

            Assert.IsNotNull(table.Images);
            Assert.IsTrue(table.Images.Count() == 3);

            Assert.IsTrue(table.Images.All(image => image.ImagePath.EndsWith(".png")));
            Assert.IsTrue(table.Images.All(image => image.Width == 160 && image.Height == 70));
            Assert.IsTrue(table.Images.All(image => image.Left >= 1 && image.Top >= 1));
        }
Ejemplo n.º 4
0
        public void ConstructorTableTest()
        {
            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 constructor = new RazorGridConstructor();
            var tables      = constructor.CreateTables(@"Content\SimpleReport.cshtml", model);
            var table       = tables.First();

            Assert.IsNotNull(table.Head);
            Assert.IsNotNull(table.Body);

            Assert.IsTrue(table.Head.Rows.Any());
            Assert.IsTrue(table.Body.Rows.Any());

            Assert.IsTrue(table.Head.Rows.First().Cells.Any());
            Assert.IsTrue(table.Body.Rows.First().Cells.Any());

            Assert.IsNotNull(table.Head.Rows.First().Cells.First().Style);
            Assert.IsNotNull(table.Body.Rows.First().Cells.First().Style);
        }
Ejemplo n.º 5
0
        public void ConstructorTest()
        {
            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
                })
            };

            Func <string, string> pathConverter = s => s.Replace("/", "\\");

            var constructor = new RazorGridConstructor();

            constructor.Init(new Dictionary <string, object> {
                { "RESOLVE_PATH_ACTION", pathConverter }
            });
            var tables = constructor.CreateTables(@"Content\SimpleReport.cshtml", model);

            try
            {
                try
                {
                    SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
                }
                catch
                {
                }

                var printer = new XlsxPrinter();

                using (var stream = new FileStream("test.xlsx", FileMode.Create, FileAccess.ReadWrite))
                {
                    printer.Print(stream, tables);

                    Assert.AreNotEqual(stream.Length, 0);
                }

                Assert.IsTrue(File.Exists("test.xlsx"));
                Assert.IsTrue(File.ReadAllBytes("test.xlsx").Length > 1024);
            }
            finally
            {
                if (File.Exists("test.xlsx"))
                {
                    //File.Delete("test.xlsx");
                }
            }
        }
Ejemplo n.º 6
0
        public void ConstructorTest()
        {
            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
                })
            };

            Func<string, string> pathConverter = s => s.Replace("/", "\\");

            var constructor = new RazorGridConstructor();
            constructor.Init(new Dictionary<string, object> { { "RESOLVE_PATH_ACTION", pathConverter } });
            var tables = constructor.CreateTables(@"Content\SimpleReport.cshtml", model);

            try
            {
                try
                {
                    SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
                }
                catch
                {
                }

                var printer = new XlsxPrinter();

                using (var stream = new FileStream("test.xlsx", FileMode.Create, FileAccess.ReadWrite))
                {
                    printer.Print(stream, tables);

                    Assert.AreNotEqual(stream.Length, 0);
                }

                Assert.IsTrue(File.Exists("test.xlsx"));
                Assert.IsTrue(File.ReadAllBytes("test.xlsx").Length > 1024);
            }
            finally
            {
                if (File.Exists("test.xlsx"))
                {
                    //File.Delete("test.xlsx");
                }
            }
        }