Skip to content

Commit

Permalink
Disable obsolete warnings in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vbreuss committed Apr 29, 2024
1 parent 1e6b35b commit 669b1ca
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public override void SkipIfLongRunningTestsShouldBeSkipped()
#endif
}}
}}");
if (!@class.Namespace.Equals("Testably.Abstractions.AccessControl.Tests", StringComparison.Ordinal))
if (IncludeSimulatedTests(@class))
{
sourceBuilder.Append(@$"
#if !NETFRAMEWORK
Expand Down Expand Up @@ -258,4 +258,10 @@ public override void SkipIfLongRunningTestsShouldBeSkipped()
#endif");
}
}

private bool IncludeSimulatedTests(ClassModel @class)
{
return !@class.Namespace.Equals(
"Testably.Abstractions.AccessControl.Tests", StringComparison.Ordinal);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ public sealed class PathMockTests
public void GetTempFileName_WithCollisions_ShouldThrowIOException(
SimulationMode simulationMode, int fixedRandomValue)
{
#pragma warning disable CS0618
MockFileSystem fileSystem = new(i => i
.SimulatingOperatingSystem(simulationMode)
.UseRandomProvider(RandomProvider.Generate(
intGenerator: new RandomProvider.Generator<int>(() => fixedRandomValue))));
#pragma warning restore CS0618
string result = fileSystem.Path.GetTempFileName();

Exception? exception = Record.Exception(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ public void OnWindowsIf_ShouldExecuteDependingOnOperatingSystem(

#region Helpers

#pragma warning disable CS0618
private static Execute FromType(SimulationMode type)
=> new(new MockFileSystem(), type);
#pragma warning restore CS0618

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ public sealed class ExecuteTests
[Fact]
public void Constructor_ForLinux_ShouldInitializeAccordingly()
{
#pragma warning disable CS0618
Execute sut = new(new MockFileSystem(), SimulationMode.Linux);
#pragma warning restore CS0618

sut.IsLinux.Should().BeTrue();
sut.IsMac.Should().BeFalse();
Expand All @@ -19,7 +21,9 @@ public void Constructor_ForLinux_ShouldInitializeAccordingly()
[Fact]
public void Constructor_ForMacOS_ShouldInitializeAccordingly()
{
#pragma warning disable CS0618
Execute sut = new(new MockFileSystem(), SimulationMode.MacOS);
#pragma warning restore CS0618

sut.IsLinux.Should().BeFalse();
sut.IsMac.Should().BeTrue();
Expand All @@ -31,7 +35,9 @@ public void Constructor_ForMacOS_ShouldInitializeAccordingly()
[Fact]
public void Constructor_ForWindows_ShouldInitializeAccordingly()
{
#pragma warning disable CS0618
Execute sut = new(new MockFileSystem(), SimulationMode.Windows);
#pragma warning restore CS0618

sut.IsLinux.Should().BeFalse();
sut.IsMac.Should().BeFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,14 @@ public void
.Which.Message.Should().Contain($"'{path}'");
}

#if !NETFRAMEWORK
[SkippableTheory]
[InlineData('|')]
[InlineData((char)1)]
[InlineData((char)31)]
public void ThrowCommonExceptionsIfPathIsInvalid_WithInvalidCharacters(
char invalidChar)
{
Skip.If(Test.IsNetFramework);

MockFileSystem fileSystem = new(i => i
.SimulatingOperatingSystem(SimulationMode.Windows));
string path = invalidChar + "path";
Expand All @@ -137,15 +136,10 @@ public void ThrowCommonExceptionsIfPathIsInvalid_WithInvalidCharacters(
{
path.EnsureValidFormat(fileSystem);
});

#if NETFRAMEWORK
exception.Should().BeOfType<ArgumentException>()
.Which.Message.Should().Contain("path");
#else
exception.Should().BeOfType<IOException>()
.Which.Message.Should().Contain(path);
#endif
}
#endif

[Fact]
public void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using System.IO;
using System.Linq;
using Testably.Abstractions.Testing.Tests.TestHelpers;
#if NET6_0_OR_GREATER
#endif

namespace Testably.Abstractions.Testing.Tests;

Expand Down Expand Up @@ -93,7 +91,9 @@ public void SimulatingOperatingSystem_ValidOSPlatform_ShouldSetOperatingSystem(
{
MockFileSystem.Initialization sut = new();

#pragma warning disable CS0618
MockFileSystem.Initialization result = sut.SimulatingOperatingSystem(simulationMode);
#pragma warning restore CS0618

result.SimulationMode.Should().Be(simulationMode);
sut.SimulationMode.Should().Be(simulationMode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ public void FileSystemMock_ShouldNotSupportSimulatingOtherOperatingSystemsOnNetF
{
Exception? exception = Record.Exception(() =>
{
#pragma warning disable CS0618
_ = new MockFileSystem(i => i.SimulatingOperatingSystem(simulationMode));
#pragma warning restore CS0618
});

exception.Should().BeOfType<NotSupportedException>()
Expand Down

0 comments on commit 669b1ca

Please sign in to comment.