public void MediaTypeResolutionForJsonBatchShouldWork() { string[] contentTypes = new string[] { "application/json", "application/json;odata.metadata=minimal", "application/json;odata.metadata=minimal;odata.streaming=true", "application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false" }; foreach (string contentType in contentTypes) { ODataMediaType mediaType; Encoding encoding; ODataPayloadKind payloadKind; ODataFormat format = MediaTypeUtils.GetFormatFromContentType(contentType, new[] { ODataPayloadKind.Batch }, ODataMediaTypeResolver.GetMediaTypeResolver(null), out mediaType, out encoding, out payloadKind); Assert.NotNull(mediaType); Assert.NotNull(encoding); Assert.Equal(ODataPayloadKind.Batch, payloadKind); Assert.Equal(ODataFormat.Json, format); } }
private ODataComplexValue GetTopLevelProperty(string res, string contentType, ODataMediaTypeResolver resolver, IEdmModel model = null, bool async = false) { Stream stream = null; // Read vcf try { stream = TestHelper.GetResourceStream(res); ODataComplexValue val = null; object value = null; using (var reader = TestHelper.CreateMessageReader(stream, contentType, resolver, model)) { stream = null; if (async) { var task = reader.ReadPropertyAsync(); task.Wait(); value = task.Result.Value; } else { value = reader.ReadProperty().Value; } } val = value as ODataComplexValue; Assert.IsNotNull(val); return(val); } finally { if (stream != null) { stream.Dispose(); } } }
public void CopyConstructorShouldCopyMediaTypeResolver() { var resolver = new ODataMediaTypeResolver(); this.settings.MediaTypeResolver = resolver; var newSetting = new ODataMessageWriterSettings(this.settings); newSetting.MediaTypeResolver.Should().Be(resolver); }
private static TestMediaTypeWithFormat GetResponseType(ODataVersion version, Action <ODataMessageWriterSettings> configureSettings) { var settings = new ODataMessageWriterSettings { Version = version }; configureSettings(settings); ODataMediaType mediaType; Encoding encoding; var format = MediaTypeUtils.GetContentTypeFromSettings(settings, ODataPayloadKind.Resource, ODataMediaTypeResolver.GetMediaTypeResolver(null), out mediaType, out encoding); Assert.NotNull(mediaType); Assert.NotNull(format); return(new TestMediaTypeWithFormat { MediaType = mediaType, Format = format }); }
internal static TestMediaTypeWithFormat ParseContentType(string contentType, ODataVersion version, ODataMediaTypeResolver resolver = null) { ODataMediaType mediaType; Encoding encoding; ODataPayloadKind payloadKind; var format = MediaTypeUtils.GetFormatFromContentType(contentType, new[] { ODataPayloadKind.Resource }, resolver ?? ODataMediaTypeResolver.GetMediaTypeResolver(null), out mediaType, out encoding, out payloadKind); Assert.NotNull(mediaType); Assert.NotNull(format); return(new TestMediaTypeWithFormat { MediaType = mediaType, Format = format }); }
public void MatchInfoCacheShouldWork() { var result1 = TestMediaTypeWithFormat.ParseContentType("application/json;odata.metadata=minimal", ODataVersion.V4); var result2 = TestMediaTypeWithFormat.ParseContentType("application/json;odata.metadata=minimal", ODataVersion.V4); var result3 = TestMediaTypeWithFormat.ParseContentType("application/json", ODataVersion.V4); var result4 = TestMediaTypeWithFormat.ParseContentType("application/json", ODataVersion.V4, ODataMediaTypeResolver.GetMediaTypeResolver(null)); result1.BeJsonLight().HaveDefaultMetadata(); result2.BeJsonLight().HaveDefaultMetadata(); result3.BeUnspecifiedJson(); result4.BeUnspecifiedJson(); }
internal static TestMediaTypeWithFormat ParseContentType(string contentType, ODataVersion version, ODataMediaTypeResolver resolver = null) { ODataMediaType mediaType; Encoding encoding; ODataPayloadKind payloadKind; string batchBoundary; var format = MediaTypeUtils.GetFormatFromContentType(contentType, new[] { ODataPayloadKind.Entry }, resolver ?? ODataMediaTypeResolver.DefaultMediaTypeResolver, out mediaType, out encoding, out payloadKind, out batchBoundary); mediaType.Should().NotBeNull(); format.Should().NotBeNull(); return new TestMediaTypeWithFormat { MediaType = mediaType, Format = format }; }
internal static TestMediaTypeWithFormat ParseContentType(string contentType, ODataVersion version, ODataMediaTypeResolver resolver = null) { ODataMediaType mediaType; Encoding encoding; ODataPayloadKind payloadKind; string batchBoundary; var format = MediaTypeUtils.GetFormatFromContentType(contentType, new[] { ODataPayloadKind.Entry }, resolver ?? ODataMediaTypeResolver.DefaultMediaTypeResolver, out mediaType, out encoding, out payloadKind, out batchBoundary); mediaType.Should().NotBeNull(); format.Should().NotBeNull(); return(new TestMediaTypeWithFormat { MediaType = mediaType, Format = format }); }
public void MultipartBoundariesShouldNotGrowCache() { for (int i = 1; i < 100; i++) { ODataMediaType mediaType; Encoding encoding; ODataPayloadKind payloadKind; MediaTypeUtils.GetFormatFromContentType(string.Format("multipart/mixed;boundary={0}", Guid.NewGuid()), new ODataPayloadKind[] { ODataPayloadKind.Batch }, ODataMediaTypeResolver.GetMediaTypeResolver(null), out mediaType, out encoding, out payloadKind); } Assert.True(MediaTypeUtils.GetCacheKeys().Count(k => k.StartsWith("multipart/mixed")) == 1, "Multiple multipart/mixed keys in cache"); }