Table of Contents

FakeHttpResponseFeature Class

Definition

Represents a way to trigger OnStarting(Func<object, Task>, object).

public class FakeHttpResponseFeature : HttpResponseFeature, IHttpResponseFeature
Inheritance
FakeHttpResponseFeature
Implements
Inherited Members

Examples

The following example creates a FakeHttpResponseFeature to simulate the HTTP response surface in a unit test. The feature provides settable properties for the status code, reason phrase, headers, and response body, allowing the test to inspect what the code under test writes to the response.

using System;
using Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http.Features;

namespace WebFixtureTests;

public class ResponseFeatureExample
{
    public void Demonstrate()
    {
        var response = new FakeHttpResponseFeature();
        Console.WriteLine(response.StatusCode);
    }
}

Constructors

Name Description
FakeHttpResponseFeature()

Initializes a new instance of the FakeHttpResponseFeature class.

Properties

Name Description
HasStarted

Indicates if the response has started. If true, the StatusCode, ReasonPhrase, and Headers are now immutable, and OnStarting should no longer be called.

Methods

Name Description
OnStarting(Func<object, Task>, object)

Registers a callback to be invoked just before the response starts. This is the last chance to modify the Headers, StatusCode, or ReasonPhrase.

See Also