Skip to content

Commit

Permalink
refactor: fix build warnings in test projects (#1203)
Browse files Browse the repository at this point in the history
Fix build warnings in test projects.
  • Loading branch information
vbreuss authored Feb 2, 2025
1 parent d2ae767 commit 2c8fb45
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,9 @@ public void Directory_exists_after_creation_with_security()
var directoryInfo = fileSystem.DirectoryInfo.New(XFS.Path(@"c:\abc"));

// Act
#pragma warning disable CA1416
directoryInfo.Create(new DirectorySecurity());
#pragma warning restore CA1416

// Assert
Assert.That(directoryInfo.Exists, Is.True);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,9 @@ public void MockDirectory_GetAccessControl_ShouldThrowExceptionOnDirectoryNotFou
var fileSystem = new MockFileSystem();

// Act
#pragma warning disable CA1416
Assert.Throws<DirectoryNotFoundException>(() => fileSystem.Directory.GetAccessControl(XFS.Path(@"c:\foo")));
#pragma warning restore CA1416
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ private static IEnumerable<Action<IFile>> GetFileSystemActionsForArgumentNullExc
yield return fs => fs.SetLastAccessTimeUtc((string)null, DateTime.Now);
yield return fs => fs.SetLastWriteTime((string)null, DateTime.Now);
yield return fs => fs.SetLastWriteTimeUtc((string)null, DateTime.Now);
#pragma warning disable CA1416
yield return fs => fs.Decrypt(null);
yield return fs => fs.Encrypt(null);
#pragma warning restore CA1416
}

[TestCaseSource(nameof(GetFileSystemActionsForArgumentNullException))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,10 @@ public void MockFileInfo_OpenRead_ShouldReturnByteContentOfFile()
byte[] result = new byte[2];
using (var stream = fileInfo.OpenRead())
{
#pragma warning disable CA2022
// ReSharper disable once MustUseReturnValue
stream.Read(result, 0, 2);
#pragma warning restore CA2022
}

Assert.That(result, Is.EqualTo(new byte[] { 1, 2 }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ public void MockFile_Read_ShouldRetainCreationTimeAndUpdateLastAccessTime()
var fi = fs.FileInfo.New(filepath);
var stream = fi.OpenRead();
var buffer = new byte[16];
#pragma warning disable CA2022
stream.Read(buffer, 0, buffer.Length);
#pragma warning restore CA2022
fi.Refresh();
// Assert
Assert.That(fi.CreationTime, Is.EqualTo(creationTime));
Expand All @@ -270,7 +272,12 @@ public async Task MockFile_ReadAsync_ShouldRetainCreationTimeAndUpdateLastAccess
var fi = fs.FileInfo.New(filepath);
var stream = fi.OpenRead();
var buffer = new byte[16];
#pragma warning disable CA1835
#pragma warning disable CA2022
// ReSharper disable once MustUseReturnValue
await stream.ReadAsync(buffer, 0, buffer.Length);
#pragma warning restore CA2022
#pragma warning restore CA1835
fi.Refresh();
// Assert
Assert.That(fi.CreationTime, Is.EqualTo(creationTime));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,9 @@ public void MockFile_Encrypt_ShouldSetEncryptedAttribute()
});

// Act
#pragma warning disable CA1416
fileSystem.File.Encrypt(filePath);
#pragma warning restore CA1416
var attributes = fileSystem.File.GetAttributes(filePath);

// Assert
Expand All @@ -623,10 +625,14 @@ public void MockFile_Decrypt_ShouldRemoveEncryptedAttribute()
{
{filePath, fileData }
});
#pragma warning disable CA1416
fileSystem.File.Encrypt(filePath);
#pragma warning restore CA1416

// Act
#pragma warning disable CA1416
fileSystem.File.Decrypt(filePath);
#pragma warning restore CA1416
var attributes = fileSystem.File.GetAttributes(filePath);

// Assert
Expand Down

0 comments on commit 2c8fb45

Please sign in to comment.