Table of Contents

Class FakeHttpResponseFeature

Namespace
Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http.Features
Assembly
Codebelt.Extensions.Xunit.Hosting.AspNetCore.dll

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

FakeHttpResponseFeature()

Initializes a new instance of the FakeHttpResponseFeature class.

public FakeHttpResponseFeature()

Properties

HasStarted

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

public override bool HasStarted { get; }

Property Value

bool

true if this instance has started; otherwise, false.

Methods

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.

public override void OnStarting(Func<object, Task> callback, object state)

Parameters

callback Func<object, Task>

The callback to invoke when starting the response.

state object

The state to pass into the callback.

See Also