|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using Xunit; |
| 4 | + |
| 5 | +using IPinfo.Models; |
| 6 | + |
| 7 | +namespace IPinfo.Tests |
| 8 | +{ |
| 9 | + public class IPApiLiteTest |
| 10 | + { |
| 11 | + [Fact] |
| 12 | + public void TestGetDetails() |
| 13 | + { |
| 14 | + string ip = "8.8.8.8"; |
| 15 | + IPinfoClientLite client = new IPinfoClientLite.Builder() |
| 16 | + .AccessToken(Environment.GetEnvironmentVariable("IPINFO_TOKEN")) |
| 17 | + .Build(); |
| 18 | + |
| 19 | + IPResponseLite actual = client.IPApi.GetDetails(ip); |
| 20 | + |
| 21 | + var expectations = new List<Tuple<object, object>>() |
| 22 | + { |
| 23 | + new("8.8.8.8", actual.IP), |
| 24 | + new("AS15169", actual.Asn), |
| 25 | + new("Google LLC", actual.AsName), |
| 26 | + new("google.com", actual.AsDomain), |
| 27 | + new("US", actual.CountryCode), |
| 28 | + new("United States", actual.Country), |
| 29 | + new("United States", actual.CountryName), |
| 30 | + new(false, actual.IsEU), |
| 31 | + new("🇺🇸", actual.CountryFlag.Emoji), |
| 32 | + new("U+1F1FA U+1F1F8", actual.CountryFlag.Unicode), |
| 33 | + new("https://cdn.ipinfo.io/static/images/countries-flags/US.svg", actual.CountryFlagURL), |
| 34 | + new("USD", actual.CountryCurrency.Code), |
| 35 | + new("$", actual.CountryCurrency.Symbol), |
| 36 | + new("NA", actual.Continent.Code), |
| 37 | + new("North America", actual.Continent.Name), |
| 38 | + }; |
| 39 | + Assert.All(expectations, pair => Assert.Equal(pair.Item1, pair.Item2)); |
| 40 | + } |
| 41 | + |
| 42 | + [Fact] |
| 43 | + public void TestGetDetailsIPV6() |
| 44 | + { |
| 45 | + string ip = "2001:4860:4860::8888"; |
| 46 | + IPinfoClientLite client = new IPinfoClientLite.Builder() |
| 47 | + .AccessToken(Environment.GetEnvironmentVariable("IPINFO_TOKEN")) |
| 48 | + .Build(); |
| 49 | + |
| 50 | + IPResponseLite actual = client.IPApi.GetDetails(ip); |
| 51 | + |
| 52 | + var expectations = new List<Tuple<object, object>>() |
| 53 | + { |
| 54 | + new("2001:4860:4860::8888", actual.IP), |
| 55 | + new("AS15169", actual.Asn), |
| 56 | + new("Google LLC", actual.AsName), |
| 57 | + new("google.com", actual.AsDomain), |
| 58 | + new("US", actual.CountryCode), |
| 59 | + new("United States", actual.Country), |
| 60 | + new("United States", actual.CountryName), |
| 61 | + new(false, actual.IsEU), |
| 62 | + new("🇺🇸", actual.CountryFlag.Emoji), |
| 63 | + new("U+1F1FA U+1F1F8", actual.CountryFlag.Unicode), |
| 64 | + new("https://cdn.ipinfo.io/static/images/countries-flags/US.svg", actual.CountryFlagURL), |
| 65 | + new("USD", actual.CountryCurrency.Code), |
| 66 | + new("$", actual.CountryCurrency.Symbol), |
| 67 | + new("NA", actual.Continent.Code), |
| 68 | + new("North America", actual.Continent.Name), |
| 69 | + }; |
| 70 | + Assert.All(expectations, pair => Assert.Equal(pair.Item1, pair.Item2)); |
| 71 | + } |
| 72 | + |
| 73 | + [Fact] |
| 74 | + public void TestGetDetailsCurrentIP() |
| 75 | + { |
| 76 | + IPinfoClientLite client = new IPinfoClientLite.Builder() |
| 77 | + .AccessToken(Environment.GetEnvironmentVariable("IPINFO_TOKEN")) |
| 78 | + .Build(); |
| 79 | + |
| 80 | + IPResponseLite actual = client.IPApi.GetDetails(); |
| 81 | + |
| 82 | + Assert.NotNull(actual.IP); |
| 83 | + Assert.NotNull(actual.Asn); |
| 84 | + Assert.NotNull(actual.AsName); |
| 85 | + Assert.NotNull(actual.AsDomain); |
| 86 | + Assert.NotNull(actual.CountryCode); |
| 87 | + Assert.NotNull(actual.Country); |
| 88 | + Assert.NotNull(actual.CountryName); |
| 89 | + Assert.NotNull(actual.CountryFlag); |
| 90 | + Assert.NotNull(actual.CountryFlag.Emoji); |
| 91 | + Assert.NotNull(actual.CountryFlag.Unicode); |
| 92 | + Assert.NotNull(actual.CountryFlagURL); |
| 93 | + Assert.NotNull(actual.CountryCurrency); |
| 94 | + Assert.NotNull(actual.Continent); |
| 95 | + } |
| 96 | + |
| 97 | + [Fact] |
| 98 | + public void TestBogonIPV4() |
| 99 | + { |
| 100 | + string ip = "127.0.0.1"; |
| 101 | + IPinfoClientLite client = new IPinfoClientLite.Builder() |
| 102 | + .AccessToken(Environment.GetEnvironmentVariable("IPINFO_TOKEN")) |
| 103 | + .Build(); |
| 104 | + |
| 105 | + IPResponseLite actual = client.IPApi.GetDetails(ip); |
| 106 | + |
| 107 | + Assert.Equal("127.0.0.1", actual.IP); |
| 108 | + Assert.True(actual.Bogon); |
| 109 | + } |
| 110 | + |
| 111 | + [Fact] |
| 112 | + public void TestBogonIPV6() |
| 113 | + { |
| 114 | + string ip = "2001:0:c000:200::0:255:1"; |
| 115 | + IPinfoClientLite client = new IPinfoClientLite.Builder() |
| 116 | + .AccessToken(Environment.GetEnvironmentVariable("IPINFO_TOKEN")) |
| 117 | + .Build(); |
| 118 | + |
| 119 | + IPResponseLite actual = client.IPApi.GetDetails(ip); |
| 120 | + |
| 121 | + Assert.Equal("2001:0:c000:200::0:255:1", actual.IP); |
| 122 | + Assert.True(actual.Bogon); |
| 123 | + } |
| 124 | + |
| 125 | + [Fact] |
| 126 | + public void TestNonBogonIPV4() |
| 127 | + { |
| 128 | + string ip = "1.1.1.1"; |
| 129 | + IPinfoClientLite client = new IPinfoClientLite.Builder() |
| 130 | + .AccessToken(Environment.GetEnvironmentVariable("IPINFO_TOKEN")) |
| 131 | + .Build(); |
| 132 | + |
| 133 | + IPResponseLite actual = client.IPApi.GetDetails(ip); |
| 134 | + |
| 135 | + Assert.Equal("1.1.1.1", actual.IP); |
| 136 | + Assert.False(actual.Bogon); |
| 137 | + } |
| 138 | + |
| 139 | + [Fact] |
| 140 | + public void TestNonBogonIPV6() |
| 141 | + { |
| 142 | + string ip = "2a03:2880:f10a:83:face:b00c:0:25de"; |
| 143 | + IPinfoClientLite client = new IPinfoClientLite.Builder() |
| 144 | + .AccessToken(Environment.GetEnvironmentVariable("IPINFO_TOKEN")) |
| 145 | + .Build(); |
| 146 | + |
| 147 | + IPResponseLite actual = client.IPApi.GetDetails(ip); |
| 148 | + |
| 149 | + Assert.Equal("2a03:2880:f10a:83:face:b00c:0:25de", actual.IP); |
| 150 | + Assert.False(actual.Bogon); |
| 151 | + } |
| 152 | + } |
| 153 | +} |
0 commit comments