private static TestODataWriterCore CreateODataWriterCore(ODataFormat format, bool writingResponse, IEdmModel model, IEdmEntitySet writerSet, IEdmEntityType writerEntityType, bool writeFeed) { var resolver = new TestUrlResolver(); var settings = new ODataMessageWriterSettings { EnableMessageStreamDisposal = false, Version = ODataVersion.V4 }; settings.SetServiceDocumentUri(new Uri("http://example.com")); var outputContext = new TestODataOutputContext(format, settings, writingResponse, false, model, resolver); return(new TestODataWriterCore(outputContext, writerSet, writerEntityType, writeFeed)); }
private static TestODataWriterCore CreateODataWriterCore(ODataFormat format, bool writingResponse, IEdmModel model, IEdmEntitySet writerSet, IEdmEntityType writerEntityType, bool writeFeed) { var resolver = new TestUrlResolver(); var settings = new ODataMessageWriterSettings { DisableMessageStreamDisposal = true, Version = ODataVersion.V4 }; settings.SetServiceDocumentUri(new Uri("http://example.com")); var outputContext = new TestODataOutputContext(format, settings, writingResponse, false, model, resolver); return new TestODataWriterCore(outputContext, writerSet, writerEntityType, writeFeed); }
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."); } } }); }