public void ExecuteAsync_ThrowsArgumentNullException_WhenHttpContextIsNull() { // Arrange var result = new Ok <object>(null); HttpContext httpContext = null; // Act & Assert Assert.ThrowsAsync <ArgumentNullException>("httpContext", () => result.ExecuteAsync(httpContext)); }
public async Task OkObjectResult_ExecuteAsync_SetsStatusCode() { // Arrange var result = new Ok <string>("Hello"); var httpContext = new DefaultHttpContext() { RequestServices = CreateServices() }; // Act await result.ExecuteAsync(httpContext); // Assert Assert.Equal(StatusCodes.Status200OK, httpContext.Response.StatusCode); }
public async Task OkObjectResult_ExecuteAsync_FormatsData() { // Arrange var result = new Ok <string>("Hello"); var stream = new MemoryStream(); var httpContext = new DefaultHttpContext() { RequestServices = CreateServices(), Response = { Body = stream, }, }; // Act await result.ExecuteAsync(httpContext); // Assert Assert.Equal("\"Hello\"", Encoding.UTF8.GetString(stream.ToArray())); }