Skip to content

Commit 6030664

Browse files
added ut
1 parent af1f30a commit 6030664

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/LCT.Common.UTests/FolderActionTest.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,44 @@ public void CopyToTargetDirectory_PassingDirsWithFiles_ReturnSuccess()
8686
//Assert
8787
Assert.IsTrue(acutal);
8888
}
89+
[Test]
90+
public void CopyToTargetDirectory_WhenIOExceptionOccurs_ReturnsFalse()
91+
{
92+
// Arrange
93+
string sourcePath = $"{Path.GetTempPath()}/sourcePath/";
94+
string targetPath = $"{Path.GetTempPath()}/targetPath/";
95+
var folderAction = new FolderAction();
96+
97+
// Simulate IOException by creating a file with the same name as the target directory
98+
File.WriteAllText(targetPath, "This will cause an IOException");
99+
100+
// Act
101+
var actual = folderAction.CopyToTargetDirectory(sourcePath, targetPath);
102+
103+
// Assert
104+
Assert.IsFalse(actual);
105+
106+
// Cleanup
107+
File.Delete(targetPath);
108+
}
109+
110+
[Test]
111+
public void CopyToTargetDirectory_WhenSecurityExceptionOccurs_ReturnsFalse()
112+
{
113+
// Arrange
114+
string sourcePath = $"{Path.GetTempPath()}/sourcePath/";
115+
string targetPath = $"{Path.GetTempPath()}/targetPath/";
116+
var folderAction = new FolderAction();
117+
118+
// Simulate SecurityException by using a restricted directory (e.g., root of C drive)
119+
string restrictedPath = "C:\\RestrictedPath";
120+
121+
// Act
122+
var actual = folderAction.CopyToTargetDirectory(sourcePath, restrictedPath);
123+
124+
// Assert
125+
Assert.IsFalse(actual);
126+
}
89127

90128
}
91129
}

0 commit comments

Comments
 (0)