示例#1
0
        // PRIVATE METHODS //////////////////////////////////////////////////
        #region Methods
        private void CreateAndAddDomReadWriteResourceIdentifierCollectionIfNeeded(int count)
        {
            Contract.Requires(count > 0);

            if (this.DomReadWriteResourceIdentifierCollection != null)
            {
                return;
            }

            var clrResourceType = typeof(TResource);
            var resourceType    = this.ServiceModel.GetResourceType(clrResourceType);

            this.ResourceType = resourceType;

            var domContainerNode = this.DomContainerNode;
            var domReadWriteResourceIdentifierCollection = new List <DomReadWriteResourceIdentifier>(count);

            for (var i = 0; i < count; ++i)
            {
                var domResourceType = DomType.CreateFromResourceType(resourceType);
                var domReadWriteResourceIdentifier = DomReadWriteResourceIdentifier.Create(domResourceType);

                domContainerNode.Add(domReadWriteResourceIdentifier);
                domReadWriteResourceIdentifierCollection.Add(domReadWriteResourceIdentifier);
            }

            this.DomReadWriteResourceIdentifierCollection = domReadWriteResourceIdentifierCollection;
        }
示例#2
0
        public void TestDomReadWriteResourceCreateWithPersonResource()
        {
            // Arrange
            var serviceModel = ClrSampleData.ServiceModelWithBlogResourceTypes;

            var personResourceType       = serviceModel.GetResourceType <Person>();
            var personResourceIdentity   = personResourceType.ResourceIdentityInfo;
            var personFirstNameAttribute = personResourceType.GetClrAttributeInfo(StaticReflection.GetMemberName <Person>(x => x.FirstName));
            var personLastNameAttribute  = personResourceType.GetClrAttributeInfo(StaticReflection.GetMemberName <Person>(x => x.LastName));
            var personTwitterAttribute   = personResourceType.GetClrAttributeInfo(StaticReflection.GetMemberName <Person>(x => x.Twitter));

            var expected = ApiSampleData.PersonResource;

            // Act
            var actual = DomReadWriteResource.Create(
                DomType.CreateFromResourceType(personResourceType),
                DomId.CreateFromApiResourceIdentity(personResourceType, expected),
                DomAttributes.Create(
                    DomAttribute.CreateFromApiResource(personFirstNameAttribute, expected),
                    DomAttribute.CreateFromApiResource(personLastNameAttribute, expected),
                    DomAttribute.CreateFromApiResource(personTwitterAttribute, expected)),
                DomReadWriteRelationships.Create(
                    DomReadWriteRelationship.Create(ApiSampleData.PersonToCommentsRel,
                                                    DomReadWriteLinks.Create(
                                                        DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.PersonToRelationshipsToCommentsHRef)),
                                                        DomReadWriteLink.Create(Keywords.Related, DomHRef.Create(ApiSampleData.PersonToCommentsHRef))))),
                DomReadWriteLinks.Create(
                    DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.PersonHRef))),
                DomReadOnlyMeta.Create(ApiSampleData.ResourceMeta));

            this.OutputDomTree(actual);

            // Assert
            DomReadWriteResourceAssert.Equal(expected, actual);
        }
示例#3
0
        public void TestDomReadWriteResourceCreateWithCommentResource()
        {
            // Arrange
            var serviceModel = ClrSampleData.ServiceModelWithBlogResourceTypes;

            var commentResourceType     = serviceModel.GetResourceType <Comment>();
            var commentResourceIdentity = commentResourceType.ResourceIdentityInfo;
            var commentBodyAttribute    = commentResourceType.GetClrAttributeInfo(StaticReflection.GetMemberName <Comment>(x => x.Body));

            var expected = ApiSampleData.CommentResource;

            // Act
            var actual = DomReadWriteResource.Create(
                DomType.CreateFromResourceType(commentResourceType),
                DomId.CreateFromApiResourceIdentity(commentResourceType, expected),
                DomAttributes.Create(
                    DomAttribute.CreateFromApiResource(commentBodyAttribute, expected)),
                DomReadWriteRelationships.Create(
                    DomReadWriteRelationship.Create(ApiSampleData.CommentToAuthorRel,
                                                    DomReadWriteLinks.Create(
                                                        DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.CommentToRelationshipsToAuthorHRef)),
                                                        DomReadWriteLink.Create(Keywords.Related, DomHRef.Create(ApiSampleData.CommentToAuthorHRef))))),
                DomReadWriteLinks.Create(
                    DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.CommentHRef))),
                DomReadOnlyMeta.Create(ApiSampleData.ResourceMeta));

            this.OutputDomTree(actual);

            // Assert
            DomReadWriteResourceAssert.Equal(expected, actual);
        }
示例#4
0
        public void TestDomReadWriteResourceCreateWithBlogResource()
        {
            // Arrange
            var serviceModel = ClrSampleData.ServiceModelWithBlogResourceTypes;

            var blogResourceType     = serviceModel.GetResourceType <Blog>();
            var blogResourceIdentity = blogResourceType.ResourceIdentityInfo;
            var blogNameAttribute    = blogResourceType.GetClrAttributeInfo(StaticReflection.GetMemberName <Blog>(x => x.Name));

            var expectedBlog = ApiSampleData.BlogResource;

            // Act
            var actual = DomReadWriteResource.Create(
                DomType.CreateFromResourceType(blogResourceType),
                DomId.CreateFromApiResourceIdentity(blogResourceType, expectedBlog),
                DomAttributes.Create(
                    DomAttribute.CreateFromApiResource(blogNameAttribute, expectedBlog)),
                DomReadWriteRelationships.Create(
                    DomReadWriteRelationship.Create(ApiSampleData.BlogToArticlesRel,
                                                    DomReadWriteLinks.Create(
                                                        DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.BlogToRelationshipsToArticlesHRef)),
                                                        DomReadWriteLink.Create(Keywords.Related, DomHRef.Create(ApiSampleData.BlogToArticlesHRef))))),
                DomReadWriteLinks.Create(
                    DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.BlogHRef))),
                DomReadOnlyMeta.Create(ApiSampleData.ResourceMeta));

            this.OutputDomTree(actual);

            // Assert
            DomReadWriteResourceAssert.Equal(expectedBlog, actual);
        }
示例#5
0
        public void TestDomReadWriteResourceCreateWithArticleResourceWithResourceLinkage()
        {
            // Arrange
            var serviceModel = ClrSampleData.ServiceModelWithBlogResourceTypes;

            var articleResourceType   = serviceModel.GetResourceType <Article>();
            var articleTitleAttribute = articleResourceType.GetClrAttributeInfo(StaticReflection.GetMemberName <Article>(x => x.Title));

            var commentResourceType = serviceModel.GetResourceType <Comment>();
            var personResourceType  = serviceModel.GetResourceType <Person>();

            var expectedArticle  = ApiSampleData.ArticleResourceWithResourceLinkage;
            var expectedAuthor   = ApiSampleData.PersonResource;
            var expectedComment1 = ApiSampleData.CommentResource1;
            var expectedComment2 = ApiSampleData.CommentResource2;

            // Act
            var actual = DomReadWriteResource.Create(
                DomType.CreateFromResourceType(articleResourceType),
                DomId.CreateFromApiResourceIdentity(articleResourceType, expectedArticle),
                DomAttributes.Create(
                    DomAttribute.CreateFromApiResource(articleTitleAttribute, expectedArticle)),
                DomReadWriteRelationships.Create(
                    DomReadWriteRelationship.Create(ApiSampleData.ArticleToAuthorRel,
                                                    DomReadWriteLinks.Create(
                                                        DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.ArticleToRelationshipsToAuthorHRef)),
                                                        DomReadWriteLink.Create(Keywords.Related, DomHRef.Create(ApiSampleData.ArticleToAuthorHRef))),
                                                    DomData.CreateFromResourceIdentifier(
                                                        DomReadWriteResourceIdentifier.Create(
                                                            DomType.CreateFromResourceType(personResourceType),
                                                            DomId.CreateFromApiResourceIdentity(personResourceType, expectedAuthor)))),
                    DomReadWriteRelationship.Create(ApiSampleData.ArticleToCommentsRel,
                                                    DomReadWriteLinks.Create(
                                                        DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.ArticleToRelationshipsToCommentsHRef)),
                                                        DomReadWriteLink.Create(Keywords.Related, DomHRef.Create(ApiSampleData.ArticleToCommentsHRef))),
                                                    DomDataCollection.CreateFromResourceIdentifiers(
                                                        DomReadWriteResourceIdentifier.Create(
                                                            DomType.CreateFromResourceType(commentResourceType),
                                                            DomId.CreateFromApiResourceIdentity(commentResourceType, expectedComment1)),
                                                        DomReadWriteResourceIdentifier.Create(
                                                            DomType.CreateFromResourceType(commentResourceType),
                                                            DomId.CreateFromApiResourceIdentity(commentResourceType, expectedComment2))))),
                DomReadWriteLinks.Create(
                    DomReadWriteLink.Create(Keywords.Canonical, DomHRef.Create(ApiSampleData.ArticleHRef)),
                    DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.ArticleHRef))),
                DomReadOnlyMeta.Create(ApiSampleData.ResourceMeta));

            this.OutputDomTree(actual);

            // Assert
            DomReadWriteResourceAssert.Equal(expectedArticle, actual);
        }
示例#6
0
        // PRIVATE METHODS //////////////////////////////////////////////////
        #region Methods
        private void CreateAndAddDomReadWriteResourceIdentifierIfNeeded()
        {
            if (this.DomReadWriteResourceIdentifier != null)
            {
                return;
            }

            var domResourceType = DomType.CreateFromResourceType(this.ResourceType);
            var domReadWriteResourceIdentifier = DomReadWriteResourceIdentifier.Create(domResourceType);

            var domContainerNode = this.DomContainerNode;

            domContainerNode.Add(domReadWriteResourceIdentifier);

            this.DomReadWriteResourceIdentifier = domReadWriteResourceIdentifier;
        }
        // PRIVATE METHODS //////////////////////////////////////////////////
        #region Methods
        private void CreateAndAddDomReadWriteResourceIdentifierIfNeeded()
        {
            if (this.DomReadWriteResourceIdentifier != null)
            {
                return;
            }

            var clrResourceType = typeof(TResource);
            var resourceType    = this.ServiceModel.GetResourceType(clrResourceType);

            this.ResourceType = resourceType;

            var domResourceType = DomType.CreateFromResourceType(resourceType);
            var domReadWriteResourceIdentifier = DomReadWriteResourceIdentifier.Create(domResourceType);

            var domContainerNode = this.DomContainerNode;

            domContainerNode.Add(domReadWriteResourceIdentifier);

            this.DomReadWriteResourceIdentifier = domReadWriteResourceIdentifier;
        }