private (Article, Person, Food, Person, Food) GetAuthorChainInstances() { var article = ArticleFaker.Generate(); var author = PersonFaker.Generate(); article.Author = author; var blogs = BlogFaker.Generate(2); author.Blogs = blogs.ToHashSet(); blogs[0].Reviewer = author; var reviewer = PersonFaker.Generate(); blogs[1].Reviewer = reviewer; var authorFood = FoodFaker.Generate(); author.FavoriteFood = authorFood; var reviewerFood = FoodFaker.Generate(); reviewer.FavoriteFood = reviewerFood; return(article, author, authorFood, reviewer, reviewerFood); }
private AuthorChainInstances GetAuthorChainInstances() { Article article = ArticleFaker.Generate(); Person author = PersonFaker.Generate(); article.Author = author; List <Blog> blogs = BlogFaker.Generate(2); author.Blogs = blogs.ToHashSet(); blogs[0].Reviewer = author; Person reviewer = PersonFaker.Generate(); blogs[1].Reviewer = reviewer; Food authorFood = FoodFaker.Generate(); author.FavoriteFood = authorFood; Food reviewerFood = FoodFaker.Generate(); reviewer.FavoriteFood = reviewerFood; return(new AuthorChainInstances(article, author, authorFood, reviewer, reviewerFood)); }
private (List <Article>, List <Tag>) CreateDummyData() { List <Tag> tagsSubset = TagFaker.Generate(3); List <ArticleTag> joinsSubSet = ArticleTagFaker.Generate(3); Article articleTagsSubset = ArticleFaker.Generate(); articleTagsSubset.ArticleTags = joinsSubSet.ToHashSet(); for (int index = 0; index < 3; index++) { joinsSubSet[index].Article = articleTagsSubset; joinsSubSet[index].Tag = tagsSubset[index]; } List <Tag> allTags = TagFaker.Generate(3).Concat(tagsSubset).ToList(); List <ArticleTag> completeJoin = ArticleTagFaker.Generate(6); Article articleWithAllTags = ArticleFaker.Generate(); articleWithAllTags.ArticleTags = completeJoin.ToHashSet(); for (int index = 0; index < 6; index++) { completeJoin[index].Article = articleWithAllTags; completeJoin[index].Tag = allTags[index]; } List <Article> articles = ArrayFactory.Create(articleTagsSubset, articleWithAllTags).ToList(); return(articles, allTags); }
private (List <Article>, List <Tag>) CreateDummyData() { var tagsSubset = TagFaker.Generate(3); var joinsSubSet = ArticleTagFaker.Generate(3); var articleTagsSubset = ArticleFaker.Generate(); articleTagsSubset.ArticleTags = joinsSubSet.ToHashSet(); for (int i = 0; i < 3; i++) { joinsSubSet[i].Article = articleTagsSubset; joinsSubSet[i].Tag = tagsSubset[i]; } var allTags = TagFaker.Generate(3).Concat(tagsSubset).ToList(); var completeJoin = ArticleTagFaker.Generate(6); var articleWithAllTags = ArticleFaker.Generate(); articleWithAllTags.ArticleTags = completeJoin.ToHashSet(); for (int i = 0; i < 6; i++) { completeJoin[i].Article = articleWithAllTags; completeJoin[i].Tag = allTags[i]; } var articles = ArrayFactory.Create(articleTagsSubset, articleWithAllTags).ToList(); return(articles, allTags); }
public void BuildIncluded_DeeplyNestedCircularChainOfManyData_BuildsWithoutDuplicates() { // Arrange (Article article, Person author, _, _, _) = GetAuthorChainInstances(); Article secondArticle = ArticleFaker.Generate(); secondArticle.Author = author; IncludedResourceObjectBuilder builder = GetBuilder(); // Act IReadOnlyCollection <RelationshipAttribute> authorChain = GetIncludedRelationshipsChain("author.blogs.reviewer.favoriteFood"); builder.IncludeRelationshipChain(authorChain, article); builder.IncludeRelationshipChain(authorChain, secondArticle); // Assert IList <ResourceObject> result = builder.Build(); Assert.Equal(6, result.Count); }
public void BuildIncluded_DeeplyNestedCircularChainOfManyData_BuildsWithoutDuplicates() { // Arrange var(article, author, _, _, _) = GetAuthorChainInstances(); var secondArticle = ArticleFaker.Generate(); secondArticle.Author = author; var builder = GetBuilder(); // Act var authorChain = GetIncludedRelationshipsChain("author.blogs.reviewer.favoriteFood"); builder.IncludeRelationshipChain(authorChain, article); builder.IncludeRelationshipChain(authorChain, secondArticle); // Assert var result = builder.Build(); Assert.Equal(6, result.Count); }
public void BuildIncluded_DuplicateChildrenMultipleChains_OnceInOutput() { Person person = PersonFaker.Generate(); List <Article> articles = ArticleFaker.Generate(5); articles.ForEach(article => article.Author = person); articles.ForEach(article => article.Reviewer = person); IncludedResourceObjectBuilder builder = GetBuilder(); IReadOnlyCollection <RelationshipAttribute> authorChain = GetIncludedRelationshipsChain("author"); IReadOnlyCollection <RelationshipAttribute> reviewerChain = GetIncludedRelationshipsChain("reviewer"); foreach (Article article in articles) { builder.IncludeRelationshipChain(authorChain, article); builder.IncludeRelationshipChain(reviewerChain, article); } IList <ResourceObject> result = builder.Build(); Assert.Single(result); Assert.Equal(person.Name, result[0].Attributes["name"]); Assert.Equal(person.Id.ToString(), result[0].Id); }
public void BuildIncluded_DuplicateChildrenMultipleChains_OnceInOutput() { var person = PersonFaker.Generate(); var articles = ArticleFaker.Generate(5); articles.ForEach(a => a.Author = person); articles.ForEach(a => a.Reviewer = person); var builder = GetBuilder(); var authorChain = GetIncludedRelationshipsChain("author"); var reviewerChain = GetIncludedRelationshipsChain("reviewer"); foreach (var article in articles) { builder.IncludeRelationshipChain(authorChain, article); builder.IncludeRelationshipChain(reviewerChain, article); } var result = builder.Build(); Assert.Single(result); Assert.Equal(person.Name, result[0].Attributes["name"]); Assert.Equal(person.Id.ToString(), result[0].Id); }