BowSoft.TestExtensions 1.0.0

dotnet add package BowSoft.TestExtensions --version 1.0.0
                    
NuGet\Install-Package BowSoft.TestExtensions -Version 1.0.0
                    
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="BowSoft.TestExtensions" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BowSoft.TestExtensions" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="BowSoft.TestExtensions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BowSoft.TestExtensions --version 1.0.0
                    
#r "nuget: BowSoft.TestExtensions, 1.0.0"
                    
#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.
#:package BowSoft.TestExtensions@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BowSoft.TestExtensions&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=BowSoft.TestExtensions&version=1.0.0
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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