Skip to content

Commit

Permalink
chore(deps): update dependency meziantou.analyzer to v2 (#544)
Browse files Browse the repository at this point in the history
* chore(deps): update dependency meziantou.analyzer to v2

* chore(deps): update dependency meziantou.analyzer to v2

* Check or fix new warnings issued by the analyer update

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Valentin Breuß <vbreuss@gmail.com>
  • Loading branch information
renovate[bot] and vbreuss authored Apr 1, 2024
1 parent 7088165 commit 6e4d75c
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 96 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,10 @@ dotnet_diagnostic.CA1513.severity = none
dotnet_diagnostic.CA1860.severity = none
dotnet_diagnostic.CA1861.severity = none

dotnet_diagnostic.MA0002.severity = none
dotnet_diagnostic.MA0005.severity = none
dotnet_diagnostic.MA0016.severity = none
dotnet_diagnostic.MA0048.severity = none
dotnet_diagnostic.MA0051.severity = none
dotnet_diagnostic.MA0099.severity = none
dotnet_diagnostic.MA0144.severity = none
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@
<PackageVersion Include="Testably.Abstractions.FluentAssertions" Version="1.0.2" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Meziantou.Analyzer" Version="1.0.758" />
<PackageVersion Include="Meziantou.Analyzer" Version="2.0.146" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal static IZipArchiveEntry CreateEntryFromFile(
lastWrite = new DateTime(1980, 1, 1, 0, 0, 0);
}

entry.LastWriteTime = lastWrite;
entry.LastWriteTime = new DateTimeOffset(lastWrite);

using (Stream es = entry.Open())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ private void Start()
InternalBufferSize, channelCapacity)));
}
});
Task.Run(() =>
_ = Task.Run(() =>
{
try
{
Expand All @@ -461,11 +461,11 @@ private void Start()
}
},
token)
.ContinueWith(_ =>
.ContinueWith(__ =>
{
if (channel.Writer.TryComplete())
{
channel.Reader.Completion.ContinueWith(_ =>
_ = channel.Reader.Completion.ContinueWith(_ =>
{
cancellationTokenSource.Dispose();
}, CancellationToken.None);
Expand Down
38 changes: 19 additions & 19 deletions Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,25 +560,6 @@ internal IReadOnlyList<IStorageContainer> GetContainers()
return drive;
}

/// <summary>
/// When you use the asterisk wildcard character in <paramref name="searchPattern" /> and you specify a three-character
/// file extension, for example, "*.txt", this method also returns files with extensions that begin with the specified
/// extension.
/// </summary>
/// <remarks>
/// For example, the search pattern "*.xls" returns both "book.xls" and "book.xlsx". This behavior only occurs if an
/// asterisk is used in the search pattern and the file extension provided is exactly three characters. If you use the
/// question mark wildcard character somewhere in the search pattern, this method returns only files that match the
/// specified file extension exactly.
/// <para />
/// <see href="https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.enumeratefiles?view=netframework-4.8" />
/// </remarks>
private static bool SearchPatternMatchesFileExtensionOnNetFramework(string searchPattern,
string extension)
=> searchPattern.Length == 5 &&
searchPattern.StartsWith("*.", StringComparison.Ordinal) &&
extension.StartsWith(searchPattern.Substring(1), StringComparison.OrdinalIgnoreCase);

private void CheckAndAdjustParentDirectoryTimes(IStorageLocation location)
{
IStorageContainer? parentContainer = GetContainer(location.GetParent());
Expand Down Expand Up @@ -768,6 +749,25 @@ private void CreateParents(MockFileSystem fileSystem, IStorageLocation location)
}
#endif

/// <summary>
/// When you use the asterisk wildcard character in <paramref name="searchPattern" /> and you specify a three-character
/// file extension, for example, "*.txt", this method also returns files with extensions that begin with the specified
/// extension.
/// </summary>
/// <remarks>
/// For example, the search pattern "*.xls" returns both "book.xls" and "book.xlsx". This behavior only occurs if an
/// asterisk is used in the search pattern and the file extension provided is exactly three characters. If you use the
/// question mark wildcard character somewhere in the search pattern, this method returns only files that match the
/// specified file extension exactly.
/// <para />
/// <see href="https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.enumeratefiles?view=netframework-4.8" />
/// </remarks>
private static bool SearchPatternMatchesFileExtensionOnNetFramework(string searchPattern,
string extension)
=> searchPattern.Length == 5 &&
searchPattern.StartsWith("*.", StringComparison.Ordinal) &&
extension.StartsWith(searchPattern.Substring(1), StringComparison.OrdinalIgnoreCase);

private void ThrowIfParentDoesNotExist(IStorageLocation location,
Func<IStorageLocation, IOException>
exceptionCallback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private void Start()

CancellationToken token = runningCancellationTokenSource.Token;
using ManualResetEventSlim startCreateTimerThreads = new();
Task.Run(
_ = Task.Run(
async () =>
{
// ReSharper disable once AccessToDisposedClosure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public void LastWriteTime_ReadOnlyArchive_ShouldThrowNotSupportedException(
IZipArchiveEntry entry1 = archive.Entries[0];
Exception? exception = Record.Exception(() =>
{
entry1.LastWriteTime = lastWriteTime;
entry1.LastWriteTime = new DateTimeOffset(lastWriteTime);
});

exception.Should().BeOfType<NotSupportedException>();
Expand All @@ -285,9 +285,9 @@ public void LastWriteTime_ShouldBeSettable(DateTime lastWriteTime)
IZipArchiveEntry entry1 = archive.Entries[0];
IZipArchiveEntry entry2 = archive.Entries[1];

entry1.LastWriteTime = lastWriteTime;
entry1.LastWriteTime.Should().Be(lastWriteTime);
entry2.LastWriteTime.Should().NotBe(lastWriteTime);
entry1.LastWriteTime = new DateTimeOffset(lastWriteTime);
entry1.LastWriteTime.DateTime.Should().Be(lastWriteTime);
entry2.LastWriteTime.DateTime.Should().NotBe(lastWriteTime);
}

[SkippableFact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void
IDisposable disposable = timeSystem.On.TaskDelay(d => receivedDelay = d);

disposable.Dispose();
timeSystem.Task.Delay(millisecondsDelay);
_ = timeSystem.Task.Delay(millisecondsDelay);

receivedDelay.Should().BeNull();
}
Expand All @@ -119,7 +119,7 @@ public void
using (timeSystem.On.TaskDelay(d => receivedDelay1 = d))
{
timeSystem.On.TaskDelay(d => receivedDelay2 = d).Dispose();
timeSystem.Task.Delay(expectedDelay);
_ = timeSystem.Task.Delay(expectedDelay);
}

receivedDelay1.Should().Be(expectedDelay);
Expand All @@ -139,7 +139,7 @@ public void
{
using (timeSystem.On.TaskDelay(d => receivedDelay2 = d))
{
timeSystem.Task.Delay(expectedDelay);
_ = timeSystem.Task.Delay(expectedDelay);
}
}

Expand All @@ -157,7 +157,7 @@ public void

using (timeSystem.On.TaskDelay(d => receivedDelay = d))
{
timeSystem.Task.Delay(millisecondsDelay, CancellationToken.None);
_ = timeSystem.Task.Delay(millisecondsDelay, CancellationToken.None);
}

receivedDelay.TotalMilliseconds.Should().Be(millisecondsDelay);
Expand All @@ -173,7 +173,7 @@ public void

using (timeSystem.On.TaskDelay(d => receivedDelay = d))
{
timeSystem.Task.Delay(millisecondsDelay);
_ = timeSystem.Task.Delay(millisecondsDelay);
}

receivedDelay.TotalMilliseconds.Should().Be(millisecondsDelay);
Expand All @@ -189,7 +189,7 @@ public void

using (timeSystem.On.TaskDelay(d => receivedDelay = d))
{
timeSystem.Task.Delay(expectedDelay, CancellationToken.None);
_ = timeSystem.Task.Delay(expectedDelay, CancellationToken.None);
}

receivedDelay.Should().Be(expectedDelay);
Expand All @@ -205,7 +205,7 @@ public void

using (timeSystem.On.TaskDelay(d => receivedDelay = d))
{
timeSystem.Task.Delay(expectedDelay);
_ = timeSystem.Task.Delay(expectedDelay);
}

receivedDelay.Should().Be(expectedDelay);
Expand Down
126 changes: 66 additions & 60 deletions Tests/Testably.Abstractions.Tests/TimeSystem/TimerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,33 +155,35 @@ public void Change_WithInt_ShouldResetTimer()
using ManualResetEventSlim ms = new();
using ManualResetEventSlim ms2 = new();
using ManualResetEventSlim ms3 = new();
#pragma warning disable MA0147 // Avoid async void method for delegate
// ReSharper disable once AsyncVoidLambda
using (ITimer timer1 = TimeSystem.Timer.New(async _ =>
{
// ReSharper disable once AccessToDisposedClosure
try
{
DateTime now = TimeSystem.DateTime.Now;
double diff = (now - previousTime).TotalMilliseconds;
previousTime = now;
ms.Set();
triggerTimes.Add((int)diff);
// ReSharper disable once AccessToDisposedClosure
ms2.Wait(30000);
if (triggerTimes.Count > 3)
try
{
DateTime now = TimeSystem.DateTime.Now;
double diff = (now - previousTime).TotalMilliseconds;
previousTime = now;
ms.Set();
triggerTimes.Add((int)diff);
// ReSharper disable once AccessToDisposedClosure
ms3.Set();
ms2.Wait(30000);
if (triggerTimes.Count > 3)
{
// ReSharper disable once AccessToDisposedClosure
ms3.Set();
}

await Task.Delay(10);
}

await Task.Delay(10);
}
catch (ObjectDisposedException)
{
// Ignore any ObjectDisposedException
}
},
null, 0 * TimerMultiplier, 200 * TimerMultiplier))
catch (ObjectDisposedException)
{
// Ignore any ObjectDisposedException
}
},
null, 0 * TimerMultiplier, 200 * TimerMultiplier))
#pragma warning restore MA0147 // Avoid async void method for delegate
{
ms.Wait(30000).Should().BeTrue();
using ITimer timer2 = TimeSystem.Timer.New(_ =>
Expand Down Expand Up @@ -228,33 +230,35 @@ public void Change_WithLong_ShouldResetTimer()
using ManualResetEventSlim ms = new();
using ManualResetEventSlim ms2 = new();
using ManualResetEventSlim ms3 = new();
#pragma warning disable MA0147 // Avoid async void method for delegate
// ReSharper disable once AsyncVoidLambda
using (ITimer timer1 = TimeSystem.Timer.New(async _ =>
{
// ReSharper disable once AccessToDisposedClosure
try
{
DateTime now = TimeSystem.DateTime.Now;
double diff = (now - previousTime).TotalMilliseconds;
previousTime = now;
ms.Set();
triggerTimes.Add((int)diff);
// ReSharper disable once AccessToDisposedClosure
ms2.Wait(30000);
if (triggerTimes.Count > 3)
try
{
DateTime now = TimeSystem.DateTime.Now;
double diff = (now - previousTime).TotalMilliseconds;
previousTime = now;
ms.Set();
triggerTimes.Add((int)diff);
// ReSharper disable once AccessToDisposedClosure
ms3.Set();
ms2.Wait(30000);
if (triggerTimes.Count > 3)
{
// ReSharper disable once AccessToDisposedClosure
ms3.Set();
}

await Task.Delay(10);
}

await Task.Delay(10);
}
catch (ObjectDisposedException)
{
// Ignore any ObjectDisposedException
}
},
null, 0L * TimerMultiplier, 200L * TimerMultiplier))
catch (ObjectDisposedException)
{
// Ignore any ObjectDisposedException
}
},
null, 0L * TimerMultiplier, 200L * TimerMultiplier))
#pragma warning restore MA0147 // Avoid async void method for delegate
{
ms.Wait(30000).Should().BeTrue();
using ITimer timer2 = TimeSystem.Timer.New(_ =>
Expand Down Expand Up @@ -301,33 +305,35 @@ public void Change_WithTimeSpan_ShouldResetTimer()
using ManualResetEventSlim ms = new();
using ManualResetEventSlim ms2 = new();
using ManualResetEventSlim ms3 = new();
#pragma warning disable MA0147 // Avoid async void method for delegate
// ReSharper disable once AsyncVoidLambda
using (ITimer timer1 = TimeSystem.Timer.New(async _ =>
{
// ReSharper disable once AccessToDisposedClosure
try
{
DateTime now = TimeSystem.DateTime.Now;
double diff = (now - previousTime).TotalMilliseconds;
previousTime = now;
ms.Set();
triggerTimes.Add((int)diff);
// ReSharper disable once AccessToDisposedClosure
ms2.Wait(30000);
if (triggerTimes.Count > 3)
try
{
DateTime now = TimeSystem.DateTime.Now;
double diff = (now - previousTime).TotalMilliseconds;
previousTime = now;
ms.Set();
triggerTimes.Add((int)diff);
// ReSharper disable once AccessToDisposedClosure
ms3.Set();
ms2.Wait(30000);
if (triggerTimes.Count > 3)
{
// ReSharper disable once AccessToDisposedClosure
ms3.Set();
}

await Task.Delay(10);
}

await Task.Delay(10);
}
catch (ObjectDisposedException)
{
// Ignore any ObjectDisposedException
}
}, null, TimeSpan.FromMilliseconds(0 * TimerMultiplier),
TimeSpan.FromMilliseconds(200 * TimerMultiplier)))
catch (ObjectDisposedException)
{
// Ignore any ObjectDisposedException
}
}, null, TimeSpan.FromMilliseconds(0 * TimerMultiplier),
TimeSpan.FromMilliseconds(200 * TimerMultiplier)))
#pragma warning restore MA0147 // Avoid async void method for delegate
{
ms.Wait(30000).Should().BeTrue();
using ITimer timer2 = TimeSystem.Timer.New(_ =>
Expand Down

0 comments on commit 6e4d75c

Please sign in to comment.