public async Task Test_Write_WritesBody() { var ms = new MemoryStream(); var resposneMock = new Mock <HttpResponse>(); resposneMock.SetupGet(x => x.Body) .Returns(ms); var httpContextMock = new Mock <HttpContext>(); httpContextMock.SetupGet(x => x.Response) .Returns(resposneMock.Object); httpContextMock.SetupGet(x => x.RequestAborted) .Returns(new CancellationToken()); var next = Mock.Of <RequestDelegate>(); var handlingContext = new HandlingContext(httpContextMock.Object, Encoding.UTF8, next) { WriteResponse = true }; var sourceResponse = new MemoryStream(new byte[1]); var sourceMock = new Mock <HttpResponse>(); sourceMock.SetupGet(x => x.StatusCode) .Returns(200); sourceMock.SetupGet(x => x.Body) .Returns(sourceResponse); var wrapper = new RawServerResponseWrapper(sourceMock.Object); await wrapper.Write(handlingContext, new HeaderJsonRpcSerializer()); ms.Length.Should().BePositive(); }
public async Task Test_Write_ChecksMemoryStream() { var ms = new MemoryStream(); var resposneMock = new Mock <HttpResponse>(); resposneMock.SetupGet(x => x.Body) .Returns(ms); var httpContextMock = new Mock <HttpContext>(); httpContextMock.SetupGet(x => x.Response) .Returns(resposneMock.Object); httpContextMock.SetupGet(x => x.RequestAborted) .Returns(new CancellationToken()); var next = Mock.Of <RequestDelegate>(); var handlingContext = new HandlingContext(httpContextMock.Object, Encoding.UTF8, next) { WriteResponse = true }; var sourceResponse = Mock.Of <Stream>(); var sourceMock = new Mock <HttpResponse>(); sourceMock.SetupGet(x => x.StatusCode) .Returns(200); sourceMock.SetupGet(x => x.Body) .Returns(sourceResponse); var wrapper = new RawServerResponseWrapper(sourceMock.Object); Func <Task> action = async() => await wrapper.Write(handlingContext, new HeaderJsonRpcSerializer()); await action.Should().ThrowAsync <JsonRpcInternalException>(); }
public async Task Test_Write_SetsResponseProperties() { var resposneMock = new Mock <HttpResponse>(); var httpContextMock = new Mock <HttpContext>(); httpContextMock.SetupGet(x => x.Response) .Returns(resposneMock.Object); var next = Mock.Of <RequestDelegate>(); var handlingContext = new HandlingContext(httpContextMock.Object, Encoding.UTF8, next) { WriteResponse = false }; var sourceMock = new Mock <HttpResponse>(); sourceMock.SetupGet(x => x.StatusCode) .Returns(201); var wrapper = new RawServerResponseWrapper(sourceMock.Object); await wrapper.Write(handlingContext, new HeaderJsonRpcSerializer()); resposneMock.VerifySet(x => x.StatusCode = 201); resposneMock.VerifySet(x => x.ContentLength = null); }
public async Task Test_Write_CopiesHeaders() { var responseHeaders = new HeaderDictionary() { { "a", "b" } }; var resposneMock = new Mock <HttpResponse>(); resposneMock.SetupGet(x => x.Headers) .Returns(responseHeaders); var httpContextMock = new Mock <HttpContext>(); httpContextMock.SetupGet(x => x.Response) .Returns(resposneMock.Object); var next = Mock.Of <RequestDelegate>(); var handlingContext = new HandlingContext(httpContextMock.Object, Encoding.UTF8, next) { WriteResponse = false }; var headers = new HeaderDictionary { { "header", "value" } }; var sourceMock = new Mock <HttpResponse>(); sourceMock.SetupGet(x => x.StatusCode) .Returns(201); sourceMock.SetupGet(x => x.Headers) .Returns(headers); var wrapper = new RawServerResponseWrapper(sourceMock.Object); await wrapper.Write(handlingContext, new HeaderJsonRpcSerializer()); resposneMock.VerifyGet(x => x.Headers); responseHeaders.Should().HaveCount(2); responseHeaders.Should().ContainKey("header"); }