public static ComplexInstance GetComplexInstanceWithManyPrimitiveProperties(EdmModel model) { var primitiveValues = TestValues.CreatePrimitiveValuesWithMetadata(true).Where( (v) => { var edmPrimitiveType = v.Annotations.OfType<EntityModelTypeAnnotation>().Single().EdmModelType as IEdmPrimitiveTypeReference; var edmPrimitiveKind = edmPrimitiveType.PrimitiveKind(); if (edmPrimitiveKind != EdmPrimitiveTypeKind.None) return edmPrimitiveKind != EdmPrimitiveTypeKind.DateTimeOffset; return false; }).ToArray(); string typeName = "ComplexTypeWithManyPrimitiveProperties"; var complexType = model.ComplexType(typeName); for (int i = 0; i < primitiveValues.Count(); ++i) { complexType.Property("property" + i, primitiveValues[i].GetAnnotation<EntityModelTypeAnnotation>().EdmModelType); } var complexValue = PayloadBuilder.ComplexValue("TestModel." + typeName).WithTypeAnnotation(complexType); for (int j = 0; j < primitiveValues.Count(); ++j) { complexValue.PrimitiveProperty("property" + j, primitiveValues[j].ClrValue); } return complexValue; }
public void CollectionReaderAtomTest() { EdmModel edmModel = new EdmModel(); EdmComplexType edmComplexTypeCity = edmModel.ComplexType("CityType", ModelNamespace); edmComplexTypeCity.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(true)); edmModel.Fixup(); IEnumerable<PayloadReaderTestDescriptor> testDescriptors = new[] { #region primitive collection // Empty primitive collection. new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings) { PayloadElement = new PrimitiveCollection().CollectionName(null), }, // Yet another empty collection with extra elements not in the d namespace. new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings) { PayloadElement = new PrimitiveCollection().CollectionName(null) .XmlRepresentation("<m:value><c:foo xmlns:c='customns'>bar</c:foo></m:value>"), }, // Empty collection with text inside the collection element. new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings) { PayloadElement = new PrimitiveCollection().CollectionName(null) .XmlRepresentation("<m:value>foo</m:value>"), }, // Empty collection with insignificant nodes inside the collection element. new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings) { PayloadElement = new PrimitiveCollection().CollectionName(null) .XmlRepresentation("<m:value><!-- some comment --> </m:value>"), }, // TODO:: Currently the test infrastructure drops any top level node other than the root element. // Once the test infrstructure is fixed, we should add some test to verify that insignificant nodes // before the collection start are discarded. // Verify that anything which is not in the d namespace, after the collection start, is discarded. new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings) { PayloadElement = new PrimitiveCollection( new PrimitiveValue[] { PayloadBuilder.PrimitiveValue("vineet"), } ).CollectionName(null) .XmlRepresentation(@"<m:value> <!-- some comment --> <c:foo xmlns:c='customns'>bar</c:foo> <m:element>vineet</m:element> <c:foo xmlns:c='customns'>bar</c:foo> </m:value>"), }, // Verify that insignificant nodes after the collection end are discarded. new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings) { PayloadElement = new PrimitiveCollection().CollectionName(null) .XmlRepresentation(@" <m:value> </m:value> <!-- some comment --> some text "), }, // Primitive collection with 'element' as collection name. new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings) { PayloadElement = new PrimitiveCollection( new PrimitiveValue[] { PayloadBuilder.PrimitiveValue("vineet"), } ).CollectionName(null), }, // Collection with 'element' as collection name. new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings) { PayloadElement = new PrimitiveCollection( new PrimitiveValue[] { PayloadBuilder.PrimitiveValue("redmond"), PayloadBuilder.PrimitiveValue(""), PayloadBuilder.PrimitiveValue("seattle"), } ).XmlRepresentation(@"<m:value> <m:element>redmond</m:element> <m:element/> <m:element>seattle</m:element> </m:value>") .CollectionName(null), }, #endregion #region complex collection // yet another empty complex collection new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings) { PayloadElement = new ComplexInstanceCollection( PayloadBuilder.ComplexValue("TestModel.CityType").PrimitiveProperty("Name", null) ).CollectionName(null), }, // Verify that anything which is not in the d namespace, after the collection start, is discarded. new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings) { PayloadElement = new ComplexInstanceCollection( PayloadBuilder.ComplexValue("TestModel.CityType").Property("City", PayloadBuilder.PrimitiveValue("Vienna")) ).CollectionName(null) .XmlRepresentation(@"<m:value> <!-- some comment --> <c:foo xmlns:c='customns'>bar</c:foo> <m:element m:type='TestModel.CityType'> <c:foo xmlns:c='customns'>bar</c:foo> <d:City>Vienna</d:City> <!-- some more comments --> </m:element> <c:foo xmlns:c='customns'>bar</c:foo> </m:value>"), }, // Verify that insignificant nodes after the collection end are discarded. new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings) { PayloadElement = new ComplexInstanceCollection( PayloadBuilder.ComplexValue("TestModel.CityType").Property("City", PayloadBuilder.PrimitiveValue("Vienna"))) .CollectionName(null) .XmlRepresentation(@" <m:value> <m:element m:type='TestModel.CityType'> <d:City>Vienna</d:City> </m:element> </m:value> <!-- some comment --> some text "), }, #endregion #region no metadata // primitive collection with no expected type and no metadata. new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings) { PayloadElement = new PrimitiveCollection( PayloadBuilder.PrimitiveValue(1), PayloadBuilder.PrimitiveValue(2) ).CollectionName(null), }, // complex collection with no expected type and no metadata. new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings) { PayloadElement = new ComplexInstanceCollection( PayloadBuilder.ComplexValue("TestModel.CityType").Property("Name", PayloadBuilder.PrimitiveValue("Vienna")), PayloadBuilder.ComplexValue("TestModel.CityType").Property("Name", PayloadBuilder.PrimitiveValue("Am Euro Platz")) ).CollectionName(null), }, #endregion }; this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.AtomFormatConfigurations, (testDescriptor, testConfiguration) => { testDescriptor.RunTest(testConfiguration); }); }
public void TopLevelPropertiesWithMetadataTest() { IEnumerable<PayloadReaderTestDescriptor> testDescriptors = PayloadReaderTestDescriptorGenerator.CreatePrimitiveValueTestDescriptors(this.Settings); testDescriptors = testDescriptors.Concat(PayloadReaderTestDescriptorGenerator.CreateComplexValueTestDescriptors(this.Settings, true)); testDescriptors = testDescriptors.Concat(PayloadReaderTestDescriptorGenerator.CreateCollectionTestDescriptors(this.Settings, true)); testDescriptors = testDescriptors.Select(collectionTestDescriptor => collectionTestDescriptor.InProperty("propertyName")); testDescriptors = testDescriptors.SelectMany(td => this.PayloadGenerator.GenerateReaderPayloads(td)); // Limit to only top-level property payloads testDescriptors = testDescriptors.Where(td => td.PayloadElement is PropertyInstance); // Add a couple of invalid cases which use a standard model EdmModel model = new EdmModel(); model.ComplexType("UnusedComplexType"); EdmEntityType unusedEntityType = model.EntityType("UnusedEntityType"); unusedEntityType.AddKeys(unusedEntityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, isNullable: false)); unusedEntityType.Property("Name", EdmPrimitiveTypeKind.String, isNullable: false); EdmEntityType streamPropertyEntityType = model.EntityType("EntityTypeWithStreamProperty"); streamPropertyEntityType.AddKeys(streamPropertyEntityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, isNullable: false)); streamPropertyEntityType.AddStructuralProperty("Video", EdmPrimitiveTypeKind.Stream, isNullable: false); streamPropertyEntityType.Property("NonStreamProperty", EdmPrimitiveTypeKind.Boolean, isNullable: false); EdmEntityType navigationPropertyEntityType = model.EntityType("EntityTypeWithNavigationProperty"); navigationPropertyEntityType.AddKeys(navigationPropertyEntityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, isNullable: false)); navigationPropertyEntityType.NavigationProperty("Navigation", streamPropertyEntityType); model.Fixup(); EdmEntityContainer container = model.EntityContainer as EdmEntityContainer; EdmFunction nameFunction = new EdmFunction(container.Namespace, "NameFunctionImport", EdmCoreModel.Instance.GetInt32(false), false /*isBound*/, null, false /*isComposable*/); model.AddElement(nameFunction); container.AddFunctionImport("NameFunctionImport", nameFunction); model.Fixup(); var videoPropertyType = model.GetEntityType("TestModel.EntityTypeWithStreamProperty").Properties().Single(p => p.Name == "Video").Type; var explicitTestDescriptors = new[] { // Non existant type name new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.Property("propertyName", PayloadBuilder.ComplexValue("TestModel.NonExistantType")), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_UnrecognizedTypeName", "TestModel.NonExistantType"), // This test has different meaning in JSON-L (no expected type + non-existent typename) SkipTestConfiguration = (tc) => tc.Format == ODataFormat.Json, }, // Existing type name without namespace new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.Property("propertyName", PayloadBuilder.ComplexValue("UnusedComplexType")), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_UnrecognizedTypeName", "UnusedComplexType"), // This test has different meaning in JSON-L (no expected type + non-existent typename) SkipTestConfiguration = (tc) => tc.Format == ODataFormat.Json, }, // Existing type of wrong kind new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.Property("propertyName", PayloadBuilder.ComplexValue("TestModel.UnusedEntityType")), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_IncorrectValueTypeKind", "TestModel.UnusedEntityType", "Entity"), // This test has different meaning in JSON-L SkipTestConfiguration = (tc) => tc.Format == ODataFormat.Json, }, // A stream is not allowed in a property with a non-stream property kind. new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.Entity("TestModel.EntityTypeWithStreamProperty").StreamProperty("NonStreamProperty", "http://readlink", "http://editlink"), PayloadEdmModel = model, ExpectedResultCallback = tc => new PayloadReaderTestExpectedResult(this.Settings.ExpectedResultSettings) { ExpectedException = tc.Format == ODataFormat.Atom ? tc.IsRequest ? null : ODataExpectedExceptions.ODataException("ValidationUtils_MismatchPropertyKindForStreamProperty", "NonStreamProperty") : tc.Format == ODataFormat.Json ? ODataExpectedExceptions.ODataException("ODataJsonLightEntryAndFeedDeserializer_PropertyWithoutValueWithWrongType", "NonStreamProperty", "Edm.Boolean") : ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "PrimitiveValue", "StartObject") }, }, // Top-level property of stream type is not allowed new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.PrimitiveProperty("Video", 42).ExpectedPropertyType(videoPropertyType), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeStream"), }, // Top-level deferred navigation property is not allowed new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.PrimitiveProperty("Video", 42).ExpectedPropertyType(streamPropertyEntityType), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityKind"), }, // Top-level expanded navigation property is not allowed new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.PrimitiveProperty("Video", 42).ExpectedPropertyType(streamPropertyEntityType), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityKind"), }, }; testDescriptors = testDescriptors.Concat(explicitTestDescriptors); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations, (testDescriptor, testConfiguration) => { var property = testDescriptor.PayloadElement as PropertyInstance; if (property != null && testConfiguration.Format == ODataFormat.Atom) { property.Name = null; } testDescriptor.RunTest(testConfiguration); }); }
public void ComplexValueIgnorePropertyNullValuesTest() { var versions = new Version[] { null, new Version(4, 0), }; EdmModel edmModel = new EdmModel(); IEdmComplexType countryRegionType = edmModel.ComplexType("CountryRegion") .Property("Name", EdmPrimitiveTypeKind.String) .Property("CountryRegionCode", EdmPrimitiveTypeKind.String); IEdmComplexType countryRegionNullType = edmModel.ComplexType("CountryRegionNull") .Property("Name", EdmPrimitiveTypeKind.String) .Property("CountryRegionCode", EdmPrimitiveTypeKind.String); IEdmComplexType addressType = edmModel.ComplexType("Address") .Property("Street", EdmPrimitiveTypeKind.String) .Property("StreetNull", EdmCoreModel.Instance.GetString(true) as EdmTypeReference) .Property("Numbers", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetInt32(false)) as EdmTypeReference) .Property("CountryRegion", new EdmComplexTypeReference(countryRegionType, false)) .Property("CountryRegionNull", new EdmComplexTypeReference(countryRegionNullType, true)); edmModel.EntityType("Customer") .KeyProperty("ID", EdmCoreModel.Instance.GetInt32(false) as EdmTypeReference) .Property("Address", new EdmComplexTypeReference(addressType, false)); edmModel.Fixup(); this.CombinatorialEngineProvider.RunCombinations( new ODataNullValueBehaviorKind[] { ODataNullValueBehaviorKind.Default, ODataNullValueBehaviorKind.DisableValidation, ODataNullValueBehaviorKind.IgnoreValue }, versions, versions, TestReaderUtils.ODataBehaviorKinds, (nullPropertyValueReaderBehavior, dataServiceVersion, edmVersion, behaviorKind) => { edmModel.SetEdmVersion(edmVersion); // Now we set the 'IgnoreNullValues' annotation on all properties IEdmComplexType edmAddressType = (IEdmComplexType)edmModel.FindType("TestModel.Address"); foreach (IEdmStructuralProperty edmProperty in edmAddressType.StructuralProperties()) { edmModel.SetNullValueReaderBehavior(edmProperty, nullPropertyValueReaderBehavior); } EntityInstance customerPayload = PayloadBuilder.Entity("TestModel.Customer") .PrimitiveProperty("ID", 1) .Property("Address", PayloadBuilder.ComplexValue("TestModel.Address") .PrimitiveProperty("Street", "One Microsoft Way") .PrimitiveProperty("StreetNull", "One Microsoft Way") .Property("Numbers", PayloadBuilder.PrimitiveMultiValue("Collection(Edm.Int32)").Item(1).Item(2)) .Property("CountryRegion", PayloadBuilder.ComplexValue("TestModel.CountryRegion") .PrimitiveProperty("Name", "Austria") .PrimitiveProperty("CountryRegionCode", "AUT")) .Property("CountryRegionNull", PayloadBuilder.ComplexValue("TestModel.CountryRegionNull") .PrimitiveProperty("Name", "Austria") .PrimitiveProperty("CountryRegionCode", "AUT"))); var testCases = new[] { // Complex types that are not nullable should not allow null values. // Null primitive property in the payload and non-nullable property in the model new IgnoreNullValueTestCase { PropertyName = "Street", ExpectedResponseException = ODataExpectedExceptions.ODataException("ReaderValidationUtils_NullNamedValueForNonNullableType", "Street", "Edm.String"), }, // Null complex property in the payload and non-nullable property in the model new IgnoreNullValueTestCase { PropertyName = "CountryRegion", ExpectedResponseException = ODataExpectedExceptions.ODataException("ReaderValidationUtils_NullNamedValueForNonNullableType", "CountryRegion", "TestModel.CountryRegion"), }, // Null collection property in the payload and non-nullable property in the model new IgnoreNullValueTestCase { PropertyName = "Numbers", ExpectedResponseException = ODataExpectedExceptions.ODataException("ReaderValidationUtils_NullNamedValueForNonNullableType", "Numbers", "Collection(Edm.Int32)"), }, // Complex types that are nullable should allow null values. // Null primitive property in the payload and nullable property in the model new IgnoreNullValueTestCase { PropertyName = "StreetNull", }, // Null complex property in the payload and nullable property in the model new IgnoreNullValueTestCase { PropertyName = "CountryRegionNull", }, }; Func<IgnoreNullValueTestCase, ReaderTestConfiguration, PayloadReaderTestDescriptor> createTestDescriptor = (testCase, testConfig) => { EntityInstance payloadValue = customerPayload.DeepCopy(); ComplexInstance payloadAddressValue = ((ComplexProperty)payloadValue.GetProperty("Address")).Value; SetToNull(payloadAddressValue, testCase.PropertyName); ComplexInstance resultValue = payloadValue; if (testConfig.IsRequest && nullPropertyValueReaderBehavior == ODataNullValueBehaviorKind.IgnoreValue) { resultValue = customerPayload.DeepCopy(); ComplexInstance resultAddressValue = ((ComplexProperty)resultValue.GetProperty("Address")).Value; resultAddressValue.Remove(resultAddressValue.GetProperty(testCase.PropertyName)); } return new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = payloadValue, PayloadEdmModel = edmModel, ExpectedResultPayloadElement = tc => { if (tc.Format == ODataFormat.Json) { // under the client knob ODL will compute edit links, ids, etc // so we need to update the expected payload if (tc.RunBehaviorKind == TestODataBehaviorKind.WcfDataServicesClient) { var entity = resultValue as EntityInstance; if (entity != null) { if (!tc.IsRequest) { entity.Id = "http://odata.org/test/Customer(1)"; entity.EditLink = "http://odata.org/test/Customer(1)"; entity.WithSelfLink("http://odata.org/test/Customer(1)"); } } } var tempDescriptor = new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = resultValue, PayloadEdmModel = edmModel, }; JsonLightPayloadElementFixup.Fixup(tempDescriptor); return tempDescriptor.PayloadElement; } return resultValue; }, ExpectedException = (testConfig.IsRequest && nullPropertyValueReaderBehavior != ODataNullValueBehaviorKind.Default) ? null : testCase.ExpectedResponseException }; }; this.CombinatorialEngineProvider.RunCombinations( testCases, this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations, (testCase, testConfiguration) => { testConfiguration = testConfiguration.CloneAndApplyBehavior(behaviorKind); testConfiguration.MessageReaderSettings.BaseUri = null; PayloadReaderTestDescriptor testDescriptor = createTestDescriptor(testCase, testConfiguration); testDescriptor.RunTest(testConfiguration); }); }); }
public void ComplexValueWithMetadataTest() { // Use some standard complex value payloads first IEnumerable<PayloadReaderTestDescriptor> testDescriptors = PayloadReaderTestDescriptorGenerator.CreateComplexValueTestDescriptors(this.Settings, true); // Add metadata validation tests EdmModel model = new EdmModel(); var innerComplexType = model.ComplexType("InnerComplexType"); innerComplexType.AddStructuralProperty("name", EdmCoreModel.Instance.GetString(true)); var complexType = model.ComplexType("ComplexType"); complexType.AddStructuralProperty("number", EdmPrimitiveTypeKind.Int32); complexType.AddStructuralProperty("string", EdmCoreModel.Instance.GetString(true)); complexType.AddStructuralProperty("complex", MetadataUtils.ToTypeReference(innerComplexType, true)); var entityType = model.EntityType("EntityType"); entityType.KeyProperty("Id", EdmCoreModel.Instance.GetInt32(false)); model.Fixup(); // Test that different types of properties not present in the metadata all fail IEnumerable<PropertyInstance> undeclaredPropertyTestCases = new PropertyInstance[] { PayloadBuilder.PrimitiveProperty("undeclared", 42), PayloadBuilder.Property("undeclared", PayloadBuilder.ComplexValue(innerComplexType.FullName())), PayloadBuilder.Property("undeclared", PayloadBuilder.PrimitiveMultiValue(EntityModelUtils.GetCollectionTypeName("Edm.Int32"))), PayloadBuilder.Property("undeclared", PayloadBuilder.ComplexMultiValue(EntityModelUtils.GetCollectionTypeName("TestModel.InnerComplexType"))), }; testDescriptors = testDescriptors.Concat( undeclaredPropertyTestCases.Select(tc => { return new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.ComplexValue(complexType.FullName()).WithTypeAnnotation(complexType) .Property(tc), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_PropertyDoesNotExistOnType", "undeclared", "TestModel.ComplexType"), }; })); testDescriptors = testDescriptors.Concat(new[] { // Property which should take typename not from value but from the parent metadata new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.ComplexValue(complexType.FullName()).WithTypeAnnotation(complexType) .Property("complex", PayloadBuilder.ComplexValue(innerComplexType.FullName()).PrimitiveProperty("name", null) .JsonRepresentation("{ \"name\" : null }").XmlRepresentation("<d:name m:null=\"true\" />") .AddAnnotation(new SerializationTypeNameTestAnnotation() { TypeName = null })), PayloadEdmModel = model, }, // Property which is declared in the metadata but with a different type new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.ComplexValue(complexType.FullName()).WithTypeAnnotation(complexType) .Property("complex", PayloadBuilder.ComplexValue(complexType.FullName())), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_IncompatibleType", "TestModel.ComplexType", "TestModel.InnerComplexType"), }, // Property which is declared in the metadata but with a wrong kind new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.ComplexValue(complexType.FullName()).WithTypeAnnotation(complexType) .Property("complex", PayloadBuilder.ComplexValue(entityType.FullName())), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_IncorrectTypeKind", "TestModel.EntityType", "Complex", "Entity"), }, new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.ComplexValue("").WithTypeAnnotation(complexType), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_UnrecognizedTypeName", string.Empty) }, new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.ComplexValue("TestModel.NonExistant").WithTypeAnnotation(complexType), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_UnrecognizedTypeName", "TestModel.NonExistant"), }, }); // Wrap the complex type in a property testDescriptors = testDescriptors .Select((td, index) => new PayloadReaderTestDescriptor(td) { PayloadDescriptor = td.PayloadDescriptor.InProperty("propertyName" + index)}) .SelectMany(td => this.PayloadGenerator.GenerateReaderPayloads(td)); // Handcrafted cases testDescriptors = testDescriptors.Concat(new[] { // Top-level complex property without expected type new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.Property("property", PayloadBuilder.ComplexValue(complexType.FullName()).PrimitiveProperty("number", 42)), PayloadEdmModel = model }, }); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations, (testDescriptor, testConfiguration) => { var property = testDescriptor.PayloadElement as PropertyInstance; if (property != null && testConfiguration.Format == ODataFormat.Atom) { property.Name = null; } testDescriptor.RunTest(testConfiguration); }); }
public void CollectionWithoutExpectedTypeAndWithMetadataTest() { // For now only top-level property can do this. // TODO: Once we have open properties, these test cases apply to those as well, then probably move these to the top-level property // tests and share them from the open properties test, or possible keep both here. IEnumerable<PayloadReaderTestDescriptor> testDescriptors = this.CreateCollectionPayloadsWithMetadata(true); testDescriptors = testDescriptors.Concat(this.CreateInvalidCollectionsWithTypeNames(false)); EdmModel model = new EdmModel(); EdmComplexType itemComplexType = model.ComplexType("ItemComplexType").Property("stringProperty", EdmPrimitiveTypeKind.String); model = model.Fixup(); testDescriptors = testDescriptors.Concat(new[] { // No expected type specified, the one in the payload should be enough new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.PrimitiveMultiValue(EntityModelUtils.GetCollectionTypeName("Edm.String")), PayloadEdmModel = model, }, new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.ComplexMultiValue(EntityModelUtils.GetCollectionTypeName("TestModel.ItemComplexType")), PayloadEdmModel = model, }, // Verify that the item type is inherited from the collection to its items if the item doesn't specify the type new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.ComplexMultiValue(EntityModelUtils.GetCollectionTypeName("TestModel.ItemComplexType")) .Item(PayloadBuilder .ComplexValue() .PrimitiveProperty("stringProperty", "test") .WithTypeAnnotation(itemComplexType) .AddAnnotation(new SerializationTypeNameTestAnnotation() { TypeName = null })), // Add item which does not have the type name PayloadEdmModel = model }, new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.ComplexMultiValue(EntityModelUtils.GetCollectionTypeName("TestModel.ItemComplexType")) .Item(PayloadBuilder .ComplexValue("TestModel.ItemComplexType") .PrimitiveProperty("stringProperty", "test") .WithTypeAnnotation(itemComplexType)) // Add an item which does have the type name .Item(PayloadBuilder .ComplexValue() .PrimitiveProperty("stringProperty", "test") .WithTypeAnnotation(itemComplexType) .AddAnnotation(new SerializationTypeNameTestAnnotation() { TypeName = null })), // Add item which does not have the type name PayloadEdmModel = model } }); // Wrap the value in a top-level property without expected type (can't use the .InProperty here, since that would put the expected type on it) testDescriptors = testDescriptors.Select(td => new PayloadReaderTestDescriptor(td) { PayloadElement = PayloadBuilder.Property("propertyName", td.PayloadElement) }); // Fill in type names for expected result from the type annotations testDescriptors = testDescriptors.Select(td => { td.ExpectedResultNormalizers.Add(tc => FillTypeNamesFromTypeAnnotationsPayloadElementVisitor.Visit); return td; }); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, // The version dependent behavior tests are implemented in the format specific tests. this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations, (testDescriptor, testConfiguration) => { testDescriptor.PayloadNormalizers.Add((tc) => tc.Format == ODataFormat.Json ? ReplaceExpectedTypeWithContextUriVisitor.VisitPayload : (Func<ODataPayloadElement, ODataPayloadElement>)null); var property = testDescriptor.PayloadElement as PropertyInstance; if (property != null && testConfiguration.Format == ODataFormat.Atom) { property.Name = null; } testDescriptor.RunTest(testConfiguration); }); }
public void DuplicatePropertyNamesTest() { PropertyInstance primitiveProperty = PayloadBuilder.PrimitiveProperty("DuplicateProperty", 42); PropertyInstance complexProperty = PayloadBuilder.Property("DuplicateProperty", PayloadBuilder.ComplexValue("TestModel.DuplicateComplexType").PrimitiveProperty("Name", "foo")); PropertyInstance collectionProperty = PayloadBuilder.Property("DuplicateProperty", PayloadBuilder.PrimitiveMultiValue(EntityModelUtils.GetCollectionTypeName("Edm.String")).WithTypeAnnotation(EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(false)))); PropertyInstance[] allProperties = new[] { primitiveProperty, complexProperty, collectionProperty }; PropertyInstance[] propertiesWithPossibleDuplication = new[] { primitiveProperty, complexProperty }; PropertyInstance[] propertiesWithNoDuplication = new[] { collectionProperty }; IEnumerable<DuplicatePropertySet> duplicatePropertySets; // Those which may allow duplication duplicatePropertySets = propertiesWithPossibleDuplication .Variations(2).Select(properties => new DuplicatePropertySet { Properties = properties, DuplicationPotentiallyAllowed = true }); // Then for each in those which don't allow duplication try it against all the others duplicatePropertySets = duplicatePropertySets.Concat(propertiesWithNoDuplication.SelectMany( propertyWithNoDuplication => allProperties.SelectMany(otherProperty => new[] { new DuplicatePropertySet { Properties = new [] { propertyWithNoDuplication, otherProperty }, DuplicationPotentiallyAllowed = false }, new DuplicatePropertySet { Properties = new [] { otherProperty, propertyWithNoDuplication }, DuplicationPotentiallyAllowed = false }, }))); this.CombinatorialEngineProvider.RunCombinations( duplicatePropertySets, new bool[] { false, true }, new bool[] { true, false }, this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations, (duplicatePropertySet, allowDuplicateProperties, useMetadata, testConfiguration) => { EdmModel model = new EdmModel(); var complexType = model.ComplexType("DuplicateComplexType"); complexType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); model.Fixup(); PropertyInstance firstProperty = duplicatePropertySet.Properties.ElementAt(0); PropertyInstance secondProperty = duplicatePropertySet.Properties.ElementAt(1); // Non-metadata reading is not possible in JSON if (!useMetadata && (testConfiguration.Format == ODataFormat.Json)) { return; } // If we will have metadata then we can only allow combinations of the same kind if (useMetadata) { if (firstProperty.ElementType != secondProperty.ElementType) { return; } } // Copy the test config testConfiguration = new ReaderTestConfiguration(testConfiguration); if (allowDuplicateProperties) { testConfiguration.MessageReaderSettings.EnableODataServerBehavior(); } // Create a descriptor with the first property PayloadReaderTestDescriptor testDescriptor = new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = firstProperty, PayloadEdmModel = useMetadata ? model : null }; // Now generate entity around it testDescriptor = testDescriptor.InComplexValue(5, 5); // Now add the second property to it ((ComplexInstance)testDescriptor.PayloadElement).Add(secondProperty); // [Astoria-ODataLib-Integration] Parsing of URLs on OData recognized places may fail, but Astoria server doesn't // Server does not read named stream links for Atom payload therefore the expected payload needs to be normalized if (testConfiguration.Format == ODataFormat.Atom) { testDescriptor.ExpectedResultNormalizers.Add(config => (payloadElement => WcfDsServerPayloadElementNormalizer.Normalize(payloadElement, ODataFormat.Atom, testDescriptor.PayloadEdmModel as EdmModel))); } // We expect failure only if we don't allow duplicates or if the property kind doesn't allow duplicates ever if ((!duplicatePropertySet.DuplicationPotentiallyAllowed || !allowDuplicateProperties)) { testDescriptor.ExpectedException = ODataExpectedExceptions.ODataException("DuplicatePropertyNamesChecker_DuplicatePropertyNamesNotAllowed", "DuplicateProperty"); } IEnumerable<PayloadReaderTestDescriptor> testDescriptors = new PayloadReaderTestDescriptor[] { testDescriptor.InProperty("TopLevelProperty"), testDescriptor.InProperty("ComplexProperty").InEntity(2, 2), testDescriptor.InCollection(5, 5).InProperty("TopLevelCollection"), }; this.CombinatorialEngineProvider.RunCombinations( testDescriptors, td => { var property = td.PayloadElement as PropertyInstance; if (property != null && testConfiguration.Format == ODataFormat.Atom) { property.Name = null; } td.RunTest(testConfiguration); }); }); }
public IEnumerable<PayloadReaderTestDescriptor> CreateInvalidCollectionsWithTypeNames(bool expectedTypeWillBeUsed) { EdmModel model = new EdmModel(); EdmComplexType itemComplexType = model.ComplexType("ItemComplexType"); model.ComplexType("ExtraComplexType"); model = model.Fixup(); // Add invalid cases var testDescriptors = new[] { // Invalid collection type name new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.PrimitiveMultiValue("") .WithTypeAnnotation(EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetInt32(false))), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_UnrecognizedTypeName", string.Empty), }, new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.PrimitiveMultiValue(EntityModelUtils.GetCollectionTypeName("")) .WithTypeAnnotation(EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetInt32(false))), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_UnrecognizedTypeName", EntityModelUtils.GetCollectionTypeName("")), }, // Invalid collection type name new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.PrimitiveMultiValue("collection(Edm.Int32)") .WithTypeAnnotation(EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetInt32(false))), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_UnrecognizedTypeName", "collection(Edm.Int32)"), }, new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.PrimitiveMultiValue("foo") .WithTypeAnnotation(EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetInt32(false))), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_UnrecognizedTypeName", "foo"), }, // Non existant type name new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.PrimitiveMultiValue(EntityModelUtils.GetCollectionTypeName("TestModel.NonExistant")) .WithTypeAnnotation(EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetInt32(false))), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_UnrecognizedTypeName", EntityModelUtils.GetCollectionTypeName("TestModel.NonExistant")), }, // Type of the item differs from the type of the collection new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.PrimitiveMultiValue(EntityModelUtils.GetCollectionTypeName("Edm.String")) .Item(-42) .WithTypeAnnotation(EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(true))), PayloadEdmModel = model, ExpectedResultCallback = tc => new PayloadReaderTestExpectedResult(this.Settings.ExpectedResultSettings) { ExpectedException = tc.Format == ODataFormat.Atom ? ODataExpectedExceptions.ODataException("ValidationUtils_IncompatibleType", "Edm.Int32", "Edm.String") : ODataExpectedExceptions.ODataException("ReaderValidationUtils_CannotConvertPrimitiveValue", "-42", "Edm.String") }, }, new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.ComplexMultiValue(EntityModelUtils.GetCollectionTypeName("TestModel.ItemComplexType")) .Item(PayloadBuilder.ComplexValue("TestModel.ExtraComplexType")) .WithTypeAnnotation(EdmCoreModel.GetCollection(itemComplexType.ToTypeReference())), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_IncompatibleType", "TestModel.ExtraComplexType", "TestModel.ItemComplexType"), } }; if (expectedTypeWillBeUsed) { testDescriptors = testDescriptors.Concat(new[] { // Type differs from the declared/expected type new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.PrimitiveMultiValue(EntityModelUtils.GetCollectionTypeName("Edm.String")) .WithTypeAnnotation(EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetInt32(false))), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_IncompatibleType", EntityModelUtils.GetCollectionTypeName("Edm.String"), EntityModelUtils.GetCollectionTypeName("Edm.Int32")), }, }).ToArray(); } foreach (var testDescriptor in testDescriptors) { testDescriptor.PayloadNormalizers.Add((tc) => tc.Format == ODataFormat.Json ? AddJsonLightTypeAnnotationToCollectionsVisitor.Normalize : (Func<ODataPayloadElement, ODataPayloadElement>)null); } return testDescriptors; }
public void CollectionWithHeterogenousItemsErrorTest() { EdmModel model = new EdmModel(); var complexType1 = model.ComplexType("ComplexTypeWithStringAndInteger32") .Property("Property1", EdmCoreModel.Instance.GetString(true) as EdmTypeReference) .Property("Property2", EdmCoreModel.Instance.GetInt32(false) as EdmTypeReference); var complexType2 = model.ComplexType("ComplexTypeWithStringAndDateTime") .Property("Property1", EdmCoreModel.Instance.GetString(true) as EdmTypeReference) .Property("Property2", EdmPrimitiveTypeKind.DateTimeOffset); model.Fixup(); IEnumerable<PayloadReaderTestDescriptor> testDescriptors = new[] { // Primitive collection containing items of different primitive types new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.PrimitiveMultiValue(EntityModelUtils.GetCollectionTypeName("Edm.Int32")).Item(1).Item(true).Item(2).WithTypeAnnotation(EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetInt32(false))), PayloadEdmModel = model, ExpectedResultCallback = tc => new PayloadReaderTestExpectedResult(this.Settings.ExpectedResultSettings) { ExpectedException = tc.Format == ODataFormat.Atom ? ODataExpectedExceptions.ODataException("ValidationUtils_IncompatibleType", "Edm.Boolean", "Edm.Int32") : ODataExpectedExceptions.ODataException("ReaderValidationUtils_CannotConvertPrimitiveValue", "True", "Edm.Int32") } }, // Complex collection containing items of different complex type (correct type attribute value) new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.ComplexMultiValue(EntityModelUtils.GetCollectionTypeName(complexType1.FullName())) .Item(PayloadBuilder.ComplexValue(complexType1.FullName()).PrimitiveProperty("Property1", "Foo").PrimitiveProperty("Property2", -1)) .Item(PayloadBuilder.ComplexValue(complexType2.FullName()).PrimitiveProperty("Property1", "Foo").PrimitiveProperty("Property2", DateTimeOffset.Now)) .WithTypeAnnotation(EdmCoreModel.GetCollection(complexType1.ToTypeReference())), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_IncompatibleType", "TestModel.ComplexTypeWithStringAndDateTime", "TestModel.ComplexTypeWithStringAndInteger32"), }, // Complex collection containing items of different complex type (incorrect type attribute value) new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.ComplexMultiValue(EntityModelUtils.GetCollectionTypeName(complexType2.FullName())) .Item(PayloadBuilder.ComplexValue(complexType2.FullName()).PrimitiveProperty("Property1", "Foo").PrimitiveProperty("Property2", -1)) .Item(PayloadBuilder.ComplexValue(complexType2.FullName()).PrimitiveProperty("Property1", "Foo").PrimitiveProperty("Property2", DateTimeOffset.Now)) .WithTypeAnnotation(EdmCoreModel.GetCollection(complexType2.ToTypeReference())), PayloadEdmModel = model, ExpectedResultCallback = tc => new PayloadReaderTestExpectedResult(this.Settings.ExpectedResultSettings) { ExpectedException = tc.Format == ODataFormat.Atom ? ODataExpectedExceptions.ODataException("ValidationUtils_IncompatibleType", "Edm.Int32", "Edm.DateTimeOffset") : ODataExpectedExceptions.ODataException("ReaderValidationUtils_CannotConvertPrimitiveValue", "-1", "Edm.DateTimeOffset") } }, }; this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations, (testDescriptor, testConfiguration) => { if (testConfiguration.Format == ODataFormat.Atom) { testDescriptor = testDescriptor.InProperty(); } else { testDescriptor = testDescriptor.InProperty("RootProperty"); } testDescriptor.RunTest(testConfiguration); }); }
public static ODataProperty[] CreateDefaultCollectionProperties(EdmModel model = null) { if (model != null) { var addressType = model.ComplexType("AddressType", "My") .Property("Street", EdmPrimitiveTypeKind.String) .Property("City", EdmPrimitiveTypeKind.String); model.EntityType("EntryWithCollectionProperties", "TestModel") .Property("EmptyCollection", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false)))) .Property("PrimitiveCollection", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetInt32(false)))) .Property("IntCollectionNoTypeName", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetInt32(false)))) .Property("StringCollectionNoTypeName", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false)))) .Property("GeographyCollectionNoTypeName", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.Geography, false)))) .Property("ComplexCollection", new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(addressType, true)))); } return new ODataProperty[] { new ODataProperty { Name = "EmptyCollection", Value = new ODataCollectionValue() { TypeName = EntityModelUtils.GetCollectionTypeName("Edm.String"), } }, new ODataProperty { Name = "PrimitiveCollection", Value = new ODataCollectionValue() { TypeName = EntityModelUtils.GetCollectionTypeName("Edm.Int32"), Items = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } } }, new ODataProperty { Name = "IntCollectionNoTypeName", Value = new ODataCollectionValue() { TypeName = EntityModelUtils.GetCollectionTypeName("Edm.Int32"), Items = new int[] { 0, 1, 2 } } }, new ODataProperty { Name = "StringCollectionNoTypeName", Value = new ODataCollectionValue() { TypeName = EntityModelUtils.GetCollectionTypeName("Edm.String"), Items = new string[] { "One", "Two", "Three" } } }, new ODataProperty { Name = "GeographyCollectionNoTypeName", Value = new ODataCollectionValue() { TypeName = EntityModelUtils.GetCollectionTypeName("Edm.Geography"), Items = new object[] { ObjectModelUtils.GeographyCollectionValue, ObjectModelUtils.GeographyLineStringValue, ObjectModelUtils.GeographyMultiLineStringValue, ObjectModelUtils.GeographyMultiPointValue, ObjectModelUtils.GeographyMultiPolygonValue, ObjectModelUtils.GeographyPointValue, ObjectModelUtils.GeographyPolygonValue, ObjectModelUtils.GeographyValue } } }, new ODataProperty { Name = "ComplexCollection", Value = new ODataCollectionValue() { TypeName = EntityModelUtils.GetCollectionTypeName("My.AddressType"), Items = new [] { new ODataComplexValue() { TypeName = "My.AddressType", Properties = new [] { new ODataProperty() { Name = "Street", Value = "One Redmond Way" }, new ODataProperty() { Name = "City", Value = " Redmond" }, } }, new ODataComplexValue() { TypeName = null, Properties = new [] { new ODataProperty() { Name = "Street", Value = "Am Euro Platz 3" }, new ODataProperty() { Name = "City", Value = "Vienna " }, } } } } }, }; }
public static ODataProperty[] CreateDefaultComplexProperties(EdmModel model = null) { if (model != null) { var addressType = model.ComplexType("AddressType", "My") .Property("Street", EdmPrimitiveTypeKind.String) .Property("City", EdmPrimitiveTypeKind.String); var streetType = model.ComplexType("StreetType", "My") .Property("StreetName", EdmPrimitiveTypeKind.String) .Property("Number", EdmPrimitiveTypeKind.Int32); var nestedAddressType = model.ComplexType("NestedAddressType", "My") .Property("Street", new EdmComplexTypeReference(streetType, true)) .Property("City", EdmPrimitiveTypeKind.String); model.EntityType("EntryWithComplexProperties", "TestModel") .Property("ComplexAddress", new EdmComplexTypeReference(addressType, true)) .Property("NestedComplex", new EdmComplexTypeReference(nestedAddressType, true)); } return new ODataProperty[] { new ODataProperty() { Name = "ComplexAddress", Value = new ODataComplexValue() { TypeName = "My.AddressType", Properties = new [] { new ODataProperty() { Name = "Street", Value = "One Redmond Way" }, new ODataProperty() { Name = "City", Value = " Redmond" }, } } }, new ODataProperty() { Name = "NestedComplex", Value = new ODataComplexValue() { TypeName = "My.NestedAddressType", Properties = new [] { new ODataProperty() { Name = "Street", Value = new ODataComplexValue() { TypeName = "My.StreetType", Properties = new [] { new ODataProperty { Name = "StreetName", Value = "One Redmond Way" }, new ODataProperty { Name = "Number", Value = 1234 }, } } }, new ODataProperty() { Name = "City", Value = "Redmond " }, } } }, }; }
private IEdmModel CreateTestMetadata(out IEdmEntityType entityType, out IEdmComplexType complexType) { EdmModel model = new EdmModel(); EdmEntityType modelEntityType = model.EntityType("EntityType", "TestNS") .KeyProperty("Id", EdmCoreModel.Instance.GetInt32(false) as EdmTypeReference); EdmComplexType modelComplexType = model.ComplexType("ComplexType", "TestNS") .Property("EntityProp", modelEntityType.ToTypeReference() as EdmTypeReference) .Property("EntityCollectionProp", EdmCoreModel.GetCollection(modelEntityType.ToTypeReference()) as EdmTypeReference); EdmEntityContainer container = new EdmEntityContainer("TestNS", "TestContainer"); container.AddFunctionAndFunctionImport(model, "FunctionImport1", EdmCoreModel.Instance.GetInt32(false)); container.AddFunctionAndFunctionImport(model, "PrimitiveValueFunctionImport", EdmCoreModel.Instance.GetInt32(false)); container.AddFunctionAndFunctionImport(model, "EntityValueFunctionImport", modelEntityType.ToTypeReference()); container.AddFunctionAndFunctionImport(model, "CollectionOfEntitiesFunctionImport", EdmCoreModel.GetCollection(modelEntityType.ToTypeReference())); model.AddElement(container); model.Fixup(); entityType = (IEdmEntityType)model.FindType("TestNS.EntityType"); ExceptionUtilities.Assert(entityType != null, "entityType != null"); complexType = (IEdmComplexType)model.FindType("TestNS.ComplexType"); ExceptionUtilities.Assert(complexType != null, "complexType != null"); return model; }