Skip to content

Add new unit tests for FileSystemInfo and hidden/system files #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions System.IO.FileSystem.UnitTests/FileUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -835,5 +835,103 @@ public void WriteAllText_should_overwrite_existing_file()
TextContent);
});
}

[TestMethod]
public void TestAccessingFileProperties()
{
string path = @$"{Root}temp\testdir\";
string fileName = "file1.txt";

// make sure the directory doesn't exist
if (Directory.Exists(path))
{
Directory.Delete(path, true);
}

Directory.CreateDirectory(path);

OutputHelper.WriteLine($"Creating {fileName}...");
File.WriteAllBytes($@"{path}{fileName}", BinaryContent);

// getting directory info
OutputHelper.WriteLine($"Getting directory info for {path}...");

var dirInfo = new DirectoryInfo(path);

// getting file info
OutputHelper.WriteLine($"Getting file info for {fileName}...");

var fileList = dirInfo.GetFiles();
var file = fileList[0];

// access file properties
OutputHelper.WriteLine($"Accessing file properties for {fileName}...");

var fileNameProperty = file.FullName;
Assert.AreEqual($@"{path}{fileName}", fileNameProperty);

var fileSizePropert = file.Length;
Assert.AreEqual(BinaryContent.Length, fileSizePropert, "Reported file length is different than expected.");

Assert.AreEqual(FileAttributes.Normal, (file.Attributes & FileAttributes.Normal), "File attribute Normal is not set.");

Assert.AreEqual(fileName, file.Name);
}

[TestMethod]
public void TestListingSysAndHiddenFiles_00()
{
string path = @$"{Root}temp\testdir\";
string fileName = "this_is_a_system_file.sys";
string filePath = Path.Combine(path, fileName);

// make sure the directory doesn't exist
if (Directory.Exists(path))
{
Directory.Delete(path, true);
}

// make sure the file doesn't exist
if (File.Exists(filePath))
{
File.Delete(filePath);
}

Directory.CreateDirectory(path);

CreateFile(filePath, EmptyContent);

// list directory
var dirInfo = new DirectoryInfo(path);

var fileList = dirInfo.GetFiles();

Assert.AreEqual(0, fileList.Length, "System file is listed when it shouldn't.");
}

[TestMethod]
public void TestListingSysAndHiddenFiles_01()
{
// this is looking for config files stored in ESP32 devices internal storage

// check if this test run is using the internal storage
if (!Root.StartsWith(@"I:\"))
{
// this is not the internal storage, skip the test
OutputHelper.WriteLine("Skipping test because it's not running on the internal storage.");

return;
}

// list directory
var dirInfo = new DirectoryInfo(Root);

var fileList = dirInfo.GetFiles();

foreach (var file in fileList)
{
Assert.IsFalse(file.Name.Contains(".sys"), "System file is listed when it shouldn't.");
}
}
}
}