public void WriteResponseBodyAsyncWritesContextToResponseBody() { Stream bodyStream = new MemoryStream(); DefaultHttpContext defaultContext = SetupDefaultContextWithResponseBodyStream(bodyStream); var context = new OutputFormatterWriteContext(defaultContext, (s, e) => new StreamWriter(s, e, 256, true), typeof(RPCAuthorization), new RPCAuthorization()); var formatter = new RPCJsonOutputFormatter(this.settings); Task task = formatter.WriteResponseBodyAsync(context, Encoding.UTF8); task.Wait(); using (var reader = new StreamReader(bodyStream)) { bodyStream.Position = 0; JToken expected = JToken.Parse(@"{""result"":{""Authorized"":[],""AllowIp"":[]},""error"":null}"); JToken actual = JToken.Parse(reader.ReadToEnd()); actual.Should().BeEquivalentTo(expected); } }