WriteToStreamAsync() приватный Метод

private WriteToStreamAsync ( Type type, object value, Stream writeStream, HttpContent content, System.Net.TransportContext transportContext ) : System.Threading.Tasks.Task
type Type
value object
writeStream System.IO.Stream
content System.Net.Http.HttpContent
transportContext System.Net.TransportContext
Результат System.Threading.Tasks.Task
 public override Task WriteToStreamAsync(
     Type type,
     object value,
     Stream writeStream,
     HttpContent content,
     TransportContext transportContext
     )
 {
     return(_innerTracer.WriteToStreamAsync(
                type,
                value,
                writeStream,
                content,
                transportContext
                ));
 }
        public void OnWriteToStreamAsync_Traces_And_Faults_When_Inner_Faults()
        {
            // Arrange
            InvalidOperationException exception     = new InvalidOperationException("test");
            Mock <MediaTypeFormatter> mockFormatter = new Mock <MediaTypeFormatter>()
            {
                CallBase = true
            };
            TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();

            tcs.TrySetException(exception);

            mockFormatter.Setup(
                f => f.WriteToStreamAsync(It.IsAny <Type>(), It.IsAny <Object>(), It.IsAny <Stream>(), It.IsAny <HttpContentHeaders>(), It.IsAny <TransportContext>())).
            Returns(tcs.Task);

            TestTraceWriter    traceWriter = new TestTraceWriter();
            HttpRequestMessage request     = new HttpRequestMessage();

            request.Content = new StringContent("");
            MediaTypeFormatterTracer tracer = new MediaTypeFormatterTracer(mockFormatter.Object, traceWriter, request);

            TraceRecord[] expectedTraces = new TraceRecord[]
            {
                new TraceRecord(request, TraceCategories.FormattingCategory, TraceLevel.Info)
                {
                    Kind = TraceKind.Begin, Operation = "WriteToStreamAsync"
                },
                new TraceRecord(request, TraceCategories.FormattingCategory, TraceLevel.Error)
                {
                    Kind = TraceKind.End, Operation = "WriteToStreamAsync"
                }
            };

            // Act
            Task task = tracer.WriteToStreamAsync(typeof(string), "sampleValue", new MemoryStream(), request.Content.Headers, transportContext: null);

            // Assert
            Exception thrown = Assert.Throws <InvalidOperationException>(() => task.Wait());

            Assert.Equal <TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
            Assert.Same(exception, thrown);
            Assert.Same(exception, traceWriter.Traces[1].Exception);
        }
        public void OnWriteToStreamAsync_Traces()
        {
            // Arrange
            Mock <MediaTypeFormatter> mockFormatter = new Mock <MediaTypeFormatter>()
            {
                CallBase = true
            };

            mockFormatter.Setup(
                f => f.WriteToStreamAsync(It.IsAny <Type>(), It.IsAny <Object>(), It.IsAny <Stream>(), It.IsAny <HttpContentHeaders>(), It.IsAny <TransportContext>())).
            Returns(TaskHelpers.Completed());
            TestTraceWriter    traceWriter = new TestTraceWriter();
            HttpRequestMessage request     = new HttpRequestMessage();

            request.Content = new StringContent("");
            MediaTypeFormatterTracer tracer = new MediaTypeFormatterTracer(mockFormatter.Object, traceWriter, request);

            TraceRecord[] expectedTraces = new TraceRecord[]
            {
                new TraceRecord(request, TraceCategories.FormattingCategory, TraceLevel.Info)
                {
                    Kind = TraceKind.Begin, Operation = "WriteToStreamAsync"
                },
                new TraceRecord(request, TraceCategories.FormattingCategory, TraceLevel.Info)
                {
                    Kind = TraceKind.End, Operation = "WriteToStreamAsync"
                }
            };

            // Act
            Task task = tracer.WriteToStreamAsync(typeof(string), "sampleValue", new MemoryStream(), request.Content.Headers, transportContext: null);

            task.Wait();

            // Assert
            Assert.Equal <TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
        }
        public void OnWriteToStreamAsync_Traces_And_Faults_When_Inner_Faults()
        {
            // Arrange
            InvalidOperationException exception = new InvalidOperationException("test");
            Mock<MediaTypeFormatter> mockFormatter = new Mock<MediaTypeFormatter>() { CallBase = true };
            TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
            tcs.TrySetException(exception);

            mockFormatter.Setup(
                f => f.WriteToStreamAsync(It.IsAny<Type>(), It.IsAny<Object>(), It.IsAny<Stream>(), It.IsAny<HttpContentHeaders>(), It.IsAny<TransportContext>())).
                Returns(tcs.Task);

            TestTraceWriter traceWriter = new TestTraceWriter();
            HttpRequestMessage request = new HttpRequestMessage();
            request.Content = new StringContent("");
            MediaTypeFormatterTracer tracer = new MediaTypeFormatterTracer(mockFormatter.Object, traceWriter, request);
            TraceRecord[] expectedTraces = new TraceRecord[]
            {
                new TraceRecord(request, TraceCategories.FormattingCategory, TraceLevel.Info) { Kind = TraceKind.Begin, Operation = "WriteToStreamAsync" },
                new TraceRecord(request, TraceCategories.FormattingCategory, TraceLevel.Error) { Kind = TraceKind.End, Operation = "WriteToStreamAsync" }
            };

            // Act
            Task task = tracer.WriteToStreamAsync(typeof(string), "sampleValue", new MemoryStream(), request.Content.Headers, transportContext: null);

            // Assert
            Exception thrown = Assert.Throws<InvalidOperationException>(() => task.Wait());
            Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
            Assert.Same(exception, thrown);
            Assert.Same(exception, traceWriter.Traces[1].Exception);
        }
        public void OnWriteToStreamAsync_Traces()
        {
            // Arrange
            Mock<MediaTypeFormatter> mockFormatter = new Mock<MediaTypeFormatter>() { CallBase = true };
            mockFormatter.Setup(
                f => f.WriteToStreamAsync(It.IsAny<Type>(), It.IsAny<Object>(), It.IsAny<Stream>(), It.IsAny<HttpContentHeaders>(), It.IsAny<TransportContext>())).
                Returns(TaskHelpers.Completed());
            TestTraceWriter traceWriter = new TestTraceWriter();
            HttpRequestMessage request = new HttpRequestMessage();
            request.Content = new StringContent("");
            MediaTypeFormatterTracer tracer = new MediaTypeFormatterTracer(mockFormatter.Object, traceWriter, request);
            TraceRecord[] expectedTraces = new TraceRecord[]
            {
                new TraceRecord(request, TraceCategories.FormattingCategory, TraceLevel.Info) { Kind = TraceKind.Begin, Operation = "WriteToStreamAsync" },
                new TraceRecord(request, TraceCategories.FormattingCategory, TraceLevel.Info) { Kind = TraceKind.End, Operation = "WriteToStreamAsync" }
            };

            // Act
            Task task = tracer.WriteToStreamAsync(typeof(string), "sampleValue", new MemoryStream(), request.Content.Headers, transportContext: null);
            task.Wait();

            // Assert
            Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
        }