public void EnsureTag_SetsSecondLevelTagString() { var taggable = new Link(); TagManager.EnsureTag(dbContext, taggable, GetLv2Tag()); Assert.AreEqual(lv2TagString, taggable.TagString); }
public void EnsureTag_SetsParentTagOfAlreadySetTag() { var taggable = new Link {TagString = lv3TagString}; TagManager.EnsureTag(dbContext, taggable, GetLv1Tag()); string[] tagPaths = taggable.TagString.Split(TagManager.Separator); Assert.AreEqual(2, tagPaths.Length); Assert.IsTrue(tagPaths.Contains(lv3TagString)); Assert.IsTrue(tagPaths.Contains(lv1TagString)); }
public void EnsureTag_DoesNotDestroyExistingTags() { const string originalTagString = "[/100/101/102/]"; var taggable = new Link {TagString = originalTagString}; TagManager.EnsureTag(dbContext, taggable, GetLv2Tag()); string[] tagStrings = taggable.TagString.Split(TagManager.Separator); Assert.IsTrue(tagStrings.Contains(originalTagString)); Assert.IsTrue(tagStrings.Contains(lv2TagString)); }
public void Execute_ConsidersMultipleSearchTerms() { DbSet<Link> testDbSet = new TestDbSet<Link>(); var firstLinkToFind = new Link {Url = "http://bar.foo"}; testDbSet.Add(firstLinkToFind); var secondLinkToFind = new Link {Name = "bar"}; testDbSet.Add(secondLinkToFind); IQueryable<Link> results = StringQuery.Execute(testDbSet, new[] {"bar"}); Assert.AreEqual(2, results.Count()); }
public void Execute_ConsidersUrl() { DbSet<Link> testDbSet = new TestDbSet<Link>(); var linkToFind = new Link {Url = "http://bar.foo"}; testDbSet.Add(linkToFind); var otherLink = new Link {Url = "foo"}; testDbSet.Add(otherLink); IQueryable<Link> results = StringQuery.Execute(testDbSet, new[] {"bar"}); Assert.AreEqual(1, results.Count()); Assert.AreEqual(linkToFind, results.First()); }
public void SyncTagStringWithTagIds_TagStringMatchesAfterSyncWithTwoTags() { var updatedTaggable = new Link {Id = 1, TagIds = new[] {3, 1}}; TagManager.SyncTagStringWithTagIds(dbContext, updatedTaggable); string[] tagPaths = updatedTaggable.TagString.Split(TagManager.Separator); Assert.IsTrue(tagPaths.Contains(lv1TagString)); Assert.IsTrue(tagPaths.Contains(lv3TagString)); }
public void SyncTagStringWithTagIds_TagStringMatchesAfterSyncWithOneTag() { var updatedTaggable = new Link {Id = 1, TagIds = new[] {3}}; TagManager.SyncTagStringWithTagIds(dbContext, updatedTaggable); Assert.AreEqual(lv3TagString, updatedTaggable.TagString); }
public void SyncTagStringWithTagIds_PreviousTagsAreRemovedIfNotInTagIds() { var updatedTaggable = new Link {Id = 1, TagString = lv2TagString, TagIds = new[] {1}}; TagManager.SyncTagStringWithTagIds(dbContext, updatedTaggable); string[] tagPaths = updatedTaggable.TagString.Split(TagManager.Separator); Assert.AreEqual(1, tagPaths.Length); Assert.IsTrue(tagPaths.Contains(lv1TagString)); }
public void RemoveTag_RemovesMultipleInheritedTag() { var originalTagString = "[/1/2/3/];[/1/2/15/];[/4/5/6/]"; var taggable = new Link { TagString = originalTagString }; TagManager.RemoveTag(taggable, 2); Assert.AreEqual("[/4/5/6/]", taggable.TagString); }
public static void SyncTagStringWithTagIds(IDbContext dbContext, Link link) { SyncTagStringWithTagIds(dbContext, dbContext.Tags.ToArray(), link); }
public void EnsureTag_SetsTwoDifferentTags() { var taggable = new Link(); TagManager.EnsureTag(dbContext, taggable, GetLv1Tag()); TagManager.EnsureTag(dbContext, taggable, GetOtherLv2Tag()); string[] tagStrings = taggable.TagString.Split(TagManager.Separator); Assert.IsTrue(tagStrings.Contains(lv1TagString)); Assert.IsTrue(tagStrings.Contains(otherLv2TagString)); }
public void Execute_IgnoresCase() { DbSet<Link> testDbSet = new TestDbSet<Link>(); var linkToFind = new Link {Name = "FOO"}; testDbSet.Add(linkToFind); var otherLink = new Link {Name = "BAR"}; testDbSet.Add(otherLink); IQueryable<Link> results = StringQuery.Execute(testDbSet, new[] {"foo"}); Assert.AreEqual(1, results.Count()); Assert.AreEqual(linkToFind, results.First()); }
private void AddLinks(IDbContext dbContext) { Tag[] allTags = dbContext.Tags.ToArray(); for (var i = 1; i <= numberOfLinks; i++) { var link = new Link { Description = GetRandomString(20), Id = i, Name = GetRandomString(5), TagIds = GetRandomTagIds() }; TagManager.SyncTagStringWithTagIds(dbContext, allTags, link); dbContext.Update(link); } }
public static void SyncTagStringWithTagIds(IDbContext dbContext, Tag[] allTags, Link link) { link.ClearTagString(); foreach (Tag tag in link.TagIds .Select(tagId => allTags.FirstOrDefault(t => t.Id == tagId)) .Where(t => t != null)) { EnsureTag(allTags, link, tag); } }
public void TagStringToTagIdsToTagString_ProducesOriginalTagString() { string originalTagString = lv1TagString + TagManager.Separator + otherLv2TagString; var firstTaggable = new Link {TagString = originalTagString}; int[] tagIds = TagManager.GetIdsFromTagString(firstTaggable.TagString); var secondTaggable = new Link {TagIds = tagIds}; TagManager.SyncTagStringWithTagIds(dbContext, secondTaggable); Assert.AreEqual(originalTagString, secondTaggable.TagString); }
public void EnsureTag_TagStringStartsWithPathStarterAndPathSeparator() { var taggable = new Link(); TagManager.EnsureTag(dbContext, taggable, new Tag {Id = 1, ParentId = 0}); Assert.IsTrue(taggable.TagString.StartsWith(TagManager.PathStarter.ToString() + TagManager.PathSeparator)); }
public void RemoveTag_RemovesAppliedTag() { var originalTagString = "[/1/2/3/];[/4/5/6/]"; var taggable = new Link {TagString = originalTagString}; TagManager.RemoveTag(taggable, 3); Assert.AreEqual("[/4/5/6/]", taggable.TagString); }
public void EnsureTag_SetsTagOnlyOnce() { var taggable = new Link(); Tag tag = GetLv1Tag(); TagManager.EnsureTag(dbContext, taggable, tag); TagManager.EnsureTag(dbContext, taggable, tag); Assert.AreEqual(lv1TagString, taggable.TagString); }
public IHttpActionResult Post(Link link) { return new UpdateLinkAction(Request, DbContext, link); }