public void SetNextLinkAfterFeedStartTests() { var testPayloads = this.CreateFeedNextLinkDescriptors().ToArray(); foreach (var descriptor in testPayloads) { // Replace each feed with one without the next link value, and an action to write it back // after writing Feed Start. var nextLink = new Uri(descriptor.PayloadItems.OfType <ODataFeed>().Single().NextPageLink.OriginalString); var newFeed = ObjectModelUtils.CreateDefaultFeed().WithAnnotation(new WriteFeedCallbacksAnnotation { AfterWriteStartCallback = (f) => f.NextPageLink = nextLink }); descriptor.PayloadItems = new ReadOnlyCollection <ODataItem>(new List <ODataItem> { newFeed }); } this.CombinatorialEngineProvider.RunCombinations( testPayloads.PayloadCases(WriterPayloads.FeedPayloads), this.WriterTestConfigurationProvider.ExplicitFormatConfigurationsWithIndent, (testDescriptor, testConfiguration) => { if (testDescriptor.IsGeneratedPayload && (testConfiguration.Format == ODataFormat.Json || testDescriptor.Model != null)) { return; } TestWriterUtils.WriteAndVerifyODataEdmPayload(testDescriptor, testConfiguration, this.Assert, this.Logger); }); }
public void FeedInlineCountTests() { PayloadWriterTestDescriptor <ODataItem>[] testDescriptors = this.CreateFeedQueryCountDescriptors(); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.WriterTestConfigurationProvider.ExplicitFormatConfigurationsWithIndent, (testDescriptor, testConfiguration) => { testConfiguration = testConfiguration.Clone(); testConfiguration.MessageWriterSettings.SetServiceDocumentUri(ServiceDocumentUri); TestWriterUtils.WriteAndVerifyODataEdmPayload(testDescriptor, testConfiguration, this.Assert, this.Logger); }); }
[Ignore] // Remove Atom // [TestMethod, Variation(Description = "Validates the payloads for various top-level errors written using an ODataWriter.")] public void TopLevelODataWriterErrorTest() { EdmEntitySet entitySet = null; this.CombinatorialEngineProvider.RunCombinations( this.CreateODataErrorTestDescriptors(/*throwOnRequest*/ true, /*topLevel*/ false), this.WriterTestConfigurationProvider.ExplicitFormatConfigurationsWithIndent, (testDescriptor, testConfiguration) => { testDescriptor.Model = CreateErrorTestModel(out entitySet); testDescriptor.PayloadEdmElementContainer = entitySet; testConfiguration = testConfiguration.Clone(); testConfiguration.MessageWriterSettings.MessageQuotas.MaxNestingDepth = this.customSetRecursionDepthLimit; TestWriterUtils.WriteAndVerifyODataEdmPayload(testDescriptor, testConfiguration, this.Assert, this.Logger); }); }
public void FeedNextLinkTests() { PayloadWriterTestDescriptor <ODataItem>[] testPayloads = this.CreateFeedNextLinkDescriptors(); this.CombinatorialEngineProvider.RunCombinations( testPayloads.PayloadCases(WriterPayloads.FeedPayloads), this.WriterTestConfigurationProvider.ExplicitFormatConfigurationsWithIndent, (testDescriptor, testConfiguration) => { if (testDescriptor.IsGeneratedPayload && (testConfiguration.Format == ODataFormat.Json || testDescriptor.Model != null)) { return; } TestWriterUtils.WriteAndVerifyODataEdmPayload(testDescriptor, testConfiguration, this.Assert, this.Logger); }); }
public void FeedTests() { PayloadWriterTestDescriptor <ODataItem>[] testPayloads = new[] { this.CreateDefaultFeedMetadataDescriptor(/*withModel*/ false), this.CreateDefaultFeedMetadataDescriptor(/*withModel*/ true), this.CreateDefaultFeedWithAtomMetadataDescriptor(/*withModel*/ false), this.CreateDefaultFeedWithAtomMetadataDescriptor(/*withModel*/ true), }; this.CombinatorialEngineProvider.RunCombinations( testPayloads.PayloadCases(WriterPayloads.FeedPayloads), this.WriterTestConfigurationProvider.JsonLightFormatConfigurationsWithIndent, (testDescriptor, testConfiguration) => { if (testDescriptor.IsGeneratedPayload && (testConfiguration.Format == ODataFormat.Json || testDescriptor.Model != null)) { return; } TestWriterUtils.WriteAndVerifyODataEdmPayload(testDescriptor, testConfiguration, this.Assert, this.Logger); }); }
public void ProjectedPropertiesTest() { // Start with top-level payloads IEnumerable <ProjectedPropertiesTestCase> topLevelTestCases = new ProjectedPropertiesTestCase[] { // No point testing case where no annotation is specified, as all the other tests do that. // It's important to sort these in the payload order, so nav props go first, then named streams and then normal properties // Also note that assoc link and nav link might have the same name, in which case they will be twice in the list below new ProjectedPropertiesTestCase { TopLevelProjectedProperties = new ProjectedPropertiesAnnotation(new string[0]), ExpectedProperties = new string[0], }, new ProjectedPropertiesTestCase { TopLevelProjectedProperties = new ProjectedPropertiesAnnotation(new string[] { "StringProperty" }), ExpectedProperties = new string[] { "StringProperty" }, }, new ProjectedPropertiesTestCase { TopLevelProjectedProperties = new ProjectedPropertiesAnnotation(new string[] { "StringProperty", "NumberProperty" }), ExpectedProperties = new string[] { "StringProperty", "NumberProperty" }, }, new ProjectedPropertiesTestCase { TopLevelProjectedProperties = new ProjectedPropertiesAnnotation(new string[] { "SimpleComplexProperty", "PrimitiveCollection" }), ExpectedProperties = new string[] { "SimpleComplexProperty", "PrimitiveCollection" }, }, new ProjectedPropertiesTestCase { TopLevelProjectedProperties = new ProjectedPropertiesAnnotation(new string[] { "NamedStream" }), ExpectedProperties = new string[] { "NamedStream" }, ResponseOnly = true, }, new ProjectedPropertiesTestCase { TopLevelProjectedProperties = new ProjectedPropertiesAnnotation(new string[] { "AssociationLink" }), ExpectedProperties = new string[] { "AssociationLink" }, ResponseOnly = true, IgnoreFormats = new ODataFormat[] { ODataFormat.Json }, }, new ProjectedPropertiesTestCase { TopLevelProjectedProperties = new ProjectedPropertiesAnnotation(new string[] { "NamedStream", "StringProperty", "NumberProperty", "SimpleComplexProperty", "DeepComplexProperty", "PrimitiveCollection", "ComplexCollection" }), ExpectedProperties = new string[] { "NamedStream", "StringProperty", "NumberProperty", "SimpleComplexProperty", "DeepComplexProperty", "PrimitiveCollection", "ComplexCollection" }, ResponseOnly = true, }, new ProjectedPropertiesTestCase { TopLevelProjectedProperties = new ProjectedPropertiesAnnotation(new string[] { "DeferredNavigation" }), ExpectedProperties = new string[] { "DeferredNavigation", "DeferredNavigation" }, ResponseOnly = true, }, new ProjectedPropertiesTestCase { TopLevelProjectedProperties = new ProjectedPropertiesAnnotation(new string[] { "ExpandedEntry" }), ExpectedProperties = new string[] { "ExpandedEntry" }, }, new ProjectedPropertiesTestCase { TopLevelProjectedProperties = new ProjectedPropertiesAnnotation(new string[] { "ExpandedFeed" }), ExpectedProperties = new string[] { "ExpandedFeed" }, }, }; // Then create wrapped test cases var nestedTestCases = topLevelTestCases.Select(t => new ProjectedPropertiesTestCase(t) { NestedPayload = true, NestedProjectedProperties = t.TopLevelProjectedProperties, TopLevelProjectedProperties = new ProjectedPropertiesAnnotation(new string[] { "Wrapping_ExpandedEntry" }), }); // Create more interesting test cases with multiple annotations var manualTestCases = new ProjectedPropertiesTestCase[] { new ProjectedPropertiesTestCase { DebugDescription = "Non-existant name in top-level annotation is ignored.", TopLevelProjectedProperties = new ProjectedPropertiesAnnotation(new string[] { "NumberProperty", "NamedStream", "NamedStream", "DeferredNavigation", "ExpandedEntry", "ExpandedFeed", "NonExistant" }), ExpectedProperties = new string[] { "DeferredNavigation", "ExpandedEntry", "ExpandedFeed", "NamedStream", "DeferredNavigation", "NumberProperty" }, ResponseOnly = true, }, new ProjectedPropertiesTestCase { DebugDescription = "Make sure a top-level annotation with invalid property names or paths projects nothing.", TopLevelProjectedProperties = new ProjectedPropertiesAnnotation(new string[] { string.Empty, null, "Invalid", "SimpleComplexProperty/Name" }), ExpectedProperties = new string[] { }, }, new ProjectedPropertiesTestCase { DebugDescription = "Make sure a nested annotation works with a top-level annotation.", NestedPayload = true, TopLevelProjectedProperties = new ProjectedPropertiesAnnotation(new string[] { "Wrapping_ExpandedEntry" }), NestedProjectedProperties = new ProjectedPropertiesAnnotation(new string[] { "StringProperty", "NumberProperty" }), ExpectedProperties = new string[] { "StringProperty", "NumberProperty" }, }, new ProjectedPropertiesTestCase { DebugDescription = "Make sure a nested annotation is ignored if a top-level annotation does not include the navigation property.", NestedPayload = true, TopLevelProjectedProperties = new ProjectedPropertiesAnnotation(new string[] { "Invalid" }), NestedProjectedProperties = new ProjectedPropertiesAnnotation(new string[] { "StringProperty", "NumberProperty" }), ExpectedProperties = new string[0], }, }; var testCases = topLevelTestCases.Concat(nestedTestCases).Concat(manualTestCases); IEdmModel edmModel = this.CreateEdmModel(); // First create test descriptors that use the model var testDescriptors = this.CreateEdmTestDescriptors(testCases, edmModel); // Then append the test descriptors without model testDescriptors = testDescriptors.Concat(this.CreateEdmTestDescriptors(testCases, /*model*/ null)); //ToDo: Fix places where we've lost JsonVerbose coverage to add JsonLight this.CombinatorialEngineProvider.RunCombinations( testDescriptors.PayloadCases(WriterPayloads.TopLevelValuePayload), this.WriterTestConfigurationProvider.ExplicitFormatConfigurations.Where(tc => tc.Format == ODataFormat.Atom), (testDescriptor, testConfiguration) => { testConfiguration = testConfiguration.Clone(); testConfiguration.MessageWriterSettings.SetServiceDocumentUri(ServiceDocumentUri); TestWriterUtils.WriteAndVerifyODataEdmPayload(testDescriptor.DeferredLinksToEntityReferenceLinksInRequest(testConfiguration), testConfiguration, this.Assert, this.Logger); }); }
public void SpatialPropertiesInEntryTest() { EdmModel model = new EdmModel(); var container = new EdmEntityContainer("TestModel", "TestContainer"); model.AddElement(container); var customerType = new EdmEntityType("TestModel", "CustomerType"); customerType.AddKeys(customerType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false))); customerType.AddStructuralProperty("Location1", EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.Geography, false)); customerType.AddStructuralProperty("Location2", EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeographyPoint, false)); model.AddElement(customerType); var customerSet = container.AddEntitySet("CustomerSet", customerType); ISpatial pointValue = GeographyFactory.Point(32.0, -100.0).Build(); IEnumerable <EntryPayloadTestCase> testCases = new[] { new EntryPayloadTestCase { DebugDescription = "Customer instance with spatial property (expected and payload type don't match).", Entry = new ODataEntry() { TypeName = "TestModel.CustomerType", Properties = new ODataProperty[] { new ODataProperty { Name = "Location1", Value = pointValue } } }, Model = model, EntitySet = customerSet, Json = string.Join("$(NL)", "{{", "{0}" + "\"" + JsonLightUtils.GetPropertyAnnotationName("Location1", JsonLightConstants.ODataTypeAnnotationName) + "\":\"GeographyPoint\"," + "\"Location1\":{{", "\"type\":\"Point\",\"coordinates\":[", "-100.0,32.0", "],\"crs\":{{", "\"type\":\"name\",\"properties\":{{", "\"name\":\"EPSG:4326\"", "}}", "}}", "}}", "}}") }, new EntryPayloadTestCase { DebugDescription = "Customer instance with spatial property (expected and payload type match).", Entry = new ODataEntry() { TypeName = "TestModel.CustomerType", Properties = new ODataProperty[] { new ODataProperty { Name = "Location2", Value = pointValue } } }, Model = model, EntitySet = customerSet, Json = string.Join("$(NL)", "{{", "{0}" + "\"Location2\":{{", "\"type\":\"Point\",\"coordinates\":[", "-100.0,32.0", "],\"crs\":{{", "\"type\":\"name\",\"properties\":{{", "\"name\":\"EPSG:4326\"", "}}", "}}", "}}", "}}") }, }; IEnumerable <PayloadWriterTestDescriptor <ODataItem> > testDescriptors = testCases.Select(testCase => new PayloadWriterTestDescriptor <ODataItem>( this.Settings, new ODataItem[] { testCase.Entry }, tc => new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings) { Json = string.Format( CultureInfo.InvariantCulture, testCase.Json, JsonLightWriterUtils.GetMetadataUrlPropertyForEntry(testCase.EntitySet.Name) + ","), FragmentExtractor = (result) => result.RemoveAllAnnotations(true) }) { DebugDescription = testCase.DebugDescription, Model = testCase.Model, PayloadEdmElementContainer = testCase.EntitySet, PayloadEdmElementType = testCase.EntityType, SkipTestConfiguration = testCase.SkipTestConfiguration }); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.WriterTestConfigurationProvider.JsonLightFormatConfigurationsWithIndent, (testDescriptor, testConfiguration) => { TestWriterUtils.WriteAndVerifyODataEdmPayload(testDescriptor, testConfiguration, this.Assert, this.Logger); }); }
public void PayloadOrderTest() { EdmModel model = new EdmModel(); var container = new EdmEntityContainer("TestModel", "DefaultContainer"); model.AddElement(container); var otherType = new EdmEntityType("TestModel", "OtherType"); otherType.AddKeys(otherType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false))); model.AddElement(otherType); var otherset = container.AddEntitySet("OtherType", otherType); var nonMLEBaseType = new EdmEntityType("TestModel", "NonMLEBaseType"); nonMLEBaseType.AddKeys(nonMLEBaseType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false))); model.AddElement(nonMLEBaseType); var nonMLESet = container.AddEntitySet("NonMLESet", nonMLEBaseType); var nonMLEType = new EdmEntityType("TestModel", "NonMLEType", nonMLEBaseType); nonMLEType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(true)); nonMLEType.AddStructuralProperty("Description", EdmCoreModel.Instance.GetString(true)); nonMLEType.AddStructuralProperty("StreamProperty", EdmPrimitiveTypeKind.Stream, isNullable: false); var nonMLENav = nonMLEType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "NavProp", Target = otherType, TargetMultiplicity = EdmMultiplicity.Many }); nonMLESet.AddNavigationTarget(nonMLENav, otherset); model.AddElement(nonMLEType); var mleBaseType = new EdmEntityType("TestModel", "MLEBaseType"); mleBaseType.AddKeys(mleBaseType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false))); model.AddElement(mleBaseType); var mleSet = container.AddEntitySet("MLESet", mleBaseType); var mleType = new EdmEntityType("TestModel", "MLEType", mleBaseType, false, false, true); mleType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(true)); mleType.AddStructuralProperty("Description", EdmCoreModel.Instance.GetString(true)); mleType.AddStructuralProperty("StreamProperty", EdmPrimitiveTypeKind.Stream, isNullable: false); var mleNav = mleType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "NavProp", Target = otherType, TargetMultiplicity = EdmMultiplicity.Many }); mleSet.AddNavigationTarget(mleNav, otherset); model.AddElement(mleType); IEnumerable <EntryPayloadTestCase> testCases = new[] { new EntryPayloadTestCase { DebugDescription = "TypeName at the beginning, nothing else", Entry = new ODataEntry() { TypeName = "TestModel.NonMLEType" }, Model = model, EntitySet = nonMLESet, Json = string.Join("$(NL)", "{{", "{1}" + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"TestModel.NonMLEType\"{0}", "}}") }, new EntryPayloadTestCase { DebugDescription = "TypeName at the beginning, changes at the end - the one from the beginning is used (also for validation).", Entry = new ODataEntry() { MediaResource = new ODataStreamReferenceValue(), Properties = new [] { new ODataProperty { Name = "ID", Value = (int)42 }, new ODataProperty { Name = "Name", Value = "test" }, } } .WithAnnotation(new WriteEntryCallbacksAnnotation { BeforeWriteStartCallback = (entry) => { entry.TypeName = "TestModel.MLEType"; }, BeforeWriteEndCallback = (entry) => { entry.TypeName = "NonExistingType"; } }), Model = model, EntitySet = mleSet, Json = string.Join("$(NL)", "{{", "{1}" + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"TestModel.MLEType\"{0},\"ID\":\"42\",\"Name\":\"test\"", "}}") }, new EntryPayloadTestCase { DebugDescription = "TypeName, ID and ETag at the beginning, nothing else", Entry = new ODataEntry() { TypeName = "TestModel.NonMLEType", Id = new Uri("urn:id"), ETag = "etag" }, Model = model, EntitySet = nonMLESet, Json = string.Join("$(NL)", "{{", "{1}" + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"TestModel.NonMLEType\"," + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataIdAnnotationName + "\":\"urn:id\"," + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataETagAnnotationName + "\":\"etag\"{0}", "}}") }, new EntryPayloadTestCase { DebugDescription = "TypeName at the beginning, ID and ETag at the end, ID and ETag are not written and are ignored at the end", Entry = new ODataEntry() { TypeName = "TestModel.NonMLEType" } .WithAnnotation(new WriteEntryCallbacksAnnotation { BeforeWriteStartCallback = (entry) => { entry.Id = null; entry.ETag = null; }, BeforeWriteEndCallback = (entry) => { entry.Id = new Uri("urn:id"); entry.ETag = "etag"; } }), Model = model, EntitySet = nonMLESet, Json = string.Join("$(NL)", "{{", "{1}" + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"TestModel.NonMLEType\"{0}", "}}") }, new EntryPayloadTestCase { DebugDescription = "Everything at the beginning", Entry = new ODataEntry() { TypeName = "TestModel.MLEType", Id = new Uri("urn:id"), ETag = "etag", EditLink = new Uri("http://odata.org/editlink"), ReadLink = new Uri("http://odata.org/readlink"), MediaResource = new ODataStreamReferenceValue() { EditLink = new Uri("http://odata.org/mediaeditlink"), ReadLink = new Uri("http://odata.org/mediareadlink"), ETag = "mediaetag", ContentType = "media/contenttype" }, Properties = new [] { new ODataProperty { Name = "ID", Value = (int)42 }, new ODataProperty { Name = "Name", Value = "test" }, } }, Model = model, EntitySet = mleSet, Json = string.Join("$(NL)", "{{", "{1}" + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"TestModel.MLEType\"," + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataIdAnnotationName + "\":\"urn:id\"," + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataETagAnnotationName + "\":\"etag\"," + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataEditLinkAnnotationName + "\":\"http://odata.org/editlink\"," + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataReadLinkAnnotationName + "\":\"http://odata.org/readlink\"," + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataMediaEditLinkAnnotationName + "\":\"http://odata.org/mediaeditlink\"," + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataMediaReadLinkAnnotationName + "\":\"http://odata.org/mediareadlink\"," + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataMediaContentTypeAnnotationName + "\":\"media/contenttype\"," + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataMediaETagAnnotationName + "\":\"mediaetag\"{0}," + "\"ID\":\"42\"," + "\"Name\":\"test\"", "}}") }, new EntryPayloadTestCase { DebugDescription = "TypeName, Id, ETag and ReadLinks at the beginning, the rest at the end", Entry = new ODataEntry() { TypeName = "TestModel.MLEType", Id = new Uri("urn:id"), ETag = "etag", ReadLink = new Uri("http://odata.org/readlink"), MediaResource = new ODataStreamReferenceValue() { ReadLink = new Uri("http://odata.org/mediareadlink") }, Properties = new [] { new ODataProperty { Name = "ID", Value = (int)42 }, new ODataProperty { Name = "Name", Value = "test" }, } }.WithAnnotation(new WriteEntryCallbacksAnnotation { BeforeWriteStartCallback = (entry) => { entry.EditLink = null; entry.MediaResource.EditLink = null; entry.MediaResource.ETag = null; entry.MediaResource.ContentType = null; }, BeforeWriteEndCallback = (entry) => { entry.EditLink = new Uri("http://odata.org/editlink"); entry.MediaResource.EditLink = new Uri("http://odata.org/mediaeditlink"); entry.MediaResource.ETag = "mediaetag"; entry.MediaResource.ContentType = "media/contenttype"; } }), Model = model, EntitySet = mleSet, Json = string.Join("$(NL)", "{{", "{1}" + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"TestModel.MLEType\"," + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataIdAnnotationName + "\":\"urn:id\"," + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataETagAnnotationName + "\":\"etag\"," + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataReadLinkAnnotationName + "\":\"http://odata.org/readlink\"," + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataMediaReadLinkAnnotationName + "\":\"http://odata.org/mediareadlink\"{0}," + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataEditLinkAnnotationName + "\":\"http://odata.org/editlink\"," + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataMediaEditLinkAnnotationName + "\":\"http://odata.org/mediaeditlink\"," + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataMediaContentTypeAnnotationName + "\":\"media/contenttype\"," + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataMediaETagAnnotationName + "\":\"mediaetag\"," + "\"ID\":\"42\"," + "\"Name\":\"test\"", "}}") }, }; IEnumerable <PayloadWriterTestDescriptor <ODataItem> > testDescriptors = testCases.Select(testCase => new PayloadWriterTestDescriptor <ODataItem>( this.Settings, new ODataItem[] { testCase.Entry }, tc => new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings) { Json = string.Format(CultureInfo.InvariantCulture, testCase.Json, string.Empty, JsonLightWriterUtils.GetMetadataUrlPropertyForEntry(testCase.EntitySet.Name) + ","), FragmentExtractor = (result) => result.RemoveAllAnnotations(true) }) { DebugDescription = testCase.DebugDescription, Model = testCase.Model, PayloadEdmElementContainer = testCase.EntitySet, PayloadEdmElementType = testCase.EntityType, SkipTestConfiguration = testCase.SkipTestConfiguration }); testDescriptors = testDescriptors.Concat(testCases.Select(testCase => new PayloadWriterTestDescriptor <ODataItem>( this.Settings, new ODataItem[] { testCase.Entry, new ODataNavigationLink { Name = "NavProp", IsCollection = true, Url = new Uri("http://odata.org/navprop/uri") } }, tc => new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings) { Json = string.Format(CultureInfo.InvariantCulture, testCase.Json, tc.IsRequest ? ",\"" + JsonLightUtils.GetPropertyAnnotationName("NavProp", JsonLightConstants.ODataBindAnnotationName) + "\":[$(NL)\"http://odata.org/navprop/uri\"$(NL)]" : ",\"" + JsonLightUtils.GetPropertyAnnotationName("NavProp", JsonLightConstants.ODataNavigationLinkUrlAnnotationName) + "\":\"http://odata.org/navprop/uri\"", JsonLightWriterUtils.GetMetadataUrlPropertyForEntry(testCase.EntitySet.Name) + ","), FragmentExtractor = (result) => result.RemoveAllAnnotations(true) }) { DebugDescription = testCase.DebugDescription + "- with navigation property", Model = testCase.Model, PayloadEdmElementContainer = testCase.EntitySet, PayloadEdmElementType = testCase.EntityType, SkipTestConfiguration = testCase.SkipTestConfiguration })) .Concat(testCases.Select(testCase => new PayloadWriterTestDescriptor <ODataItem>( this.Settings, new ODataItem[] { testCase.Entry, new ODataNavigationLink { Name = "NavProp", IsCollection = true, Url = new Uri("http://odata.org/navprop/uri"), AssociationLinkUrl = new Uri("http://odata.org/assoclink") } }, tc => new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings) { Json = string.Format(CultureInfo.InvariantCulture, testCase.Json, tc.IsRequest ? ",\"" + JsonLightUtils.GetPropertyAnnotationName("NavProp", JsonLightConstants.ODataBindAnnotationName) + "\":[$(NL)\"http://odata.org/navprop/uri\"$(NL)]" : ",\"" + JsonLightUtils.GetPropertyAnnotationName("NavProp", JsonLightConstants.ODataNavigationLinkUrlAnnotationName) + "\":\"http://odata.org/navprop/uri\"" + ",\"" + JsonLightUtils.GetPropertyAnnotationName("NavProp", JsonLightConstants.ODataAssociationLinkUrlAnnotationName) + "\":\"http://odata.org/assoclink\"", JsonLightWriterUtils.GetMetadataUrlPropertyForEntry(testCase.EntitySet.Name) + ","), FragmentExtractor = (result) => result.RemoveAllAnnotations(true) }) { DebugDescription = testCase.DebugDescription + "- with navigation property", Model = testCase.Model, PayloadEdmElementContainer = testCase.EntitySet, PayloadEdmElementType = testCase.EntityType, SkipTestConfiguration = testCase.SkipTestConfiguration })); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.WriterTestConfigurationProvider.JsonLightFormatConfigurationsWithIndent, (testDescriptor, testConfiguration) => { TestWriterUtils.WriteAndVerifyODataEdmPayload(testDescriptor.DeferredLinksToEntityReferenceLinksInRequest(testConfiguration), testConfiguration, this.Assert, this.Logger); }); }
public void ActionAndFunctionPayloadOrderTest() { EdmModel model = new EdmModel(); var container = new EdmEntityContainer("TestModel", "TestContainer"); model.AddElement(container); var otherType = new EdmEntityType("TestModel", "OtherType"); otherType.AddKeys(otherType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false))); model.AddElement(otherType); container.AddEntitySet("OtherType", otherType); var nonMLEBaseType = new EdmEntityType("TestModel", "NonMLEBaseType"); nonMLEBaseType.AddKeys(nonMLEBaseType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false))); model.AddElement(nonMLEBaseType); var nonMLESet = container.AddEntitySet("NonMLESet", nonMLEBaseType); var nonMLEType = new EdmEntityType("TestModel", "NonMLEType", nonMLEBaseType); nonMLEType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(true)); nonMLEType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "NavProp", Target = otherType, TargetMultiplicity = EdmMultiplicity.Many }); model.AddElement(nonMLEType); container.AddEntitySet("NonMLEType", nonMLEType); ODataAction action = new ODataAction { Metadata = new Uri("http://odata.org/test/$metadata#defaultAction"), Title = "Default Action", Target = new Uri("http://www.odata.org/defaultAction"), }; ODataFunction function = new ODataFunction { Metadata = new Uri("http://odata.org/test/$metadata#defaultFunction()"), Title = "Default Function", Target = new Uri("defaultFunctionTarget", UriKind.Relative) }; string defaultJson = string.Join("$(NL)", "{{", "{1}" + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"#TestModel.NonMLEType\"{0},\"#defaultAction\":{{", "\"title\":\"Default Action\",\"target\":\"http://www.odata.org/defaultAction\"", "}},\"#defaultFunction()\":{{", "\"title\":\"Default Function\",\"target\":\"defaultFunctionTarget\"", "}}", "}}"); var entryWithActionAndFunction = new ODataEntry() { TypeName = "TestModel.NonMLEType", }; entryWithActionAndFunction.AddAction(action); entryWithActionAndFunction.AddFunction(function); IEnumerable <EntryPayloadTestCase> testCases = new[] { new EntryPayloadTestCase { DebugDescription = "Functions and actions available at the beginning.", Entry = entryWithActionAndFunction, Model = model, EntitySet = nonMLESet, Json = defaultJson }, }; IEnumerable <PayloadWriterTestDescriptor <ODataItem> > testDescriptors = testCases.Select(testCase => new PayloadWriterTestDescriptor <ODataItem>( this.Settings, new ODataItem[] { testCase.Entry }, tc => new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings) { Json = string.Format(CultureInfo.InvariantCulture, testCase.Json, string.Empty, tc.IsRequest ? string.Empty : (JsonLightWriterUtils.GetMetadataUrlPropertyForEntry(testCase.EntitySet.Name) + ",")), FragmentExtractor = (result) => result.RemoveAllAnnotations(true) }) { DebugDescription = testCase.DebugDescription, Model = testCase.Model, PayloadEdmElementContainer = testCase.EntitySet, PayloadEdmElementType = testCase.EntityType, SkipTestConfiguration = testCase.SkipTestConfiguration }); testDescriptors = testDescriptors.Concat(testCases.Select(testCase => new PayloadWriterTestDescriptor <ODataItem>( this.Settings, new ODataItem[] { testCase.Entry, new ODataNavigationLink { Name = "NavProp", IsCollection = true, Url = new Uri("http://odata.org/navprop/uri") } }, tc => new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings) { Json = string.Format(CultureInfo.InvariantCulture, testCase.Json, tc.IsRequest ? ",\"NavProp\":[$(NL){$(NL)\"__metadata\":{$(NL)\"uri\":\"http://odata.org/navprop/uri\"$(NL)}$(NL)}$(NL)]" : ",\"" + JsonLightUtils.GetPropertyAnnotationName("NavProp", JsonLightConstants.ODataNavigationLinkUrlAnnotationName) + "\":\"http://odata.org/navprop/uri\"", tc.IsRequest ? string.Empty : (JsonLightWriterUtils.GetMetadataUrlPropertyForEntry(testCase.EntitySet.Name) + ",")), FragmentExtractor = (result) => result.RemoveAllAnnotations(true) }) { DebugDescription = testCase.DebugDescription + "- with navigation property", Model = testCase.Model, PayloadEdmElementContainer = testCase.EntitySet, PayloadEdmElementType = testCase.EntityType, SkipTestConfiguration = testCase.SkipTestConfiguration })); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, // Actions/functions are only supported in responses. this.WriterTestConfigurationProvider.JsonLightFormatConfigurationsWithIndent.Where(tc => !tc.IsRequest), (testDescriptor, testConfiguration) => { TestWriterUtils.WriteAndVerifyODataEdmPayload(testDescriptor.DeferredLinksToEntityReferenceLinksInRequest(testConfiguration), testConfiguration, this.Assert, this.Logger); }); }
public void FeedUserExceptionTests() { IEdmModel edmModel = Microsoft.Test.OData.Utils.Metadata.TestModels.BuildTestModel(); ODataFeed cityFeed = ObjectModelUtils.CreateDefaultFeed(); ODataEntry cityEntry = ObjectModelUtils.CreateDefaultEntry("TestModel.CityType"); ODataNavigationLink cityHallCollectionLink = ObjectModelUtils.CreateDefaultCollectionLink("CityHall"); ODataNavigationLink policeStationSingletonLink = ObjectModelUtils.CreateDefaultSingletonLink("PoliceStation"); ODataFeed officeFeed = ObjectModelUtils.CreateDefaultFeed(); ODataEntry officeEntry = ObjectModelUtils.CreateDefaultEntry("TestModel.OfficeType"); var container = edmModel.FindEntityContainer("DefaultContainer"); var citySet = container.FindEntitySet("Cities") as EdmEntitySet; var cityType = edmModel.FindType("TestModel.CityType") as EdmEntityType; ODataItem[] writerPayload = new ODataItem[] { cityFeed, cityEntry, null, cityEntry, cityHallCollectionLink, officeFeed, officeEntry, null, null, null, null, cityEntry, null, cityEntry, policeStationSingletonLink, officeEntry, null, null, null, }; IEnumerable <PayloadWriterTestDescriptor <ODataItem> > testDescriptors = new PayloadWriterTestDescriptor <ODataItem>[] { new PayloadWriterTestDescriptor <ODataItem>( this.Settings, writerPayload, tc => new WriterTestExpectedResults(this.Settings.ExpectedResultSettings) { ExpectedException = new Exception("User code triggered an exception."), } ) { Model = edmModel, PayloadEdmElementContainer = citySet, PayloadEdmElementType = cityType, } }; this.CombinatorialEngineProvider.RunCombinations( testDescriptors.PayloadCases(WriterPayloads.FeedPayloads), this.WriterTestConfigurationProvider.ExplicitFormatConfigurationsWithIndent, (testDescriptor, testConfiguration) => { if (testDescriptor.IsGeneratedPayload && (testConfiguration.Format == ODataFormat.Json || testDescriptor.Model != null)) { return; } foreach (int throwUserExceptionAt in Enumerable.Range(0, testDescriptor.PayloadItems.Count + 1)) { var configuredTestDescriptor = new PayloadWriterTestDescriptor <ODataItem>(this.Settings, testDescriptor.PayloadItems, testDescriptor.ExpectedResultCallback) { Model = testDescriptor.Model, PayloadEdmElementContainer = testDescriptor.PayloadEdmElementContainer, PayloadEdmElementType = testDescriptor.PayloadEdmElementType, ThrowUserExceptionAt = throwUserExceptionAt, }; TestWriterUtils.WriteAndVerifyODataEdmPayload(configuredTestDescriptor, testConfiguration, this.Assert, this.Logger); } }); }
public void WriteEntityReferenceLinkAfterFeedJsonLightErrorTest() { EdmModel model = new EdmModel(); var container = new EdmEntityContainer("TestModel", "DefaultContainer"); model.AddElement(container); var customerType = new EdmEntityType("TestModel", "Customer"); var orderType = new EdmEntityType("TestModel", "Order"); var orderNavProp = customerType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Orders", Target = orderType, TargetMultiplicity = EdmMultiplicity.Many }); var bestFriendNavProp = customerType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "BestFriend", Target = customerType, TargetMultiplicity = EdmMultiplicity.One }); var customerSet = container.AddEntitySet("Customers", customerType); var orderSet = container.AddEntitySet("Order", orderType); customerSet.AddNavigationTarget(orderNavProp, orderSet); customerSet.AddNavigationTarget(bestFriendNavProp, customerSet); model.AddElement(customerType); model.AddElement(orderType); ODataResource expandedOrderInstance = ObjectModelUtils.CreateDefaultEntryWithAtomMetadata(); expandedOrderInstance.TypeName = "TestModel.Order"; var testCases = new WriterNavigationLinkTests.NavigationLinkTestCase[] { // Entity reference link after empty feed in collection navigation link new WriterNavigationLinkTests.NavigationLinkTestCase { Items = new ODataItem[] { new ODataNestedResourceInfo() { IsCollection = true, Name = "Orders", Url = new Uri("http://odata.org/nav") }, ObjectModelUtils.CreateDefaultFeedWithAtomMetadata(), null, new ODataEntityReferenceLink() { Url = new Uri("http://odata.org/singleton") }, }, ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightWriter_EntityReferenceLinkAfterResourceSetInRequest") }, // Entity reference link after non-empty feed in collection navigation link new WriterNavigationLinkTests.NavigationLinkTestCase { Items = new ODataItem[] { new ODataNestedResourceInfo() { IsCollection = true, Name = "Orders", Url = new Uri("http://odata.org/nav") }, ObjectModelUtils.CreateDefaultFeedWithAtomMetadata(), expandedOrderInstance, null, null, new ODataEntityReferenceLink() { Url = new Uri("http://odata.org/singleton") }, }, ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightWriter_EntityReferenceLinkAfterResourceSetInRequest") }, // Entity reference link before and after empty feed in collection navigation link new WriterNavigationLinkTests.NavigationLinkTestCase { Items = new ODataItem[] { new ODataNestedResourceInfo() { IsCollection = true, Name = "Orders", Url = new Uri("http://odata.org/nav") }, new ODataEntityReferenceLink() { Url = new Uri("http://odata.org/singleton") }, ObjectModelUtils.CreateDefaultFeedWithAtomMetadata(), null, new ODataEntityReferenceLink() { Url = new Uri("http://odata.org/singleton") }, }, ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightWriter_EntityReferenceLinkAfterResourceSetInRequest") }, // Entity reference link after two empty feeds in collection navigation link new WriterNavigationLinkTests.NavigationLinkTestCase { Items = new ODataItem[] { new ODataNestedResourceInfo() { IsCollection = true, Name = "Orders", Url = new Uri("http://odata.org/nav") }, new ODataEntityReferenceLink() { Url = new Uri("http://odata.org/singleton") }, ObjectModelUtils.CreateDefaultFeedWithAtomMetadata(), null, ObjectModelUtils.CreateDefaultFeedWithAtomMetadata(), null, new ODataEntityReferenceLink() { Url = new Uri("http://odata.org/singleton") }, }, ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightWriter_EntityReferenceLinkAfterResourceSetInRequest") }, }; IEnumerable <PayloadWriterTestDescriptor <ODataItem> > testDescriptors = testCases.Select(testCase => testCase.ToEdmTestDescriptor(this.Settings, model, customerSet, customerType)); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.WriterTestConfigurationProvider.JsonLightFormatConfigurations.Where(tc => tc.IsRequest), (testDescriptor, testConfiguration) => { TestWriterUtils.WriteAndVerifyODataEdmPayload(testDescriptor, testConfiguration, this.Assert, this.Logger); }); }