Esempio n. 1
0
        public async Task IpStackInfoProvider_GetDetailsAsync_Real_Ip_Returns_Success(string ip)
        {
            var ipStackInfoProvider = new IpStackInfoClient(new System.Net.Http.HttpClient(), _configuration);

            var actual = await ipStackInfoProvider.GetDetailsAsync(ip);

            actual.Should().NotBeNull();
            actual.Country.Should().NotBeNullOrWhiteSpace();
            actual.City.Should().NotBeNullOrWhiteSpace();
            actual.Continent.Should().NotBeNullOrWhiteSpace();
        }
Esempio n. 2
0
        public async Task IpStackInfoProvider_GetDetailsAsync_With_InvalidIp_Returns_Empty()
        {
            var ipStackInfoProvider = new IpStackInfoClient(new System.Net.Http.HttpClient(), _configuration);
            var ip = "notvalidip";

            var actual = await ipStackInfoProvider.GetDetailsAsync(ip);

            actual.Should().NotBeNull();
            actual.Country.Should().BeNullOrWhiteSpace();
            actual.City.Should().BeNullOrWhiteSpace();
            actual.Continent.Should().BeNullOrWhiteSpace();
        }
Esempio n. 3
0
        public void IpStackInfoProvider_GetDetailsAsync_NotValidKey_Throws_Exception()
        {
            var configuration = new Mock <IConfiguration>();

            configuration.Setup(z => z.GetSection("BaseUrl").Value).Returns("http://api.ipstack.com/");

            // setup an invalid key.
            configuration.Setup(z => z.GetSection("ApiKey").Value).Returns("11111111");

            var ipStackInfoProvider = new IpStackInfoClient(new System.Net.Http.HttpClient(), configuration.Object);
            var ip = "8.8.8.8";

            // Act
            Func <Task> action = async() => { await ipStackInfoProvider.GetDetailsAsync(ip); };

            // Assert
            action.Should().Throw <IPServiceNotAvailableException>();
        }