Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to test on .NET 8 #82

Merged
merged 5 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions .github/workflows/BuildAndPack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ jobs:
with:
dotnet-version: |
2.1.x
3.0.x
3.1.x
5.0.x
6.0.x
7.0.103
- name: Force globaljson
run: dotnet new globaljson --sdk-version "7.0.103" --force
7.0.x
8.0.x
- name: Cache .nuke/temp, ~/.nuget/packages
uses: actions/cache@v2
with:
Expand All @@ -69,12 +68,11 @@ jobs:
with:
dotnet-version: |
2.1.x
3.0.x
3.1.x
5.0.x
6.0.x
7.0.103
- name: Force globaljson
run: dotnet new globaljson --sdk-version "7.0.103" --force
7.0.x
8.0.x
- name: Cache .nuke/temp, ~/.nuget/packages
uses: actions/cache@v2
with:
Expand All @@ -101,12 +99,11 @@ jobs:
with:
dotnet-version: |
2.1.x
3.0.x
3.1.x
5.0.x
6.0.x
7.0.103
- name: Force globaljson
run: dotnet new globaljson --sdk-version "7.0.103" --force
7.0.x
8.0.x
- name: Cache .nuke/temp, ~/.nuget/packages
uses: actions/cache@v2
with:
Expand Down
12 changes: 12 additions & 0 deletions test/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net461;netcoreapp2.0;netcoreapp3.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0;netcoreapp3.0</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net461;$(TargetFrameworks)</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="xunit" Version="2.3.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\NetEscapades.Configuration.KubeSecrets\NetEscapades.Configuration.KubeSecrets.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net461;netcoreapp2.0;netcoreapp3.0;net5.0;net6.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0;netcoreapp3.0;net5.0;net6.0</TargetFrameworks>

<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net461;$(TargetFrameworks)</TargetFrameworks>
<AssemblyName>NetEscapades.Configuration.Remote.Tests</AssemblyName>
<PackageId>NetEscapades.Configuration.Remote.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
Expand All @@ -18,13 +19,6 @@
<ProjectReference Include="..\..\src\NetEscapades.Configuration.Remote\NetEscapades.Configuration.Remote.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="xunit" Version="2.3.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="System.Threading.Tasks" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../../'))" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="System.Threading.Tasks" />
</ItemGroup>

<ItemGroup>
<None Include="..\Directory.Build.props">
<Link>Directory.Build.props</Link>
</None>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net461;netcoreapp2.0;netcoreapp3.0;net5.0;net6.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0;netcoreapp3.0;net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net461;$(TargetFrameworks)</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' OR '$(TargetFramework)' == 'net461'">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.3" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.0' ">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.0.1" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="5.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\NetEscapades.Configuration.Validation\NetEscapades.Configuration.Validation.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net461;netcoreapp2.0;netcoreapp3.0;net5.0;net6.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0;netcoreapp3.0;net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net461;$(TargetFrameworks)</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand All @@ -11,11 +11,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="Moq" Version="4.8.2" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net461;netcoreapp2.0;netcoreapp3.0;net5.0;net6.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0;netcoreapp3.0;net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net461;$(TargetFrameworks)</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AssemblyName>NetEscapades.Configuration.Yaml.Tests</AssemblyName>
<PackageId>NetEscapades.Configuration.Yaml.Tests</PackageId>
Expand All @@ -19,15 +19,20 @@
<ProjectReference Include="..\..\src\NetEscapades.Configuration.Yaml\NetEscapades.Configuration.Yaml.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="xunit" Version="2.3.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="System.Threading.Tasks" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0'">
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using System;
using System.IO;
using Microsoft.Extensions.Configuration;
using NetEscapades.Configuration.Tests.Common;
using Xunit;

#if NET6_0_OR_GREATER

namespace NetEscapades.Configuration.Yaml
{
public class YamlConfigurationExtensionsConfigurationManagerTests
{
[Theory]
[InlineData(null)]
[InlineData("")]
public void AddYamlFile_ThrowsIfFilePathIsNullOrEmpty(string path)
{
// Arrange
var configurationManager = new ConfigurationManager();

// Act and Assert
var ex = Assert.Throws<ArgumentException>(() => YamlConfigurationExtensions.AddYamlFile(configurationManager, path));
Assert.Equal("path", ex.ParamName);
Assert.StartsWith("File path must be a non-empty string.", ex.Message);
}

[Fact]
public void AddYamlFile_ThrowsIfFileDoesNotExistAtPathAndIsOptional()
{
// Arrange
var path = "file-does-not-exist.Yaml";

// Act and Assert
var ex = Assert.Throws<FileNotFoundException>(() => new ConfigurationManager().AddYamlFile(path).Build());
Assert.StartsWith($"The configuration file '{path}' was not found and is not optional.", ex.Message);
}

[Fact]
public void AddYamlFile_DoesNotThrowIfFileDoesNotExistAndIsOptional()
{
// Arrange
var path = "file-does-not-exist.Yaml";

// Act and Assert
new ConfigurationManager().AddYamlFile(path, optional: true).Build();
}

[Fact]
public void AddYamlFile_DoesNotThrowIfAbsolutePathDirectoryDoesNotExist()
{
// Arrange
var path = Path.Combine(Directory.GetCurrentDirectory(), "does", "not", "exist", "file-does-not-exist.Yaml");

// Act and Assert
new ConfigurationManager()
.AddYamlFile(path, optional: true)
.Build();
}

[Fact]
public void AddYamlStream_ThrowIfIsNull()
{
// Act and Assert
Assert.Throws<ArgumentNullException>(() => new ConfigurationManager().AddYamlStream(null).Build());
}

[Fact]
public void AddYamlStream_DoesNotThrowIfIsNotNull()
{
// Arrange
var stream = TestStreamHelpers.StringToStream("Test: test");

// Act and Assert
var builder = new ConfigurationManager().AddYamlStream(stream);
var config = builder.Build();
Assert.Equal("test", config["Test"]);
}

[Fact]
public void AddYamlStream_SupportsLoadingDataTwice()
{
// Arrange
var stream = TestStreamHelpers.StringToStream("Test: test");

var builder = new ConfigurationManager()
.AddYamlStream(stream);
builder.Build();

var config = builder.Build();
Assert.Equal("test", config["Test"]);
}

[Fact]
public void AddYamlStream_SupportsDisposingStream()
{
// Arrange
var builder = new ConfigurationManager();
using (var stream = TestStreamHelpers.StringToStream("Test: test"))
{
builder.AddYamlStream(stream);
}

Assert.Equal("test", builder["Test"]);
}
}
}

#endif
Loading