public void EnsureNoLegend() { PlotModel graphModel = new PlotModel(); graphModel.Series.Add(new OxyPlot.Series.LineSeries()); graphModel.Axes.Add(new OxyPlot.Axes.LinearAxis()); graphModel.Legends.Add(new OxyPlot.Legends.Legend()); Mock <IGraphExporter> mockExporter = new Mock <IGraphExporter>(); mockExporter.Setup <IPlotModel>(e => e.ToPlotModel(graph)).Returns(() => graphModel); mockExporter.Setup(e => e.Export(It.IsAny <IPlotModel>(), It.IsAny <double>(), It.IsAny <double>())).Returns((IPlotModel plot, double width, double height) => { PlotModel model = plot as PlotModel; Assert.AreEqual(0, model.Legends.Count); return(image); }); IGraphExporter exporter = mockExporter.Object; renderer = new GraphPageTagRenderer(exporter); GraphPage page = new GraphPage(new[] { graph }); renderer.Render(page, pdfBuilder); // (Sanity check, just to make sure that the above plumbing actually worked.) Assert.AreEqual(1, TestContext.CurrentContext.AssertCount); }
public void TestGraphElementSizing() { PlotModel graphModel = new PlotModel(); graphModel.Series.Add(new OxyPlot.Series.LineSeries()); graphModel.Axes.Add(new OxyPlot.Axes.LinearAxis()); Mock <IGraphExporter> mockExporter = new Mock <IGraphExporter>(); mockExporter.Setup <IPlotModel>(e => e.ToPlotModel(graph)).Returns(() => graphModel); mockExporter.Setup(e => e.Export(It.IsAny <IPlotModel>(), It.IsAny <double>(), It.IsAny <double>())).Returns((IPlotModel plot, double width, double height) => { PlotModel model = plot as PlotModel; Assert.AreEqual(2, ((OxyPlot.Series.LineSeries)model.Series[0]).MarkerSize); Assert.AreEqual(10, model.DefaultFontSize); Assert.AreEqual(10, model.Axes[0].FontSize); Assert.AreEqual(10, model.TitleFontSize); return(image); }); IGraphExporter exporter = mockExporter.Object; renderer = new GraphPageTagRenderer(exporter); GraphPage page = new GraphPage(new[] { graph }); renderer.Render(page, pdfBuilder); }
public void EnsureAllGraphsAreWritten(int numGraphs) { List <IGraph> graphs = new List <IGraph>(numGraphs); Mock <IGraphExporter> mockExporter = new Mock <IGraphExporter>(); List <Image> images = new List <Image>(); for (int i = 0; i < numGraphs; i++) { // This is a little tricky because I want to have each graph // generate a unique image, so we need to mock out the graph, // the intermediary plot model, and the graph exporter as well. Mock <IGraph> mockGraph = new Mock <IGraph>(); IGraph graph = mockGraph.Object; Image graphImage = CreateImage(i + 1); Mock <IPlotModel> mockModel = new Mock <IPlotModel>(); IPlotModel graphModel = mockModel.Object; mockExporter.Setup <IPlotModel>(e => e.ToPlotModel(graph)).Returns(() => graphModel); mockExporter.Setup <Image>(e => e.Export(graphModel, It.IsAny <double>(), It.IsAny <double>())).Returns(() => graphImage); graphs.Add(graph); images.Add(graphImage); } GraphPage page = new GraphPage(graphs); renderer = new GraphPageTagRenderer(mockExporter.Object); renderer.Render(page, pdfBuilder); if (numGraphs < 1) { // No child graphs - document should be empty. Assert.AreEqual(0, document.LastSection.Elements.Count); } else { // There should be a single paragraph, containing all graphs. Assert.AreEqual(1, document.LastSection.Elements.Count); Paragraph paragraph = document.LastSection.Elements[0] as Paragraph; Assert.NotNull(paragraph); // The paragraph should contain n images. Assert.AreEqual(numGraphs, paragraph.Elements.Count); // Ensure that all images have been renderered correctly. for (int i = 0; i < numGraphs; i++) { MigraDocImage actual = paragraph.Elements[i] as MigraDocImage; AssertEqual(images[i], actual); images[i].Dispose(); } images.Clear(); } }
public void TestGraphSizing() { Mock <IGraphExporter> mockExporter = new Mock <IGraphExporter>(); mockExporter.Setup(e => e.Export(It.IsAny <IPlotModel>(), It.IsAny <double>(), It.IsAny <double>())).Returns((IPlotModel plot, double width, double height) => { // This should be 1/2 page width and 1/3 page height in px. // fixme: this isn't really the best way to verify this but it'll do for now. Assert.AreEqual(302.362204724, width, 1e-2); Assert.AreEqual(317.4803405921916, height, 1e-2); return(image); }); IGraphExporter exporter = mockExporter.Object; renderer = new GraphPageTagRenderer(exporter); GraphPage page = new GraphPage(new[] { graph }); renderer.Render(page, pdfBuilder); }
public void SetUp() { document = new MigraDocCore.DocumentObjectModel.Document(); // Workaround for a quirk in the migradoc API. _ = document.AddSection().Elements; pdfBuilder = new PdfBuilder(document, PdfOptions.Default); pdfBuilder.UseTagRenderer(new MockTagRenderer()); image = new Bitmap(4, 4); Mock <IGraph> mockGraph = new Mock <IGraph>(); graph = mockGraph.Object; // Mock graph exporter - this will just return the image field of this class. Mock <IGraphExporter> mockExporter = new Mock <IGraphExporter>(); mockExporter.Setup <Image>(e => e.Export(It.IsAny <IGraph>(), It.IsAny <double>(), It.IsAny <double>())).Returns(() => image); mockExporter.Setup <Image>(e => e.Export(It.IsAny <IPlotModel>(), It.IsAny <double>(), It.IsAny <double>())).Returns(() => image); renderer = new GraphPageTagRenderer(mockExporter.Object); }