public void BaseUriErrorTest() { Uri baseUri = new Uri("http://odata.org"); Uri testUri = new Uri("http://odata.org/relative"); IEnumerable <Func <Uri, BaseUriErrorTestCase> > testCaseFuncs = new Func <Uri, BaseUriErrorTestCase>[] { relativeUri => new BaseUriErrorTestCase { // next page link ItemFunc = new Func <IEnumerable <ODataItem> >(() => { ODataResourceSet feed = ObjectModelUtils.CreateDefaultFeed(); feed.NextPageLink = relativeUri; return(new [] { feed }); }), Formats = new [] { ODataFormat.Json } }, relativeUri => new BaseUriErrorTestCase { // entry read link ItemFunc = new Func <IEnumerable <ODataItem> >(() => { ODataResource entry = ObjectModelUtils.CreateDefaultEntry(); entry.ReadLink = relativeUri; return(new [] { entry }); }), Formats = new [] { ODataFormat.Json } }, relativeUri => new BaseUriErrorTestCase { // entry edit link ItemFunc = new Func <IEnumerable <ODataItem> >(() => { ODataResource entry = ObjectModelUtils.CreateDefaultEntry(); entry.EditLink = relativeUri; return(new [] { entry }); }), Formats = new [] { ODataFormat.Json } }, relativeUri => new BaseUriErrorTestCase { // media resource (default stream) read link ItemFunc = new Func <IEnumerable <ODataItem> >(() => { ODataStreamReferenceValue mediaResource = new ODataStreamReferenceValue(); mediaResource.ContentType = "image/jpg"; mediaResource.ReadLink = relativeUri; ODataResource entry = ObjectModelUtils.CreateDefaultEntry(); entry.MediaResource = mediaResource; return(new [] { entry }); }), Formats = new [] { ODataFormat.Json } }, relativeUri => new BaseUriErrorTestCase { // media resource (default stream) edit link ItemFunc = new Func <IEnumerable <ODataItem> >(() => { ODataStreamReferenceValue mediaResource = new ODataStreamReferenceValue(); mediaResource.ContentType = "image/jpg"; // required mediaResource.ReadLink = testUri; // required mediaResource.EditLink = relativeUri; ODataResource entry = ObjectModelUtils.CreateDefaultEntry(); entry.MediaResource = mediaResource; return(new [] { entry }); }), Formats = new [] { ODataFormat.Json } }, relativeUri => new BaseUriErrorTestCase { // link Url ItemFunc = new Func <IEnumerable <ODataItem> >(() => { ODataNestedResourceInfo link = ObjectModelUtils.CreateDefaultCollectionLink(); link.Url = relativeUri; ODataResource entry = ObjectModelUtils.CreateDefaultEntry(); return(new ODataItem[] { entry, link }); }), Formats = new [] { ODataFormat.Json } }, relativeUri => new BaseUriErrorTestCase { // association link Url ItemFunc = new Func <IEnumerable <ODataItem> >(() => { ODataNestedResourceInfo link = ObjectModelUtils.CreateDefaultSingletonLink(); link.AssociationLinkUrl = relativeUri; ODataResource entry = ObjectModelUtils.CreateDefaultEntry(); return(new ODataItem[] { entry, link }); }), Formats = new [] { ODataFormat.Json } }, relativeUri => new BaseUriErrorTestCase { // named stream read link ItemFunc = new Func <IEnumerable <ODataItem> >(() => { ODataStreamReferenceValue namedStream = new ODataStreamReferenceValue() { ContentType = "image/jpg", ReadLink = relativeUri, }; ODataResource entry = ObjectModelUtils.CreateDefaultEntry(); ODataProperty property = new ODataProperty() { Name = "NamedStream", Value = namedStream }; entry.Properties = new[] { property }; return(new [] { entry }); }), Formats = new [] { ODataFormat.Json } }, relativeUri => new BaseUriErrorTestCase { // named stream edit link ItemFunc = new Func <IEnumerable <ODataItem> >(() => { ODataStreamReferenceValue namedStream = new ODataStreamReferenceValue() { ContentType = "image/jpg", ReadLink = testUri, EditLink = relativeUri }; ODataResource entry = ObjectModelUtils.CreateDefaultEntry(); ODataProperty property = new ODataProperty() { Name = "NamedStream", Value = namedStream }; entry.Properties = new[] { property }; return(new [] { entry }); }), Formats = new [] { ODataFormat.Json } }, relativeUri => new BaseUriErrorTestCase { // Atom metadata: feed generator Uri ItemFunc = new Func <IEnumerable <ODataItem> >(() => { ODataResourceSet feed = ObjectModelUtils.CreateDefaultFeed(); return(new [] { feed }); }), Formats = new [] { ODataFormat.Json } }, relativeUri => new BaseUriErrorTestCase { // Atom metadata: feed logo ItemFunc = new Func <IEnumerable <ODataItem> >(() => { ODataResourceSet feed = ObjectModelUtils.CreateDefaultFeed(); return(new [] { feed }); }), Formats = new [] { ODataFormat.Json } }, relativeUri => new BaseUriErrorTestCase { // Atom metadata: feed icon ItemFunc = new Func <IEnumerable <ODataItem> >(() => { ODataResourceSet feed = ObjectModelUtils.CreateDefaultFeed(); return(new [] { feed }); }), Formats = new [] { ODataFormat.Json } }, relativeUri => new BaseUriErrorTestCase { // Atom metadata: feed author ItemFunc = new Func <IEnumerable <ODataItem> >(() => { ODataResourceSet feed = ObjectModelUtils.CreateDefaultFeed(); return(new [] { feed }); }), Formats = new [] { ODataFormat.Json } }, relativeUri => new BaseUriErrorTestCase { // Atom metadata: feed contributor ItemFunc = new Func <IEnumerable <ODataItem> >(() => { ODataResourceSet feed = ObjectModelUtils.CreateDefaultFeed(); return(new [] { feed }); }), Formats = new [] { ODataFormat.Json } }, relativeUri => new BaseUriErrorTestCase { // Atom metadata: feed link ItemFunc = new Func <IEnumerable <ODataItem> >(() => { ODataResourceSet feed = ObjectModelUtils.CreateDefaultFeed(); return(new [] { feed }); }), Formats = new [] { ODataFormat.Json } }, relativeUri => new BaseUriErrorTestCase { // Atom metadata: entry author ItemFunc = new Func <IEnumerable <ODataItem> >(() => { ODataResource entry = ObjectModelUtils.CreateDefaultEntry(); return(new [] { entry }); }), Formats = new [] { ODataFormat.Json } }, relativeUri => new BaseUriErrorTestCase { // Atom metadata: entry contributor ItemFunc = new Func <IEnumerable <ODataItem> >(() => { ODataResource entry = ObjectModelUtils.CreateDefaultEntry(); return(new [] { entry }); }), Formats = new [] { ODataFormat.Json } }, relativeUri => new BaseUriErrorTestCase { // Atom metadata: entry link ItemFunc = new Func <IEnumerable <ODataItem> >(() => { ODataResource entry = ObjectModelUtils.CreateDefaultEntry(); return(new [] { entry }); }), Formats = new [] { ODataFormat.Json } }, }; // ToDo: Fix places where we've lost JsonVerbose coverage to add JsonLight Uri testRelativeUri = baseUri.MakeRelativeUri(testUri); Uri invalidRelativeUri = new Uri("../invalid/relative/uri", UriKind.Relative); this.CombinatorialEngineProvider.RunCombinations( testCaseFuncs, this.WriterTestConfigurationProvider.ExplicitFormatConfigurations.Where(c => false), new Uri[] { testRelativeUri, invalidRelativeUri }, new bool[] { false, true }, (testCaseFunc, testConfiguration, uri, implementUrlResolver) => { var testCase = testCaseFunc(uri); var testDescriptor = new { Descriptor = new PayloadWriterTestDescriptor <ODataItem>( this.Settings, testCase.ItemFunc(), testConfig => new WriterTestExpectedResults(this.Settings.ExpectedResultSettings) { ExpectedException2 = ODataExpectedExceptions.ODataException("ODataWriter_RelativeUriUsedWithoutBaseUriSpecified", uri.OriginalString) }), Formats = testCase.Formats }; if (testDescriptor.Formats.Contains(testConfiguration.Format)) { PayloadWriterTestDescriptor <ODataItem> payloadTestDescriptor = testDescriptor.Descriptor; TestUrlResolver urlResolver = null; if (implementUrlResolver) { payloadTestDescriptor = new PayloadWriterTestDescriptor <ODataItem>(payloadTestDescriptor); urlResolver = new TestUrlResolver(); payloadTestDescriptor.UrlResolver = urlResolver; } testConfiguration = testConfiguration.Clone(); testConfiguration.MessageWriterSettings.SetServiceDocumentUri(ServiceDocumentUri); TestWriterUtils.WriteAndVerifyODataPayload(payloadTestDescriptor, testConfiguration, this.Assert, this.Logger); if (implementUrlResolver) { this.Assert.AreEqual(1, urlResolver.Calls.Where(call => call.Value.OriginalString == uri.OriginalString).Count(), "The resolver should be called exactly once for each URL."); } } }); }
public void EntityReferenceLinkValidationTest() { var testCases = new[] { new { InvalidateEntityReferenceLink = new Action <ODataEntityReferenceLink>(entityReferenceLink => entityReferenceLink.Url = null), ExpectedException = ODataExpectedExceptions.ODataException("WriterValidationUtils_EntityReferenceLinkUrlMustNotBeNull"), }, }; var testDescriptors = testCases.SelectMany(testCase => { ODataEntityReferenceLink entityReferenceLink = ObjectModelUtils.CreateDefaultEntityReferenceLink(); testCase.InvalidateEntityReferenceLink(entityReferenceLink); ODataEntityReferenceLinks entityReferenceLinks = ObjectModelUtils.CreateDefaultEntityReferenceLinks(); testCase.InvalidateEntityReferenceLink(entityReferenceLinks.Links.First()); return(new PayloadWriterTestDescriptor[] { // Top level entity reference link new PayloadWriterTestDescriptor <ODataEntityReferenceLink>( this.Settings, entityReferenceLink, testConfiguration => new WriterTestExpectedResults(this.Settings.ExpectedResultSettings) { ExpectedException2 = testCase.ExpectedException }), // Entity reference link in entity reference links new PayloadWriterTestDescriptor <ODataEntityReferenceLinks>( this.Settings, entityReferenceLinks, testConfiguration => new WriterTestExpectedResults(this.Settings.ExpectedResultSettings) { // Top-level EntityReferenceLinks payload write requests are not allowed. ExpectedException2 = testConfiguration.IsRequest ? ODataExpectedExceptions.ODataException("ODataMessageWriter_EntityReferenceLinksInRequestNotAllowed") : testCase.ExpectedException }), new PayloadWriterTestDescriptor <ODataItem>( this.Settings, new ODataItem[] { ObjectModelUtils.CreateDefaultEntry(), ObjectModelUtils.CreateDefaultSingletonLink(), entityReferenceLink, null, null }, testConfiguration => new WriterTestExpectedResults(this.Settings.ExpectedResultSettings) { ExpectedException2 = testConfiguration.IsRequest ? testCase.ExpectedException : ODataExpectedExceptions.ODataException("ODataWriterCore_EntityReferenceLinkInResponse") }), }); }); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.WriterTestConfigurationProvider.AtomFormatConfigurations, (testDescriptor, testConfiguration) => { testConfiguration = testConfiguration.Clone(); testConfiguration.MessageWriterSettings.SetServiceDocumentUri(ServiceDocumentUri); PayloadWriterTestDescriptor <ODataEntityReferenceLink> entityReferenceLinkTestDescriptor = testDescriptor as PayloadWriterTestDescriptor <ODataEntityReferenceLink>; if (entityReferenceLinkTestDescriptor != null) { TestWriterUtils.WriteAndVerifyTopLevelContent( entityReferenceLinkTestDescriptor, testConfiguration, (messageWriter) => messageWriter.WriteEntityReferenceLink(entityReferenceLinkTestDescriptor.PayloadItems.Single()), this.Assert, baselineLogger: this.Logger); return; } PayloadWriterTestDescriptor <ODataEntityReferenceLinks> entityReferenceLinksTestDescriptor = testDescriptor as PayloadWriterTestDescriptor <ODataEntityReferenceLinks>; if (entityReferenceLinksTestDescriptor != null) { TestWriterUtils.WriteAndVerifyTopLevelContent( entityReferenceLinksTestDescriptor, testConfiguration, (messageWriter) => messageWriter.WriteEntityReferenceLinks(entityReferenceLinksTestDescriptor.PayloadItems.Single()), this.Assert, baselineLogger: this.Logger); return; } TestWriterUtils.WriteAndVerifyODataPayload((PayloadWriterTestDescriptor <ODataItem>)testDescriptor, testConfiguration, this.Assert, this.Logger); }); }
/// <summary> /// Returns all interesting payloads for an entry. /// </summary> /// <param name="testDescriptor">The test descriptor which will end up writing a single entry.</param> /// <returns>Enumeration of test descriptors which will include the original entry in some interesting scenarios.</returns> public static IEnumerable <PayloadWriterTestDescriptor <ODataItem> > EntryPayloads(PayloadWriterTestDescriptor <ODataItem> testDescriptor) { Debug.Assert(testDescriptor.PayloadItems[0] is ODataResource, "The payload does not specify an entry."); var payloadCases = new WriterPayloadCase <ODataItem>[] { // Feed with a single entry new WriterPayloadCase <ODataItem>() { GetPayloadItems = () => new ODataItem[] { ObjectModelUtils.CreateDefaultFeed() }.Concat(testDescriptor.PayloadItems), AtomFragmentExtractor = (testConfiguration, result) => { return(result.Elements(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomEntryElementName).First()); }, //ToDo: Fix places where we've lost JsonVerbose coverage to add JsonLight }, // Feed with three (identical) entries, picking the second one new WriterPayloadCase <ODataItem>() { GetPayloadItems = () => new ODataItem[] { ObjectModelUtils.CreateDefaultFeed() } .Concat(testDescriptor.PayloadItems) .Concat(LinqExtensions.FromSingle((ODataItem)null)) .Concat(testDescriptor.PayloadItems) .Concat(LinqExtensions.FromSingle((ODataItem)null)) .Concat(testDescriptor.PayloadItems) .Concat(LinqExtensions.FromSingle((ODataItem)null)), AtomFragmentExtractor = (testConfiguration, result) => { var entries = result.Elements(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomEntryElementName); Debug.Assert(entries.Count() == 3, "Expected three entries in the feed."); return(entries.ElementAt(2)); }, //ToDo: Fix places where we've lost JsonVerbose coverage to add JsonLight }, // Top-level entry with an expanded link containing a single entry new WriterPayloadCase <ODataItem>() { GetPayloadItems = () => new ODataItem[] { ObjectModelUtils.CreateDefaultEntry(), ObjectModelUtils.CreateDefaultSingletonLink(), }.Concat(testDescriptor.PayloadItems), AtomFragmentExtractor = (testConfiguration, result) => { return(result.Elements(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomLinkElementName) .First(e => e.Element(TestAtomConstants.ODataMetadataXNamespace + TestAtomConstants.ODataInlineElementName) != null) .Element(TestAtomConstants.ODataMetadataXNamespace + TestAtomConstants.ODataInlineElementName) .Element(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomEntryElementName)); }, //ToDo: Fix places where we've lost JsonVerbose coverage to add JsonLight }, // Top-level entry with an expanded link containing a feed with a single entry new WriterPayloadCase <ODataItem>() { GetPayloadItems = () => new ODataItem[] { ObjectModelUtils.CreateDefaultEntry(), ObjectModelUtils.CreateDefaultCollectionLink(), ObjectModelUtils.CreateDefaultFeed() }.Concat(testDescriptor.PayloadItems), AtomFragmentExtractor = (testConfiguration, result) => { return(result.Elements(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomLinkElementName) .First(e => e.Element(TestAtomConstants.ODataMetadataXNamespace + TestAtomConstants.ODataInlineElementName) != null) .Element(TestAtomConstants.ODataMetadataXNamespace + TestAtomConstants.ODataInlineElementName) .Element(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomFeedElementName) .Element(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomEntryElementName)); }, //ToDo: Fix places where we've lost JsonVerbose coverage to add JsonLight }, // Top-level entry with an expanded link containing a feed with three entries; picking the second one new WriterPayloadCase <ODataItem>() { GetPayloadItems = () => new ODataItem[] { ObjectModelUtils.CreateDefaultEntry(), ObjectModelUtils.CreateDefaultCollectionLink(), ObjectModelUtils.CreateDefaultFeed() } .Concat(testDescriptor.PayloadItems) .Concat(LinqExtensions.FromSingle((ODataItem)null)) .Concat(testDescriptor.PayloadItems) .Concat(LinqExtensions.FromSingle((ODataItem)null)) .Concat(testDescriptor.PayloadItems) .Concat(LinqExtensions.FromSingle((ODataItem)null)), AtomFragmentExtractor = (testConfiguration, result) => { return(result.Elements(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomLinkElementName) .First(e => e.Element(TestAtomConstants.ODataMetadataXNamespace + TestAtomConstants.ODataInlineElementName) != null) .Element(TestAtomConstants.ODataMetadataXNamespace + TestAtomConstants.ODataInlineElementName) .Element(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomFeedElementName) .Elements(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomEntryElementName) .ElementAt(2)); }, //ToDo: Fix places where we've lost JsonVerbose coverage to add JsonLight }, // Top-level entry with an expanded link containing a feed with a single entry; // that entry has another expanded link containing a feed with the payload entry new WriterPayloadCase <ODataItem>() { GetPayloadItems = () => new ODataItem[] { ObjectModelUtils.CreateDefaultEntry(), ObjectModelUtils.CreateDefaultCollectionLink(), ObjectModelUtils.CreateDefaultFeed(), ObjectModelUtils.CreateDefaultEntry(), ObjectModelUtils.CreateDefaultCollectionLink(), ObjectModelUtils.CreateDefaultFeed(), }.Concat(testDescriptor.PayloadItems), AtomFragmentExtractor = (testConfiguration, result) => { return(result.Elements(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomLinkElementName) .First(e => e.Element(TestAtomConstants.ODataMetadataXNamespace + TestAtomConstants.ODataInlineElementName) != null) .Element(TestAtomConstants.ODataMetadataXNamespace + TestAtomConstants.ODataInlineElementName) .Element(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomFeedElementName) .Element(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomEntryElementName) .Elements(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomLinkElementName) .First(e => e.Element(TestAtomConstants.ODataMetadataXNamespace + TestAtomConstants.ODataInlineElementName) != null) .Element(TestAtomConstants.ODataMetadataXNamespace + TestAtomConstants.ODataInlineElementName) .Element(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomFeedElementName) .Element(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomEntryElementName)); }, //ToDo: Fix places where we've lost JsonVerbose coverage to add JsonLight }, }; return(ApplyPayloadCases <ODataItem>(testDescriptor, payloadCases)); }
public void AssociationLinkMetadataValidationTest() { EdmModel model = new EdmModel(); var container = new EdmEntityContainer("TestModel", "Default"); model.AddElement(container); var edmEntityTypeOrderType = new EdmEntityType("TestModel", "OrderType"); model.AddElement(edmEntityTypeOrderType); var edmEntityTypeCustomerType = new EdmEntityType("TestModel", "CustomerType"); edmEntityTypeCustomerType.AddKeys(new EdmStructuralProperty(edmEntityTypeCustomerType, "ID", EdmCoreModel.Instance.GetInt32(false))); edmEntityTypeCustomerType.AddStructuralProperty("PrimitiveProperty", EdmCoreModel.Instance.GetString(true)); var edmNavigationPropertyAssociationLinkOne = edmEntityTypeCustomerType.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "Orders", Target = edmEntityTypeOrderType, TargetMultiplicity = EdmMultiplicity.Many }); var edmNavigationPropertyAssociationLinkTwo = edmEntityTypeCustomerType.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "BestFriend", Target = edmEntityTypeCustomerType, TargetMultiplicity = EdmMultiplicity.One }); model.AddElement(edmEntityTypeCustomerType); var edmEntityTypeOpenCustomerType = new EdmEntityType("TestModel", "OpenCustomerType", edmEntityTypeCustomerType, isAbstract: false, isOpen: true); model.AddElement(edmEntityTypeOpenCustomerType); var customerSet = container.AddEntitySet("Customers", edmEntityTypeCustomerType); var orderSet = container.AddEntitySet("Orders", edmEntityTypeOrderType); customerSet.AddNavigationTarget(edmNavigationPropertyAssociationLinkOne, orderSet); customerSet.AddNavigationTarget(edmNavigationPropertyAssociationLinkTwo, customerSet); Uri associationLinkUrl = new Uri("http://odata.org/associationlink"); var testCases = new[] { // Valid collection new { TypeName = "TestModel.CustomerType", NavigationLink = ObjectModelUtils.CreateDefaultCollectionLink("Orders"), ExpectedException = (ExpectedException)null, }, // Valid singleton new { TypeName = "TestModel.CustomerType", NavigationLink = ObjectModelUtils.CreateDefaultSingletonLink("BestFriend"), ExpectedException = (ExpectedException)null, }, // Undeclared on closed type new { TypeName = "TestModel.CustomerType", NavigationLink = ObjectModelUtils.CreateDefaultCollectionLink("NonExistant"), ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_PropertyDoesNotExistOnType", "NonExistant", "TestModel.CustomerType"), }, // Undeclared on open type new { TypeName = "TestModel.OpenCustomerType", NavigationLink = ObjectModelUtils.CreateDefaultCollectionLink("NonExistant"), ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_OpenNavigationProperty", "NonExistant", "TestModel.OpenCustomerType"), }, // Declared but of wrong kind new { TypeName = "TestModel.CustomerType", NavigationLink = ObjectModelUtils.CreateDefaultSingletonLink("PrimitiveProperty"), ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_NavigationPropertyExpected", "PrimitiveProperty", "TestModel.CustomerType", "Structural"), }, }; var testDescriptors = testCases.Select(testCase => { ODataResource entry = ObjectModelUtils.CreateDefaultEntry(); entry.TypeName = testCase.TypeName; ODataNestedResourceInfo navigationLink = testCase.NavigationLink; navigationLink.AssociationLinkUrl = associationLinkUrl; return(new PayloadWriterTestDescriptor <ODataItem>( this.Settings, new ODataItem[] { entry, navigationLink }, tc => (WriterTestExpectedResults) new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings) { ExpectedException2 = testCase.ExpectedException }) { Model = model, PayloadEdmElementContainer = customerSet }); }); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.WriterTestConfigurationProvider.AtomFormatConfigurations .Where(testConfiguration => !testConfiguration.IsRequest), (testDescriptor, testConfiguration) => { testConfiguration = testConfiguration.Clone(); testConfiguration.MessageWriterSettings.SetServiceDocumentUri(ServiceDocumentUri); TestWriterUtils.WriteAndVerifyODataPayload(testDescriptor, 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); } }); }