Skip to content

Commit 74b7c79

Browse files
committed
.NET 9 & show features in test's displayname
- Updated to .net 9. - Changed C# language version to 13.0 - Removed Microsoft.CodeAnalysis.NetAnalyzers package and alwaus using the bundled version. - Updated all library versions. - Show on/off features in test's displayname
1 parent 15885f5 commit 74b7c79

File tree

15 files changed

+92
-57
lines changed

15 files changed

+92
-57
lines changed

.github/workflows/dotnet-core.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ jobs:
1010
build:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
14-
- uses: actions/setup-dotnet@v3
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-dotnet@v4
1515
with:
16-
dotnet-version: |
17-
8.0.100
16+
global-json-file: "./global.json"
1817
- run: dotnet restore
1918
- run: dotnet build --configuration Release --no-restore
2019
- run: dotnet test --no-build --configuration Release --verbosity normal

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
55
</PropertyGroup>
66
<PropertyGroup>
7-
<LangVersion>12.0</LangVersion>
7+
<LangVersion>13.0</LangVersion>
88
<Nullable>enable</Nullable>
99
<ImplicitUsings>enable</ImplicitUsings>
1010
<GenerateDocumentationFile>true</GenerateDocumentationFile>

Directory.Build.targets

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<Project>
22
<ItemGroup>
3-
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
4-
<PrivateAssets>all</PrivateAssets>
5-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
6-
</PackageReference>
73
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
84
<PrivateAssets>all</PrivateAssets>
95
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

global.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
2-
"sdk": {
3-
"version": "8.0.100",
4-
"rollForward": "latestFeature"
5-
}
2+
"sdk": {
3+
"version": "9.0.100",
4+
"rollForward": "latestFeature"
5+
},
6+
"msbuild-sdks": {
7+
"MSTest.Sdk": "3.6.3"
8+
}
69
}

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Import Project="..\Directory.Build.props" />
33

44
<PropertyGroup>
5-
<TargetFrameworks>net8.0</TargetFrameworks>
5+
<TargetFrameworks>net9.0</TargetFrameworks>
66
</PropertyGroup>
77

88
<PropertyGroup>

src/FeatureSwitches.MSTest/FeatureSwitches.MSTest.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
<PropertyGroup>
44
<Description>FeatureSwitches MSTest</Description>
55
<PackageId>FeatureSwitches.MSTest</PackageId>
6-
<Version>8.0.0</Version>
6+
<Version>9.0.0</Version>
77
</PropertyGroup>
88

99
<ItemGroup>
1010
<ProjectReference Include="..\FeatureSwitches\FeatureSwitches.csproj" />
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="MSTest.TestFramework" Version="3.0.0" />
14+
<PackageReference Include="MSTest.TestFramework" Version="3.6.3" />
1515
</ItemGroup>
1616
</Project>

src/FeatureSwitches.MSTest/FeatureTestMethodAttribute.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ public sealed class FeatureTestMethodAttribute : TestMethodAttribute
1818
/// <param name="onOff">A comma separated string of features to vary between on/off.</param>
1919
/// <param name="on">A comma separated string of features that are always on.</param>
2020
/// <param name="off">A comma separated string of features that are always off.</param>
21-
public FeatureTestMethodAttribute(string? onOff, string? on = null, string? off = null)
21+
/// <param name="displayName">The display name.</param>
22+
public FeatureTestMethodAttribute(string? onOff, string? on = null, string? off = null, string? displayName = null)
23+
: base(displayName)
2224
{
2325
this.OnOff = onOff;
2426
this.On = on;
@@ -50,7 +52,7 @@ public static IReadOnlyList<FeatureDefinition> GetFeatures(TestContext context)
5052
return features;
5153
}
5254

53-
return Array.Empty<FeatureDefinition>();
55+
return [];
5456
}
5557

5658
public override TestResult[] Execute(ITestMethod testMethod)
@@ -89,16 +91,16 @@ static string[] Convert(string? arg)
8991

9092
onCombinationValues = onCombinationValues.SelectMany(o =>
9193
onValues.Select(onValue =>
92-
o.Concat(new List<FeatureDefinition>
93-
{
94+
o.Concat(
95+
[
9496
new()
9597
{
9698
Name = feature,
9799
IsOn = true,
98100
OffValue = offValue,
99101
OnValue = onValue,
100102
},
101-
})));
103+
])));
102104
}
103105

104106
foreach (var onCombinationValue in onCombinationValues)
@@ -121,9 +123,23 @@ static string[] Convert(string? arg)
121123
}
122124

123125
var fullMethodName = testMethod.TestClassName + '/' + testMethod.TestMethodName;
124-
ExecutingTestFeatures.TryAdd(fullMethodName, featureDefinitions.OrderBy(x => x.Name).ToList());
126+
var sortedFeatures = featureDefinitions.OrderBy(x => x.Name).ToList();
127+
ExecutingTestFeatures.TryAdd(fullMethodName, sortedFeatures);
125128

126129
var result = testMethod.Invoke(null);
130+
131+
static string GetOnOffValue(object? value)
132+
{
133+
return value switch
134+
{
135+
bool b => b ? "on" : "off",
136+
_ => value?.ToString() ?? "null",
137+
};
138+
}
139+
140+
var featureSet = string.Join(", ", sortedFeatures.Select(x => $"{x.Name}: {(x.IsOn ? $"{GetOnOffValue(x.OnValue)}" : $"{GetOnOffValue(x.OffValue)}")}"));
141+
result.DisplayName = $"{this.DisplayName ?? testMethod.TestMethodName} ({featureSet})";
142+
127143
results.Add(result);
128144

129145
ExecutingTestFeatures.TryRemove(fullMethodName, out _);

src/FeatureSwitches.ServiceCollection/FeatureSwitches.ServiceCollection.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<PropertyGroup>
44
<Description>ServiceCollection extensions for FeatureSwitches</Description>
55
<PackageId>FeatureSwitches.ServiceCollection</PackageId>
6-
<Version>8.0.0</Version>
6+
<Version>9.0.0</Version>
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
10+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

src/FeatureSwitches/Definitions/FeatureDefinition.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ public sealed class FeatureDefinition
2525
/// <summary>
2626
/// Gets a list of filters.
2727
/// </summary>
28-
public IList<FeatureFilterDefinition> Filters { get; init; } = new List<FeatureFilterDefinition>();
28+
public IList<FeatureFilterDefinition> Filters { get; init; } = [];
2929

3030
/// <summary>
3131
/// Gets a list of filter groups.
3232
/// </summary>
33-
public IList<FeatureFilterGroupDefinition> FilterGroups { get; init; } = new List<FeatureFilterGroupDefinition>();
33+
public IList<FeatureFilterGroupDefinition> FilterGroups { get; init; } = [];
3434
}

src/FeatureSwitches/Definitions/InMemoryFeatureDefinitionProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public void LoadFromJson(string json)
201201
/// <returns>A list of feature definitions.</returns>
202202
public IList<FeatureDefinition> Save()
203203
{
204-
return this.featureSwitches.Values.ToList();
204+
return [.. this.featureSwitches.Values];
205205
}
206206

207207
/// <summary>

0 commit comments

Comments
 (0)