given-fixture 1.0.0

.NET Standard 2.0
There is a newer version of this package available.
See the version list below for details.
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.
dotnet add package given-fixture --version 1.0.0
<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.
paket add given-fixture --version 1.0.0
#r "nuget: given-fixture, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install given-fixture as a Cake Addin
#addin nuget:?package=given-fixture&version=1.0.0

// Install given-fixture as a Cake Tool
#tool nuget:?package=given-fixture&version=1.0.0

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 Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
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 9,868 8/25/2019
1.1.33 16,992 12/28/2018
1.1.31 552 12/28/2018
1.1.29 547 12/28/2018
1.1.27 582 12/28/2018
1.1.25 551 12/28/2018
1.1.23 603 12/26/2018
1.1.21 548 12/26/2018
1.1.19 592 12/20/2018
1.1.17 634 12/18/2018
1.1.15 537 12/17/2018
1.1.13 592 12/17/2018
1.1.11 573 12/9/2018
1.1.9 567 12/9/2018
1.1.7 597 12/7/2018
1.1.5 579 12/7/2018
1.0.2 776 11/28/2018
1.0.1 640 11/22/2018
1.0.0 604 11/22/2018