@@ -89,20 +89,20 @@ public override void Copy(string sourceFileName, string destFileName, bool overw
8989 {
9090 if ( sourceFileName == null )
9191 {
92- throw new ArgumentNullException ( nameof ( sourceFileName ) , StringResources . Manager . GetString ( "FILENAME_CANNOT_BE_NULL" ) ) ;
92+ throw CommonExceptions . FilenameCannotBeNull ( nameof ( sourceFileName ) ) ;
9393 }
9494
9595 if ( destFileName == null )
9696 {
97- throw new ArgumentNullException ( nameof ( destFileName ) , StringResources . Manager . GetString ( "FILENAME_CANNOT_BE_NULL" ) ) ;
97+ throw CommonExceptions . FilenameCannotBeNull ( nameof ( destFileName ) ) ;
9898 }
9999
100- mockFileDataAccessor . PathVerifier . IsLegalAbsoluteOrRelative ( sourceFileName , " sourceFileName" ) ;
101- mockFileDataAccessor . PathVerifier . IsLegalAbsoluteOrRelative ( destFileName , " destFileName" ) ;
100+ mockFileDataAccessor . PathVerifier . IsLegalAbsoluteOrRelative ( sourceFileName , nameof ( sourceFileName ) ) ;
101+ mockFileDataAccessor . PathVerifier . IsLegalAbsoluteOrRelative ( destFileName , nameof ( destFileName ) ) ;
102102
103103 if ( ! Exists ( sourceFileName ) )
104104 {
105- throw new FileNotFoundException ( string . Format ( CultureInfo . InvariantCulture , StringResources . Manager . GetString ( "COULD_NOT_FIND_FILE_EXCEPTION" ) , sourceFileName ) ) ;
105+ throw CommonExceptions . FileNotFound ( sourceFileName ) ;
106106 }
107107
108108 VerifyDirectoryExists ( destFileName ) ;
@@ -205,7 +205,7 @@ public override FileSecurity GetAccessControl(string path)
205205
206206 if ( ! mockFileDataAccessor . FileExists ( path ) )
207207 {
208- throw new FileNotFoundException ( string . Format ( CultureInfo . InvariantCulture , StringResources . Manager . GetString ( "COULD_NOT_FIND_FILE_EXCEPTION" ) , path ) ) ;
208+ throw CommonExceptions . FileNotFound ( path ) ;
209209 }
210210
211211 var fileData = mockFileDataAccessor . GetFile ( path ) ;
@@ -233,7 +233,7 @@ public override FileAttributes GetAttributes(string path)
233233 {
234234 if ( path != null && path . Length == 0 )
235235 {
236- throw new ArgumentException ( StringResources . Manager . GetString ( "THE_PATH_IS_NOT_OF_A_LEGAL_FORM" ) , " path" ) ;
236+ throw CommonExceptions . PathIsNotOfALegalForm ( nameof ( path ) ) ;
237237 }
238238
239239 mockFileDataAccessor . PathVerifier . IsLegalAbsoluteOrRelative ( path , "path" ) ;
@@ -255,7 +255,7 @@ public override FileAttributes GetAttributes(string path)
255255 {
256256 VerifyDirectoryExists ( path ) ;
257257
258- throw new FileNotFoundException ( string . Format ( CultureInfo . InvariantCulture , "Could not find file '{0}'." , path ) ) ;
258+ throw CommonExceptions . FileNotFound ( path ) ;
259259 }
260260 }
261261
@@ -324,16 +324,16 @@ public override void Move(string sourceFileName, string destFileName)
324324 {
325325 if ( sourceFileName == null )
326326 {
327- throw new ArgumentNullException ( nameof ( sourceFileName ) , StringResources . Manager . GetString ( "FILENAME_CANNOT_BE_NULL" ) ) ;
327+ throw CommonExceptions . FilenameCannotBeNull ( nameof ( sourceFileName ) ) ;
328328 }
329329
330330 if ( destFileName == null )
331331 {
332- throw new ArgumentNullException ( nameof ( destFileName ) , StringResources . Manager . GetString ( "FILENAME_CANNOT_BE_NULL" ) ) ;
332+ throw CommonExceptions . FilenameCannotBeNull ( nameof ( destFileName ) ) ;
333333 }
334334
335- mockFileDataAccessor . PathVerifier . IsLegalAbsoluteOrRelative ( sourceFileName , " sourceFileName" ) ;
336- mockFileDataAccessor . PathVerifier . IsLegalAbsoluteOrRelative ( destFileName , " destFileName" ) ;
335+ mockFileDataAccessor . PathVerifier . IsLegalAbsoluteOrRelative ( sourceFileName , nameof ( sourceFileName ) ) ;
336+ mockFileDataAccessor . PathVerifier . IsLegalAbsoluteOrRelative ( destFileName , nameof ( destFileName ) ) ;
337337
338338 if ( mockFileDataAccessor . GetFile ( destFileName ) != null )
339339 {
@@ -351,7 +351,9 @@ public override void Move(string sourceFileName, string destFileName)
351351 var sourceFile = mockFileDataAccessor . GetFile ( sourceFileName ) ;
352352
353353 if ( sourceFile == null )
354- throw new FileNotFoundException ( string . Format ( CultureInfo . InvariantCulture , "The file \" {0}\" could not be found." , sourceFileName ) , sourceFileName ) ;
354+ {
355+ throw CommonExceptions . FileNotFound ( sourceFileName ) ;
356+ }
355357
356358 VerifyDirectoryExists ( destFileName ) ;
357359
@@ -391,7 +393,7 @@ private Stream OpenInternal(
391393 throw new IOException ( string . Format ( CultureInfo . InvariantCulture , "The file '{0}' already exists." , path ) ) ;
392394
393395 if ( ( mode == FileMode . Open || mode == FileMode . Truncate ) && ! exists )
394- throw new FileNotFoundException ( path ) ;
396+ throw CommonExceptions . FileNotFound ( path ) ;
395397
396398 if ( ! exists || mode == FileMode . CreateNew )
397399 return Create ( path ) ;
@@ -442,7 +444,7 @@ public override byte[] ReadAllBytes(string path)
442444
443445 if ( ! mockFileDataAccessor . FileExists ( path ) )
444446 {
445- throw new FileNotFoundException ( string . Format ( CultureInfo . InvariantCulture , StringResources . Manager . GetString ( "COULD_NOT_FIND_FILE_EXCEPTION" ) , path ) ) ;
447+ throw CommonExceptions . FileNotFound ( path ) ;
446448 }
447449
448450 return mockFileDataAccessor . GetFile ( path ) . Contents ;
@@ -454,7 +456,7 @@ public override string[] ReadAllLines(string path)
454456
455457 if ( ! mockFileDataAccessor . FileExists ( path ) )
456458 {
457- throw new FileNotFoundException ( string . Format ( CultureInfo . InvariantCulture , StringResources . Manager . GetString ( "COULD_NOT_FIND_FILE_EXCEPTION" ) , path ) ) ;
459+ throw CommonExceptions . FileNotFound ( path ) ;
458460 }
459461
460462 return mockFileDataAccessor
@@ -474,7 +476,7 @@ public override string[] ReadAllLines(string path, Encoding encoding)
474476
475477 if ( ! mockFileDataAccessor . FileExists ( path ) )
476478 {
477- throw new FileNotFoundException ( string . Format ( CultureInfo . InvariantCulture , "Can't find {0}" , path ) ) ;
479+ throw CommonExceptions . FileNotFound ( path ) ;
478480 }
479481
480482 return encoding
@@ -488,7 +490,7 @@ public override string ReadAllText(string path)
488490
489491 if ( ! mockFileDataAccessor . FileExists ( path ) )
490492 {
491- throw new FileNotFoundException ( string . Format ( CultureInfo . InvariantCulture , "Can't find {0}" , path ) ) ;
493+ throw CommonExceptions . FileNotFound ( path ) ;
492494 }
493495
494496 return ReadAllText ( path , MockFileData . DefaultEncoding ) ;
@@ -541,12 +543,12 @@ public override void Replace(string sourceFileName, string destinationFileName,
541543
542544 if ( ! mockFileDataAccessor . FileExists ( sourceFileName ) )
543545 {
544- throw new FileNotFoundException ( string . Format ( CultureInfo . InvariantCulture , StringResources . Manager . GetString ( "COULD_NOT_FIND_FILE_EXCEPTION" ) , sourceFileName ) ) ;
546+ throw CommonExceptions . FileNotFound ( sourceFileName ) ;
545547 }
546548
547549 if ( ! mockFileDataAccessor . FileExists ( destinationFileName ) )
548550 {
549- throw new FileNotFoundException ( string . Format ( CultureInfo . InvariantCulture , StringResources . Manager . GetString ( "COULD_NOT_FIND_FILE_EXCEPTION" ) , destinationFileName ) ) ;
551+ throw CommonExceptions . FileNotFound ( destinationFileName ) ;
550552 }
551553
552554 if ( destinationBackupFileName != null )
@@ -565,7 +567,7 @@ public override void SetAccessControl(string path, FileSecurity fileSecurity)
565567
566568 if ( ! mockFileDataAccessor . FileExists ( path ) )
567569 {
568- throw new FileNotFoundException ( string . Format ( CultureInfo . InvariantCulture , "Can't find {0}" , path ) , path ) ;
570+ throw CommonExceptions . FileNotFound ( path ) ;
569571 }
570572
571573 var fileData = mockFileDataAccessor . GetFile ( path ) ;
@@ -586,7 +588,7 @@ public override void SetAttributes(string path, FileAttributes fileAttributes)
586588 }
587589 else
588590 {
589- throw new FileNotFoundException ( string . Format ( CultureInfo . InvariantCulture , StringResources . Manager . GetString ( "COULD_NOT_FIND_FILE_EXCEPTION" ) , path ) , path ) ;
591+ throw CommonExceptions . FileNotFound ( path ) ;
590592 }
591593 }
592594 else
@@ -676,7 +678,7 @@ public override void WriteAllBytes(string path, byte[] bytes)
676678 mockFileDataAccessor . AddFile ( path , new MockFileData ( bytes ) ) ;
677679 }
678680
679- /// <summary>
681+ /// <summary>
680682 /// Creates a new file, writes a collection of strings to the file, and then closes the file.
681683 /// </summary>
682684 /// <param name="path">The file to write to.</param>
@@ -937,7 +939,7 @@ public override void WriteAllText(string path, string contents, Encoding encodin
937939
938940 if ( mockFileDataAccessor . Directory . Exists ( path ) )
939941 {
940- throw new UnauthorizedAccessException ( string . Format ( CultureInfo . InvariantCulture , StringResources . Manager . GetString ( "ACCESS_TO_THE_PATH_IS_DENIED" ) , path ) ) ;
942+ throw CommonExceptions . AccessDenied ( path ) ;
941943 }
942944
943945 VerifyDirectoryExists ( path ) ;
@@ -976,11 +978,7 @@ private void VerifyDirectoryExists(string path)
976978
977979 if ( ! mockFileDataAccessor . Directory . Exists ( dir ) )
978980 {
979- throw new DirectoryNotFoundException (
980- string . Format (
981- CultureInfo . InvariantCulture ,
982- StringResources . Manager . GetString ( "COULD_NOT_FIND_PART_OF_PATH_EXCEPTION" ) ,
983- path ) ) ;
981+ throw CommonExceptions . CouldNotFindPartOfPath ( path ) ;
984982 }
985983 }
986984 }
0 commit comments