// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) 2014 OxyPlot contributors
//
//
// Provides methods to assert that plots look as expected.
//
// --------------------------------------------------------------------------------------------------------------------
namespace OxyPlot.Tests
{
using System.IO;
using NUnit.Framework;
///
/// Provides methods to assert that plots look as expected.
///
public static class OxyAssert
{
///
/// Asserts that a plot is equal to the plot stored in the "baseline" folder.
/// 1. Renders the plot to file.svg
/// 2. If the baseline does not exist, the current plot is copied to the baseline folder.
/// 3. Checks that the svg file is equal to a baseline svg.
///
/// The plot.
/// The name of the baseline file.
public static void AreEqual(PlotModel plot, string name)
{
// string name = new System.Diagnostics.StackFrame(1).GetMethod().Name;
string path = name + ".svg";
string baseline = @"baseline\" + path;
using (var s = File.Create(path))
{
SvgExporter.Export(plot, s, 800, 500, false);
}
if (!Directory.Exists("baseline"))
{
Directory.CreateDirectory("baseline");
}
if (!File.Exists(baseline))
{
File.Copy(path, baseline);
return;
}
var baselineSvg = File.ReadAllText(baseline);
var actualSvg = File.ReadAllText(path);
Assert.IsTrue(string.Equals(baselineSvg, actualSvg), "Actual svg is not equal to baseline (" + Path.GetFullPath(baseline) + ")");
}
}
}