Skip to content

Commit b4d8c2b

Browse files
authored
Fix OpenStreetMap example (#1642) (#1667)
1 parent 1a6e922 commit b4d8c2b

18 files changed

Lines changed: 82 additions & 32 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ All notable changes to this project will be documented in this file.
6767
- Axes with `AxisPosition.None` make no contribution to margins (#1574)
6868
- `AngleAxis` has position `AxisPosition.All` by default (#1574)
6969
- Clipping API changed from SetClip(...) and ResetClip() to PushClip(...) and PopClip() (#1593)
70+
- Remove TileMapAnnotation examples from automated testing (#1667)
7071

7172
### Removed
7273
- Remove PlotModel.Legends (#644)
@@ -103,6 +104,7 @@ All notable changes to this project will be documented in this file.
103104
- MinimumPadding incorrect when MaximumPadding is non-zero (#1625)
104105
- Don't clip zerocrossing axis lines within plot bounds (#1441)
105106
- Incorrect margins when using Color Axes with AxisPosition.None (#1574)
107+
- OpenStreetMap example (#1642)
106108

107109
## [2.0.0] - 2019-10-19
108110
### Added

Source/Examples/ExampleLibrary/Annotations/TileMapAnnotation.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public TileMapAnnotation()
4949
this.MaxZoomLevel = 20;
5050
this.Opacity = 1.0;
5151
this.MaxNumberOfDownloads = 8;
52+
this.UserAgent = "OxyPlotExampleLibrary";
5253
}
5354

5455
/// <summary>
@@ -93,6 +94,11 @@ public TileMapAnnotation()
9394
/// <value>The opacity.</value>
9495
public double Opacity { get; set; }
9596

97+
/// <summary>
98+
/// Gets or sets the user agent used for requests.
99+
/// </summary>
100+
public string UserAgent { get; set; }
101+
96102
/// <summary>
97103
/// Renders the annotation on the specified context.
98104
/// </summary>
@@ -312,6 +318,15 @@ private void BeginDownload()
312318
string uri = this.queue.Dequeue();
313319
var request = (HttpWebRequest)WebRequest.Create(uri);
314320
request.Method = "GET";
321+
322+
#if NET45
323+
// unavailable in NET Standard 1.0
324+
request.UserAgent = this.UserAgent;
325+
#else
326+
// compiles but does not run under NET Framework
327+
request.Headers["User-Agent"] = this.UserAgent;
328+
#endif
329+
315330
Interlocked.Increment(ref this.numberOfDownloads);
316331
request.BeginGetResponse(
317332
r =>

Source/Examples/ExampleLibrary/Annotations/TileMapAnnotationExamples.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ namespace ExampleLibrary
1313
[Examples("TileMapAnnotation"), Tags("Annotations")]
1414
public static class TileMapAnnotationExamples
1515
{
16-
[Example("TileMapAnnotation (openstreetmap.org)")]
16+
[Example("TileMapAnnotation (openstreetmap.org)", true)]
1717
public static PlotModel TileMapAnnotation2()
1818
{
19+
// See policy document: https://operations.osmfoundation.org/policies/tiles/
20+
1921
var model = new PlotModel { Title = "TileMapAnnotation" };
2022
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = 10.4, Maximum = 10.6, Title = "Longitude" });
2123
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = 59.88, Maximum = 59.96, Title = "Latitude" });
@@ -25,13 +27,14 @@ public static PlotModel TileMapAnnotation2()
2527
new TileMapAnnotation
2628
{
2729
Url = "http://tile.openstreetmap.org/{Z}/{X}/{Y}.png",
28-
CopyrightNotice = "OpenStreetMap"
30+
CopyrightNotice = "OpenStreetMap",
31+
MaxNumberOfDownloads = 2,
2932
});
3033

3134
return model;
3235
}
3336

34-
[Example("TileMapAnnotation (statkart.no)")]
37+
[Example("TileMapAnnotation (statkart.no)", true)]
3538
public static PlotModel TileMapAnnotation()
3639
{
3740
var model = new PlotModel { Title = "TileMapAnnotation" };
@@ -64,4 +67,4 @@ public static PlotModel TileMapAnnotation()
6467
return model;
6568
}
6669
}
67-
}
70+
}

Source/Examples/ExampleLibrary/Attributes/ExampleAttribute.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ public class ExampleAttribute : Attribute
1818
/// Initializes a new instance of the <see cref="ExampleAttribute"/> class.
1919
/// </summary>
2020
/// <param name="title">The title.</param>
21-
public ExampleAttribute(string title = null)
21+
/// <param name="excludeFromAutomatedTests">A value indiciating whether the example should be excluded from automated tests.</param>
22+
public ExampleAttribute(string title = null, bool excludeFromAutomatedTests = false)
2223
{
2324
this.Title = title;
25+
this.ExcludeFromAutomatedTests = excludeFromAutomatedTests;
2426
}
2527

2628
/// <summary>
@@ -30,5 +32,13 @@ public ExampleAttribute(string title = null)
3032
/// The title.
3133
/// </value>
3234
public string Title { get; private set; }
35+
36+
/// <summary>
37+
/// Gets a value indiciating whether this example should be excluded from automated tests.
38+
/// </summary>
39+
/// <value>
40+
/// <c>true</c> if the example should be excluded from automated tests, otherwise <c>false</c>.
41+
/// </value>
42+
public bool ExcludeFromAutomatedTests { get; }
3343
}
34-
}
44+
}

Source/Examples/ExampleLibrary/ExampleInfo.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ public class ExampleInfo
5151
/// <param name="title">The title.</param>
5252
/// <param name="tags">The tags.</param>
5353
/// <param name="method">The method.</param>
54-
public ExampleInfo(string category, string title, string[] tags, MethodInfo method)
54+
/// <param name="excludeFromAutomatedTests">A value indiciating whether the example should be excluded from automated tests.</param>
55+
public ExampleInfo(string category, string title, string[] tags, MethodInfo method, bool excludeFromAutomatedTests)
5556
{
5657
this.Category = category;
5758
this.Title = title;
5859
this.Tags = tags;
5960
this.method = method;
61+
this.ExcludeFromAutomatedTests = excludeFromAutomatedTests;
6062
}
6163

6264
/// <summary>
@@ -203,6 +205,14 @@ public PlotModel PlotModel
203205
/// </value>
204206
public string[] Tags { get; }
205207

208+
/// <summary>
209+
/// Gets a value indiciating whether this example should be excluded from automated tests.
210+
/// </summary>
211+
/// <value>
212+
/// <c>true</c> if the example should be excluded from automated tests, otherwise <c>false</c>.
213+
/// </value>
214+
public bool ExcludeFromAutomatedTests { get; }
215+
206216
/// <summary>
207217
/// Gets the title.
208218
/// </summary>

Source/Examples/ExampleLibrary/Examples.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public static IEnumerable<ExampleInfo> GetCategory(Type categoryType)
4949
examplesAttribute.Category,
5050
exampleAttribute.Title,
5151
tags.ToArray(),
52-
method);
52+
method,
53+
exampleAttribute.ExcludeFromAutomatedTests);
5354
}
5455
}
5556
}
@@ -75,21 +76,29 @@ public static IEnumerable<ExampleInfo> GetList()
7576
}
7677

7778
/// <summary>
78-
/// Gets the first example of each category.
79+
/// Gets all examples suitable for automated test.
7980
/// </summary>
80-
public static IEnumerable<ExampleInfo> GetFirstExampleOfEachCategory()
81+
public static IEnumerable<ExampleInfo> GetListForAutomatedTest()
8182
{
82-
return GetList()
83+
return GetList().Where(ex => !ex.ExcludeFromAutomatedTests);
84+
}
85+
86+
/// <summary>
87+
/// Gets the first example of each category suitable for automated test.
88+
/// </summary>
89+
public static IEnumerable<ExampleInfo> GetFirstExampleOfEachCategoryForAutomatedTest()
90+
{
91+
return GetListForAutomatedTest()
8392
.GroupBy(example => example.Category)
8493
.Select(group => group.First());
8594
}
8695

8796
/// <summary>
88-
/// Gets the 'rendering capabilities' examples.
97+
/// Gets the 'rendering capabilities' examples suitable for automated test.
8998
/// </summary>
90-
public static IEnumerable<ExampleInfo> GetRenderingCapabilities()
99+
public static IEnumerable<ExampleInfo> GetRenderingCapabilitiesForAutomatedTest()
91100
{
92-
return GetCategory(typeof(RenderingCapabilities));
101+
return GetCategory(typeof(RenderingCapabilities)).Where(ex => !ex.ExcludeFromAutomatedTests);
93102
}
94103
}
95104
}

Source/OxyPlot.ImageSharp.Tests/JpegExporterTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace OxyPlot.ImageSharp.Tests
1414
using OxyPlot.ImageSharp;
1515
using OxyPlot.Annotations;
1616
using ExampleLibrary;
17+
using System.Linq;
1718

1819
[TestFixture]
1920
public class JpegExporterTests
@@ -33,7 +34,7 @@ public void Export_SomeExamplesInExampleLibrary_CheckThatAllFilesExist()
3334
{
3435
var exporter = new JpegExporter(400, 300);
3536
var directory = Path.Combine(this.outputDirectory, "ExampleLibrary");
36-
ExportTest.ExportExamples_CheckThatAllFilesExist(Examples.GetFirstExampleOfEachCategory(), exporter, directory, ".jpg");
37+
ExportTest.ExportExamples_CheckThatAllFilesExist(Examples.GetFirstExampleOfEachCategoryForAutomatedTest(), exporter, directory, ".jpg");
3738
}
3839

3940
[Test]

Source/OxyPlot.ImageSharp.Tests/PngExporterTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public void Export_SomeExamplesInExampleLibrary_CheckThatAllFilesExist()
3333
{
3434
var exporter = new PngExporter(400, 300);
3535
var directory = Path.Combine(this.outputDirectory, "ExampleLibrary");
36-
ExportTest.ExportExamples_CheckThatAllFilesExist(Examples.GetFirstExampleOfEachCategory(), exporter, directory, ".png");
36+
ExportTest.ExportExamples_CheckThatAllFilesExist(Examples.GetFirstExampleOfEachCategoryForAutomatedTest(), exporter, directory, ".png");
3737
exporter.Width = 800;
3838
exporter.Height = 600;
39-
ExportTest.ExportExamples_CheckThatAllFilesExist(Examples.GetRenderingCapabilities(), exporter, directory, ".png");
39+
ExportTest.ExportExamples_CheckThatAllFilesExist(Examples.GetRenderingCapabilitiesForAutomatedTest(), exporter, directory, ".png");
4040
}
4141

4242
[Test]

Source/OxyPlot.Pdf.Tests/PdfExporterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void Export_AllExamplesInExampleLibrary_CheckThatAllFilesExist()
3333
const double Width = 297 / 25.4 * 72;
3434
const double Height = 210 / 25.4 * 72;
3535

36-
foreach (var example in Examples.GetList())
36+
foreach (var example in Examples.GetListForAutomatedTest())
3737
{
3838
void ExportModelAndCheckFileExists(PlotModel model, string fileName)
3939
{

Source/OxyPlot.SkiaSharp.Tests/JpegExporterTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ public void Export_SomeExamplesInExampleLibrary_CheckThatAllFilesExist()
3232
{
3333
var exporter = new JpegExporter { Width = 400, Height = 300 };
3434
var directory = Path.Combine(this.outputDirectory, "ExampleLibrary");
35-
ExportTest.ExportExamples_CheckThatAllFilesExist(Examples.GetFirstExampleOfEachCategory(), exporter, directory, ".jpg");
35+
ExportTest.ExportExamples_CheckThatAllFilesExist(Examples.GetFirstExampleOfEachCategoryForAutomatedTest(), exporter, directory, ".jpg");
3636
exporter.Width = 800;
3737
exporter.Height = 600;
38-
ExportTest.ExportExamples_CheckThatAllFilesExist(Examples.GetRenderingCapabilities(), exporter, directory, ".jpg");
38+
ExportTest.ExportExamples_CheckThatAllFilesExist(Examples.GetRenderingCapabilitiesForAutomatedTest(), exporter, directory, ".jpg");
3939
}
4040

4141
[Test]

0 commit comments

Comments
 (0)