public void EdmPathExpressionWithInvalidNonInheritedTypeCastSegmentShouldError() { EdmEntityType entityType = new EdmEntityType("ds.s", "entityType"); EdmEntityType otherEntityType = new EdmEntityType("ds.s", "otherEntityType"); EdmModel model = new EdmModel(); model.AddElement(entityType); model.AddElement(otherEntityType); EdmFunction function = new EdmFunction("ns", "GetStuff", new EdmEntityTypeReference(entityType, true), true /*isBound*/, new EdmPathExpression("bindingEntity/ds.s.otherEntityType"), false); function.AddParameter("bindingEntity", new EdmEntityTypeReference(entityType, false)); model.AddElement(function); ValidateErrorInList( model, function, EdmErrorCode.InvalidPathInvalidTypeCastSegment, Strings.EdmModel_Validator_Semantic_InvalidEntitySetPathInvalidTypeCastSegment("EntitySetPath", "bindingEntity/ds.s.otherEntityType", entityType.FullName(), otherEntityType.FullName())); }
public void WriterStreamPropertiesTests() { Uri baseUri = new Uri("http://www.odata.org/", UriKind.Absolute); Uri relativeReadLinkUri = new Uri("readlink", UriKind.RelativeOrAbsolute); Uri relativeEditLinkUri = new Uri("editlink", UriKind.RelativeOrAbsolute); Uri absoluteReadLinkUri = new Uri(baseUri, relativeReadLinkUri.OriginalString); Uri absoluteEditLinkUri = new Uri(baseUri, relativeEditLinkUri.OriginalString); string contentType = "application/binary"; string etag = "\"myetagvalue\""; string streamPropertyName = "stream1"; var namedStreamProperties = new[] { // with only read link new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { ReadLink = relativeReadLinkUri }}, new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { ReadLink = relativeReadLinkUri, ContentType = contentType}}, new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { ReadLink = absoluteReadLinkUri }}, new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { ReadLink = absoluteReadLinkUri, ContentType = contentType}}, // with only edit link new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { EditLink = relativeEditLinkUri }}, new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { EditLink = relativeEditLinkUri, ContentType = contentType }}, new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { EditLink = relativeEditLinkUri, ContentType = contentType, ETag = etag }}, new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { EditLink = absoluteEditLinkUri }}, new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { EditLink = absoluteEditLinkUri, ContentType = contentType }}, new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { EditLink = absoluteEditLinkUri, ContentType = contentType, ETag = etag }}, // with both edit and read link new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { ReadLink = relativeReadLinkUri, EditLink = relativeEditLinkUri }}, new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { ReadLink = relativeReadLinkUri, EditLink = relativeEditLinkUri, ContentType = contentType}}, new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { ReadLink = relativeReadLinkUri, EditLink = relativeEditLinkUri, ContentType = contentType, ETag = etag }}, new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { ReadLink = absoluteReadLinkUri, EditLink = relativeEditLinkUri }}, new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { ReadLink = absoluteReadLinkUri, EditLink = relativeEditLinkUri, ContentType = contentType}}, new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { ReadLink = absoluteReadLinkUri, EditLink = relativeEditLinkUri, ContentType = contentType, ETag = etag }}, }; var testCases = namedStreamProperties.Select(property => { var propertyName = property.Name; var streamReferenceValue = (ODataStreamReferenceValue)property.Value; return new StreamPropertyTestCase { NamedStreamProperty = property, GetExpectedAtomPayload = (testConfiguration) => { return (streamReferenceValue.ReadLink == null ? string.Empty : ( "<link rel=\"http://docs.oasis-open.org/odata/ns/mediaresource/" + property.Name + "\" " + (streamReferenceValue.ContentType == null ? string.Empty : "type=\"" + streamReferenceValue.ContentType + "\" ") + "title=\"" + property.Name + "\" " + "href=\"" + (((ODataStreamReferenceValue)property.Value).ReadLink.IsAbsoluteUri ? absoluteReadLinkUri.OriginalString : relativeReadLinkUri.OriginalString) + "\" " + "xmlns=\"" + TestAtomConstants.AtomNamespace + "\" />")) + (streamReferenceValue.EditLink == null ? string.Empty : ( "<link rel=\"http://docs.oasis-open.org/odata/ns/edit-media/" + property.Name + "\" " + (streamReferenceValue.ContentType == null ? string.Empty : "type=\"" + streamReferenceValue.ContentType + "\" ") + "title=\"" + property.Name + "\" " + "href=\"" + (((ODataStreamReferenceValue)property.Value).EditLink.IsAbsoluteUri ? absoluteEditLinkUri.OriginalString : relativeEditLinkUri.OriginalString) + "\" " + (streamReferenceValue.ETag == null ? string.Empty : "m:etag=\"" + streamReferenceValue.ETag.Replace("\"", """) + "\" xmlns:m=\"" + TestAtomConstants.ODataMetadataNamespace + "\" ") + "xmlns=\"" + TestAtomConstants.AtomNamespace + "\" />")); }, GetExpectedJsonLightPayload = (testConfiguration) => { return JsonLightWriterUtils.CombineProperties( (streamReferenceValue.EditLink == null ? string.Empty : ("\"" + JsonLightUtils.GetPropertyAnnotationName(propertyName, JsonLightConstants.ODataMediaEditLinkAnnotationName) + "\":\"" + absoluteEditLinkUri.OriginalString + "\"")), (streamReferenceValue.ReadLink == null ? string.Empty : ("\"" + JsonLightUtils.GetPropertyAnnotationName(propertyName, JsonLightConstants.ODataMediaReadLinkAnnotationName) + "\":\"" + absoluteReadLinkUri.OriginalString + "\"")), (streamReferenceValue.ContentType == null ? string.Empty : ("\"" + JsonLightUtils.GetPropertyAnnotationName(propertyName, JsonLightConstants.ODataMediaContentTypeAnnotationName) + "\":\"" + streamReferenceValue.ContentType + "\"")), (streamReferenceValue.ETag == null ? string.Empty : ("\"" + JsonLightUtils.GetPropertyAnnotationName(propertyName, JsonLightConstants.ODataMediaETagAnnotationName) + "\":\"" + streamReferenceValue.ETag.Replace("\"", "\\\"") + "\""))); }, }; }); var testDescriptors = testCases.SelectMany(testCase => { EdmModel model = new EdmModel(); EdmEntityType edmEntityType = new EdmEntityType("TestModel", "StreamPropertyEntityType"); EdmStructuralProperty edmStructuralProperty= edmEntityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, false); edmEntityType.AddKeys(new IEdmStructuralProperty[]{edmStructuralProperty}); model.AddElement(edmEntityType); EdmEntityContainer edmEntityContainer = new EdmEntityContainer("TestModel", "DefaultContainer"); model.AddElement(edmEntityContainer); EdmEntitySet edmEntitySet = new EdmEntitySet(edmEntityContainer, "StreamPropertyEntitySet", edmEntityType); edmEntityContainer.AddElement(edmEntitySet); ODataEntry entry = new ODataEntry() { Id = ObjectModelUtils.DefaultEntryId, ReadLink = ObjectModelUtils.DefaultEntryReadLink, TypeName = edmEntityType.FullName() }; var streamReference = (ODataStreamReferenceValue)testCase.NamedStreamProperty.Value; bool needBaseUri = (streamReference.ReadLink != null && !streamReference.ReadLink.IsAbsoluteUri) || (streamReference.EditLink != null && !streamReference.EditLink.IsAbsoluteUri); entry.Properties = new ODataProperty[] { testCase.NamedStreamProperty }; var resultDescriptor = new PayloadWriterTestDescriptor<ODataItem>( this.Settings, entry, (testConfiguration) => { if (testConfiguration.Format == ODataFormat.Atom) { return new AtomWriterTestExpectedResults(this.Settings.ExpectedResultSettings) { Xml = "<NamedStream>" + testCase.GetExpectedAtomPayload(testConfiguration) + "</NamedStream>", FragmentExtractor = result => result, }; } else if (testConfiguration.Format == ODataFormat.Json) { return new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings) { Json = string.Join( "$(NL)", "{", testCase.GetExpectedJsonLightPayload(testConfiguration), "}"), FragmentExtractor = result => result.RemoveAllAnnotations(true), }; } else { throw new NotSupportedException("Unsupported ODataFormat found: " + testConfiguration.Format.ToString()); } }) { Model = model, PayloadEdmElementContainer = edmEntityContainer, PayloadEdmElementType = edmEntityType, }; var resultTestCases = new List<StreamPropertyTestDescriptor>(); if (needBaseUri) { resultTestCases.Add(new StreamPropertyTestDescriptor { BaseUri = baseUri, TestDescriptor = resultDescriptor }); } else { resultTestCases.Add(new StreamPropertyTestDescriptor { BaseUri = null, TestDescriptor = resultDescriptor }); resultTestCases.Add(new StreamPropertyTestDescriptor { BaseUri = baseUri, TestDescriptor = resultDescriptor }); resultTestCases.Add(new StreamPropertyTestDescriptor { BaseUri = new Uri("http://mybaseuri/", UriKind.Absolute), TestDescriptor = resultDescriptor }); } return resultTestCases; }); var testDescriptorBaseUriPairSet = testDescriptors.SelectMany(descriptor => WriterPayloads.NamedStreamPayloads(descriptor.TestDescriptor).Select(namedStreamPayload => new Tuple<PayloadWriterTestDescriptor<ODataItem>, Uri>(namedStreamPayload, descriptor.BaseUri))); this.CombinatorialEngineProvider.RunCombinations( testDescriptorBaseUriPairSet, this.WriterTestConfigurationProvider.ExplicitFormatConfigurationsWithIndent, (testDescriptorBaseUriPair, testConfiguration) => { var testDescriptor = testDescriptorBaseUriPair.Item1; if (testDescriptor.IsGeneratedPayload && testConfiguration.Format == ODataFormat.Json) { return; } ODataMessageWriterSettings settings = testConfiguration.MessageWriterSettings.Clone(); settings.PayloadBaseUri = testDescriptorBaseUriPair.Item2; settings.SetServiceDocumentUri(ServiceDocumentUri); WriterTestConfiguration config = new WriterTestConfiguration(testConfiguration.Format, settings, testConfiguration.IsRequest, testConfiguration.Synchronous); if (testConfiguration.IsRequest) { ODataEntry payloadEntry = (ODataEntry)testDescriptor.PayloadItems[0]; ODataProperty firstStreamProperty = payloadEntry.Properties.Where(p => p.Value is ODataStreamReferenceValue).FirstOrDefault(); this.Assert.IsNotNull(firstStreamProperty, "firstStreamProperty != null"); testDescriptor = new PayloadWriterTestDescriptor<ODataItem>(testDescriptor) { ExpectedResultCallback = tc => new WriterTestExpectedResults(this.Settings.ExpectedResultSettings) { ExpectedException2 = ODataExpectedExceptions.ODataException("WriterValidationUtils_StreamPropertyInRequest", firstStreamProperty.Name) } }; } TestWriterUtils.WriteAndVerifyODataPayload(testDescriptor, config, this.Assert, this.Logger); }); }
/// <summary>Adds a new entity type (without any properties).</summary> /// <param name="name">The name of the type.</param> /// <param name="instanceType">The instance type or null if this should be untyped resource.</param> /// <param name="baseType">The base type.</param> /// <param name="isAbstract">If the type should be abstract.</param> /// <param name="nameSpace">The namespace of the entity type</param> /// <returns>The newly created entity type.</returns> public IEdmEntityType AddEntityType(string name, Type instanceType, IEdmEntityType baseType, bool isAbstract, string nameSpace, bool isOpen = false) { EdmEntityType entityType = new EdmEntityType( this.namespaceName, name, baseType, isAbstract, isOpen); this.entityTypes.Add(entityType.FullName(), entityType); if (entityType.BaseType != null) { List<IEdmStructuredType> derivedTypes; if (!this.derivedTypeMappings.TryGetValue(entityType.BaseType, out derivedTypes)) { derivedTypes = new List<IEdmStructuredType>(); this.derivedTypeMappings[entityType.BaseType] = derivedTypes; } } return entityType; }
public void DefaultStreamMetadataWcfDSServerTest() { EdmModel model = new EdmModel(); var cityType = new EdmEntityType("TestModel", "CityType"); model.AddElement(cityType); var cityWithMapType = new EdmEntityType("TestModel", "CityWithMapType", null, false, false, true); model.AddElement(cityWithMapType); var container = new EdmEntityContainer("TestModel", "TestContainer"); container.AddEntitySet("CityType", cityType); container.AddEntitySet("CityWithMapType", cityWithMapType); model.AddElement(container); IEnumerable<PayloadWriterTestDescriptor<ODataItem>> testDescriptors = // non-MLE payload and non-MLE type NonMLEDefaultStreamValues.Select(mr => this.CreateDefaultStreamMetadataTestDescriptor(model, cityType.FullName(), mr)) // non-MLE payload and MLE type .Concat(NonMLEDefaultStreamValues.Select(mr => this.CreateDefaultStreamMetadataTestDescriptor(model, cityWithMapType.FullName(), mr, ODataExpectedExceptions.ODataException("ValidationUtils_EntryWithoutMediaResourceAndMLEType", "TestModel.CityWithMapType")))) // MLE payload and non-MLE type .Concat(MLEDefaultStreamValues.Select(mr => this.CreateDefaultStreamMetadataTestDescriptor(model, cityType.FullName(), mr, ODataExpectedExceptions.ODataException("ValidationUtils_EntryWithMediaResourceAndNonMLEType", "TestModel.CityType")))) // MLE payload and MLE type .Concat(MLEDefaultStreamValues.Select(mr => this.CreateDefaultStreamMetadataTestDescriptor(model, cityWithMapType.FullName(), mr))); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.WriterTestConfigurationProvider.AtomFormatConfigurations, (testDescriptor, testConfiguration) => { testConfiguration = testConfiguration.Clone(); testConfiguration.MessageWriterSettings.EnableODataServerBehavior(false); testConfiguration.MessageWriterSettings.SetServiceDocumentUri(ServiceDocumentUri); TestWriterUtils.WriteAndVerifyODataPayload(testDescriptor, testConfiguration, this.Assert, this.Logger); }); }
public void GeolocatedUriTest() { // Geolocated URIs are cases where the read/edit/etc URIs for the same resource use different services string baseUri = "http://www.test.com/foo.svc/Target"; EdmModel model = new EdmModel(); var mleType = new EdmEntityType("TestModel", "MediaLinkType", null, false, false, true); mleType.AddKeys(mleType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetString(true))); model.AddElement(mleType); var entityType = new EdmEntityType("TestModel", "GeolocatedUriType"); entityType.AddKeys(entityType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetString(true))); var navProp = entityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "NavProp", Target = mleType, TargetMultiplicity = EdmMultiplicity.Many }); entityType.AddStructuralProperty("StreamProperty", EdmPrimitiveTypeKind.Stream); model.AddElement(entityType); var container = new EdmEntityContainer("TestModel", "DefaultContainer"); var mleSet = container.AddEntitySet("MediaLinkSet", mleType); var entitySet = container.AddEntitySet("GeolocatedUriSet", entityType); model.AddElement(container); entitySet.AddNavigationTarget(navProp, mleSet); var testDescriptors = new[] { new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.Entity(entityType.FullName()) .PrimitiveProperty("Id", System.Guid.NewGuid().ToString()) .Property(PayloadBuilder.NavigationProperty("NavProp", baseUri.Replace("foo", "geo1"), baseUri.Replace("foo", "geo2")).IsCollection(true)) .StreamProperty("StreamProperty", baseUri.Replace("foo", "read"), baseUri.Replace("foo", "edit")) .ExpectedEntityType(entityType, entitySet), PayloadEdmModel = model, // No stream properties in requests or <V3 payloads SkipTestConfiguration = tc => tc.IsRequest }, new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.Entity(mleType.FullName()) .EnsureMediaLinkEntry() .PrimitiveProperty("Id", System.Guid.NewGuid().ToString()) .StreamContentType("image/jpeg") .StreamEditLink(baseUri.Replace("foo", "edit-stream")) .StreamSourceLink(baseUri.Replace("foo", "source-stream")) .ExpectedEntityType(mleType, mleSet), PayloadEdmModel = model }, }; this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations, new[] { true, false }, (testDescriptor, testConfiguration, withBaseUri) => { var actualConfiguration = new ReaderTestConfiguration(testConfiguration); actualConfiguration.MessageReaderSettings.BaseUri = withBaseUri ? new Uri(baseUri) : (testConfiguration.Format != ODataFormat.Json ? null : new Uri(baseUri)); testDescriptor.RunTest(actualConfiguration); }); }
public PayloadWriterTestDescriptor<ODataItem> ToEdmTestDescriptor(PayloadWriterTestDescriptor.Settings settings, EdmModel model = null, EdmEntitySet entitySet = null, EdmEntityType entityType = null) { ODataEntry entry = ObjectModelUtils.CreateDefaultEntry(); entry.TypeName = entityType == null ? null : entityType.FullName(); return new PayloadWriterTestDescriptor<ODataItem>( settings, new ODataItem[] { entry }.Concat(this.Items).ToArray(), testConfiguration => { ExpectedException expectedException = this.ExpectedException; if (this.EdmExpectedExceptionCallback != null) { expectedException = this.EdmExpectedExceptionCallback(testConfiguration, model); } if (testConfiguration.Format == ODataFormat.Atom) { return new AtomWriterTestExpectedResults(settings.ExpectedResultSettings) { FragmentExtractor = result => new XElement("results", result.Elements(TestAtomConstants.AtomXNamespace + "link") .Where(e => e.Attribute("rel").Value == (TestAtomConstants.ODataNavigationPropertiesRelatedLinkRelationPrefix + this.PropertyName))), Xml = "<results>" + this.Xml + "</results>", ExpectedException2 = expectedException }; } else if (testConfiguration.Format == ODataFormat.Json) { return new JsonWriterTestExpectedResults(settings.ExpectedResultSettings) { FragmentExtractor = result => new JsonObject().AddProperties(result.RemoveAllAnnotations(true).Object().GetPropertyAnnotationsAndProperty(this.PropertyName)), Json = this.JsonLight, ExpectedException2 = expectedException }; } else { settings.Assert.Fail("Unsupported format {0}", testConfiguration.Format); return null; } }) { SkipTestConfiguration = this.SkipTestConfiguration, Model = model, PayloadEdmElementContainer = entitySet, PayloadEdmElementType = entityType, }; }
/// <summary> /// Creates an ODataEntry instance with the default values for 'Id', 'ReadLink' and 'Updated' /// that can be used and modified in tests. /// </summary> /// <param name="typeName">The optional type name for the default entry.</param> /// <param name="model">The product model to generate the type in (if not null).</param> /// <returns>The newly created ODataEntry instance.</returns> public static ODataEntry CreateDefaultEntryWithAtomMetadata(string entitySetName = null, string typeName = null, EdmModel model = null) { if (model != null && typeName != null) { EdmEntityType entityType = new EdmEntityType(DefaultNamespaceName, typeName); entityType.AddKeys(entityType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(isNullable: false))); model.AddElement(entityType); typeName = entityType.FullName(); EdmEntityContainer container = new EdmEntityContainer(DefaultNamespaceName, "DefaultContainer"); model.AddElement(container); if (entitySetName != null) { container.AddEntitySet(entitySetName, entityType); } } ODataEntry entry = new ODataEntry() { Id = DefaultEntryId, ReadLink = DefaultEntryReadLink, TypeName = typeName, SerializationInfo = MySerializationInfo }; AtomEntryMetadata metadata = new AtomEntryMetadata() { Updated = DateTimeOffset.Parse(DefaultEntryUpdated) }; entry.SetAnnotation<AtomEntryMetadata>(metadata); return entry; }
// [TestMethod, Variation(Description = "Verify correct parsing of entries with geolocated URIs")] public void GeolocatedUriTest() { // Geolocated URIs are cases where the read/edit/etc URIs for the same resource use different services string baseUri = "http://www.test.com/foo.svc/Target"; EdmModel model = new EdmModel(); var mleType = new EdmEntityType("TestModel", "MediaLinkType", null, false, false, true); model.AddElement(mleType); var entityType = new EdmEntityType("TestModel", "GeolocatedUriType"); entityType.AddKeys(entityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.String, isNullable: true)); var navProp = entityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "NavProp", Target = mleType, TargetMultiplicity = EdmMultiplicity.Many }); entityType.AddStructuralProperty("StreamProperty", EdmPrimitiveTypeKind.Stream, isNullable: false); model.AddElement(entityType); var container = new EdmEntityContainer("TestModel", "DefaultContainer"); var mediaLinkSet = container.AddEntitySet("MediaLinkType", mleType); var geolocatedUriSet = container.AddEntitySet("GeolocatedUriType", entityType); geolocatedUriSet.AddNavigationTarget(navProp, mediaLinkSet); model.AddElement(container); EntityInstance entityInstance = PayloadBuilder.Entity(entityType.FullName()) .Property("Id", PayloadBuilder.PrimitiveValue(System.Guid.NewGuid().ToString())) .Property(PayloadBuilder.DeferredNavigationProperty("NavProp", PayloadBuilder.DeferredLink(baseUri.Replace("foo", "geo1")).IsCollection(true), PayloadBuilder.DeferredLink(baseUri.Replace("foo", "geo2")))) .StreamProperty("StreamProperty", baseUri.Replace("foo", "read"), baseUri.Replace("foo", "edit")); entityInstance.Id = "1"; EntityInstance mleInstance = PayloadBuilder.Entity(mleType.FullName()).EnsureMediaLinkEntry(); mleInstance.Id = "1"; mleInstance.StreamContentType = "image/jpeg"; mleInstance.StreamEditLink = baseUri.Replace("foo", "edit-stream"); mleInstance.StreamSourceLink = baseUri.Replace("foo", "source-stream"); var testDescriptors = new[] { new PayloadWriterTestDescriptor<ODataPayloadElement>(this.Settings,entityInstance) { Model = model, PayloadDescriptor = new PayloadTestDescriptor() { PayloadElement = entityInstance }, ExpectedResultCallback = (tc) => { return new PayloadWriterTestExpectedResults(this.ExpectedResultSettings) { ExpectedPayload = entityInstance, }; }, }, new PayloadWriterTestDescriptor<ODataPayloadElement>(this.Settings, mleInstance) { Model = model, PayloadDescriptor = new PayloadTestDescriptor() { PayloadElement = mleInstance }, ExpectedResultCallback = (tc) => { return new PayloadWriterTestExpectedResults(this.ExpectedResultSettings) { ExpectedPayload = mleInstance }; }, }, }; this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.WriterTestConfigurationProvider.JsonLightFormatConfigurationsWithIndent, (testDescriptor, testConfiguration) => { testDescriptor.RunTest(testConfiguration, this.Logger); }); }
/// <summary> /// Generates an open entity set containing entities with different amounts of primitive open properties. /// </summary> /// <param name="model">The entity model. The method will modify the model and call Fixup().</param> /// <param name="withTypeNames">True if the payloads should specify type names.</param> /// <param name="primitiveValueFilter">A function for excluding primitives which are unsupported for open properties.</param> /// <returns>The open entity set containing entities with primitive open properties.</returns> public static ODataPayloadElement CreateOpenEntitySetInstance(EdmModel model, bool withTypeNames, Func<PrimitiveValue, bool> primitiveValueFilter) { ExceptionUtilities.CheckArgumentNotNull(model, "model"); ExceptionUtilities.CheckArgumentNotNull(primitiveValueFilter, "primitiveValueFilter"); var edmEntityType = new EdmEntityType("TestModel", "OpenEntityType", baseType: null, isAbstract: false, isOpen: true); model.AddElement(edmEntityType); edmEntityType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String, true); var container = new EdmEntityContainer("TestModel", "DefaultContainer"); container.AddEntitySet("OpenEntityTypes", edmEntityType); model.AddElement(container); var feed = PayloadBuilder.EntitySet().WithTypeAnnotation(edmEntityType); string entityTypeName = withTypeNames ? edmEntityType.FullName() : null; var primitiveValues = TestValues.CreatePrimitiveValuesWithMetadata(true).Where(p => primitiveValueFilter(p)); int idx = 0; for (int i = 0; i <= primitiveValues.Count(); ++i) { var entityInstance = PayloadBuilder.Entity(entityTypeName).PrimitiveProperty("Name", Guid.NewGuid().ToString()); foreach (var property in primitiveValues.Take(i)) { entityInstance.PrimitiveProperty("Property" + (idx++), property.ClrValue); } feed.Add(entityInstance); } return feed; }