|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using Xunit; |
| 7 | +using Xunit.Sdk; |
| 8 | +using Plotly.NET.CSharp; |
| 9 | + |
| 10 | +// avoid the namespace 'Plotly.NET', as we dont want to accidentally use F# type extensions instead of real C# bindings |
| 11 | +namespace CSharp.Tests.HtmlCodegen |
| 12 | +{ |
| 13 | + public class SimpleTests |
| 14 | + { |
| 15 | + static Plotly.NET.GenericChart.GenericChart simpleChart = |
| 16 | + Chart.Point<double, double, string>( |
| 17 | + x: Enumerable.Range(0, 11).Select(x => Convert.ToDouble(x)).ToArray(), |
| 18 | + y: Enumerable.Range(0, 11).Select(x => Convert.ToDouble(x)).ToArray(), |
| 19 | + UseDefaults: false |
| 20 | + ) |
| 21 | + .WithXAxisStyle<int, int, int>(TitleText: "xAxis") |
| 22 | + .WithYAxisStyle<int, int, int>(TitleText: "yAxis"); |
| 23 | + |
| 24 | + public class HtmlLayoutTests |
| 25 | + { |
| 26 | + [Fact] |
| 27 | + public void PlotlyJsScriptInGeneratedHTMLDocument() |
| 28 | + { |
| 29 | + TestUtils.SubstringIsInChart( |
| 30 | + simpleChart, |
| 31 | + Plotly.NET.GenericChart.toEmbeddedHTML, |
| 32 | + $"https://cdn.plot.ly/plotly-{Globals.PLOTLYJS_VERSION}.min" |
| 33 | + ); |
| 34 | + } |
| 35 | + |
| 36 | + [Fact] |
| 37 | + public void ExpectingData() |
| 38 | + { |
| 39 | + TestUtils.ChartGeneratedContains( |
| 40 | + simpleChart, |
| 41 | + """var data = [{"type":"scatter","mode":"markers","x":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0],"y":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0],"marker":{},"line":{}}];""" |
| 42 | + ); |
| 43 | + } |
| 44 | + |
| 45 | + [Fact] |
| 46 | + public void ExpectingLayoutInfo() |
| 47 | + { |
| 48 | + TestUtils.ChartGeneratedContains( |
| 49 | + simpleChart, |
| 50 | + """var layout = {"xaxis":{"title":{"text":"xAxis"}},"yaxis":{"title":{"text":"yAxis"}}};""" |
| 51 | + ); |
| 52 | + } |
| 53 | + |
| 54 | + [Fact] |
| 55 | + public void ExpectingHTMLTagsInEmbeddedPageOnly() |
| 56 | + { |
| 57 | + string[] tags = new string[] { "<html>", "</html>", "<head>", "</head>", "<body>", "</body>", "<script type=\"text/javascript\">", "</script>" }; |
| 58 | + TestUtils.SubstringListIsInChart( |
| 59 | + simpleChart, |
| 60 | + Plotly.NET.GenericChart.toEmbeddedHTML, |
| 61 | + tags |
| 62 | + ); |
| 63 | + } |
| 64 | + |
| 65 | + [Fact] |
| 66 | + public void ExpectingSomeHTMLTagsInBothEmbeddedAndNotEmbedded() |
| 67 | + { |
| 68 | + string[] tags = new string[] { "<script type=\"text/javascript\">", "</script>" }; |
| 69 | + TestUtils.ChartGeneratedContainsList( |
| 70 | + simpleChart, |
| 71 | + tags |
| 72 | + ); |
| 73 | + } |
| 74 | + |
| 75 | + [Fact] |
| 76 | + public void PassingArgsToTheFunction() |
| 77 | + { |
| 78 | + TestUtils.ChartGeneratedContains( |
| 79 | + simpleChart, |
| 80 | + "data, layout, config);" |
| 81 | + ); |
| 82 | + } |
| 83 | + |
| 84 | + } |
| 85 | + } |
| 86 | +} |
0 commit comments