33 using Collections . Generic ;
44
55 using NUnit . Framework ;
6-
6+ using NUnit . Framework . Constraints ;
77 using XFS = MockUnixSupport ;
88 class MockFileLockTests
99 {
@@ -16,7 +16,7 @@ public void MockFile_Lock_FileShareNoneThrows()
1616 { filepath , new MockFileData ( "I'm here" ) { AllowedFileShare = FileShare . None } }
1717 } ) ;
1818
19- Assert . Throws ( typeof ( IOException ) , ( ) => filesystem . File . Open ( filepath , FileMode . Open , FileAccess . Read , FileShare . Read ) ) ;
19+ Assert . Throws ( IOException ( ) , ( ) => filesystem . File . Open ( filepath , FileMode . Open , FileAccess . Read , FileShare . Read ) ) ;
2020 }
2121 [ Test ]
2222 public void MockFile_Lock_FileShareReadDoesNotThrowOnRead ( )
@@ -38,7 +38,7 @@ public void MockFile_Lock_FileShareReadThrowsOnWrite()
3838 { filepath , new MockFileData ( "I'm here" ) { AllowedFileShare = FileShare . Read } }
3939 } ) ;
4040
41- Assert . Throws ( typeof ( IOException ) , ( ) => filesystem . File . Open ( filepath , FileMode . Open , FileAccess . Write , FileShare . Read ) ) ;
41+ Assert . Throws ( IOException ( ) , ( ) => filesystem . File . Open ( filepath , FileMode . Open , FileAccess . Write , FileShare . Read ) ) ;
4242 }
4343 [ Test ]
4444 public void MockFile_Lock_FileShareWriteThrowsOnRead ( )
@@ -49,7 +49,7 @@ public void MockFile_Lock_FileShareWriteThrowsOnRead()
4949 { filepath , new MockFileData ( "I'm here" ) { AllowedFileShare = FileShare . Write } }
5050 } ) ;
5151
52- Assert . Throws ( typeof ( IOException ) , ( ) => filesystem . File . Open ( filepath , FileMode . Open , FileAccess . Read , FileShare . Read ) ) ;
52+ Assert . Throws ( IOException ( ) , ( ) => filesystem . File . Open ( filepath , FileMode . Open , FileAccess . Read , FileShare . Read ) ) ;
5353 }
5454 [ Test ]
5555 public void MockFile_Lock_FileShareWriteDoesNotThrowOnWrite ( )
@@ -73,7 +73,7 @@ public void MockFile_Lock_FileShareNoneThrowsOnOpenRead()
7373 { filepath , new MockFileData ( "I'm here" ) { AllowedFileShare = FileShare . None } }
7474 } ) ;
7575
76- var exception = Assert . Throws ( typeof ( IOException ) , ( ) => filesystem . File . OpenRead ( filepath ) ) ;
76+ var exception = Assert . Throws ( IOException ( ) , ( ) => filesystem . File . OpenRead ( filepath ) ) ;
7777 Assert . That ( exception . Message , Is . EqualTo ( $ "The process cannot access the file '{ filepath } ' because it is being used by another process.") ) ;
7878 }
7979 [ Test ]
@@ -85,7 +85,7 @@ public void MockFile_Lock_FileShareNoneThrowsOnWriteAllLines()
8585 { filepath , new MockFileData ( "I'm here" ) { AllowedFileShare = FileShare . None } }
8686 } ) ;
8787
88- var exception = Assert . Throws ( typeof ( IOException ) , ( ) => filesystem . File . WriteAllLines ( filepath , new string [ ] { "hello" , "world" } ) ) ;
88+ var exception = Assert . Throws ( IOException ( ) , ( ) => filesystem . File . WriteAllLines ( filepath , new string [ ] { "hello" , "world" } ) ) ;
8989 Assert . That ( exception . Message , Is . EqualTo ( $ "The process cannot access the file '{ filepath } ' because it is being used by another process.") ) ;
9090 }
9191 [ Test ]
@@ -97,7 +97,7 @@ public void MockFile_Lock_FileShareNoneThrowsOnReadAllLines()
9797 { filepath , new MockFileData ( "I'm here" ) { AllowedFileShare = FileShare . None } }
9898 } ) ;
9999
100- var exception = Assert . Throws ( typeof ( IOException ) , ( ) => filesystem . File . ReadAllLines ( filepath ) ) ;
100+ var exception = Assert . Throws ( IOException ( ) , ( ) => filesystem . File . ReadAllLines ( filepath ) ) ;
101101 Assert . That ( exception . Message , Is . EqualTo ( $ "The process cannot access the file '{ filepath } ' because it is being used by another process.") ) ;
102102 }
103103 [ Test ]
@@ -109,7 +109,7 @@ public void MockFile_Lock_FileShareNoneThrowsOnReadAllText()
109109 { filepath , new MockFileData ( "I'm here" ) { AllowedFileShare = FileShare . None } }
110110 } ) ;
111111
112- var exception = Assert . Throws ( typeof ( IOException ) , ( ) => filesystem . File . ReadAllText ( filepath ) ) ;
112+ var exception = Assert . Throws ( IOException ( ) , ( ) => filesystem . File . ReadAllText ( filepath ) ) ;
113113 Assert . That ( exception . Message , Is . EqualTo ( $ "The process cannot access the file '{ filepath } ' because it is being used by another process.") ) ;
114114 }
115115 [ Test ]
@@ -121,7 +121,7 @@ public void MockFile_Lock_FileShareNoneThrowsOnReadAllBytes()
121121 { filepath , new MockFileData ( "I'm here" ) { AllowedFileShare = FileShare . None } }
122122 } ) ;
123123
124- var exception = Assert . Throws ( typeof ( IOException ) , ( ) => filesystem . File . ReadAllBytes ( filepath ) ) ;
124+ var exception = Assert . Throws ( IOException ( ) , ( ) => filesystem . File . ReadAllBytes ( filepath ) ) ;
125125 Assert . That ( exception . Message , Is . EqualTo ( $ "The process cannot access the file '{ filepath } ' because it is being used by another process.") ) ;
126126 }
127127 [ Test ]
@@ -133,7 +133,7 @@ public void MockFile_Lock_FileShareNoneThrowsOnAppendLines()
133133 { filepath , new MockFileData ( "I'm here" ) { AllowedFileShare = FileShare . None } }
134134 } ) ;
135135
136- var exception = Assert . Throws ( typeof ( IOException ) , ( ) => filesystem . File . AppendAllLines ( filepath , new string [ ] { "hello" , "world" } ) ) ;
136+ var exception = Assert . Throws ( IOException ( ) , ( ) => filesystem . File . AppendAllLines ( filepath , new string [ ] { "hello" , "world" } ) ) ;
137137 Assert . That ( exception . Message , Is . EqualTo ( $ "The process cannot access the file '{ filepath } ' because it is being used by another process.") ) ;
138138 }
139139
@@ -147,7 +147,7 @@ public void MockFile_Lock_FileShareNoneThrowsFileMove()
147147 { filepath , new MockFileData ( "I'm here" ) { AllowedFileShare = FileShare . None } }
148148 } ) ;
149149
150- var exception = Assert . Throws ( typeof ( IOException ) , ( ) => filesystem . File . Move ( filepath , target ) ) ;
150+ var exception = Assert . Throws ( IOException ( ) , ( ) => filesystem . File . Move ( filepath , target ) ) ;
151151 Assert . That ( exception . Message , Is . EqualTo ( "The process cannot access the file because it is being used by another process." ) ) ;
152152 }
153153 [ Test ]
@@ -171,7 +171,7 @@ public void MockFile_Lock_FileShareNoneThrowsDelete()
171171 { filepath , new MockFileData ( "I'm here" ) { AllowedFileShare = FileShare . None } }
172172 } ) ;
173173
174- var exception = Assert . Throws ( typeof ( IOException ) , ( ) => filesystem . File . Delete ( filepath ) ) ;
174+ var exception = Assert . Throws ( IOException ( ) , ( ) => filesystem . File . Delete ( filepath ) ) ;
175175 Assert . That ( exception . Message , Is . EqualTo ( $ "The process cannot access the file '{ filepath } ' because it is being used by another process.") ) ;
176176 }
177177 [ Test ]
@@ -185,5 +185,7 @@ public void MockFile_Lock_FileShareDeleteDoesNotThrowDelete()
185185
186186 Assert . DoesNotThrow ( ( ) => filesystem . File . Delete ( filepath ) ) ;
187187 }
188+
189+ private static IResolveConstraint IOException ( ) => Is . TypeOf < IOException > ( ) . And . Property ( "HResult" ) . EqualTo ( unchecked ( ( int ) 0x80070020 ) ) ;
188190 }
189191}
0 commit comments