FsHttpClientMock 1.5.5.62151
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
dotnet add package FsHttpClientMock --version 1.5.5.62151
NuGet\Install-Package FsHttpClientMock -Version 1.5.5.62151
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FsHttpClientMock" Version="1.5.5.62151" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FsHttpClientMock --version 1.5.5.62151
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FsHttpClientMock, 1.5.5.62151"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FsHttpClientMock as a Cake Addin #addin nuget:?package=FsHttpClientMock&version=1.5.5.62151 // Install FsHttpClientMock as a Cake Tool #tool nuget:?package=FsHttpClientMock&version=1.5.5.62151
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
FsHttpClientMock
A really simple http client mock.
Examples
Match by simple url
[Fact]
public async void match_by_simple_url()
{
var builder = new MockedHttpClientBuilder();
builder
.WhenGet("/Test")
.Respond(HttpStatusCode.OK);s
using var httpClient = builder.Build("http://localhost:1122");
var response = await httpClient.GetAsync("http://localhost:1122/test");
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
Return some response
[Fact]
public async void return_some_response()
{
var builder = new MockedHttpClientBuilder();
builder
.WhenGet("/Test")
.Respond(HttpStatusCode.OK, new People { Name = "John Doe"});
using var httpClient = builder.Build("http://localhost:1122");
var response = await httpClient.GetAsync("http://localhost:1122/test");
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var people = await response.Content.ReadFromJsonAsync<People>();
Assert.Equal("John Doe", people?.Name);
}
Capture request being sent
[Fact]
public async void capture_request_being_sent()
{
var builder = new MockedHttpClientBuilder();
var capture = builder.WhenGet("/test").Respond(HttpStatusCode.OK).Capture();
using var httpClient = builder.Build("http://localhost:1122");
// no request being sent yet
Assert.Null(capture());
// when send the request
var response = await httpClient.GetAsync("http://localhost:1122/test");
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
// should get the request by retriever
var requestCapture = capture();
Assert.NotNull(requestCapture);
Assert.Equal(HttpMethod.Get, requestCapture.HttpMethod);
Assert.Equal("http://localhost:1122/test", requestCapture.RequestUri.ToString());
}
Hamcrest Style Matchers
- Matchers.Regex
[Fact]
public async void hamcrest_style_matchers()
{
var builder = new MockedHttpClientBuilder();
builder
.WhenGet(UrlMatchers.Regex(@"/(staff)|(user)s"))
.Respond(HttpStatusCode.InternalServerError);
using var httpClient = builder.Build("http://localhost:1122");
var response = await httpClient.GetAsync("http://localhost:1122/users");
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
}
- Matchers.WildCard
builder
.WhenGet(Matchers.Wildcard(@"/staffs/?"))
.Respond(HttpStatusCode.Unauthorized);
- Matchers.Is
builder
.WhenGet(Matchers.Is("/staffs"))
.Respond(HttpStatusCode.OK);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- FSharp.Core (>= 6.0.3)
- System.Net.Http.Json (>= 6.0.0)
-
net6.0
- FSharp.Core (>= 6.0.3)
- System.Net.Http.Json (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.5.5.62151 | 2,609 | 12/13/2022 |
1.4.5.26392 | 430 | 5/3/2022 |
1.3.4.65499 | 330 | 11/16/2021 |