BowSoft.TestExtensions
1.0.0
dotnet add package BowSoft.TestExtensions --version 1.0.0
NuGet\Install-Package BowSoft.TestExtensions -Version 1.0.0
<PackageReference Include="BowSoft.TestExtensions" Version="1.0.0" />
<PackageVersion Include="BowSoft.TestExtensions" Version="1.0.0" />
<PackageReference Include="BowSoft.TestExtensions" />
paket add BowSoft.TestExtensions --version 1.0.0
#r "nuget: BowSoft.TestExtensions, 1.0.0"
#:package BowSoft.TestExtensions@1.0.0
#addin nuget:?package=BowSoft.TestExtensions&version=1.0.0
#tool nuget:?package=BowSoft.TestExtensions&version=1.0.0
BowSoft
BowSoft is a collection utilities for developing with .Net code.
Introduction
I am beginning with some extension methods to use when testing. These target the HttpResponseMessage object and initially getting the body, confirming that it is JSON and checking if is the expected json from a test.
This is particularly useful for when doing integration tests calling an API. It will throw an Fluent Assertion if the object does not match what is expected.
Getting Started
BowSoft.TestExtensions
When using the library is Test Projects that return an HttpResponseMessage using the following methods:
- ShouldBeJson()
- ShouldBeJson<T>()
- ShouldBeJson<T>(Action)
- ShouldBeContentType(string)
- ShouldBeBody()
Code Snippets
ShouldBeJson<T> is an extension method from HttpResponseMessage which goes and gets the content and deserialises in to a type of T.
// Fluent Assertions
[Fact]
public async Task ReturnExpectedObject()
{
// Arrange
var client = _factory.CreateClient();
var expectedCustomer = new Customer()
{
Id = 42,
Name = "Ian Bowyer",
City = "Leeds"
};
// Act
var response = await client.GetAsync("api/tester/ReturnsJsonObject");
// Assert
var actual = await response.ShouldBeJson<Customer>();
actual.Should().BeEquivalentTo(expectedCustomer)
}
There is then an action that you can use your assertion framework to verify the object from the API matches your expected object.
[Fact]
public async Task ReturnExpectedObject()
{
// Arrange
var client = _factory.CreateClient();
var expectedCustomer = new Customer()
{
Id = 42,
Name = "Ian Bowyer",
City = "Leeds"
};
// Act
var response = await client.GetAsync("api/tester/ReturnsJsonObject");
// Assert
await response.ShouldBeJson<Customer>(customer =>
{
// Add your checking code here using an Assertion framework such as FluentAssertions
customer.Should().BeEquivalentTo(expectedCustomer)
// or using XUnit
Assert.Equal(expectedCustomer.Id, customer.Id);
});
}
Feedback
Please feel free to leave feedback on my GitHub page.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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. |
-
.NETStandard 2.0
- FluentAssertions (>= 6.12.0)
- System.Text.Json (>= 8.0.4)
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.0.0 | 194 | 9/9/2024 |