From 1e59c912979ff8282fc77f99af2ef6733b9b4700 Mon Sep 17 00:00:00 2001 From: defnegoncu Date: Wed, 29 Jan 2025 13:16:32 +0100 Subject: [PATCH] ZipExtensionWrapperUt updated CreateFromDirectoryAsync_NoWritePermission_ThrowsUnauthorizedAccessException updated with NSubstitute. --- AuthoringTool/electron.manifest.json | 2 +- .../Extensions/ZipExtensionWrapperUt.cs | 22 ++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/AuthoringTool/electron.manifest.json b/AuthoringTool/electron.manifest.json index e676ef16..1881ec1e 100644 --- a/AuthoringTool/electron.manifest.json +++ b/AuthoringTool/electron.manifest.json @@ -21,7 +21,7 @@ "appId": "com.AuthoringTool.app", "productName": "AuthoringTool", "copyright": "Copyright © 2023 Team AdLer", - "buildVersion": "2.2.2", + "buildVersion": "1.0.0", "compression": "maximum", "directories": { "output": "../../../bin/Desktop_Publish" diff --git a/DataAccessTest/Extensions/ZipExtensionWrapperUt.cs b/DataAccessTest/Extensions/ZipExtensionWrapperUt.cs index e8965002..c03a4602 100644 --- a/DataAccessTest/Extensions/ZipExtensionWrapperUt.cs +++ b/DataAccessTest/Extensions/ZipExtensionWrapperUt.cs @@ -320,20 +320,22 @@ public void CreateFromDirectoryAsync_NoWritePermission_ThrowsUnauthorizedAccessE { string sourcePath = @"C:\source"; string destinationPath = @"C:\output.zip"; - _mockFileSystem.AddDirectory(sourcePath); - _mockFileSystem.AddFile(Path.Combine(sourcePath, "file1.txt"), new MockFileData("File1 content")); - _mockFileSystem.AddFile(destinationPath, new MockFileData("Existing content") - { - Attributes = FileAttributes.ReadOnly - }); - - var systemUnderTest = CreateZipExtensionWrapper(_mockFileSystem); + _mockFileSystem.AddFile(Path.Combine(sourcePath, "file1.txt"), new MockFileData("File content")); + + var fileSystemMock = Substitute.For(); + fileSystemMock.FileSystemWatcher.Returns(_mockFileSystem.FileSystemWatcher); + fileSystemMock.Directory.Returns(_mockFileSystem.Directory); + fileSystemMock.File.OpenWrite(Arg.Any()) + .Throws(new UnauthorizedAccessException("Simulated Unauthorized Access")); + + var systemUnderTest = CreateZipExtensionWrapper(fileSystemMock); + var exception = Assert.ThrowsAsync(async () => await systemUnderTest.CreateFromDirectoryAsync(sourcePath, destinationPath)); - + Assert.That(exception, Is.Not.Null); - Assert.That(exception.Message, Contains.Substring("Access to the path")); + Assert.That(exception.Message, Contains.Substring("Simulated Unauthorized Access")); }