forked from SolrNet/SolrNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocationTests.cs
68 lines (57 loc) · 2.82 KB
/
LocationTests.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
using System;
using System.Collections.Generic;
using MbUnit.Framework;
using SolrNet.Impl.FieldParsers;
namespace SolrNet.Tests {
public static class LocationTests {
[StaticTestFactory]
public static IEnumerable<Test> Tests() {
var locations = new[] {
new { location = new Location(12, 23), toString = "12,23" },
new { location = new Location(-4.3, 0.20), toString = "-4.3,0.2" },
};
foreach (var l in locations) {
var x = l;
yield return new TestCase("ToString " + x.toString,
() => Assert.AreEqual(x.toString, x.location.ToString()));
yield return new TestCase("Parse " + x.toString, () => {
var parsedLocation = LocationFieldParser.Parse(x.toString);
Assert.AreEqual(x.location, parsedLocation);
Assert.AreEqual(x.location.Latitude, parsedLocation.Latitude);
Assert.AreEqual(x.location.Longitude, parsedLocation.Longitude);
});
}
var invalidLatitudes = new[] {-100, 120};
foreach (var x in invalidLatitudes) {
var latitude = x;
yield return new TestCase("Latitude " + latitude + " is invalid",
() => Assert.IsFalse(Location.IsValidLatitude(latitude)));
yield return new TestCase("Invalid latitude throws: " + latitude,
() => Assert.Throws<ArgumentOutOfRangeException>(() => new Location(latitude, 0)));
}
var invalidLongitudes = new[] {-200, 999};
foreach (var x in invalidLongitudes) {
var longitude = x;
yield return new TestCase("Longitude " + longitude + " is invalid",
() => Assert.IsFalse(Location.IsValidLongitude(longitude)));
yield return new TestCase("Invalid longitude throws: " + longitude,
() => Assert.Throws<ArgumentOutOfRangeException>(() => new Location(0, longitude)));
}
yield return new TestCase("TryCreate returns null with invalid lat/long", () => {
foreach (var lat in invalidLatitudes)
foreach (var lng in invalidLongitudes) {
var loc = Location.TryCreate(lat, lng);
Assert.IsNull(loc);
}
});
yield return new TestCase("TryCreate returns non-null with valid lat/long", () => {
foreach (var l in locations) {
var loc = l.location;
var loc2 = Location.TryCreate(loc.Latitude, loc.Longitude);
Assert.IsNotNull(loc2);
Assert.AreEqual(loc, loc2);
}
});
}
}
}