File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments