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(); } }
/// <summary>Initializes a new instance of the <see cref="T:Microsoft.OData.Core.ODataMessageReaderSettings" /> class.</summary> /// <param name="other">The other message reader settings.</param> public ODataMessageReaderSettings(ODataMessageReaderSettings other) : base(other) { ExceptionUtils.CheckArgumentNotNull(other, "other"); this.BaseUri = other.BaseUri; this.DisableMessageStreamDisposal = other.DisableMessageStreamDisposal; this.DisablePrimitiveTypeConversion = other.DisablePrimitiveTypeConversion; this.UndeclaredPropertyBehaviorKinds = other.UndeclaredPropertyBehaviorKinds; this.MaxProtocolVersion = other.MaxProtocolVersion; // NOTE: reader behavior is immutable; copy by reference is ok. this.readerBehavior = other.ReaderBehavior; this.EnableAtom = other.EnableAtom; this.EnableFullValidation = other.EnableFullValidation; this.UseKeyAsSegment = other.UseKeyAsSegment; this.mediaTypeResolver = other.mediaTypeResolver; this.ODataSimplified = other.ODataSimplified; }
/// <summary>Initializes a new instance of the <see cref="T:Microsoft.OData.Core.ODataMessageWriterSettings" /> class with specified settings.</summary> /// <param name="other">The specified settings.</param> public ODataMessageWriterSettings(ODataMessageWriterSettings other) : base(other) { ExceptionUtils.CheckArgumentNotNull(other, "other"); this.acceptCharSets = other.acceptCharSets; this.acceptMediaTypes = other.acceptMediaTypes; this.PayloadBaseUri = other.PayloadBaseUri; this.DisableMessageStreamDisposal = other.DisableMessageStreamDisposal; this.format = other.format; this.useFormat = other.useFormat; this.Version = other.Version; this.JsonPCallback = other.JsonPCallback; this.shouldIncludeAnnotation = other.shouldIncludeAnnotation; this.AutoComputePayloadMetadataInJson = other.AutoComputePayloadMetadataInJson; this.UseKeyAsSegment = other.UseKeyAsSegment; this.alwaysUseDefaultXmlNamespaceForRootElement = other.alwaysUseDefaultXmlNamespaceForRootElement; this.ODataUri = other.ODataUri; // NOTE: writer behavior is immutable; copy by reference is ok. this.writerBehavior = other.writerBehavior; this.EnableAtom = other.EnableAtom; this.EnableFullValidation = other.EnableFullValidation; this.mediaTypeResolver = other.mediaTypeResolver; }
/// <summary>Initializes a new instance of the <see cref="T:Microsoft.OData.Core.ODataMessageWriterSettings" /> class with default settings. </summary> public ODataMessageWriterSettings() : base() { // Create the default writer behavior this.writerBehavior = ODataWriterBehavior.DefaultBehavior; this.EnableAtom = false; this.EnableFullValidation = true; this.mediaTypeResolver = null; }
public void CopyConstructorShouldCopyMediaTypeResolver() { var resolver = new ODataMediaTypeResolver(); this.settings.MediaTypeResolver = resolver; var newSetting = new ODataMessageWriterSettings(this.settings); newSetting.MediaTypeResolver.Should().Be(resolver); }
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 static ODataMessageReader CreateMessageReader( Stream stream, string contenttype = "application/json", ODataMediaTypeResolver resolver = null, IEdmModel model = null, bool isResponse = false) { var message = new InMemoryMessage { Stream = stream }; message.SetHeader("Content-Type", contenttype); var messageSettings = new ODataMessageReaderSettings() { MediaTypeResolver = resolver ?? new ODataMediaTypeResolver(), ShouldIncludeAnnotation = st => true, }; if (isResponse) { return new ODataMessageReader((IODataResponseMessage)message, messageSettings, model); } else { return new ODataMessageReader((IODataRequestMessage)message, messageSettings, model); } }
public static string GetToplevelPropertyPayloadString( object value, string contenttype = "application/json", ODataMediaTypeResolver resolver = null) { Stream stream = null; try { stream = new MemoryStream(); using (var omw = CreateMessageWriter(stream, contenttype, resolver, null, false)) { omw.WriteProperty(new ODataProperty { Name = "fa", Value = value }); } stream.Seek(0, SeekOrigin.Begin); using (var sr = new StreamReader(stream)) { stream = null; return sr.ReadToEnd(); } } finally { if (stream != null) stream.Dispose(); } }
public static ODataMessageWriter CreateMessageWriter( Stream stream, string contenttype = "application/json", ODataMediaTypeResolver resolver = null, IEdmModel model = null, bool isResponse = true) { var message = new InMemoryMessage { Stream = stream }; message.SetHeader("Content-Type", contenttype); var messageSettings = new ODataMessageWriterSettings { MediaTypeResolver = resolver ?? new ODataMediaTypeResolver(), DisableMessageStreamDisposal = true, Indent = true, }; if (isResponse) { return new ODataMessageWriter((IODataResponseMessage)message, messageSettings, model); } else { return new ODataMessageWriter((IODataRequestMessage)message, messageSettings, model); } }
public void CopyConstructorShouldCopyMediaTypeResolver() { var resolver = new ODataMediaTypeResolver(); ODataMessageReaderSettings testSubject = new ODataMessageReaderSettings(); testSubject.MediaTypeResolver = resolver; var copy = new ODataMessageReaderSettings(testSubject); copy.MediaTypeResolver.Should().Be(resolver); }