Пример #1
0
        public void Test()
        {
            var testGeolocation = new Geolocation()
            {
                Ip        = "ip",
                Latitude  = 1,
                Longitude = 2,
                Location  = "secret test location"
            };
            var result = GeolocationDao.Insert(testGeolocation);

            Assert.IsTrue(result);
            var geolocationResult = GeolocationDao.GetGeolocationByIp("ip");

            Assert.AreEqual(testGeolocation.Ip, geolocationResult.Ip);
            Assert.AreEqual(testGeolocation.Host, geolocationResult.Host);
            Assert.AreEqual(testGeolocation.Latitude, geolocationResult.Latitude);
            Assert.AreEqual(testGeolocation.Longitude, geolocationResult.Longitude);
            Assert.AreEqual(testGeolocation.Location, geolocationResult.Location);

            Assert.IsNull(GeolocationDao.GetGeolocationByIpOrHost(null));
            Assert.IsNull(GeolocationDao.GetGeolocationByIpOrHost(""));
            Assert.IsNull(GeolocationDao.GetGeolocationByIpOrHost("ip2"));

            Assert.IsFalse(GeolocationDao.DeleteByHost(null));
            Assert.IsFalse(GeolocationDao.DeleteByHost(""));
            Assert.IsFalse(GeolocationDao.DeleteByHost("ip"));
            Assert.IsFalse(GeolocationDao.DeleteByIp(null));
            Assert.IsFalse(GeolocationDao.DeleteByIp(""));
            Assert.IsFalse(GeolocationDao.DeleteByIp("test ip"));
            Assert.IsTrue(GeolocationDao.DeleteByIp("ip"));

            Assert.IsNull(GeolocationDao.GetGeolocationByIp("ip"));

            testGeolocation = new Geolocation()
            {
                Ip        = "ip",
                Host      = "host",
                Latitude  = 1,
                Longitude = 2,
                Location  = "secret test location"
            };
            result = GeolocationDao.Insert(testGeolocation);
            Assert.IsTrue(result);

            Assert.IsNotNull(GeolocationDao.GetGeolocationByIpOrHost("host"));
            Assert.IsTrue(GeolocationDao.DeleteByHost("host"));
            Assert.IsNull(GeolocationDao.GetGeolocationByIpOrHost("host"));
        }
Пример #2
0
        public void DeleteGeolocationTest()
        {
            var geolocation = new Geolocation()
            {
                Host      = "host",
                Ip        = "ip2",
                Latitude  = 0,
                Longitude = 0,
                Location  = "location"
            };

            GeolocationDao.Insert(geolocation);
            var response = _controller.DeleteGeolocation(geolocation.Host);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsFalse(GeolocationDao.DeleteByHost(geolocation.Host));
        }