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"); }
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); } }
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)); } }