From 377be903d62b3b7ff87bc05fb163fa4173634067 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 12 Jul 2024 22:42:54 +0200 Subject: [PATCH 1/9] fixed mock file system exception when using root path as a parameter --- .../MockFileSystem.cs | 6 ++++++ .../MockFileSystemTests.cs | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs index cac9b0648..1909e97ec 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs @@ -243,6 +243,12 @@ public void AddFile(string path, MockFileData mockFile) } var directoryPath = Path.GetDirectoryName(fixedPath); + if (directoryPath == null) + { + AddDrive(fixedPath, new MockDriveData()); + SetEntry(fixedPath, mockFile); + return; + } if (!DirectoryExistsWithoutFixingPath(directoryPath)) { diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs index 28fed6d61..4c5073f44 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs @@ -435,6 +435,26 @@ public void MockFileSystem_Constructor_ThrowsForNonRootedCurrentDirectory() ); Assert.That(ae.ParamName, Is.EqualTo("currentDirectory")); } + + [Test] + public void MockFileSystem_Constructor_ShouldSupportDifferentRootDrives() + { + var fileSystem = new MockFileSystem(new Dictionary + { + [@"c:\"] = new MockDirectoryData(), + [@"z:\"] = new MockDirectoryData(), + [@"d:\"] = new MockDirectoryData(), + }); + + var cExists = fileSystem.Directory.Exists(@"c:\"); + var zExists = fileSystem.Directory.Exists(@"z:\"); + var dExists = fileSystem.Directory.Exists(@"d:\"); + + Assert.That(fileSystem, Is.Not.Null); + Assert.That(cExists, Is.True); + Assert.That(zExists, Is.True); + Assert.That(dExists, Is.True); + } [Test] public void MockFileSystem_DefaultState_DefaultTempDirectoryExists() From cecb624f7908c7231b06fe5a380107d3cb05091d Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 13 Jul 2024 13:38:35 +0200 Subject: [PATCH 2/9] test: added a test to cover new drive creation with nested directories --- .../MockFileSystemTests.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs index 4c5073f44..d8d8661f3 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs @@ -456,6 +456,23 @@ public void MockFileSystem_Constructor_ShouldSupportDifferentRootDrives() Assert.That(dExists, Is.True); } + [Test] + public void MockFileSystem_Constructor_ShouldAddDifferentDrivesIfNotExist() + { + var fileSystem = new MockFileSystem(new Dictionary + { + [@"d:\foo\bar\"] = new MockDirectoryData() + }); + + var driveInfo = fileSystem.DriveInfo.GetDrives(); + var fooExists = fileSystem.Directory.Exists(@"d:\foo\"); + var barExists = fileSystem.Directory.Exists(@"d:\foo\bar\"); + + Assert.That(driveInfo.Any(d => string.Equals(d.Name, @"D:\", StringComparison.InvariantCultureIgnoreCase)), Is.True); + Assert.That(fooExists, Is.True); + Assert.That(barExists, Is.True); + } + [Test] public void MockFileSystem_DefaultState_DefaultTempDirectoryExists() { From 7f350da6018a6775ffab75ab612c7f15eca79f8d Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 13 Jul 2024 13:40:38 +0200 Subject: [PATCH 3/9] fix: fixed code structure PR comment --- .../MockFileSystem.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs index 1909e97ec..1828a0c23 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs @@ -247,10 +247,8 @@ public void AddFile(string path, MockFileData mockFile) { AddDrive(fixedPath, new MockDriveData()); SetEntry(fixedPath, mockFile); - return; } - - if (!DirectoryExistsWithoutFixingPath(directoryPath)) + else if (!DirectoryExistsWithoutFixingPath(directoryPath)) { AddDirectory(directoryPath); } From f0089ae3bd240ff43b88500ddae0fb0cbb96cb42 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 13 Jul 2024 13:50:33 +0200 Subject: [PATCH 4/9] test: added one more test to make sure there is no duplicate drives created --- .../MockFileSystemTests.cs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs index d8d8661f3..f0b7a8cc7 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs @@ -461,18 +461,32 @@ public void MockFileSystem_Constructor_ShouldAddDifferentDrivesIfNotExist() { var fileSystem = new MockFileSystem(new Dictionary { - [@"d:\foo\bar\"] = new MockDirectoryData() + [@"d:\foo\bar\"] = new MockDirectoryData(), }); - var driveInfo = fileSystem.DriveInfo.GetDrives(); + var drivesInfo = fileSystem.DriveInfo.GetDrives(); var fooExists = fileSystem.Directory.Exists(@"d:\foo\"); var barExists = fileSystem.Directory.Exists(@"d:\foo\bar\"); - Assert.That(driveInfo.Any(d => string.Equals(d.Name, @"D:\", StringComparison.InvariantCultureIgnoreCase)), Is.True); + Assert.That(drivesInfo.Any(d => string.Equals(d.Name, @"D:\", StringComparison.InvariantCultureIgnoreCase)), Is.True); Assert.That(fooExists, Is.True); Assert.That(barExists, Is.True); } + [Test] + public void MockFileSystem_Constructor_ShouldNotDuplicateDrives() + { + var fileSystem = new MockFileSystem(new Dictionary + { + [@"d:\foo\bar\"] = new MockDirectoryData(), + [@"d:\"] = new MockDirectoryData() + }); + + var drivesInfo = fileSystem.DriveInfo.GetDrives(); + + Assert.That(drivesInfo.Where(d => string.Equals(d.Name, @"D:\", StringComparison.InvariantCultureIgnoreCase)), Has.Exactly(1).Items); + } + [Test] public void MockFileSystem_DefaultState_DefaultTempDirectoryExists() { From 7c68d60e1e5776fbd057caa647736833a8a9a08a Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 13 Jul 2024 13:53:20 +0200 Subject: [PATCH 5/9] docs: added information about conventional commits repo convention --- CONTRIBUTING.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2dc3bc1f9..01e0efb31 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -12,3 +12,7 @@ The base version represents the MAJOR and MINOR parts of [SemVer](https://semver - `main` contains the latest sources. Each merge there triggers a deploy to `nuget.org`. - All versions on `nuget.org` have a matching GitHub release/tag. + +## Commits + +- Please use [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) guideline when writing a commit message \ No newline at end of file From 6e001c5e451c5779236057bb7560785ddb912b9d Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 13 Jul 2024 16:57:40 +0200 Subject: [PATCH 6/9] docs: revert back CONTRIBUTING.md changes --- CONTRIBUTING.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 01e0efb31..ddcf153d3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,8 +11,4 @@ The base version represents the MAJOR and MINOR parts of [SemVer](https://semver ## Branches / tags - `main` contains the latest sources. Each merge there triggers a deploy to `nuget.org`. -- All versions on `nuget.org` have a matching GitHub release/tag. - -## Commits - -- Please use [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) guideline when writing a commit message \ No newline at end of file +- All versions on `nuget.org` have a matching GitHub release/tag. \ No newline at end of file From 1e135682738a334c5a8402e47ef87ebe4c537279 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 13 Jul 2024 16:58:40 +0200 Subject: [PATCH 7/9] fix: fixed duplicate call to SetEntry method --- .../MockFileSystem.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs index 1828a0c23..278042cb3 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs @@ -246,7 +246,6 @@ public void AddFile(string path, MockFileData mockFile) if (directoryPath == null) { AddDrive(fixedPath, new MockDriveData()); - SetEntry(fixedPath, mockFile); } else if (!DirectoryExistsWithoutFixingPath(directoryPath)) { From dcf71b72a3518462a4c4ec6d93625fcb3d9298b6 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 13 Jul 2024 17:04:29 +0200 Subject: [PATCH 8/9] docs: revert back CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ddcf153d3..2dc3bc1f9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,4 +11,4 @@ The base version represents the MAJOR and MINOR parts of [SemVer](https://semver ## Branches / tags - `main` contains the latest sources. Each merge there triggers a deploy to `nuget.org`. -- All versions on `nuget.org` have a matching GitHub release/tag. \ No newline at end of file +- All versions on `nuget.org` have a matching GitHub release/tag. From d6584bbb386392747c5f21322eda143c62f8f5c9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 13 Jul 2024 19:03:06 +0200 Subject: [PATCH 9/9] test: mark Drives tests as windows only --- .../MockFileSystemTests.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs index f0b7a8cc7..4b681421c 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs @@ -437,6 +437,7 @@ public void MockFileSystem_Constructor_ThrowsForNonRootedCurrentDirectory() } [Test] + [WindowsOnly(WindowsSpecifics.Drives)] public void MockFileSystem_Constructor_ShouldSupportDifferentRootDrives() { var fileSystem = new MockFileSystem(new Dictionary @@ -457,6 +458,7 @@ public void MockFileSystem_Constructor_ShouldSupportDifferentRootDrives() } [Test] + [WindowsOnly(WindowsSpecifics.Drives)] public void MockFileSystem_Constructor_ShouldAddDifferentDrivesIfNotExist() { var fileSystem = new MockFileSystem(new Dictionary @@ -474,6 +476,7 @@ public void MockFileSystem_Constructor_ShouldAddDifferentDrivesIfNotExist() } [Test] + [WindowsOnly(WindowsSpecifics.Drives)] public void MockFileSystem_Constructor_ShouldNotDuplicateDrives() { var fileSystem = new MockFileSystem(new Dictionary