|
| 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 IPApiCoreTest |
| 10 | + { |
| 11 | + [Fact] |
| 12 | + public void TestGetDetailsIPV4() |
| 13 | + { |
| 14 | + string ip = "8.8.8.8"; |
| 15 | + IPinfoClientCore client = new IPinfoClientCore.Builder() |
| 16 | + .AccessToken(Environment.GetEnvironmentVariable("IPINFO_TOKEN")) |
| 17 | + .Build(); |
| 18 | + |
| 19 | + IPResponseCore actual = client.IPApi.GetDetails(ip); |
| 20 | + |
| 21 | + Assert.Equal("8.8.8.8", actual.IP); |
| 22 | + Assert.Equal("dns.google", actual.Hostname); |
| 23 | + Assert.False(actual.Bogon); |
| 24 | + |
| 25 | + // Geo assertions |
| 26 | + Assert.NotNull(actual.Geo); |
| 27 | + Assert.NotNull(actual.Geo.City); |
| 28 | + Assert.NotNull(actual.Geo.Region); |
| 29 | + Assert.NotNull(actual.Geo.RegionCode); |
| 30 | + Assert.Equal("US", actual.Geo.CountryCode); |
| 31 | + Assert.Equal("United States", actual.Geo.Country); |
| 32 | + Assert.Equal("United States", actual.Geo.CountryName); |
| 33 | + Assert.False(actual.Geo.IsEU); |
| 34 | + Assert.NotNull(actual.Geo.Continent); |
| 35 | + Assert.NotNull(actual.Geo.ContinentCode); |
| 36 | + Assert.NotEqual(0, actual.Geo.Latitude); |
| 37 | + Assert.NotEqual(0, actual.Geo.Longitude); |
| 38 | + Assert.NotNull(actual.Geo.Timezone); |
| 39 | + Assert.NotNull(actual.Geo.PostalCode); |
| 40 | + Assert.Equal("🇺🇸", actual.Geo.CountryFlag.Emoji); |
| 41 | + Assert.Equal("U+1F1FA U+1F1F8", actual.Geo.CountryFlag.Unicode); |
| 42 | + Assert.Equal("https://cdn.ipinfo.io/static/images/countries-flags/US.svg", actual.Geo.CountryFlagURL); |
| 43 | + Assert.Equal("USD", actual.Geo.CountryCurrency.Code); |
| 44 | + Assert.Equal("$", actual.Geo.CountryCurrency.Symbol); |
| 45 | + Assert.Equal("NA", actual.Geo.ContinentInfo.Code); |
| 46 | + Assert.Equal("North America", actual.Geo.ContinentInfo.Name); |
| 47 | + |
| 48 | + // AS assertions |
| 49 | + Assert.NotNull(actual.As); |
| 50 | + Assert.Equal("AS15169", actual.As.Asn); |
| 51 | + Assert.NotNull(actual.As.Name); |
| 52 | + Assert.NotNull(actual.As.Domain); |
| 53 | + Assert.NotNull(actual.As.Type); |
| 54 | + |
| 55 | + // Network flags |
| 56 | + Assert.False(actual.IsAnonymous); |
| 57 | + Assert.True(actual.IsAnycast); |
| 58 | + Assert.True(actual.IsHosting); |
| 59 | + Assert.False(actual.IsMobile); |
| 60 | + Assert.False(actual.IsSatellite); |
| 61 | + } |
| 62 | + |
| 63 | + [Fact] |
| 64 | + public void TestGetDetailsIPV6() |
| 65 | + { |
| 66 | + string ip = "2001:4860:4860::8888"; |
| 67 | + IPinfoClientCore client = new IPinfoClientCore.Builder() |
| 68 | + .AccessToken(Environment.GetEnvironmentVariable("IPINFO_TOKEN")) |
| 69 | + .Build(); |
| 70 | + |
| 71 | + IPResponseCore actual = client.IPApi.GetDetails(ip); |
| 72 | + |
| 73 | + Assert.Equal("2001:4860:4860::8888", actual.IP); |
| 74 | + |
| 75 | + // Geo assertions |
| 76 | + Assert.NotNull(actual.Geo); |
| 77 | + Assert.Equal("US", actual.Geo.CountryCode); |
| 78 | + Assert.Equal("United States", actual.Geo.Country); |
| 79 | + Assert.NotNull(actual.Geo.City); |
| 80 | + Assert.NotNull(actual.Geo.Region); |
| 81 | + |
| 82 | + // AS assertions |
| 83 | + Assert.NotNull(actual.As); |
| 84 | + Assert.NotNull(actual.As.Asn); |
| 85 | + Assert.NotNull(actual.As.Name); |
| 86 | + Assert.NotNull(actual.As.Domain); |
| 87 | + |
| 88 | + // Network flags |
| 89 | + Assert.False(actual.IsAnonymous); |
| 90 | + Assert.False(actual.IsMobile); |
| 91 | + Assert.False(actual.IsSatellite); |
| 92 | + } |
| 93 | + |
| 94 | + [Fact] |
| 95 | + public void TestBogonIPV4() |
| 96 | + { |
| 97 | + string ip = "127.0.0.1"; |
| 98 | + IPinfoClientCore client = new IPinfoClientCore.Builder() |
| 99 | + .AccessToken(Environment.GetEnvironmentVariable("IPINFO_TOKEN")) |
| 100 | + .Build(); |
| 101 | + |
| 102 | + IPResponseCore actual = client.IPApi.GetDetails(ip); |
| 103 | + |
| 104 | + Assert.Equal("127.0.0.1", actual.IP); |
| 105 | + Assert.True(actual.Bogon); |
| 106 | + } |
| 107 | + |
| 108 | + [Fact] |
| 109 | + public void TestBogonIPV6() |
| 110 | + { |
| 111 | + string ip = "2001:0:c000:200::0:255:1"; |
| 112 | + IPinfoClientCore client = new IPinfoClientCore.Builder() |
| 113 | + .AccessToken(Environment.GetEnvironmentVariable("IPINFO_TOKEN")) |
| 114 | + .Build(); |
| 115 | + |
| 116 | + IPResponseCore actual = client.IPApi.GetDetails(ip); |
| 117 | + |
| 118 | + Assert.Equal("2001:0:c000:200::0:255:1", actual.IP); |
| 119 | + Assert.True(actual.Bogon); |
| 120 | + } |
| 121 | + } |
| 122 | +} |
0 commit comments