예제 #1
0
        public void InnerStreamIsNotFlushedOnDispose()
        {
            var stream           = FlushReportingStream.GetThrowingStream();
            var delegatingStream = new DelegatingStream(stream);

            // Act & Assert
            delegatingStream.Dispose();
        }
예제 #2
0
        public async Task InnerStreamIsNotFlushedOnFlushAsync()
        {
            // Arrange
            var stream = FlushReportingStream.GetThrowingStream();

            var delegatingStream = new DelegatingStream(stream);

            // Act & Assert
            await delegatingStream.FlushAsync();
        }
예제 #3
0
        public void InnerStreamIsNotFlushedOnFlush()
        {
            // Arrange
            var stream = FlushReportingStream.GetThrowingStream();

            var delegatingStream = new DelegatingStream(stream);

            // Act & Assert
            delegatingStream.Flush();
        }
예제 #4
0
        public void InnerStreamIsOpenOnDispose()
        {
            // Arrange
            var innerStream      = new MemoryStream();
            var delegatingStream = new DelegatingStream(innerStream);

            // Act
            delegatingStream.Dispose();

            // Assert
            Assert.True(innerStream.CanRead);
        }
예제 #5
0
        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));
        }
예제 #6
0
        /// <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));
        }
예제 #7
0
        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));
        }