From 359e6f53e474d3fed92bdb3cc9c8d39d82655711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 21 Jan 2026 15:46:29 +0100 Subject: [PATCH 1/2] refactor: fix or ignore sonar issues --- .../FileSystem/FileStreamMock.cs | 8 +++++--- .../Statistics/CallStatistics.cs | 3 ++- .../Statistics/StatisticsTests.Helpers.cs | 4 ++-- .../Testably.Abstractions.Tests/TimeSystem/TimerTests.cs | 6 +++--- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Source/Testably.Abstractions.Testing/FileSystem/FileStreamMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/FileStreamMock.cs index 9448e3e37..ce21826bc 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/FileStreamMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/FileStreamMock.cs @@ -193,7 +193,7 @@ internal FileStreamMock(MockFileSystem fileSystem, #if FEATURE_FILESYSTEM_UNIXFILEMODE ,UnixFileMode? unixFileMode = null #endif - ) + ) : this(new MemoryStream(), fileSystem, path.EnsureValidFormat(fileSystem, nameof(path)), @@ -205,10 +205,11 @@ internal FileStreamMock(MockFileSystem fileSystem, #if FEATURE_FILESYSTEM_UNIXFILEMODE ,unixFileMode #endif - ) + ) { } + #pragma warning disable S3776 // Cognitive Complexity of methods should not be too high private FileStreamMock(MemoryStream stream, MockFileSystem fileSystem, string? path, @@ -220,7 +221,7 @@ FileOptions options #if FEATURE_FILESYSTEM_UNIXFILEMODE ,UnixFileMode? unixFileMode #endif - ) + ) : base( stream, path == null ? "" : fileSystem.Execute.Path.GetFullPath(path), @@ -293,6 +294,7 @@ FileOptions options InitializeStream(); } + #pragma warning restore S3776 // Cognitive Complexity of methods should not be too high #region IFileSystemExtensibility Members diff --git a/Source/Testably.Abstractions.Testing/Statistics/CallStatistics.cs b/Source/Testably.Abstractions.Testing/Statistics/CallStatistics.cs index 71e9bcfc9..55096993d 100644 --- a/Source/Testably.Abstractions.Testing/Statistics/CallStatistics.cs +++ b/Source/Testably.Abstractions.Testing/Statistics/CallStatistics.cs @@ -180,7 +180,7 @@ internal IDisposable RegisterMethod(string name, T1 para return release; } - + #pragma warning disable S107 // Method has too many parameters /// /// Registers the method with , , /// , , and @@ -205,6 +205,7 @@ internal IDisposable RegisterMethod(string name, T1 return release; } + #pragma warning restore S107 // Method has too many parameters #if FEATURE_SPAN /// diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/StatisticsTests.Helpers.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/StatisticsTests.Helpers.cs index ba1a09422..814e7e539 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/StatisticsTests.Helpers.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/StatisticsTests.Helpers.cs @@ -92,7 +92,7 @@ private static void CheckMethods(StringBuilder builder, .OrderBy(m => m.Name) .ThenBy(m => m.GetParameters().Length)) { - if (methodInfo.GetCustomAttribute() != null) + if (methodInfo.IsDefined(typeof(ObsoleteAttribute))) { continue; } @@ -125,7 +125,7 @@ private static void CheckProperties(StringBuilder builder, .Where(p => !p.IsSpecialName && (p.CanRead || p.CanWrite)) .OrderBy(m => m.Name)) { - if (propertyInfo.GetCustomAttribute() != null || + if (propertyInfo.IsDefined(typeof(ObsoleteAttribute)) || string.Equals(propertyInfo.Name, nameof(IFileSystemEntity.FileSystem), StringComparison.Ordinal)) { diff --git a/Tests/Testably.Abstractions.Tests/TimeSystem/TimerTests.cs b/Tests/Testably.Abstractions.Tests/TimeSystem/TimerTests.cs index 5a9231bb6..e59e472b7 100644 --- a/Tests/Testably.Abstractions.Tests/TimeSystem/TimerTests.cs +++ b/Tests/Testably.Abstractions.Tests/TimeSystem/TimerTests.cs @@ -344,7 +344,7 @@ await That(ms2.Wait(ExpectSuccess, TestContext.Current.CancellationToken)) { // Ignore any ObjectDisposedException } - }, null, TimeSpan.FromMilliseconds(0 * TimerMultiplier), + }, null, TimeSpan.FromMilliseconds(TimerMultiplier), TimeSpan.FromMilliseconds(200 * TimerMultiplier))) #pragma warning restore MA0147 // Avoid async void method for delegate { @@ -354,7 +354,7 @@ await That(ms2.Wait(ExpectSuccess, TestContext.Current.CancellationToken)) // ReSharper disable once AccessToDisposedClosure try { - timer1.Change(TimeSpan.FromMilliseconds(0 * TimerMultiplier), + timer1.Change(TimeSpan.FromMilliseconds(TimerMultiplier), TimeSpan.FromMilliseconds(200 * TimerMultiplier)); // ReSharper disable once AccessToDisposedClosure ms2.Set(); @@ -364,7 +364,7 @@ await That(ms2.Wait(ExpectSuccess, TestContext.Current.CancellationToken)) // Ignore any ObjectDisposedException } }, null, TimeSpan.FromMilliseconds(100 * TimerMultiplier), - TimeSpan.FromMilliseconds(0 * TimerMultiplier)); + TimeSpan.FromMilliseconds(TimerMultiplier)); await That(ms3.Wait(ExpectSuccess, TestContext.Current.CancellationToken)).IsTrue(); } From eeba06e39b0a74fdba4f407cc26ac21ad4130dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 21 Jan 2026 16:51:44 +0100 Subject: [PATCH 2/2] Disable complexity warning in `FileSsystemWatcherMcok` --- .../FileSystem/FileSystemWatcherMock.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs index 63ab5845f..cd59c1946 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs @@ -600,6 +600,7 @@ private void TriggerRenameNotification(ChangeDescription item) } } + #pragma warning disable S3776 // Cognitive Complexity of methods should not be too high private void TriggerWindowsRenameNotification(ChangeDescription item, RenamedContext context) { CheckRenamePremise(context); @@ -718,6 +719,7 @@ private void TriggerLinuxRenameNotification(ChangeDescription item, RenamedConte Renamed?.Invoke(this, eventArgs!); } } + #pragma warning restore S3776 // Cognitive Complexity of methods should not be too high private static void CheckRenamePremise(RenamedContext context) {