Ejemplo n.º 1
0
        public async Task TestNearest()
        {
            TraceIpReport nearest = _service.GetReportByNearestCountry();

            Assert.IsNotNull(nearest);
            Assert.AreEqual(nearest.CountryCode, "UY");

            // We add Argentina (distance 0), but still nearest country is UY
            Assert.IsNotNull(await _service.GetTraceReport("24.232.255.255"));

            nearest = _service.GetReportByNearestCountry();
            Assert.IsNotNull(nearest);
            Assert.AreEqual(nearest.CountryCode, "UY");
        }
Ejemplo n.º 2
0
        public async Task InitServiceAsync()
        {
            _redis = ConnectionMultiplexer.Connect("localhost:6379,allowAdmin=true");
            _redis.GetServer(_redis.GetEndPoints()[0]).FlushAllDatabases();
            _service = new TraceIpService(new TraceReportRepositorie(_redis), new StatsRepositorie(_redis));

            string testData = System.IO.File.ReadAllText(@"test_data.txt");
            var    IPs      = testData.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);

            foreach (var ip in IPs)
            {
                TraceIpReport report = await _service.GetTraceReport(ip);

                Assert.IsNotNull(report);
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> TraceIp([FromQuery] string ip)
        {
            try
            {
                if (String.IsNullOrEmpty(ip))
                {
                    return(BadRequest("Missing IP."));
                }

                TraceIpReport report = await _traceIpservice.GetTraceReport(ip);

                if (report == null)
                {
                    return(BadRequest("Invalid or missing IP address."));
                }

                return(Ok(report.ToString()));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }