Fhi.BaseConfigTests 2.0.0

dotnet add package Fhi.BaseConfigTests --version 2.0.0                
NuGet\Install-Package Fhi.BaseConfigTests -Version 2.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="Fhi.BaseConfigTests" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Fhi.BaseConfigTests --version 2.0.0                
#r "nuget: Fhi.BaseConfigTests, 2.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.
// Install Fhi.BaseConfigTests as a Cake Addin
#addin nuget:?package=Fhi.BaseConfigTests&version=2.0.0

// Install Fhi.BaseConfigTests as a Cake Tool
#tool nuget:?package=Fhi.BaseConfigTests&version=2.0.0                

Usage of BaseConfigTests

This is a base class for use when testing configurations, or when your tests needs to load configurations. Your test class should derive from the baseclass. By default it knows about the appsettings.json, the other sub-appsettings, like appsettings.development.json or whatever you prefer to call them, you need to set in your derived class. The baseclass will load the settings as specified, and you can extract the section you need using a built-in utility method.

It depends on NUnit, which is used underneath.

Usage

If you want to test your development settings, and combine them with the parent appsettings.json, the code will be something like the below:


using Fhi.TestUtilities;
using NUnit.Framework;

public class MyTest : BaseConfigTests
{
    public MyTest() : base("appsettings.development.json")
    {
    }

    [Test]
    public void Test()
    {
        var section = GetConfiguration<MySection>(nameof(MySection));
        Assert.That(section, Is.Not.Null);
        Assert.That(section.MyProperty, Is.EqualTo("MyValue"));
    }
}

If you however want to test just your appsettings file, which is the default, you can do just:


using Fhi.TestUtilities;
using NUnit.Framework;

public class MyTest : BaseConfigTests
{
    [Test]
    public void Test()
    {
        var section = GetConfiguration<MySection>(nameof(MySection));
        Assert.That(section, Is.Not.Null);
        Assert.That(section.MyProperty, Is.EqualTo("MyValue"));
    }
}

And if you want to test just a specific appsettings file without mixing in the base appsettings.json, then:


using Fhi.TestUtilities;
using NUnit.Framework;

public class MyTest : BaseConfigTests
{
    public MyTest() 
    {
       AppSettings = "appsettings.development.json";
    }

    [Test]
    public void Test()
    {
        var section = GetConfiguration<MySection>(nameof(MySection));
        Assert.That(section, Is.Not.Null);
        Assert.That(section.MyProperty, Is.EqualTo("MyValue"));
    }
}

Details

The baseclass will run a OneTimeSetup. Anything you do in the constructor will be done before the OneTimeSetup of the baseclass is run. The OneTimeSetup loads the specified appsettings files.

If some of the specified appsettings don't exist at the binary output location, then the baseclass will assert with an error message about what file is not found and its full path.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
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
2.0.0 221 11/18/2024
1.0.0-beta.3 3,981 10/9/2023
1.0.0-beta.2 730 8/19/2023
1.0.0-beta.1 88 8/19/2023
0.9.1 1,360 11/30/2022
0.9.0 209 11/30/2022