public void InnerStreamIsNotFlushedOnDispose() { var stream = FlushReportingStream.GetThrowingStream(); var delegatingStream = new DelegatingStream(stream); // Act & Assert delegatingStream.Dispose(); }
public async Task InnerStreamIsNotFlushedOnFlushAsync() { // Arrange var stream = FlushReportingStream.GetThrowingStream(); var delegatingStream = new DelegatingStream(stream); // Act & Assert await delegatingStream.FlushAsync(); }
public void InnerStreamIsNotFlushedOnFlush() { // Arrange var stream = FlushReportingStream.GetThrowingStream(); var delegatingStream = new DelegatingStream(stream); // Act & Assert delegatingStream.Flush(); }
public void InnerStreamIsOpenOnDispose() { // Arrange var innerStream = new MemoryStream(); var delegatingStream = new DelegatingStream(innerStream); // Act delegatingStream.Dispose(); // Assert Assert.True(innerStream.CanRead); }
public override Task WriteResponseBodyAsync(OutputFormatterContext context) { var response = context.ActionContext.HttpContext.Response; var selectedEncoding = context.SelectedEncoding; using (var delegatingStream = new DelegatingStream(response.Body)) using (var writer = new StreamWriter(delegatingStream, selectedEncoding, 1024, leaveOpen: true)) { WriteObject(writer, context.Object); } return(Task.FromResult(true)); }
/// <inheritdoc /> public override Task WriteResponseBodyAsync([NotNull] OutputFormatterContext context) { var tempWriterSettings = WriterSettings.Clone(); tempWriterSettings.Encoding = context.SelectedEncoding; var innerStream = context.ActionContext.HttpContext.Response.Body; using (var outputStream = new DelegatingStream(innerStream)) using (var xmlWriter = CreateXmlWriter(outputStream, tempWriterSettings)) { var dataContractSerializer = (DataContractSerializer)CreateSerializer(GetObjectType(context)); dataContractSerializer.WriteObject(xmlWriter, context.Object); } return(Task.FromResult(true)); }
public override async Task WriteResponseBodyAsync(OutputFormatterContext context) { var valueAsString = (string)context.Object; if (valueAsString == null) { // if the value is null don't write anything. return; } var response = context.ActionContext.HttpContext.Response; using (var delegatingStream = new DelegatingStream(response.Body)) using (var writer = new StreamWriter(delegatingStream, context.SelectedEncoding, 1024, leaveOpen: true)) { await writer.WriteAsync(valueAsString); } }
/// <inheritdoc /> public override Task WriteResponseBodyAsync([NotNull] OutputFormatterContext context) { var response = context.ActionContext.HttpContext.Response; var tempWriterSettings = WriterSettings.Clone(); tempWriterSettings.Encoding = context.SelectedEncoding; var innerStream = context.ActionContext.HttpContext.Response.Body; using (var outputStream = new DelegatingStream(innerStream)) using (var xmlWriter = CreateXmlWriter(outputStream, tempWriterSettings)) { var runtimeType = context.Object == null ? null : context.Object.GetType(); var type = GetSerializableType(context.DeclaredType, runtimeType); var xmlSerializer = CreateSerializer(type); xmlSerializer.Serialize(xmlWriter, context.Object); } return(Task.FromResult(true)); }