Skip to content

Commit

Permalink
Run ReSharper cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vbreuss committed Apr 29, 2024
1 parent 4221106 commit 4aee39d
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Guid Parse(string input)
#endif

#if FEATURE_GUID_PARSE
#pragma warning disable MA0011
#pragma warning disable MA0011
/// <inheritdoc cref="IGuid.Parse(ReadOnlySpan{char})" />
public Guid Parse(ReadOnlySpan<char> input)
=> Guid.Parse(input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ private bool TryMakeRenamedEventArgs(
.GetField("_oldFullPath", BindingFlags.Instance | BindingFlags.NonPublic)?
.SetValue(eventArgs, oldFullPath);
}

return _fileSystem.Execute.Path.GetDirectoryName(changeDescription.Path)?
.Equals(_fileSystem.Execute.Path.GetDirectoryName(changeDescription.OldPath),
_fileSystem.Execute.StringComparisonMode) ?? true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ private int GetCommonPathLength(string first, string second,
return commonChars;
}

if (second.Length > commonChars && IsDirectorySeparator(second[commonChars]) ||
if ((second.Length > commonChars && IsDirectorySeparator(second[commonChars])) ||
IsDirectorySeparator(first[commonChars - 1]))
{
return commonChars;
Expand Down
3 changes: 2 additions & 1 deletion Source/Testably.Abstractions.Testing/Helpers/Execute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ internal partial class Execute
#if !CAN_SIMULATE_OTHER_OS
[Obsolete("Simulating other operating systems is not supported on .NET Framework")]
#endif
internal Execute(MockFileSystem fileSystem, SimulationMode simulationMode, bool isNetFramework = false)
internal Execute(MockFileSystem fileSystem, SimulationMode simulationMode,
bool isNetFramework = false)
{
IsLinux = simulationMode == SimulationMode.Linux;
IsMac = simulationMode == SimulationMode.MacOS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ internal static string GetSubdirectoryPath(this MockFileSystem fileSystem,
{
fullFilePath = fullFilePath.Substring(currentDirectory.Length);
}
else if (fullFilePath.StartsWith(currentDirectory + fileSystem.Execute.Path.DirectorySeparatorChar,
else if (fullFilePath.StartsWith(
currentDirectory + fileSystem.Execute.Path.DirectorySeparatorChar,
fileSystem.Execute.StringComparisonMode))
{
fullFilePath = fullFilePath.Substring(currentDirectory.Length + 1);
Expand All @@ -75,11 +76,13 @@ internal static string GetSubdirectoryPath(this MockFileSystem fileSystem,
{
string? parentName = currentDirectory;
while (parentName != null &&
!fullFilePath.StartsWith(parentName + fileSystem.Execute.Path.DirectorySeparatorChar,
!fullFilePath.StartsWith(
parentName + fileSystem.Execute.Path.DirectorySeparatorChar,
fileSystem.Execute.StringComparisonMode))
{
parentName = fileSystem.Execute.Path.GetDirectoryName(parentName);
int lastIndex = givenPath.LastIndexOf(fileSystem.Execute.Path.DirectorySeparatorChar);
int lastIndex =
givenPath.LastIndexOf(fileSystem.Execute.Path.DirectorySeparatorChar);
if (lastIndex >= 0)
{
givenPath = givenPath.Substring(0, lastIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public CallStatistics(IStatisticsGate statisticsGate, string name)
_name = name;
}

#region IStatistics Members
#region IStatistics<TType> Members

/// <inheritdoc cref="IStatistics.Methods" />
public MethodStatistic[] Methods => _methods.ToArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

namespace Testably.Abstractions.Testing.Statistics;

internal class PathStatistics<TFactory, TType> : CallStatistics<TFactory>, IPathStatistics<TFactory, TType>
internal class PathStatistics<TFactory, TType> : CallStatistics<TFactory>,
IPathStatistics<TFactory, TType>
{
private readonly MockFileSystem _fileSystem;

Expand All @@ -26,7 +27,7 @@ public PathStatistics(
_fileSystem = fileSystem;
}

#region IPathStatistics Members
#region IPathStatistics<TFactory,TType> Members

/// <inheritdoc cref="IPathStatistics{TFactory,TType}.this[string]" />
public IStatistics<TType> this[string path]
Expand Down
12 changes: 10 additions & 2 deletions Source/Testably.Abstractions.Testing/Storage/InMemoryContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,11 @@ internal FileAttributes AdjustAttributes(FileAttributes attributes)
return attributes;
}

private bool CanGetAccess(FileAccess access, FileShare share, bool deleteAccess, bool ignoreFileShare)
private bool CanGetAccess(
FileAccess access,
FileShare share,
bool deleteAccess,
bool ignoreFileShare)
{
foreach (KeyValuePair<Guid, FileHandle> fileHandle in _fileHandles)
{
Expand Down Expand Up @@ -386,7 +390,11 @@ public void Dispose()

#endregion

public bool GrantAccess(FileAccess access, FileShare share, bool deleteAccess, bool ignoreFileShare)
public bool GrantAccess(
FileAccess access,
FileShare share,
bool deleteAccess,
bool ignoreFileShare)
{
FileShare usedShare = share;
FileShare currentShare = Share;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ public static AdjustedLocation AdjustLocationFromSearchPattern(
StringBuilder givenPathPrefix = new();

while (searchPattern.StartsWith(
".." + fileSystem.Execute.Path.DirectorySeparatorChar, StringComparison.Ordinal) ||
".." + fileSystem.Execute.Path.DirectorySeparatorChar,
StringComparison.Ordinal) ||
searchPattern.StartsWith(
".." + fileSystem.Execute.Path.AltDirectorySeparatorChar, StringComparison.Ordinal))
".." + fileSystem.Execute.Path.AltDirectorySeparatorChar,
StringComparison.Ordinal))
{
fileSystem.Execute.OnNetFramework(
() => throw ExceptionFactory.SearchPatternCannotContainTwoDots());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,17 @@ private sealed class DummyZipArchiveEntry(
Stream? stream = null)
: IZipArchiveEntry
{
/// <inheritdoc cref="IZipArchiveEntry.Comment" />
public string Comment { get; set; } = comment;

/// <inheritdoc cref="IZipArchiveEntry.IsEncrypted" />
public bool IsEncrypted { get; } = isEncrypted;

#region IZipArchiveEntry Members

/// <inheritdoc cref="IZipArchiveEntry.Archive" />
public IZipArchive Archive => archive ?? throw new NotSupportedException();

/// <inheritdoc cref="IZipArchiveEntry.Comment" />
public string Comment { get; set; } = comment;

/// <inheritdoc cref="IZipArchiveEntry.CompressedLength" />
public long CompressedLength => stream?.Length ?? 0L;

Expand All @@ -69,9 +72,6 @@ private sealed class DummyZipArchiveEntry(
/// <inheritdoc cref="IZipArchiveEntry.FullName" />
public string FullName { get; } = fullName ?? "";

/// <inheritdoc cref="IZipArchiveEntry.IsEncrypted" />
public bool IsEncrypted { get; } = isEncrypted;

/// <inheritdoc cref="IZipArchiveEntry.LastWriteTime" />
public DateTimeOffset LastWriteTime { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,7 @@ public sealed class EventArgsTests
public void FileSystemEventArgs_ShouldUseDirectorySeparatorFromSimulatedFileSystem(
SimulationMode simulationMode, string parentDirectory, string directoryName)
{
MockFileSystem fileSystem =
new MockFileSystem(s => s.SimulatingOperatingSystem(simulationMode));
MockFileSystem fileSystem = new(s => s.SimulatingOperatingSystem(simulationMode));
fileSystem.Directory.CreateDirectory(parentDirectory);
FileSystemEventArgs? result = null;
string expectedFullPath = fileSystem.Path.GetFullPath(
Expand Down Expand Up @@ -287,8 +286,7 @@ public void RenamedEventArgs_ShouldUseDirectorySeparatorFromSimulatedFileSystem(
SimulationMode simulationMode, string parentDirectory,
string sourceName, string destinationName)
{
MockFileSystem fileSystem =
new MockFileSystem(s => s.SimulatingOperatingSystem(simulationMode));
MockFileSystem fileSystem = new(s => s.SimulatingOperatingSystem(simulationMode));
fileSystem.Directory.CreateDirectory(parentDirectory);
RenamedEventArgs? result = null;
string expectedOldFullPath = fileSystem.Path.GetFullPath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ public void OnLinux_ShouldExecuteDependingOnOperatingSystem(
[InlineData(SimulationMode.MacOS, false, 5, 6, 6)]
[InlineData(SimulationMode.Windows, false, 1, 2, 2)]
public void OnLinux_WithValue_ShouldExecuteDependingOnOperatingSystem(
SimulationMode type, bool isNetFramework, int value, int alternativeValue, int expectedValue)
SimulationMode type,
bool isNetFramework,
int value,
int alternativeValue,
int expectedValue)
{
Execute sut = FromType(type, isNetFramework);

Expand Down Expand Up @@ -128,7 +132,11 @@ public void OnNetFramework_ShouldExecuteDependingOnOperatingSystem(
[InlineData(SimulationMode.MacOS, true, 5, 6, 6)]
[InlineData(SimulationMode.Windows, true, 1, 2, 1)]
public void OnNetFramework_WithValue_ShouldExecuteDependingOnOperatingSystem(
SimulationMode type, bool isNetFramework, int value, int alternativeValue, int expectedValue)
SimulationMode type,
bool isNetFramework,
int value,
int alternativeValue,
int expectedValue)
{
Execute sut = FromType(type, isNetFramework);

Expand Down Expand Up @@ -183,7 +191,11 @@ public void OnWindows_ShouldExecuteDependingOnOperatingSystem(
[InlineData(SimulationMode.Windows, false, 1, 2, 1)]
[InlineData(SimulationMode.Windows, true, 1, 2, 1)]
public void OnWindows_WithValue_ShouldExecuteDependingOnOperatingSystem(
SimulationMode type, bool isNetFramework, int value, int alternativeValue, int expectedValue)
SimulationMode type,
bool isNetFramework,
int value,
int alternativeValue,
int expectedValue)
{
Execute sut = FromType(type, isNetFramework);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public void Operations_WhenValueIsNull_ShouldThrowArgumentNullException(
$"\n{callback}\n has `null` parameter for '{paramName}' (ignored: {ignoreParamCheck})");
}

#region Helpers
#region Helpers

#pragma warning disable MA0018
public static TheoryData<Expression<Action<IFileSystemInfo>>, string, bool>
#pragma warning disable MA0018
public static TheoryData<Expression<Action<IFileSystemInfo>>, string, bool>
GetFileSystemInfoCallbacks(string? path)
{
TheoryData<Expression<Action<IFileSystemInfo>>, string, bool> theoryData = new();
Expand All @@ -68,7 +68,7 @@ public static TheoryData<Expression<Action<IFileSystemInfo>>, string, bool>
}
#pragma warning restore MA0018

private static IEnumerable<(ExceptionTestHelper.TestTypes TestType, string ParamName,
private static IEnumerable<(ExceptionTestHelper.TestTypes TestType, string ParamName,
Expression<Action<IFileSystemInfo>> Callback)>
GetFileSystemInfoCallbackTestParameters(string value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,25 @@ public void GetExtension_Span_ShouldReturnExtensionWithLeadingDot(

[SkippableTheory]
[AutoData]
public void GetExtension_TrailingDot_ShouldReturnEmptyString(
public void GetExtension_StartingDot_ShouldReturnCompleteFileName(
string directory, string filename)
{
string path = directory + FileSystem.Path.DirectorySeparatorChar + filename + ".";
string path = directory + FileSystem.Path.DirectorySeparatorChar + "." + filename;

string result = FileSystem.Path.GetExtension(path);

result.Should().Be("");
result.Should().Be("." + filename);
}

[SkippableTheory]
[AutoData]
public void GetExtension_StartingDot_ShouldReturnCompleteFileName(
public void GetExtension_TrailingDot_ShouldReturnEmptyString(
string directory, string filename)
{
string path = directory + FileSystem.Path.DirectorySeparatorChar + "." + filename;
string path = directory + FileSystem.Path.DirectorySeparatorChar + filename + ".";

string result = FileSystem.Path.GetExtension(path);

result.Should().Be("." + filename);
result.Should().Be("");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public void GetPathRoot_RootedDrive_ShouldReturnDriveOnWindows(string path)
[SkippableTheory]
[InlineData("D:some-path", "D:")]
[InlineData("D:\\some-path", "D:\\")]
public void GetPathRoot_RootedDriveWithPath_ShouldReturnDriveOnWindows(string path, string expected)
public void GetPathRoot_RootedDriveWithPath_ShouldReturnDriveOnWindows(
string path, string expected)
{
Skip.IfNot(Test.RunsOnWindows);

Expand Down
28 changes: 14 additions & 14 deletions Tests/Testably.Abstractions.Tests/RandomSystem/GuidTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections.Concurrent;
using System.Threading.Tasks;
#if FEATURE_GUID_PARSE
using System.Collections.Generic;
#endif
using System.Collections.Concurrent;
using System.Threading.Tasks;
#if FEATURE_GUID_FORMATPROVIDER
using System.Globalization;
#endif
Expand Down Expand Up @@ -41,10 +41,10 @@ public void Parse_SpanArray_ShouldReturnCorrectGuid(Guid guid)
ReadOnlySpan<char> serializedGuid = guid.ToString().AsSpan();

#pragma warning disable MA0011
Guid result = RandomSystem.Guid.Parse(serializedGuid);
#pragma warning restore MA0011
Guid result = RandomSystem.Guid.Parse(serializedGuid);
#pragma warning restore MA0011

result.Should().Be(guid);
result.Should().Be(guid);
}
#endif

Expand All @@ -56,10 +56,10 @@ public void Parse_String_ShouldReturnCorrectGuid(Guid guid)
string serializedGuid = guid.ToString();

#pragma warning disable MA0011
Guid result = RandomSystem.Guid.Parse(serializedGuid);
#pragma warning restore MA0011
Guid result = RandomSystem.Guid.Parse(serializedGuid);
#pragma warning restore MA0011

result.Should().Be(guid);
result.Should().Be(guid);
}
#endif

Expand Down Expand Up @@ -124,10 +124,10 @@ public void TryParse_SpanArray_ShouldReturnTrue(Guid guid)
ReadOnlySpan<char> serializedGuid = guid.ToString().AsSpan();

#pragma warning disable MA0011
bool result = RandomSystem.Guid.TryParse(serializedGuid, out Guid value);
#pragma warning restore MA0011
bool result = RandomSystem.Guid.TryParse(serializedGuid, out Guid value);
#pragma warning restore MA0011

result.Should().BeTrue();
result.Should().BeTrue();
value.Should().Be(guid);
}
#endif
Expand All @@ -140,10 +140,10 @@ public void TryParse_String_ShouldReturnTrue(Guid guid)
string serializedGuid = guid.ToString();

#pragma warning disable MA0011
bool result = RandomSystem.Guid.TryParse(serializedGuid, out Guid value);
#pragma warning restore MA0011
bool result = RandomSystem.Guid.TryParse(serializedGuid, out Guid value);
#pragma warning restore MA0011

result.Should().BeTrue();
result.Should().BeTrue();
value.Should().Be(guid);
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static T DependsOnOS<T>(this Test test, T windows, T macOS, T linux)
public static bool RunsOn(this Test test, TestOS operatingSystem)
=> (operatingSystem.HasFlag(TestOS.Linux) && test.RunsOnLinux) ||
(operatingSystem.HasFlag(TestOS.Mac) && test.RunsOnMac) ||
(operatingSystem.HasFlag(TestOS.Windows) && test is { RunsOnWindows: true, IsNetFramework: false }) ||
(operatingSystem.HasFlag(TestOS.Windows) &&
test is { RunsOnWindows: true, IsNetFramework: false }) ||
(operatingSystem.HasFlag(TestOS.Framework) && test.IsNetFramework);
}

0 comments on commit 4aee39d

Please sign in to comment.