public async Task ReadFromStream_Traces() { // Arrange string contentType = "text/plain"; object value = new object(); CustomMediaTypeFormatter formatter = new CustomMediaTypeFormatter(value); formatter.SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse(contentType)); TestTraceWriter traceWriter = new TestTraceWriter(); HttpRequestMessage request = new HttpRequestMessage(); request.Content = new StringContent("42", Encoding.Default, contentType); MediaTypeFormatterTracer tracer = new MediaTypeFormatterTracer(formatter, traceWriter, request); TraceRecord[] expectedTraces = new TraceRecord[] { new TraceRecord(request, TraceCategories.FormattingCategory, TraceLevel.Info) { Kind = TraceKind.Begin, Operation = "ReadFromStreamAsync" }, new TraceRecord(request, TraceCategories.FormattingCategory, TraceLevel.Info) { Kind = TraceKind.End, Operation = "ReadFromStreamAsync" } }; // Act object valueReturned = await request.Content.ReadAsAsync<object>(new[] { tracer }); // Assert Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer()); Assert.Equal(value, valueReturned); }
public async Task ReadFromStream_Traces() { // Arrange string contentType = "text/plain"; object value = new object(); CustomMediaTypeFormatter formatter = new CustomMediaTypeFormatter(value); formatter.SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse(contentType)); TestTraceWriter traceWriter = new TestTraceWriter(); HttpRequestMessage request = new HttpRequestMessage(); request.Content = new StringContent("42", Encoding.Default, contentType); MediaTypeFormatterTracer tracer = new MediaTypeFormatterTracer(formatter, traceWriter, request); TraceRecord[] expectedTraces = new TraceRecord[] { new TraceRecord(request, TraceCategories.FormattingCategory, TraceLevel.Info) { Kind = TraceKind.Begin, Operation = "ReadFromStreamAsync" }, new TraceRecord(request, TraceCategories.FormattingCategory, TraceLevel.Info) { Kind = TraceKind.End, Operation = "ReadFromStreamAsync" } }; // Act object valueReturned = await request.Content.ReadAsAsync <object>(new[] { tracer }); // Assert Assert.Equal <TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer()); Assert.Equal(value, valueReturned); }
public async Task WriteToStream_Traces() { // Arrange object value = new object(); CustomMediaTypeFormatter formatter = new CustomMediaTypeFormatter(value); TestTraceWriter traceWriter = new TestTraceWriter(); HttpRequestMessage request = new HttpRequestMessage(); MediaTypeFormatterTracer tracer = new MediaTypeFormatterTracer(formatter, traceWriter, request); request.Content = new ObjectContent <object>(value, tracer); 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 await request.Content.CopyToAsync(new MemoryStream()); // Assert Assert.Equal <TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer()); }
public async Task WriteToStream_Traces() { // Arrange object value = new object(); CustomMediaTypeFormatter formatter = new CustomMediaTypeFormatter(value); TestTraceWriter traceWriter = new TestTraceWriter(); HttpRequestMessage request = new HttpRequestMessage(); MediaTypeFormatterTracer tracer = new MediaTypeFormatterTracer(formatter, traceWriter, request); request.Content = new ObjectContent<object>(value, tracer); 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 await request.Content.CopyToAsync(new MemoryStream()); // Assert Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer()); }