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

refactor: fix analyzer warnings (3) #713

Merged
merged 5 commits into from
Jan 13, 2025
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
4 changes: 2 additions & 2 deletions Pipeline/Build.UnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ partial class Build
{
if (retry == 0)
{
Log.Error($"All {MaxRetries} tries failed: {ex}");
Log.Error($"All {MaxRetries + 1} tries failed: {ex}");
throw;
}

Expand Down Expand Up @@ -91,7 +91,7 @@ partial class Build
{
if (retry == 0)
{
Log.Error($"All {MaxRetries} tries failed: {ex}");
Log.Error($"All {MaxRetries + 1} tries failed: {ex}");
throw;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal static IOException AclAccessToPathDenied(string path)

internal static ArgumentException AppendAccessOnlyInWriteOnlyMode(
string paramName = "access")
=> new($"{FileMode.Append} access can be requested only in write-only mode.",
=> new($"{nameof(FileMode.Append)} access can be requested only in write-only mode.",
paramName)
{
#if FEATURE_EXCEPTION_HRESULT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,7 @@ internal static string GetSubdirectoryPath(this MockFileSystem fileSystem,
/// Ignores all registrations on the <see cref="MockFileSystem.Statistics" /> until the return value is disposed.
/// </summary>
internal static IDisposable IgnoreStatistics(this IFileSystem fileSystem)
{
if (fileSystem is MockFileSystem mockFileSystem)
{
return mockFileSystem.Registration.Ignore();
}

return new NoOpDisposable();
}
=> FileSystemRegistration.Ignore();

/// <summary>
/// Returns the shared <see cref="IRandom" /> instance from the <paramref name="fileSystem" />, if it is a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public bool TryGetLock(out IDisposable release)
/// <summary>
/// Ignores all registrations until the return value is disposed.
/// </summary>
internal IDisposable Ignore()
internal static IDisposable Ignore()
{
if (IsDisabled.Value)
{
Expand All @@ -59,7 +59,7 @@ internal IDisposable Ignore()
});
}

internal bool IsInitializing()
internal static bool IsInitializing()
=> IsInit.Value;

private sealed class TemporaryDisable : IDisposable
Expand Down
2 changes: 1 addition & 1 deletion Source/Testably.Abstractions.Testing/MockFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public MockFileSystem(Func<MockFileSystemOptions, MockFileSystemOptions> options
#endif
Registration = new FileSystemRegistration();
StatisticsRegistration = new FileSystemStatistics(this);
using IDisposable release = Registration.Ignore();
using IDisposable release = FileSystemRegistration.Ignore();
RandomSystem =
new MockRandomSystem(initialization.RandomProvider ?? RandomProvider.Default());
TimeSystem = new MockTimeSystem(TimeProvider.Now());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public IStorageAccessHandle RequestAccess(FileAccess access, FileShare share,
bool ignoreMetadataErrors = true,
int? hResult = null)
{
if (_fileSystem.Registration.IsInitializing())
if (FileSystemRegistration.IsInitializing())
{
return FileHandle.Ignore;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ public bool DeleteContainer(IStorageLocation location, bool recursive = false)
if (!_containers.TryGetValue(location, out IStorageContainer? container))
{
IStorageLocation? parentLocation = location.GetParent();
if (parentLocation != null &&
!_containers.TryGetValue(parentLocation, out _))
if (parentLocation != null && !_containers.ContainsKey(parentLocation))
{
throw ExceptionFactory.DirectoryNotFound(parentLocation.FullPath);
}
Expand Down Expand Up @@ -1044,7 +1043,7 @@ private void ThrowIfParentDoesNotExist(IStorageLocation location,
_fileSystem.Execute.Path.GetPathRoot(parentLocation.FullPath),
parentLocation.FullPath,
_fileSystem.Execute.StringComparisonMode) &&
!_containers.TryGetValue(parentLocation, out _))
!_containers.ContainsKey(parentLocation))
{
throw exceptionCallback(parentLocation);
}
Expand Down
2 changes: 2 additions & 0 deletions Source/Testably.Abstractions.Testing/TimeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ public static ITimeProvider Now()
/// </summary>
public static ITimeProvider Random()
{
#pragma warning disable MA0113 // Use DateTime.UnixEpoch
DateTime randomTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
.AddSeconds(RandomFactory.Shared.Next());
#pragma warning restore MA0113
return new TimeProviderMock(randomTime, "Random");
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<NoWarn>$(NoWarn);701;1702;CA1845;MA0003;MA0004;MA0042;MA0076;xUnit1044;xUnit1045;NU1603</NoWarn>
<NoWarn>$(NoWarn);701;1702;CA1845;MA0003;MA0004;MA0018;MA0020;MA0042;MA0076;xUnit1044;xUnit1045;NU1603</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ private static void AssertExceptionMessage<TException>(TException exception,
{
if (messageContains != null)
{
#pragma warning disable MA0074
#pragma warning disable MA0074 // Avoid implicit culture-sensitive methods
#pragma warning disable MA0001 // Use an overload of 'Contains' that has a StringComparison parameter
Execute.Assertion
.ForCondition(exception.Message.Contains(messageContains))
.BecauseOf(because, becauseArgs)
Expand All @@ -133,6 +134,7 @@ private static void AssertExceptionMessage<TException>(TException exception,
"Expected {context} to have a message containing {0}{reason}, but found {1}.",
messageContains,
exception.Message);
#pragma warning restore MA0001
#pragma warning restore MA0074
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public override void SkipIfLongRunningTestsShouldBeSkipped()
}
}

private bool IncludeSimulatedTests(ClassModel @class)
private static bool IncludeSimulatedTests(ClassModel @class)
{
return [email protected](
"Testably.Abstractions.AccessControl.Tests", StringComparison.Ordinal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void New_DriveNameWithUncPath_ShouldUseTopMostDirectory(
expectedName = expectedName
.Replace('/', FileSystem.Path.DirectorySeparatorChar);

IDriveInfo drive =
DriveInfoMock drive =
DriveInfoMock.New(driveName, FileSystem);

drive.Name.Should().Be(expectedName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void New_AppendAccessWithReadWriteMode_ShouldThrowArgumentException(
});

exception.Should().BeException<ArgumentException>(
messageContains: FileMode.Append.ToString(),
messageContains: nameof(FileMode.Append),
hResult: -2147024809,
paramName: Test.IsNetFramework ? null : "access");
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Testably.Abstractions.Tests/RandomSystem/RandomTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public void Shuffle_Array_ShouldShuffleItemsInPlace()

values.Should().OnlyHaveUniqueItems();
values.Should().NotContainInOrder(originalValues);
values.OrderBy(x => x).Should().ContainInOrder(originalValues);
values.Order().Should().ContainInOrder(originalValues);
}
#endif

Expand All @@ -337,7 +337,7 @@ public void Shuffle_Span_ShouldShuffleItemsInPlace()
int[] result = values.ToArray();
result.Should().OnlyHaveUniqueItems();
result.Should().NotContainInOrder(originalValues);
result.OrderBy(x => x).Should().ContainInOrder(originalValues);
result.Order().Should().ContainInOrder(originalValues);
}
#endif
}
2 changes: 2 additions & 0 deletions Tests/Testably.Abstractions.Tests/TimeSystem/DateTimeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public void Today_ShouldBeSetToToday()
[SkippableFact]
public void UnixEpoch_ShouldReturnDefaultValue()
{
#pragma warning disable MA0113 // Use DateTime.UnixEpoch
DateTime expectedResult = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
#pragma warning restore MA0113

DateTime result = TimeSystem.DateTime.UnixEpoch;

Expand Down
3 changes: 0 additions & 3 deletions Tests/Testably.Abstractions.Tests/TimeSystem/TimerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ public void Change_WithInt_ShouldResetTimer()
}

triggerTimes[0].Should()
.BeGreaterThan(70 * TimerMultiplier).And
.BeLessThan(130 * TimerMultiplier);
for (int i = 1; i < triggerTimes.Count; i++)
{
Expand Down Expand Up @@ -304,7 +303,6 @@ public void Change_WithLong_ShouldResetTimer()
}

triggerTimes[0].Should()
.BeGreaterThan(70 * TimerMultiplier).And
.BeLessThan(130 * TimerMultiplier);
for (int i = 1; i < triggerTimes.Count; i++)
{
Expand Down Expand Up @@ -381,7 +379,6 @@ public void Change_WithTimeSpan_ShouldResetTimer()
}

triggerTimes[0].Should()
.BeGreaterThan(70 * TimerMultiplier).And
.BeLessThan(130 * TimerMultiplier);
for (int i = 1; i < triggerTimes.Count; i++)
{
Expand Down
Loading