// PUBLIC METHODS /////////////////////////////////////////////////// #region Assert Methods public static void Equal(ResourceIdentifier expectedApiResourceIdentifier, DomReadWriteResourceIdentifier actual) { if (expectedApiResourceIdentifier == null) { Assert.Null(actual); return; } Assert.NotNull(actual); Assert.Equal(DomNodeType.ResourceIdentifier, actual.NodeType); // Type var domType = actual.GetNode <DomNodeType, DomType>(DomNodeType.Type); DomTypeAssert.Equal(expectedApiResourceIdentifier.Type, domType); // Id var domId = actual.GetNode <DomNodeType, DomId>(DomNodeType.Id); DomIdAssert.Equal(expectedApiResourceIdentifier.Id, domId); // Meta var domMeta = actual.GetNode(DomNodeType.Meta); DomMetaAssert.Equal(expectedApiResourceIdentifier.Meta, domMeta); }
// 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; }
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); }
// 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; }
internal void TestDomReadWriteResourceIdentifierCreate(string name, ResourceIdentifier expected, DomReadWriteResourceIdentifier actual) { // Arrange // Act this.Output.WriteLine("Test Name: {0}", name); this.Output.WriteLine(String.Empty); this.OutputDomTree(actual); // Assert DomReadWriteResourceIdentifierAssert.Equal(expected, actual); }