public async Task VerifyMetaDataIsGeneratedCorrectly() { var response = await Client.GetAsync(BaseAddress + "/$metadata"); var stream = await response.Content.ReadAsStreamAsync(); IODataResponseMessage message = new ODataMessageWrapper(stream, response.Content.Headers); var reader = new ODataMessageReader(message); var edmModel = reader.ReadMetadataDocument(); Assert.Equal(4, edmModel.GetEdmVersion().Major); var container = edmModel.EntityContainer; Assert.Equal("Container", container.Name); Assert.Equal(3, container.Elements.Count()); var address = edmModel.SchemaElements.OfType <IEdmComplexType>().First(); Assert.Equal("Address", address.Name); Assert.Equal(5, address.Properties().Count()); var product = edmModel.SchemaElements.Where(e => e.Name == "Product").First() as IEdmEntityType; Assert.Single(product.Key()); Assert.Equal("ID", product.Key().First().Name); Assert.Equal(5, product.Properties().Count()); var supplier = edmModel.SchemaElements.Where(e => e.Name == "Supplier").First() as IEdmEntityType; Assert.Single(supplier.Key()); Assert.Equal("ID", supplier.Key().First().Name); Assert.Equal(7, supplier.Properties().Count()); var addressesProperty = supplier.Properties().First(p => p.Name == "Addresses").Type.AsCollection(); Assert.Equal(typeof(Address).FullName, addressesProperty.CollectionDefinition().ElementType.FullName()); // [ODATA-CSDL] // In 6.2.1 // a) If not value is specified for a property whose Type attribute does not specify a collection, // the Nuallable attribute defaults to true // b) A property whose Type attribute specifies a collection MUST NOT specify a value for the // Nullable attribute as the collection always exists, it may just be empty. Assert.True(addressesProperty.IsNullable); var tagsProperty = supplier.Properties().First(p => p.Name == "Tags").Type.AsCollection(); Assert.Equal("Edm.String", tagsProperty.CollectionDefinition().ElementType.FullName()); Assert.True(tagsProperty.IsNullable); }
public async Task VerifyMetaDataIsGeneratedCorrectly() { var response = await Client.GetAsync(this.BaseAddress + "/$metadata"); var stream = await response.Content.ReadAsStreamAsync(); IODataResponseMessage message = new ODataMessageWrapper(stream, response.Content.Headers); var reader = new ODataMessageReader(message); var edmModel = reader.ReadMetadataDocument(); Assert.Equal(4, edmModel.GetEdmVersion().Major); var container = edmModel.EntityContainer; Assert.Equal("Container", container.Name); Assert.Equal(3, container.Elements.Count()); var address = edmModel.SchemaElements.OfType <IEdmComplexType>().First(); Assert.Equal("Address", address.Name); Assert.Equal(5, address.Properties().Count()); var product = edmModel.SchemaElements.First(e => e.Name == "Product") as IEdmEntityType; Assert.Single(product.Key()); Assert.Equal("ID", product.Key().First().Name); Assert.Equal(5, product.Properties().Count()); var supplier = edmModel.SchemaElements.First(e => e.Name == "Supplier") as IEdmEntityType; Assert.Single(supplier.Key()); Assert.Equal("ID", supplier.Key().First().Name); Assert.Equal(6, supplier.Properties().Count()); var addressesProperty = supplier.Properties().First(p => p.Name == "Addresses").Type.AsCollection(); Assert.Equal(typeof(Address).FullName, addressesProperty.CollectionDefinition().ElementType.FullName()); Assert.False(addressesProperty.IsNullable); var tagsProperty = supplier.Properties().First(p => p.Name == "Tags").Type.AsCollection(); Assert.Equal("Edm.String", tagsProperty.CollectionDefinition().ElementType.FullName()); Assert.True(tagsProperty.IsNullable); }
public async Task VerifyMetaDataIsGeneratedCorrectly() { var response = await Client.GetAsync(this.BaseAddress + "/$metadata"); var stream = await response.Content.ReadAsStreamAsync(); IODataResponseMessage message = new ODataMessageWrapper(stream, response.Content.Headers); var reader = new ODataMessageReader(message); var edmModel = reader.ReadMetadataDocument(); Assert.Equal(4, edmModel.GetEdmVersion().Major); var container = edmModel.EntityContainer; Assert.Equal("Container", container.Name); Assert.Equal(5, container.Elements.Count()); var address = edmModel.SchemaElements.OfType <IEdmComplexType>().First(); Assert.Equal("Address", address.Name); Assert.Equal(5, address.Properties().Count()); var product = edmModel.SchemaElements.First(e => e.Name == "Product") as IEdmEntityType; Assert.Single(product.Key()); Assert.Equal("ID", product.Key().First().Name); Assert.Equal(5, product.Properties().Count()); var supplier = edmModel.SchemaElements.First(e => e.Name == "Supplier") as IEdmEntityType; Assert.Single(supplier.Key()); Assert.Equal("ID", supplier.Key().First().Name); Assert.Equal(7, supplier.Properties().Count()); var addressesProperty = supplier.Properties().First(p => p.Name == "Addresses").Type.AsCollection(); Assert.Equal(typeof(Address).FullName, addressesProperty.CollectionDefinition().ElementType.FullName()); Assert.False(addressesProperty.IsNullable); var tagsProperty = supplier.Properties().First(p => p.Name == "Tags").Type.AsCollection(); Assert.Equal("Edm.String", tagsProperty.CollectionDefinition().ElementType.FullName()); Assert.True(tagsProperty.IsNullable); var vocabularyAnnotations = edmModel.VocabularyAnnotations.ToList(); Action <IEdmVocabularyAnnotation> isDerivedTypeConstraintTerm = a => { Assert.Equal(ValidationVocabularyModel.DerivedTypeConstraintTerm, a.Term); }; Assert.All(vocabularyAnnotations, isDerivedTypeConstraintTerm); Assert.Equal("MainAddress", vocabularyAnnotations[2].Target.GetType().GetProperty("Name").GetValue(vocabularyAnnotations[2].Target).ToString()); Assert.Equal("Supplier", vocabularyAnnotations[3].Target.GetType().GetProperty("Name").GetValue(vocabularyAnnotations[3].Target).ToString()); Assert.Equal("supplier", vocabularyAnnotations[4].Target.GetType().GetProperty("Name").GetValue(vocabularyAnnotations[4].Target).ToString()); Assert.Equal("Suppliers", vocabularyAnnotations[5].Target.GetType().GetProperty("Name").GetValue(vocabularyAnnotations[5].Target).ToString()); Assert.Equal("MainSupplier", vocabularyAnnotations[6].Target.GetType().GetProperty("Name").GetValue(vocabularyAnnotations[6].Target).ToString()); var declaringOperation = vocabularyAnnotations[0].Target.GetType().GetProperty("DeclaringOperation") .GetValue(vocabularyAnnotations[0].Target); Assert.Equal("GetAddress", declaringOperation.GetType().GetProperty("Name").GetValue(declaringOperation).ToString()); declaringOperation = vocabularyAnnotations[1].Target.GetType().GetProperty("DeclaringOperation") .GetValue(vocabularyAnnotations[1].Target); Assert.Equal("GetAddress", declaringOperation.GetType().GetProperty("Name").GetValue(declaringOperation).ToString()); Assert.Equal(7, vocabularyAnnotations.Count); }