public void ExecuteAsync_ThrowsArgumentNullException_WhenHttpContextIsNull() { // Arrange var result = new Accepted <object>("location", null); HttpContext httpContext = null; // Act & Assert Assert.ThrowsAsync <ArgumentNullException>("httpContext", () => result.ExecuteAsync(httpContext)); }
public async Task ExecuteAsync_SetsStatusCodeAndLocationHeader() { // Arrange var expectedUrl = "testAction"; var httpContext = GetHttpContext(); // Act var result = new Accepted(expectedUrl); await result.ExecuteAsync(httpContext); // Assert Assert.Equal(StatusCodes.Status202Accepted, httpContext.Response.StatusCode); Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]); }
public async Task ExecuteResultAsync_FormatsData() { // Arrange var httpContext = GetHttpContext(); var stream = new MemoryStream(); httpContext.Response.Body = stream; // Act var result = new Accepted <string>("my-location", value: "Hello world"); await result.ExecuteAsync(httpContext); // Assert var response = Encoding.UTF8.GetString(stream.ToArray()); Assert.Equal("\"Hello world\"", response); }