Table of Contents

Mock response

Fluxzy provides various way to mock a response.

MockedResponseAction is the starting point for mocking a response body and keeping control on low level settings.

However, the ConfigureRule chain has several fluent mocking methods that can be used to mock a response quickly. These mocking methods starts with the word Reply....

using Fluxzy;
using Fluxzy.Rules.Actions;
using Fluxzy.Rules.Actions.HighLevelActions;
using Fluxzy.Rules.Filters;
using Fluxzy.Rules.Filters.RequestFilters;

var fluxzySetting = FluxzySetting.CreateDefault();

    .WhenUriMatch("", StringSelectorOperation.StartsWith)
    .ReplyFile("/path/to/dog.jpeg", 200, "image/jpeg")
    .WhenUriMatch("", StringSelectorOperation.StartsWith)
                       "name": "opale"
    .WhenAll(new PostFilter(), new HostFilter(""))

// Create a new proxy instance 
await using var proxy = new Proxy(fluxzySetting);

Console.WriteLine("Press any key to exit");

Mocked response doesn't not create a connection to the expected host. It's a simple substitution of the response body. If you're mocked response depends on the actual server response, you should use a IStreamSubstitution instead.