Exemplo n.º 1
0
        public void InsertDeleteTest()
        {
            var cache = new Cache {
                Id                = -1,
                Name              = "my special test cache",
                CreationDate      = new DateTime(2010, 10, 17),
                TerrainDifficulty = 1.9,
                CacheDifficulty   = 2.5,
                Size              = "Regular",
                OwnerId           = 223,
                Position          = new GeoPosition(47.451, 13.89),
                Description       = "this is a test unit test cache"
            };

            int id = target.Insert(cache);

            Assert.IsTrue(id > 0);

            Cache newState = target.GetById(id);

            Assert.AreEqual(cache.TerrainDifficulty, newState.TerrainDifficulty);
            Assert.AreEqual(cache.Name, newState.Name);
            Assert.AreEqual(cache.OwnerId, newState.OwnerId);

            bool success = target.Delete(cache.Id);

            Assert.IsTrue(success);
            Assert.IsNull(target.GetById(id));
        }
Exemplo n.º 2
0
        public bool DeleteCache(int cacheId)
        {
            ValidateCacheOwner(cacheId);

            // check if there are no assigned log entries or ratings
            if (logEntryDao.GetLogEntriesForCache(cacheId).Count == 0 ||
                ratingDao.GetRatingsForCache(cacheId).Count == 0)
            {
                imageDao.DeleteAllForCache(cacheId);
                return(cacheDao.Delete(cacheId));
            }
            throw new Exception("Error: Unable to delete cache due to assigned log entries/ratings.");
        }