public void GetBlogPostIdsFromTags_AddMultipleEntriesForOneTag_ReturnsIds() { // Arrange var fakeAccess = Substitute.ForPartsOf <TagFileS3Access>(); TagFile fakeTagFile = new TagFile(); fakeTagFile.AddEntry("test1", new SortedSet <string> { "1", "2", "8" }); fakeTagFile.AddEntry("test2", new SortedSet <string> { "1", "2", "9" }); fakeTagFile.AddEntry("test1", new SortedSet <string> { "1", "4", "10" }); fakeAccess.Configure().GetTagFile().ReturnsForAnyArgs(fakeTagFile); // Act var response = fakeAccess.GetBlogPostIdsFromTags(new string[] { "test1" }); response.Wait(); List <BlogPost> result = response.Result; // Assert var ids = result.Select(r => r.Id).ToList(); ids.Sort(); Assert.That(ids.All(new List <int> { 1, 2, 4, 8, 10 }.Contains)); }
public void GetBlogPostIdsFromTag_MultipleInstancesOfSamePost_NoDuplicates() { // Arrange var fakeAccess = Substitute.ForPartsOf <TagFileS3Access>(); TagFile fakeTagFile = new TagFile(); fakeTagFile.AddEntry("scripture", new SortedSet <string> { "1", "4" }); fakeTagFile.AddEntry("theology", new SortedSet <string> { "1", "4" }); fakeAccess.Configure().GetTagFile().ReturnsForAnyArgs(fakeTagFile); // Act var response = fakeAccess.GetBlogPostIdsFromTags(new string[] { "scripture", "theology" }); response.Wait(); List <BlogPost> result = response.Result; // Assert var ids = result.Select(r => r.Id).ToList(); ids.Sort(); Assert.That(ids.All(new List <int> { 1, 4 }.Contains)); }
public void GetBlogPostIdsFromTags_NormalInput_ReturnsIds() { // Arrange var fakeAccess = Substitute.ForPartsOf <TagFileS3Access>(); TagFile fakeTagFile = new TagFile(); fakeTagFile.AddEntry("test1", new SortedSet <string> { "1", "2", "8" }); fakeTagFile.AddEntry("test2", new SortedSet <string> { "1", "2", "9" }); fakeTagFile.AddEntry("test3", new SortedSet <string> { "1", "4", "10" }); fakeAccess.Configure().GetTagFile().ReturnsForAnyArgs(fakeTagFile); // Act var response = fakeAccess.GetBlogPostIdsFromTags(new string[] { "test1" }); response.Wait(); List <BlogPost> result = response.Result; // Assert var ids = result.Select(r => r.Id).ToList(); Assert.That(String.Join(",", ids).Equals(String.Join(",", new List <int> { 1, 2, 8 }))); }
// what is the wisdom of my base object retrieval class getting things as strings? public virtual async Task <TagFile> GetTagFile() { // use GetObject to retrieve the TagFile string tagFileContents = await GetObject(new GetObjectRequest { BucketName = EnvironmentHandler.GetEnvironmentHandler().GetVariable("BucketName"), Key = TagFileS3Access.TagFileName }); // parse string into TagFile // each line is one entry string[] lines = tagFileContents.Split("\n", StringSplitOptions.RemoveEmptyEntries); if (tagFileContents == string.Empty) { throw new TagFileException("Exception - Empty TagFile."); } TagFile tagFile = new TagFile(); for (int i = 0; i < lines.Length; i++) { var line = lines[i]; // parse each line - split on '-'; LHS is tag, RHS is array of ids string[] lineContents = line.Split('-'); if (lineContents.Length != 2) { throw new TagFileException($"there is an issue with tagfile format on line {i}."); } List <string> ids = lineContents[1].Split(',').ToList(); tagFile.AddEntry(lineContents[0], new SortedSet <string>(ids)); } return(tagFile); }