/
MapboxUnitTests_ForwardGeocodeResource.cs
150 lines (122 loc) · 6.35 KB
/
MapboxUnitTests_ForwardGeocodeResource.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//-----------------------------------------------------------------------
// <copyright file="ForwardGeocodeResourceTest.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.MapboxSdkCs.UnitTest
{
using System;
using Mapbox.Utils;
using NUnit.Framework;
[TestFixture]
internal class ForwardGeocodeResourceTest
{
private const string _query = "Minneapolis, MN";
private Geocoding.ForwardGeocodeResource _forwardGeocodeResource;
[SetUp]
public void SetUp()
{
_forwardGeocodeResource = new Geocoding.ForwardGeocodeResource(_query);
}
public void BadType()
{
_forwardGeocodeResource.Types = new string[] { "fake" };
}
public void BadTypeWithGoodType()
{
_forwardGeocodeResource.Types = new string[] { "place", "fake" };
}
public void BadCountry()
{
_forwardGeocodeResource.Types = new string[] { "zz" };
}
public void BadCountryWithGoodType()
{
_forwardGeocodeResource.Types = new string[] { "zz", "ar" };
}
[Test]
public void SetInvalidTypes()
{
Assert.Throws<Exception>(BadType);
Assert.Throws<Exception>(BadTypeWithGoodType);
}
[Test]
public void SetInvalidCountries()
{
Assert.Throws<Exception>(BadCountry);
Assert.Throws<Exception>(BadCountryWithGoodType);
}
[Test]
public void GetUrl()
{
// With only constructor
// TODO: find proper fix for encoded url parameters crashing on some iPhones
#if UNITY_IOS
UnityEngine.Debug.LogWarning("ForwardGeocodeResourceTest.GetUrl() TODO: find proper fix for encoded url parameters crashing on some iPhones");
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis++MN.json", _forwardGeocodeResource.GetUrl());
#else
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis%2C%20MN.json", _forwardGeocodeResource.GetUrl());
#endif
// With autocomplete
_forwardGeocodeResource.Autocomplete = false;
#if UNITY_IOS
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis++MN.json?autocomplete=false", _forwardGeocodeResource.GetUrl());
#else
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis%2C%20MN.json?autocomplete=false", _forwardGeocodeResource.GetUrl());
#endif
// With bbox
_forwardGeocodeResource.Bbox = new Vector2dBounds(new Vector2d(15, 10), new Vector2d(25, 20));
#if UNITY_IOS
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis++MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000".ToLower(), _forwardGeocodeResource.GetUrl().ToLower());
#else
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis++MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000", _forwardGeocodeResource.GetUrl());
#endif
// With one country
_forwardGeocodeResource.Country = new string[] { "ar" };
#if UNITY_IOS
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis++MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000&country=ar".ToLower(), _forwardGeocodeResource.GetUrl().ToLower());
#else
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis%2C%20MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000&country=ar", _forwardGeocodeResource.GetUrl());
#endif
// With multiple countries
_forwardGeocodeResource.Country = new string[] { "ar", "fi" };
#if UNITY_IOS
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis++MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000&country=ar%2Cfi".ToLower(), _forwardGeocodeResource.GetUrl().ToLower());
#else
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis%2C%20MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000&country=ar%2Cfi", _forwardGeocodeResource.GetUrl());
#endif
// With proximity
_forwardGeocodeResource.Proximity = new Vector2d(10, 5);
#if UNITY_IOS
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis++MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000&country=ar%2Cfi&proximity=5.00000%2C10.00000".ToLower(), _forwardGeocodeResource.GetUrl().ToLower());
#else
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis%2C%20MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000&country=ar%2Cfi&proximity=5.00000%2C10.00000", _forwardGeocodeResource.GetUrl());
#endif
// With one types
_forwardGeocodeResource.Types = new string[] { "country" };
#if UNITY_IOS
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis++MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000&country=ar%2Cfi&proximity=5.00000%2C10.00000&types=country".ToLower(), _forwardGeocodeResource.GetUrl().ToLower());
#else
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis%2C%20MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000&country=ar%2Cfi&proximity=5.00000%2C10.00000&types=country", _forwardGeocodeResource.GetUrl());
#endif
// With multiple types
_forwardGeocodeResource.Types = new string[] { "country", "region" };
#if UNITY_IOS
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis++MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000&country=ar%2Cfi&proximity=5.00000%2C10.00000&types=country%2Cregion".ToLower(), _forwardGeocodeResource.GetUrl().ToLower());
#else
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis%2C%20MN.json?autocomplete=false&bbox=10.00000%2C15.00000%2C20.00000%2C25.00000&country=ar%2Cfi&proximity=5.00000%2C10.00000&types=country%2Cregion", _forwardGeocodeResource.GetUrl());
#endif
// Set all to null
_forwardGeocodeResource.Autocomplete = null;
_forwardGeocodeResource.Bbox = null;
_forwardGeocodeResource.Country = null;
_forwardGeocodeResource.Proximity = null;
_forwardGeocodeResource.Types = null;
#if UNITY_IOS
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis++MN.json", _forwardGeocodeResource.GetUrl());
#else
Assert.AreEqual("https://api.mapbox.com/geocoding/v5/mapbox.places/Minneapolis%2C%20MN.json", _forwardGeocodeResource.GetUrl());
#endif
}
}
}