Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Source/Testably.Abstractions.Testing/Helpers/PathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal static bool HasIllegalCharacters(this string path, IFileSystem fileSyst
() => false);
}

internal static bool IsUncPath(this string? path)
internal static bool IsUncPath([NotNullWhen(true)]this string? path)
{
if (path == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,14 @@ public IStorageContainer GetOrCreateContainer(
out IStorageContainer? initialContainer) &&
initialContainer.LinkTarget != null)
{
IStorageLocation nextLocation =
IStorageLocation? nextLocation =
_fileSystem.Storage.GetLocation(initialContainer.LinkTarget);
if (_containers.TryGetValue(nextLocation,
out IStorageContainer? container))
{
if (returnFinalTarget)
{
nextLocation = ResolveFinalLinkTarget(container, location) ??
nextLocation;
nextLocation = ResolveFinalLinkTarget(container, location);
}

return nextLocation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,57 +45,6 @@ public void Copy_Overwrite_ShouldAdjustAvailableFreeSpace(
.Be(availableFreeSpaceBefore + file2Size - file1Size);
}

[Theory]
[AutoData]
public void Replace_WithoutBackup_ShouldNotChangeAvailableFreeSpace(
int file1Size, int file2Size)
{
MockFileSystem fileSystem = new();
IDriveInfo mainDrive = fileSystem.DriveInfo.New("".PrefixRoot());
IRandom random = RandomFactory.Shared;
byte[] file1Content = new byte[file1Size];
byte[] file2Content = new byte[file2Size];
random.NextBytes(file1Content);
random.NextBytes(file2Content);

fileSystem.File.WriteAllBytes("foo", file1Content);
fileSystem.File.WriteAllBytes("bar", file2Content);
long availableFreeSpaceBefore = mainDrive.AvailableFreeSpace;

fileSystem.File.Replace("foo", "bar", "backup");

long availableFreeSpaceAfter = mainDrive.AvailableFreeSpace;
availableFreeSpaceAfter.Should()
.Be(availableFreeSpaceBefore);
}

[Theory]
[AutoData]
public void Replace_WithBackup_ShouldChangeAvailableFreeSpace(
int file1Size, int file2Size, int file3Size)
{
MockFileSystem fileSystem = new();
IDriveInfo mainDrive = fileSystem.DriveInfo.New("".PrefixRoot());
IRandom random = RandomFactory.Shared;
byte[] file1Content = new byte[file1Size];
byte[] file2Content = new byte[file2Size];
byte[] file3Content = new byte[file3Size];
random.NextBytes(file1Content);
random.NextBytes(file2Content);
random.NextBytes(file3Content);

fileSystem.File.WriteAllBytes("foo", file1Content);
fileSystem.File.WriteAllBytes("bar", file2Content);
fileSystem.File.WriteAllBytes("backup", file3Content);
long availableFreeSpaceBefore = mainDrive.AvailableFreeSpace;

fileSystem.File.Replace("foo", "bar", "backup", true);

long availableFreeSpaceAfter = mainDrive.AvailableFreeSpace;
availableFreeSpaceAfter.Should()
.Be(availableFreeSpaceBefore + file2Size);
}

[Fact]
public void CurrentDirectory_ShouldBeInitializedToDefaultRoot()
{
Expand Down Expand Up @@ -126,6 +75,18 @@ public void Delete_RaceCondition_ShouldReturnFalse()
exception.Should().BeOfType<DirectoryNotFoundException>();
}

[Theory]
[InlineData((string?)null)]
[InlineData("")]
[InlineData(" ")]
[InlineData("\t")]
public void GetDrive_NullOrWhitespace_ShouldReturnNull(string? driveName)
{
IStorageDrive? result = Storage.GetDrive(driveName);

result.Should().BeNull();
}

[Theory]
[AutoData]
public void Move_RequestDeniedForChild_ShouldRollback(
Expand All @@ -134,9 +95,9 @@ public void Move_RequestDeniedForChild_ShouldRollback(
IStorageLocation location = Storage.GetLocation(locationPath);
IStorageLocation destination = Storage.GetLocation(destinationPath);
IStorageLocation child1Location =
Storage.GetLocation(Path.Combine(locationPath, "foo"));
Storage.GetLocation(Path.Combine(locationPath, "foo1"));
IStorageLocation child2Location =
Storage.GetLocation(Path.Combine(locationPath, "bar"));
Storage.GetLocation(Path.Combine(locationPath, "foo2"));
LockableContainer lockedContainer = new(FileSystem);
Storage.TryAddContainer(
location,
Expand Down Expand Up @@ -164,6 +125,57 @@ public void Move_RequestDeniedForChild_ShouldRollback(
exception.Should().BeOfType<IOException>();
}

[Theory]
[AutoData]
public void Replace_WithBackup_ShouldChangeAvailableFreeSpace(
int file1Size, int file2Size, int file3Size)
{
MockFileSystem fileSystem = new();
IDriveInfo mainDrive = fileSystem.DriveInfo.New("".PrefixRoot());
IRandom random = RandomFactory.Shared;
byte[] file1Content = new byte[file1Size];
byte[] file2Content = new byte[file2Size];
byte[] file3Content = new byte[file3Size];
random.NextBytes(file1Content);
random.NextBytes(file2Content);
random.NextBytes(file3Content);

fileSystem.File.WriteAllBytes("foo", file1Content);
fileSystem.File.WriteAllBytes("bar", file2Content);
fileSystem.File.WriteAllBytes("backup", file3Content);
long availableFreeSpaceBefore = mainDrive.AvailableFreeSpace;

fileSystem.File.Replace("foo", "bar", "backup", true);

long availableFreeSpaceAfter = mainDrive.AvailableFreeSpace;
availableFreeSpaceAfter.Should()
.Be(availableFreeSpaceBefore + file2Size);
}

[Theory]
[AutoData]
public void Replace_WithoutBackup_ShouldNotChangeAvailableFreeSpace(
int file1Size, int file2Size)
{
MockFileSystem fileSystem = new();
IDriveInfo mainDrive = fileSystem.DriveInfo.New("".PrefixRoot());
IRandom random = RandomFactory.Shared;
byte[] file1Content = new byte[file1Size];
byte[] file2Content = new byte[file2Size];
random.NextBytes(file1Content);
random.NextBytes(file2Content);

fileSystem.File.WriteAllBytes("foo", file1Content);
fileSystem.File.WriteAllBytes("bar", file2Content);
long availableFreeSpaceBefore = mainDrive.AvailableFreeSpace;

fileSystem.File.Replace("foo", "bar", "backup");

long availableFreeSpaceAfter = mainDrive.AvailableFreeSpace;
availableFreeSpaceAfter.Should()
.Be(availableFreeSpaceBefore);
}

[Theory]
[AutoData]
public void TryAddContainer_ShouldNotifyWhenAdded(string path)
Expand Down