Refactor filesystem tests to use FluentAssertions for improved readability and consistency

This commit is contained in:
2026-04-20 00:28:20 +01:00
parent 0f9357118c
commit 5cdd000e30

View File

@@ -5,6 +5,8 @@ using Aaru.CommonTypes.AaruMetadata;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
using Aaru.Core;
using FluentAssertions;
using FluentAssertions.Execution;
using NUnit.Framework;
using File = System.IO.File;
using Partition = Aaru.CommonTypes.Partition;
@@ -30,14 +32,14 @@ public abstract class FilesystemTest(string fileSystemType)
{
Environment.CurrentDirectory = DataFolder;
Assert.Multiple(() =>
using(new AssertionScope())
{
foreach(FileSystemTest test in Tests)
{
string testFile = test.TestFile;
bool exists = File.Exists(testFile);
Assert.That(exists, string.Format(Localization._0_not_found, testFile));
exists.Should().BeTrue(Localization._0_not_found, testFile);
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
// It arrives here...
@@ -45,15 +47,15 @@ public abstract class FilesystemTest(string fileSystemType)
IFilter inputFilter = PluginRegister.Singleton.GetFilter(testFile);
Assert.That(inputFilter, Is.Not.Null, string.Format(Localization.Filter_0, testFile));
inputFilter.Should().NotBeNull(Localization.Filter_0, testFile);
var image = ImageFormat.Detect(inputFilter) as IMediaImage;
Assert.That(image, Is.Not.Null, string.Format(Localization.Image_format_0, testFile));
image.Should().NotBeNull(Localization.Image_format_0, testFile);
Assert.That(image.Open(inputFilter),
Is.EqualTo(ErrorNumber.NoError),
string.Format(Localization.Cannot_open_image_for_0, testFile));
image.Open(inputFilter)
.Should()
.Be(ErrorNumber.NoError, string.Format(Localization.Cannot_open_image_for_0, testFile));
List<string> idPlugins;
@@ -61,9 +63,7 @@ public abstract class FilesystemTest(string fileSystemType)
{
List<Partition> partitionsList = Core.Partitions.GetAll(image);
Assert.That(partitionsList,
Is.Not.Empty,
string.Format(Localization.No_partitions_found_for_0, testFile));
partitionsList.Should().NotBeEmpty(Localization.No_partitions_found_for_0, testFile);
var found = false;
@@ -80,7 +80,7 @@ public abstract class FilesystemTest(string fileSystemType)
break;
}
Assert.That(found, string.Format(Localization.Filesystem_not_identified_for_0, testFile));
found.Should().BeTrue(Localization.Filesystem_not_identified_for_0, testFile);
}
else
{
@@ -93,16 +93,13 @@ public abstract class FilesystemTest(string fileSystemType)
Core.Filesystems.Identify(image, out idPlugins, wholePart, true);
Assert.That(idPlugins,
Is.Not.Empty,
string.Format(Localization.No_filesystems_found_for_0, testFile));
idPlugins.Should().NotBeEmpty(Localization.No_filesystems_found_for_0, testFile);
Assert.That(idPlugins,
Does.Contain(Plugin.Id.ToString()),
string.Format(Localization.Not_identified_for_0, testFile));
idPlugins.Should()
.Contain(Plugin.Id.ToString(), string.Format(Localization.Not_identified_for_0, testFile));
}
}
});
}
}
[Test]
@@ -110,14 +107,14 @@ public abstract class FilesystemTest(string fileSystemType)
{
Environment.CurrentDirectory = DataFolder;
Assert.Multiple(() =>
using(new AssertionScope())
{
foreach(FileSystemTest test in Tests)
{
string testFile = test.TestFile;
bool exists = File.Exists(testFile);
Assert.That(exists, string.Format(Localization._0_not_found, testFile));
exists.Should().BeTrue(Localization._0_not_found, testFile);
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
// It arrives here...
@@ -125,21 +122,21 @@ public abstract class FilesystemTest(string fileSystemType)
IFilter inputFilter = PluginRegister.Singleton.GetFilter(testFile);
Assert.That(inputFilter, Is.Not.Null, string.Format(Localization.Filter_0, testFile));
inputFilter.Should().NotBeNull(Localization.Filter_0, testFile);
var image = ImageFormat.Detect(inputFilter) as IMediaImage;
Assert.That(image, Is.Not.Null, string.Format(Localization.Image_format_0, testFile));
image.Should().NotBeNull(Localization.Image_format_0, testFile);
Assert.That(image.Open(inputFilter),
Is.EqualTo(ErrorNumber.NoError),
string.Format(Localization.Cannot_open_image_for_0, testFile));
image.Open(inputFilter)
.Should()
.Be(ErrorNumber.NoError, string.Format(Localization.Cannot_open_image_for_0, testFile));
Assert.That(image.Info.MediaType, Is.EqualTo(test.MediaType), testFile);
Assert.That(image.Info.Sectors, Is.EqualTo(test.Sectors), testFile);
Assert.That(image.Info.SectorSize, Is.EqualTo(test.SectorSize), testFile);
image.Info.MediaType.Should().Be(test.MediaType, testFile);
image.Info.Sectors.Should().Be(test.Sectors, testFile);
image.Info.SectorSize.Should().Be(test.SectorSize, testFile);
}
});
}
}
[Test]
@@ -147,7 +144,7 @@ public abstract class FilesystemTest(string fileSystemType)
{
Environment.CurrentDirectory = DataFolder;
Assert.Multiple(() =>
using(new AssertionScope())
{
foreach(FileSystemTest test in Tests)
{
@@ -156,7 +153,7 @@ public abstract class FilesystemTest(string fileSystemType)
var partition = new Partition();
bool exists = File.Exists(testFile);
Assert.That(exists, string.Format(Localization._0_not_found, testFile));
exists.Should().BeTrue(Localization._0_not_found, testFile);
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
// It arrives here...
@@ -164,15 +161,15 @@ public abstract class FilesystemTest(string fileSystemType)
IFilter inputFilter = PluginRegister.Singleton.GetFilter(testFile);
Assert.That(inputFilter, Is.Not.Null, string.Format(Localization.Filter_0, testFile));
inputFilter.Should().NotBeNull(Localization.Filter_0, testFile);
var image = ImageFormat.Detect(inputFilter) as IMediaImage;
Assert.That(image, Is.Not.Null, string.Format(Localization.Image_format_0, testFile));
image.Should().NotBeNull(Localization.Image_format_0, testFile);
Assert.That(image.Open(inputFilter),
Is.EqualTo(ErrorNumber.NoError),
string.Format(Localization.Cannot_open_image_for_0, testFile));
image.Open(inputFilter)
.Should()
.Be(ErrorNumber.NoError, string.Format(Localization.Cannot_open_image_for_0, testFile));
List<string> idPlugins;
@@ -180,9 +177,7 @@ public abstract class FilesystemTest(string fileSystemType)
{
List<Partition> partitionsList = Core.Partitions.GetAll(image);
Assert.That(partitionsList,
Is.Not.Empty,
string.Format(Localization.No_partitions_found_for_0, testFile));
partitionsList.Should().NotBeEmpty(Localization.No_partitions_found_for_0, testFile);
// In reverse to skip boot partitions we're not interested in
for(int index = partitionsList.Count - 1; index >= 0; index--)
@@ -210,14 +205,12 @@ public abstract class FilesystemTest(string fileSystemType)
Core.Filesystems.Identify(image, out idPlugins, partition, true);
Assert.That(idPlugins,
Is.Not.Empty,
string.Format(Localization.No_filesystems_found_for_0, testFile));
idPlugins.Should().NotBeEmpty(Localization.No_filesystems_found_for_0, testFile);
found = idPlugins.Contains(Plugin.Id.ToString());
}
Assert.That(found, string.Format(Localization.Filesystem_not_identified_for_0, testFile));
found.Should().BeTrue(Localization.Filesystem_not_identified_for_0, testFile);
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
// It is not the case, it changes
@@ -225,50 +218,37 @@ public abstract class FilesystemTest(string fileSystemType)
var fs = Activator.CreateInstance(Plugin.GetType()) as IFilesystem;
Assert.That(fs,
Is.Not.Null,
string.Format(Localization.Could_not_instantiate_filesystem_for_0, testFile));
fs.Should().NotBeNull(Localization.Could_not_instantiate_filesystem_for_0, testFile);
fs.GetInformation(image, partition, null, out _, out FileSystem fsMetadata);
if(test.ApplicationId != null)
{
Assert.That(fsMetadata.ApplicationIdentifier,
Is.EqualTo(test.ApplicationId),
string.Format(Localization.Application_ID_0, testFile));
fsMetadata.ApplicationIdentifier.Should()
.Be(test.ApplicationId, string.Format(Localization.Application_ID_0, testFile));
}
Assert.That(fsMetadata.Bootable,
Is.EqualTo(test.Bootable),
string.Format(Localization.Bootable_0, testFile));
fsMetadata.Bootable.Should().Be(test.Bootable, string.Format(Localization.Bootable_0, testFile));
Assert.That(fsMetadata.Clusters,
Is.EqualTo(test.Clusters),
string.Format(Localization.Clusters_0, testFile));
fsMetadata.Clusters.Should().Be((ulong)test.Clusters, string.Format(Localization.Clusters_0, testFile));
Assert.That(fsMetadata.ClusterSize,
Is.EqualTo(test.ClusterSize),
string.Format(Localization.Cluster_size_0, testFile));
fsMetadata.ClusterSize.Should()
.Be(test.ClusterSize, string.Format(Localization.Cluster_size_0, testFile));
if(test.SystemId != null)
{
Assert.That(fsMetadata.SystemIdentifier,
Is.EqualTo(test.SystemId),
string.Format(Localization.System_ID_0, testFile));
fsMetadata.SystemIdentifier.Should()
.Be(test.SystemId, string.Format(Localization.System_ID_0, testFile));
}
Assert.That(fsMetadata.Type,
Is.EqualTo(fileSystemType ?? test.Type),
string.Format(Localization.Filesystem_type_0, testFile));
fsMetadata.Type.Should()
.Be(fileSystemType ?? test.Type, string.Format(Localization.Filesystem_type_0, testFile));
Assert.That(fsMetadata.VolumeName,
Is.EqualTo(test.VolumeName),
string.Format(Localization.Volume_name_0, testFile));
fsMetadata.VolumeName.Should().Be(test.VolumeName, string.Format(Localization.Volume_name_0, testFile));
Assert.That(fsMetadata.VolumeSerial,
Is.EqualTo(test.VolumeSerial),
string.Format(Localization.Volume_serial_0, testFile));
fsMetadata.VolumeSerial.Should()
.Be(test.VolumeSerial, string.Format(Localization.Volume_serial_0, testFile));
}
});
}
}
}