public void TestInsertsFireInvalidationTriggers() { Tag tag = new Tag(); tag.Update(); Photo photo = new Photo(); photo.Update(); Caching.Instances.Main.FlushAll(); string version = Guid.NewGuid().ToString(); Caching.Instances.Main.Set(Caching.CacheKeys.Tag.TagPhotos(tag.K), version); TagPhoto tagPhoto = new TagPhoto() { TagK = tag.K, PhotoK = photo.K}; Assert.AreEqual(version, Caching.Instances.Main.Get(Caching.CacheKeys.Tag.TagPhotos(tag.K))); tagPhoto.Update(); Assert.AreNotEqual(version, Caching.Instances.Main.Get(Caching.CacheKeys.Tag.TagPhotos(tag.K))); }
public void TestDeletesFireInvalidationTriggers() { Tag tag = new Tag(); tag.Update(); Photo photo2 = new Photo(); photo2.Update(); Photo photo = new Photo(); photo.Update(); Caching.Instances.Main.FlushAll(); TagPhoto tagPhoto = new TagPhoto() { TagK = tag.K, PhotoK = photo.K}; tagPhoto.Update(); string version = Caching.Instances.Main.Get(Caching.CacheKeys.Tag.TagPhotos(tag.K)) as string; tagPhoto.Delete(); Assert.AreNotEqual(version, Caching.Instances.Main.Get(Caching.CacheKeys.Tag.TagPhotos(tag.K))); }
public static Tag AddTag(string tagText, Tagging.ITaggable objectToTag, Usr usrAddingTag) { try { Transaction t = new Transaction(); try { Tag tag = Tag.GetTag(tagText); if (tag.Blocked) { throw new InvalidTagException(); } TagPhoto tagPhoto = TagPhoto.GetTagPhoto(tag.K, objectToTag.K); TagPhotoHistory.TagPhotoHistoryAction action = TagPhotoHistory.TagPhotoHistoryAction.Created; if (tagPhoto == null) { tagPhoto = new TagPhoto() { TagK = tag.K, PhotoK = objectToTag.K, Disabled = false }; tagPhoto.Update(t); action = TagPhotoHistory.TagPhotoHistoryAction.Created; } if (tagPhoto.Disabled) { if (!usrAddingTag.IsJunior) { throw new Exception("You do not have rights to re-enable that tag"); } tagPhoto.Disabled = false; tagPhoto.Update(t); action = TagPhotoHistory.TagPhotoHistoryAction.Enabled; } TagPhotoHistory history = new TagPhotoHistory() { DateTime = DateTime.Now, Action = action, UsrK = usrAddingTag.K, TagPhotoK = tagPhoto.K }; history.Update(t); t.Commit(); return tag; } catch (Exception ex) { t.Rollback(); throw ex; } } catch (InvalidTagException) { return null; } }