Exemplo n.º 1
0
        public void BuildIncluded_OverlappingDeeplyNestedCircularChains_CanBuild()
        {
            // Arrange
            IReadOnlyCollection <RelationshipAttribute> authorChain = GetIncludedRelationshipsChain("author.blogs.reviewer.favoriteFood");

            (Article article, Person author, _, Person reviewer, Food reviewerFood) = GetAuthorChainInstances();
            Blog   sharedBlog       = author.Blogs.First();
            Person sharedBlogAuthor = reviewer;
            Song   authorSong       = GetReviewerChainInstances(article, sharedBlog, sharedBlogAuthor);
            IReadOnlyCollection <RelationshipAttribute> reviewerChain = GetIncludedRelationshipsChain("reviewer.blogs.author.favoriteSong");
            IncludedResourceObjectBuilder builder = GetBuilder();

            // Act
            builder.IncludeRelationshipChain(authorChain, article);
            builder.IncludeRelationshipChain(reviewerChain, article);
            IList <ResourceObject> result = builder.Build();

            // Assert
            Assert.Equal(10, result.Count);
            ResourceObject overlappingBlogResourceObject = result.Single(ro => ro.Type == "blogs" && ro.Id == sharedBlog.StringId);

            Assert.Equal(2, overlappingBlogResourceObject.Relationships.Keys.Count);
            List <ResourceObject> nonOverlappingBlogs = result.Where(ro => ro.Type == "blogs" && ro.Id != sharedBlog.StringId).ToList();

            foreach (ResourceObject blog in nonOverlappingBlogs)
            {
                Assert.Single(blog.Relationships.Keys);
            }

            Assert.Equal(authorSong.StringId, sharedBlogAuthor.FavoriteSong.StringId);
            Assert.Equal(reviewerFood.StringId, sharedBlogAuthor.FavoriteFood.StringId);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public void BuildIncluded_DeeplyNestedCircularChainOfSingleData_CanBuild()
        {
            // Arrange
            (Article article, Person author, _, Person reviewer, _) = GetAuthorChainInstances();
            IReadOnlyCollection <RelationshipAttribute> authorChain = GetIncludedRelationshipsChain("author.blogs.reviewer.favoriteFood");
            IncludedResourceObjectBuilder builder = GetBuilder();

            // Act
            builder.IncludeRelationshipChain(authorChain, article);
            IList <ResourceObject> result = builder.Build();

            // Assert
            Assert.Equal(6, result.Count);

            ResourceObject           authorResourceObject = result.Single(ro => ro.Type == "people" && ro.Id == author.StringId);
            ResourceIdentifierObject authorFoodRelation   = authorResourceObject.Relationships["favoriteFood"].SingleData;

            Assert.Equal(author.FavoriteFood.StringId, authorFoodRelation.Id);

            ResourceObject           reviewerResourceObject = result.Single(ro => ro.Type == "people" && ro.Id == reviewer.StringId);
            ResourceIdentifierObject reviewerFoodRelation   = reviewerResourceObject.Relationships["favoriteFood"].SingleData;

            Assert.Equal(reviewer.FavoriteFood.StringId, reviewerFoodRelation.Id);
        }