Skip to content

Commit bccfb6c

Browse files
committed
Update project configuration and tests for .NET compatibility
- Update dotnet.yml to include bugfix branches - Modify Changelog.md to reflect changes in framework support - Change default framework from net461 to net462 in Directory.Build.props - Update EasyConsoleApplication.Tests.csproj to support multiple target frameworks - Refactor MenuRendererTests to use MSTest and update assertions - Enhance ConsoleHelpers to check for input redirection - Upgrade Microsoft.SourceLink.GitHub package to version 10.0.301
1 parent 52f7aab commit bccfb6c

7 files changed

Lines changed: 39 additions & 14 deletions

File tree

.github/workflows/dotnet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ name: .NET
55

66
on:
77
push:
8-
branches: [ "main", "master", "develop", "feature/*", "release/*", "hotfix/*", "support/*" ]
8+
branches: [ "main", "master", "develop", "feature/*", "release/*", "hotfix/*", "support/*", "bugfix/*" ]
99
pull_request:
1010
branches: [ "main", "master" ]
1111
workflow_dispatch:

Changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
## vNext
22

3+
- Removed support for net461
4+
- Added support for net462
35
- Avoid clearing the console when output is redirected or the console is unavailable.
46

7+
### Breaking Changes
8+
9+
- Removed support for net461, use net462 instead.
10+
511
## 0.8.0
612

713
- Added support for net10.0

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Nullable>enable</Nullable>
77

88
<!-- Defaults (can be overridden with /p:netCoreMinimum=... etc) -->
9-
<NetFullFramework Condition="'$(NetFullFramework)'==''">net461</NetFullFramework>
9+
<NetFullFramework Condition="'$(NetFullFramework)'==''">net462</NetFullFramework>
1010
<NetCoreMinimum Condition="'$(NetCoreMinimum)'==''">net8.0</NetCoreMinimum>
1111
<NetCorePrevious Condition="'$(NetCorePrevious)'==''">net9.0</NetCorePrevious>
1212
<NetCoreCurrent Condition="'$(NetCoreCurrent)'==''">net10.0</NetCoreCurrent>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net8.0</TargetFramework>
3+
<TargetFrameworks>$(NetFullFramework);$(NetCoreFrameworks)</TargetFrameworks>
44
<IsPackable>false</IsPackable>
55
</PropertyGroup>
66
<ItemGroup>
77
<ProjectReference Include="..\EasyConsoleApplication\EasyConsoleApplication.csproj" />
8-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
9-
<PackageReference Include="xunit" Version="2.9.3" />
10-
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
8+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.8.1" />
9+
<PackageReference Include="MSTest.TestAdapter" Version="4.3.3">
1110
<PrivateAssets>all</PrivateAssets>
1211
</PackageReference>
12+
<PackageReference Include="MSTest.TestFramework" Version="4.3.3" />
1313
</ItemGroup>
1414
</Project>

src/EasyConsoleApplication.Tests/MenuRendererTests.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using EasyConsoleApplication.Menus;
2-
using Xunit;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
33

44
namespace EasyConsoleApplication.Tests;
55

6+
[TestClass]
7+
[DoNotParallelize]
68
public sealed class MenuRendererTests
79
{
8-
[Fact]
10+
[TestMethod]
911
public void Render_does_not_clear_redirected_output()
1012
{
1113
var originalOut = Console.Out;
@@ -27,7 +29,7 @@ public void Render_does_not_clear_redirected_output()
2729
}
2830
}
2931

30-
[Fact]
32+
[TestMethod]
3133
public void Render_stops_when_input_reaches_eof()
3234
{
3335
var originalOut = Console.Out;
@@ -49,7 +51,7 @@ public void Render_stops_when_input_reaches_eof()
4951
}
5052
}
5153

52-
[Fact]
54+
[TestMethod]
5355
public void Key_prompts_do_not_require_interactive_input()
5456
{
5557
var originalOut = Console.Out;
@@ -62,7 +64,7 @@ public void Key_prompts_do_not_require_interactive_input()
6264
var answer = ConsoleHelpers.AskToUserYesNoQuestion(ConsoleColor.Gray, "Continue?");
6365
ConsoleHelpers.HitEnterToContinue();
6466

65-
Assert.Equal(ConsoleKey.Y, answer.Key);
67+
Assert.AreEqual(ConsoleKey.Y, answer.Key);
6668
}
6769
finally
6870
{

src/EasyConsoleApplication/ConsoleHelpers.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static void WriteRed(string message, bool newLine = true)
9595
public static ConsoleKeyInfo AskToUserYesNoQuestion(ConsoleColor color, string question, bool newLine = true)
9696
{
9797
Write(color, question + " [y/n] ", false);
98-
if (Console.IsInputRedirected)
98+
if (IsInputRedirected())
9999
{
100100
// ReadKey requires an interactive terminal, so consume redirected input as a line.
101101
while (true)
@@ -132,6 +132,23 @@ public static ConsoleKeyInfo AskToUserYesNoQuestion(ConsoleColor color, string q
132132
return key;
133133
}
134134

135+
private static bool IsInputRedirected()
136+
{
137+
try
138+
{
139+
_ = Console.KeyAvailable;
140+
return Console.IsInputRedirected || Console.IsOutputRedirected;
141+
}
142+
catch (InvalidOperationException)
143+
{
144+
return true;
145+
}
146+
catch (IOException)
147+
{
148+
return true;
149+
}
150+
}
151+
135152
/// <summary>
136153
/// Reads a line of input from the console with the specified color.
137154
/// </summary>
@@ -156,7 +173,7 @@ public static ConsoleKeyInfo AskToUserYesNoQuestion(ConsoleColor color, string q
156173
public static void HitEnterToContinue()
157174
{
158175
Write(ConsoleSettings.HitEnterToContinueColor, "Hit 'Enter' to continue.", newLine: true);
159-
if (Console.IsInputRedirected)
176+
if (IsInputRedirected())
160177
{
161178
// There is no key event to wait for when stdin is redirected.
162179
return;

src/EasyConsoleApplication/EasyConsoleApplication.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<AnalysisLevel>latest-recommended</AnalysisLevel>
2323
</PropertyGroup>
2424
<ItemGroup>
25-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
25+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.301">
2626
<PrivateAssets>all</PrivateAssets>
2727
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2828
</PackageReference>

0 commit comments

Comments
 (0)