Beispiel #1
0
        public void ExportWithResolution(double factor)
        {
            var resolution = (int)(96 * factor);
            var plotModel  = CreateTestModel1();

            Directory.CreateDirectory("Actual");
            Directory.CreateDirectory("Baseline");
            var fileName = string.Format(CultureInfo.InvariantCulture, "PngExporterTests_ExportWithResolution_{0}dpi.png", resolution);
            var exporter = new PngExporter {
                Width = (int)(400 * factor), Height = (int)(300 * factor), Resolution = resolution
            };
            var actual = Path.Combine("Actual", fileName);

            using (var stream = File.OpenWrite(actual))
            {
                exporter.Export(plotModel, stream);
            }

            Assert.IsTrue(File.Exists(actual));
            var baselinePath = Path.Combine("Baseline", fileName);

            if (File.Exists(baselinePath))
            {
                PngAssert.AreEqual(baselinePath, actual, fileName, Path.Combine("Diff", fileName));
            }
            else
            {
                File.Copy(actual, baselinePath);
            }
        }
Beispiel #2
0
        public void ExportPngAndCompareWithBaseline()
        {
            const string DestinationDirectory = "ExampleLibrary.Actual";
            const string BaselineDirectory    = "ExampleLibrary.Baseline";
            const string DiffDirectory        = "ExampleLibrary.Diff";

            if (!Directory.Exists(BaselineDirectory))
            {
                Directory.CreateDirectory(BaselineDirectory);
            }

            if (!Directory.Exists(DestinationDirectory))
            {
                Directory.CreateDirectory(DestinationDirectory);
            }

            if (!Directory.Exists(DiffDirectory))
            {
                Directory.CreateDirectory(DiffDirectory);
            }

            foreach (var example in ExampleLibrary.Examples.GetList())
            {
                void ExportAndCompareToBaseline(PlotModel model, string fileName)
                {
                    if (model == null)
                    {
                        return;
                    }

                    var baselinePath = Path.Combine(BaselineDirectory, fileName);
                    var path         = Path.Combine(DestinationDirectory, fileName);
                    var diffpath     = Path.Combine(DiffDirectory, fileName);

                    PngExporter.Export(model, path, 800, 500);
                    if (File.Exists(baselinePath))
                    {
                        PngAssert.AreEqual(baselinePath, path, example.Title, diffpath);
                    }
                    else
                    {
                        File.Copy(path, baselinePath);
                    }
                }

                ExportAndCompareToBaseline(example.PlotModel, CreateValidFileName($"{example.Category} - {example.Title}", ".png"));
                ExportAndCompareToBaseline(example.TransposedPlotModel, CreateValidFileName($"{example.Category} - {example.Title} - Transposed", ".png"));
            }
        }
        public void ExportWithResolution(double factor)
        {
            var resolution = (int)(96 * factor);
            var plotModel  = TestModels.CreateTestModel1();
            var fileName   = string.Format(CultureInfo.InvariantCulture, "PngExporterTests_ExportWithResolution_{0}dpi.png", resolution);
            var exporter   = new PngExporter {
                Width = (int)(400 * factor), Height = (int)(300 * factor), Resolution = resolution
            };

            using (var stream = File.OpenWrite(fileName))
            {
                exporter.Export(plotModel, stream);
            }

            Assert.IsTrue(File.Exists(fileName));
            PngAssert.AreEqual(Path.Combine("Baseline", fileName), fileName, fileName, Path.Combine("Diff", fileName));
        }
        public void ExportPngAndCompareWithBaseline()
        {
            const string DestinationDirectory = "ExampleLibrary.Actual";
            const string BaselineDirectory    = "ExampleLibrary.Baseline";
            const string DiffDirectory        = "ExampleLibrary.Diff";

            if (!Directory.Exists(BaselineDirectory))
            {
                Directory.CreateDirectory(BaselineDirectory);
            }

            if (!Directory.Exists(DestinationDirectory))
            {
                Directory.CreateDirectory(DestinationDirectory);
            }

            if (!Directory.Exists(DiffDirectory))
            {
                Directory.CreateDirectory(DiffDirectory);
            }

            foreach (var example in ExampleLibrary.Examples.GetList())
            {
                if (example.PlotModel == null)
                {
                    continue;
                }

                var filename     = FileNameUtilities.CreateValidFileName(example.Category + " - " + example.Title, ".png");
                var baselinePath = Path.Combine(BaselineDirectory, filename);
                var path         = Path.Combine(DestinationDirectory, filename);
                var diffpath     = Path.Combine(DiffDirectory, filename);

                PngExporter.Export(example.PlotModel, path, 800, 500, OxyColors.White);
                if (File.Exists(baselinePath))
                {
                    PngAssert.AreEqual(baselinePath, path, example.Title, diffpath);
                }
                else
                {
                    File.Copy(path, baselinePath);
                }
            }
        }