public async Task BadRequestErrorMessageResult_WritesHttpError() { // Arrange var httpContext = new DefaultHttpContext(); httpContext.RequestServices = CreateServices(); var stream = new MemoryStream(); httpContext.Response.Body = stream; var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); var result = new BadRequestErrorMessageResult("Error"); // Act await result.ExecuteResultAsync(context); // Assert using (var reader = new StreamReader(stream)) { stream.Seek(0, SeekOrigin.Begin); var content = reader.ReadToEnd(); Assert.Equal("{\"Message\":\"Error\"}", content); } }
public async Task BadRequestErrorMessageResult_SetsStatusCode() { // Arrange var httpContext = new DefaultHttpContext(); httpContext.RequestServices = CreateServices(); var stream = new MemoryStream(); httpContext.Response.Body = stream; var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); var result = new BadRequestErrorMessageResult("Error"); // Act await result.ExecuteResultAsync(context); // Assert Assert.Equal(StatusCodes.Status400BadRequest, context.HttpContext.Response.StatusCode); }
public async Task BadRequestErrorMessageResult_SetsStatusCode() { // Arrange var httpContext = new DefaultHttpContext(); httpContext.RequestServices = CreateServices(); var stream = new MemoryStream(); httpContext.Response.Body = stream; var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); var result = new BadRequestErrorMessageResult("Error"); // Act await result.ExecuteResultAsync(context); // Assert Assert.Equal(StatusCodes.Status400BadRequest, context.HttpContext.Response.StatusCode); }
public async Task BadRequestErrorMessageResult_WritesHttpError() { // Arrange var httpContext = new DefaultHttpContext(); httpContext.RequestServices = CreateServices(); var stream = new MemoryStream(); httpContext.Response.Body = stream; var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); var result = new BadRequestErrorMessageResult("Error"); // Act await result.ExecuteResultAsync(context); // Assert using (var reader = new StreamReader(stream)) { stream.Seek(0, SeekOrigin.Begin); var content = reader.ReadToEnd(); Assert.Equal("{\"Message\":\"Error\"}", content); } }