public async Task GetGeoIpInfo_ReturnsDataFromProvider()
        {
            var service = new GeoIpService(this.mockedProvider);
            var actual  = await service.GetGeoIpInfo(Host1);

            var actual2 = await service.GetGeoIpInfo(Host2);

            Assert.Equal(this.expectedForHost1.Ip, actual.Ip);
            Assert.Equal(this.expectedForHost2.Ip, actual2.Ip);
        }
Пример #2
0
        public void Test_LocationService_GeoLocation()
        {
            string target = "http://api.ipstack.com/201.200.0.127?access_key=065fbf702ae92e9a0d0806adbdac908a";

            GeoIpService service = new GeoIpService();

            var result = Task.Run(async() =>
            {
                return(await service.GetLocation(target));
            })
                         .GetAwaiter()
                         .GetResult();

            Assert.IsNotNull(result);
        }
Пример #3
0
        public HttpResponseMessage WhoAmI()
        {
            HttpResponseMessage response;

            try
            {
                var userIpAddress = GeoIpService.GetUserIpAddress();

                WhoIsInformation whoami = LookupManager.GetInformationByIp(userIpAddress.ToString());

                var userAgent = Request.Headers.UserAgent.ToString();
                var di        = DeviceDetectionManager.GetDeviceInformation(userAgent);

                response = Request.CreateResponse(HttpStatusCode.OK, new
                {
                    Ip = userIpAddress.ToString(),
                    whoami.Country,
                    whoami.City,
                    whoami.Region,
                    whoami.PostalCode,
                    Latitude  = whoami.Latitude ?? 0,
                    Longitude = whoami.Longitude ?? 0,
                    Device    = new
                    {
                        di.DeviceIsSmartphone,
                        di.DeviceModelName,
                        di.Browser,
                        DeviceType = Enum.GetName(typeof(DeviceType), di.DeviceType),
                        di.DeviceVendor
                    }
                });

                return(response);
            }
            catch (Exception ex)
            {
                Log.Error($"HomeController.WhoAmI(): Error while getting user's GeoIP and Device Detection information.", ex, this);

                response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Oops, it looks like something went wrong. Please try again.");
                return(response);
            }
        }
 public PassiveLogDetectionController(ApplicationDbContext db, GeoIpService geoIpService)
 {
     this.db           = db;
     this.geoIpService = geoIpService;
 }
 public GeoIpController(GeoIpService geoIpService)
 {
     _geoIpService = geoIpService;
 }
 public IpAddressController(GeoIpService geoIpService)
 {
     this.geoIpService = geoIpService;
 }