mirror of
https://github.com/BepInEx/dotnet-runtime.git
synced 2026-11-22 19:10:41 -10:00
- References dotnet/corefx#2460. File.Move and FileInfo.MoveTo no longer always overwrite the destination file; added a non-concurrent validity check to MoveFile in the Unix implementation to serve as a temporary solution. - Resolves dotnet/corefx#2459. Reenabled Directory_CreateDirectory.DriveLetter_Unix as it's previous failures were not the fault of the method but of the system. - Added test checks to work around the issue in dotnet/corefx#2537 until a final decision is reached for the desktop. - Added Interop.Link to the Interop files for the (possible) implementation of File.Move - Consolidated all of the related files that did nothing but inherit from other classes (e.g. File_GetFiles_str and File_GetFiles_str_str were consolidated into File_GetFiles) - Removed the "partial" keyword from some test classes - Finished overhauling all test cases that don't directly require solutions to Build System issues before being re-added (e.g. those that require networked drives or altering the current directory) - Added some tests to increase code coverage slightly in some cases. - All classes and files have been renamed to match the standard set by FileStream: only include parameters in the test/class name if there are overloads - Modified the Unix behavior for distinguishing between a FileNotFoundException and a DirectoryNotFoundException to match that of Windows. - Removed some redundant error checks that never catch - DirectoryInfo.MoveTo(destPath) did not have checks for destinations with paths that are over MAXPATH. I added them to better match the behavior and error timing of Directory.Move(source, dest). Commit migrated from https://github.com/dotnet/corefx/commit/481d5c645763da79145af50d123db3f4041aa05e
125 lines
4.0 KiB
C#
125 lines
4.0 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
using Xunit;
|
|
|
|
namespace System.IO.FileSystem.Tests
|
|
{
|
|
public class FileInfo_GetSetAttributes : FileSystemTest
|
|
{
|
|
#region Utilities
|
|
|
|
protected virtual FileAttributes Get(string path)
|
|
{
|
|
var info = new FileInfo(path);
|
|
return info.Attributes;
|
|
}
|
|
|
|
protected virtual void Set(string path, FileAttributes attributes)
|
|
{
|
|
var info = new FileInfo(path);
|
|
info.Attributes = attributes;
|
|
}
|
|
|
|
#endregion
|
|
|
|
[Fact]
|
|
public void NullParameters()
|
|
{
|
|
Assert.Throws<ArgumentNullException>(() => Get(null));
|
|
Assert.Throws<ArgumentNullException>(() => Set(null, FileAttributes.Normal));
|
|
}
|
|
|
|
[Fact]
|
|
public void InvalidParameters()
|
|
{
|
|
Assert.Throws<ArgumentException>(() => Get(string.Empty));
|
|
Assert.Throws<ArgumentException>(() => Set(string.Empty, FileAttributes.Normal));
|
|
}
|
|
|
|
[Fact]
|
|
public void NonExistentFile()
|
|
{
|
|
Assert.Throws<FileNotFoundException>(() => Set(GetTestFilePath(), FileAttributes.Normal));
|
|
}
|
|
|
|
[Fact]
|
|
public void IsReadOnly_Set_And_Get()
|
|
{
|
|
var test = new FileInfo(GetTestFilePath());
|
|
test.Create().Dispose();
|
|
// Set to True
|
|
test.IsReadOnly = true;
|
|
test.Refresh();
|
|
Assert.Equal(true, test.IsReadOnly);
|
|
|
|
// Set To False
|
|
test.IsReadOnly = false;
|
|
test.Refresh();
|
|
Assert.Equal(false, test.IsReadOnly);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(FileAttributes.ReadOnly)]
|
|
[InlineData(FileAttributes.Normal)]
|
|
[PlatformSpecific(PlatformID.AnyUnix)]
|
|
public void UnixAttributeSetting(FileAttributes attr)
|
|
{
|
|
var test = new FileInfo(GetTestFilePath());
|
|
test.Create().Dispose();
|
|
Set(test.FullName, attr);
|
|
test.Refresh();
|
|
Assert.Equal(attr, Get(test.FullName));
|
|
Set(test.FullName, 0);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(FileAttributes.ReadOnly)]
|
|
[InlineData(FileAttributes.Hidden)]
|
|
[InlineData(FileAttributes.System)]
|
|
[InlineData(FileAttributes.Archive)]
|
|
[InlineData(FileAttributes.Normal)]
|
|
[InlineData(FileAttributes.Temporary)]
|
|
[InlineData(FileAttributes.ReadOnly | FileAttributes.Hidden)]
|
|
[PlatformSpecific(PlatformID.Windows)]
|
|
public void WindowsAttributeSetting(FileAttributes attr)
|
|
{
|
|
var test = new FileInfo(GetTestFilePath());
|
|
test.Create().Dispose();
|
|
Set(test.FullName, attr);
|
|
test.Refresh();
|
|
Assert.Equal(attr, Get(test.FullName));
|
|
Set(test.FullName, 0);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(FileAttributes.Temporary)]
|
|
[InlineData(FileAttributes.Encrypted)]
|
|
[InlineData(FileAttributes.SparseFile)]
|
|
[InlineData(FileAttributes.ReparsePoint)]
|
|
[InlineData(FileAttributes.Compressed)]
|
|
[PlatformSpecific(PlatformID.AnyUnix)]
|
|
public void UnixInvalidAttributes(FileAttributes attr)
|
|
{
|
|
var path = GetTestFilePath();
|
|
File.Create(path).Dispose();
|
|
Set(path, attr);
|
|
Assert.Equal(FileAttributes.Normal, Get(path));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(FileAttributes.Normal)]
|
|
[InlineData(FileAttributes.Encrypted)]
|
|
[InlineData(FileAttributes.SparseFile)]
|
|
[InlineData(FileAttributes.ReparsePoint)]
|
|
[InlineData(FileAttributes.Compressed)]
|
|
[PlatformSpecific(PlatformID.Windows)]
|
|
public void WindowsInvalidAttributes(FileAttributes attr)
|
|
{
|
|
var path = GetTestFilePath();
|
|
File.Create(path).Dispose();
|
|
Set(path, attr);
|
|
Assert.Equal(FileAttributes.Normal, Get(path));
|
|
}
|
|
}
|
|
} |