/
SearchAddressTests.cs
165 lines (146 loc) · 6.42 KB
/
SearchAddressTests.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Threading.Tasks;
using Azure.Core.GeoJson;
using Azure.Core.TestFramework;
using Azure.Maps.Search.Models;
using NUnit.Framework;
namespace Azure.Maps.Search.Tests
{
public class SearchAddressTests: SearchClientLiveTestsBase
{
public SearchAddressTests(bool isAsync) : base(isAsync)
{
}
[RecordedTest]
public async Task CanSearchAddress()
{
var client = CreateClient();
#region Snippet:SearchAddress
Response<SearchAddressResult> searchResult = await client.SearchAddressAsync("Seattle");
SearchAddressResultItem resultItem = searchResult.Value.Results[0];
Console.WriteLine("First result - Coordinate: {0}, Address: {1}",
resultItem.Position, resultItem.Address.FreeformAddress);
#endregion
Assert.AreEqual("Washington", searchResult.Value.Results[0].Address.CountrySubdivisionName);
}
[RecordedTest]
public async Task CanSearchMunicipality()
{
var client = CreateClient();
var searchResult = await client.SearchAddressAsync("Redmond", new SearchAddressOptions
{
EntityType = GeographicEntity.Municipality
});
Assert.AreEqual("Redmond, WA", searchResult.Value.Results[0].Address.FreeformAddress);
}
[RecordedTest]
public async Task CanSearchAddressBiasedAroundCoordinates()
{
var client = CreateClient();
var searchResult = await client.SearchAddressAsync("Road", new SearchAddressOptions
{
Coordinates = new GeoPosition(121.56, 25.04),
Language = SearchLanguage.EnglishUsa
});
Assert.AreEqual("Xinyi District", searchResult.Value.Results[0].Address.MunicipalitySubdivision);
searchResult = await client.SearchAddressAsync("Road", new SearchAddressOptions
{
Coordinates = new GeoPosition(-122.0910, 47.6773)
});
Assert.AreEqual("Redmond", searchResult.Value.Results[0].Address.Municipality);
}
[RecordedTest]
public async Task CanSearchAddressRestrictedByRegion()
{
var client = CreateClient();
var searchResult = await client.SearchAddressAsync("Road", new SearchAddressOptions
{
CountryFilter = new[] { "FJI" }
});
Assert.AreEqual("Fiji", searchResult.Value.Results[0].Address.Country);
searchResult = await client.SearchAddressAsync("Road", new SearchAddressOptions
{
CountryFilter = new[] { "NZ" }
});
Assert.AreEqual("New Zealand", searchResult.Value.Results[0].Address.Country);
}
[RecordedTest]
public async Task CanSearchAddressRestrictedByBoundingBox()
{
var client = CreateClient();
var searchResult = await client.SearchAddressAsync("Moke", new SearchAddressOptions {
BoundingBox = new GeoBoundingBox(-191.4481, -45.0128, -191.4148, -44.990)
});
Assert.AreEqual("Moke Lake Road", searchResult.Value.Results[0].Address.StreetName);
}
[RecordedTest]
public async Task CanSearchStructuredAddress()
{
var client = CreateClient();
#region Snippet:SearchStructuredAddress
var address = new StructuredAddress
{
CountryCode = "US",
StreetNumber = "15127",
StreetName = "NE 24th Street",
Municipality = "Redmond",
CountrySubdivision = "WA",
PostalCode = "98052"
};
Response<SearchAddressResult> searchResult = await client.SearchStructuredAddressAsync(address);
SearchAddressResultItem resultItem = searchResult.Value.Results[0];
Console.WriteLine("First result - Coordinate: {0}, Address: {1}",
resultItem.Position, resultItem.Address.FreeformAddress);
#endregion
Assert.AreEqual("15127 Northeast 24th Street, Redmond, WA 98052", resultItem.Address.FreeformAddress);
}
[RecordedTest]
public void InvalidSearchStructuredAddressTest()
{
var client = CreateClient();
var address = new StructuredAddress { CountryCode = "" };
RequestFailedException ex = Assert.ThrowsAsync<RequestFailedException>(
async () => await client.SearchStructuredAddressAsync(address));
Assert.AreEqual(400, ex.Status);
}
[RecordedTest]
public async Task CanSearchStructuredPartialAddress()
{
var client = CreateClient();
var address = new StructuredAddress
{
CountryCode = "NZ",
Municipality = "Closeburn"
};
var searchResult = await client.SearchStructuredAddressAsync(address);
Assert.AreEqual("South Island", searchResult.Value.Results[0].Address.CountrySubdivision);
}
[RecordedTest]
public async Task CanSearchAddressBatch()
{
var client = CreateClient();
var searchResult = await client.GetImmediateSearchAddressBatchAsync(new[]
{
new SearchAddressQuery("Microsoft Campus"),
new SearchAddressQuery("Millenium", new SearchAddressOptions { CountryFilter = new[] { "US" }}),
});
Assert.AreEqual(2, searchResult.Value.Results.Count);
Assert.AreEqual("Tucson", searchResult.Value.Results[1].Results[0].Address.Municipality);
}
[RecordedTest]
public async Task CanPollSearchAddressBatch()
{
var client = CreateClient();
var operation = await client.SearchAddressBatchAsync(WaitUntil.Started, new[]
{
new SearchAddressQuery("Microsoft Campus"),
new SearchAddressQuery("Millenium", new SearchAddressOptions { CountryFilter = new[] { "US" }}),
});
var searchResult = operation.WaitForCompletion();
Assert.AreEqual(2, searchResult.Value.Results.Count);
Assert.AreEqual("Tucson", searchResult.Value.Results[1].Results[0].Address.Municipality);
}
}
}