given-fixture 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package given-fixture --version 1.0.0
                    
NuGet\Install-Package given-fixture -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="given-fixture" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="given-fixture" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="given-fixture" />
                    
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 given-fixture --version 1.0.0
                    
#r "nuget: given-fixture, 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 given-fixture@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=given-fixture&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=given-fixture&version=1.0.0
                    
Install as a Cake Tool

Build status NuGet

given-fixture

Simple but opinionated, fluent test fixture pattern.

Lets us write unit tests like this:

public class BreakfastServiceTests
{
    [Fact]
    public Task When_attempting_to_get_breakfast_with_null_request() =>
        Given.Fixture
             .When<BreakfastService, Breakfast>(x => x.GetBreakfastAsync(null))
             .ShouldThrowArgumentNullException("request")
             .RunAsync();

    [Fact]
    public Task When_attempting_to_get_breakfast_with_no_items() =>
        Given.Fixture
             .WhenGettingBreakfast()
             .ShouldThrowArgumentException("request")
             .RunAsync();

    [Fact]
    public Task When_getting_full_english_breakfast() =>
        Given.Fixture
             .HavingBreakfastItem(BreakfastItemType.Bacon, out var bacon)
             .HavingBreakfastItem(BreakfastItemType.Egg, out var egg)
             .HavingBreakfastItem(BreakfastItemType.Sausage, out var sausage)
             .HavingBreakfastItem(BreakfastItemType.Toast, out var toast)
             .WhenGettingBreakfast(BreakfastItemType.Bacon, BreakfastItemType.Egg,
                                   BreakfastItemType.Sausage, BreakfastItemType.Toast)
             .ShouldReturnBreakfastWithCorrectNameAndPrice("Full English Breakfast", bacon, egg, sausage, toast)
             .RunAsync();
}

We use extension methods to keep the fluent test conversation going:

internal static class BreakfastTestExtensions
{
    public static ITestFixture HavingBreakfastItem(this ITestFixture fixture, BreakfastItemType type, out BreakfastItem item) =>
        fixture.HavingModel(out item, c => c.With(x => x.Type, type)
                                            .With(x => x.Name, type.ToString()))
               .HavingMocked<IBreakfastItemRepository, BreakfastItem>(x => x.GetBreakfastItemAsync(type), item);


    public static ITestFixture WhenGettingBreakfast(this ITestFixture fixture, params BreakfastItemType[] types) =>
        fixture.When<BreakfastService, Breakfast>(x => x.GetBreakfastAsync(new GetBreakfastRequest { BreakfastItems = types }));

    public static ITestFixture ShouldReturnBreakfastWithCorrectNameAndPrice(this ITestFixture fixture,
                                                                            string expectedName,
                                                                            params BreakfastItem[] expectedItems) =>
        fixture.ShouldReturnEquivalent(new Breakfast { Name = expectedName, Price = expectedItems.Sum(i => i.Price) });
}
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.1.35 14,321 8/25/2019
1.1.33 22,764 12/28/2018
1.1.31 940 12/28/2018
1.1.29 947 12/28/2018
1.1.27 988 12/28/2018
1.1.25 961 12/28/2018
1.1.23 1,006 12/26/2018
1.1.21 957 12/26/2018
1.1.19 972 12/20/2018
1.1.17 1,049 12/18/2018
1.1.15 989 12/17/2018
1.1.13 990 12/17/2018
1.1.11 955 12/9/2018
1.1.9 1,010 12/9/2018
1.1.7 996 12/7/2018
1.1.5 984 12/7/2018
1.0.2 1,197 11/28/2018
1.0.1 1,083 11/22/2018
1.0.0 1,017 11/22/2018