Fhi.BaseConfigTests
0.9.1
See the version list below for details.
dotnet add package Fhi.BaseConfigTests --version 0.9.1
NuGet\Install-Package Fhi.BaseConfigTests -Version 0.9.1
<PackageReference Include="Fhi.BaseConfigTests" Version="0.9.1" />
paket add Fhi.BaseConfigTests --version 0.9.1
#r "nuget: Fhi.BaseConfigTests, 0.9.1"
// Install Fhi.BaseConfigTests as a Cake Addin #addin nuget:?package=Fhi.BaseConfigTests&version=0.9.1 // Install Fhi.BaseConfigTests as a Cake Tool #tool nuget:?package=Fhi.BaseConfigTests&version=0.9.1
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 | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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. |
-
net6.0
- Microsoft.Extensions.Configuration (>= 6.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 6.0.0)
- Microsoft.Extensions.Configuration.FileExtensions (>= 6.0.0)
- Microsoft.Extensions.Configuration.Json (>= 6.0.0)
- nunit (>= 3.13.3)
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 | 211 | 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 |