@@ -20,9 +20,9 @@ internal DirectoryAssertions(IDirectoryInfo? instance)
2020 /// Asserts that the current directory has at least <paramref name="minimumCount" /> directories which match the
2121 /// <paramref name="searchPattern" />.
2222 /// </summary>
23- public AndConstraint < DirectoryAssertions > HasDirectoriesMatching (
24- string searchPattern = "*" ,
25- int minimumCount = 1 ,
23+ public AndConstraint < DirectoryAssertions > HasDirectories (
24+ string searchPattern ,
25+ int minimumCount ,
2626 string because = "" ,
2727 params object [ ] becauseArgs )
2828 {
@@ -52,109 +52,109 @@ public AndConstraint<DirectoryAssertions> HasDirectoriesMatching(
5252 /// <summary>
5353 /// Asserts that the current directory has at least one directory which matches the <paramref name="searchPattern" />.
5454 /// </summary>
55- public AndConstraint < DirectoryAssertions > HasDirectoryMatching (
55+ public AndConstraint < DirectoryAssertions > HasDirectories (
5656 string searchPattern = "*" , string because = "" , params object [ ] becauseArgs )
57- => HasDirectoriesMatching ( searchPattern , 1 , because , becauseArgs ) ;
57+ => HasDirectories ( searchPattern , 1 , because , becauseArgs ) ;
5858
5959 /// <summary>
60- /// Asserts that the current directory has at least one file which matches the <paramref name="searchPattern" />.
60+ /// Asserts that the directory contains exactly one directory matching the given <paramref name="searchPattern" />.
6161 /// </summary>
62- public AndConstraint < DirectoryAssertions > HasFileMatching (
62+ public AndWhichConstraint < FileSystemAssertions , DirectoryAssertions > HasDirectory (
6363 string searchPattern = "*" , string because = "" , params object [ ] becauseArgs )
64- => HasFilesMatching ( searchPattern , 1 , because , becauseArgs ) ;
65-
66- /// <summary>
67- /// Asserts that the current directory has at least <paramref name="minimumCount" /> files which match the
68- /// <paramref name="searchPattern" />.
69- /// </summary>
70- public AndConstraint < DirectoryAssertions > HasFilesMatching (
71- string searchPattern = "*" ,
72- int minimumCount = 1 ,
73- string because = "" ,
74- params object [ ] becauseArgs )
7564 {
7665 Execute . Assertion
7766 . WithDefaultIdentifier ( Identifier )
7867 . BecauseOf ( because , becauseArgs )
7968 . ForCondition ( Subject != null )
8069 . FailWith (
81- "You can't assert a directory having files if the DirectoryInfo is null." )
70+ "You can't assert a directory having a given directory if it is null." )
8271 . Then
8372 . ForCondition ( ! string . IsNullOrEmpty ( searchPattern ) )
8473 . FailWith (
85- "You can't assert a directory having files if you don't pass a proper search pattern." )
74+ "You can't assert a directory having a given directory if you don't pass a proper search pattern." )
8675 . Then
8776 . Given ( ( ) => Subject ! )
8877 . ForCondition ( directoryInfo
89- => directoryInfo . GetFiles ( searchPattern ) . Length >= minimumCount )
78+ => directoryInfo . GetDirectories ( searchPattern ) . Length == 1 )
9079 . FailWith (
91- $ "Expected {{ context}} {{1}} to contain at least { ( minimumCount == 1 ? " one file" : $ " { minimumCount } files" ) } matching {{0}}{{ reason}} , but { ( minimumCount == 1 ? "none was" : "only {2} were" ) } found .",
80+ "Expected {context} {1} to contain exactly one directory matching {0}{ reason}, but found {2}." ,
9281 _ => searchPattern ,
9382 directoryInfo => directoryInfo . Name ,
94- directoryInfo => directoryInfo . GetFiles ( searchPattern ) . Length ) ;
83+ directoryInfo => directoryInfo . GetDirectories ( searchPattern ) . Length ) ;
9584
96- return new AndConstraint < DirectoryAssertions > ( this ) ;
85+ return new AndWhichConstraint < FileSystemAssertions , DirectoryAssertions > (
86+ new FileSystemAssertions ( Subject ! . FileSystem ) ,
87+ new DirectoryAssertions ( Subject ! . GetDirectories ( searchPattern ) . Single ( ) ) ) ;
9788 }
9889
9990 /// <summary>
100- /// Asserts that the directory contains exactly one directory matching the given <paramref name="searchPattern" />.
91+ /// Asserts that the directory contains exactly one file matching the given <paramref name="searchPattern" />.
10192 /// </summary>
102- public AndWhichConstraint < FileSystemAssertions , DirectoryAssertions > HasSingleDirectoryMatching (
93+ public AndWhichConstraint < FileSystemAssertions , FileAssertions > HasFile (
10394 string searchPattern = "*" , string because = "" , params object [ ] becauseArgs )
10495 {
10596 Execute . Assertion
10697 . WithDefaultIdentifier ( Identifier )
10798 . BecauseOf ( because , becauseArgs )
10899 . ForCondition ( Subject != null )
109100 . FailWith (
110- "You can't assert a directory having a given directory if it is null." )
101+ "You can't assert a directory having a given file if it is null." )
111102 . Then
112103 . ForCondition ( ! string . IsNullOrEmpty ( searchPattern ) )
113104 . FailWith (
114- "You can't assert a directory having a given directory if you don't pass a proper search pattern." )
105+ "You can't assert a directory having a given file if you don't pass a proper search pattern." )
115106 . Then
116107 . Given ( ( ) => Subject ! )
117108 . ForCondition ( directoryInfo
118- => directoryInfo . GetDirectories ( searchPattern ) . Length == 1 )
109+ => directoryInfo . GetFiles ( searchPattern ) . Length == 1 )
119110 . FailWith (
120- "Expected {context} {1} to contain exactly one directory matching {0}{reason}, but found {2}." ,
111+ "Expected {context} {1} to contain exactly one file matching {0}{reason}, but found {2}." ,
121112 _ => searchPattern ,
122113 directoryInfo => directoryInfo . Name ,
123- directoryInfo => directoryInfo . GetDirectories ( searchPattern ) . Length ) ;
114+ directoryInfo => directoryInfo . GetFiles ( searchPattern ) . Length ) ;
124115
125- return new AndWhichConstraint < FileSystemAssertions , DirectoryAssertions > (
116+ return new AndWhichConstraint < FileSystemAssertions , FileAssertions > (
126117 new FileSystemAssertions ( Subject ! . FileSystem ) ,
127- new DirectoryAssertions ( Subject ! . GetDirectories ( searchPattern ) . Single ( ) ) ) ;
118+ new FileAssertions ( Subject ! . GetFiles ( searchPattern ) . Single ( ) ) ) ;
128119 }
129120
130121 /// <summary>
131- /// Asserts that the directory contains exactly one file matching the given <paramref name="searchPattern" />.
122+ /// Asserts that the current directory has at least one file which matches the <paramref name="searchPattern" />.
132123 /// </summary>
133- public AndWhichConstraint < FileSystemAssertions , FileAssertions > HasSingleFileMatching (
124+ public AndConstraint < DirectoryAssertions > HasFiles (
134125 string searchPattern = "*" , string because = "" , params object [ ] becauseArgs )
126+ => HasFiles ( searchPattern , 1 , because , becauseArgs ) ;
127+
128+ /// <summary>
129+ /// Asserts that the current directory has at least <paramref name="minimumCount" /> files which match the
130+ /// <paramref name="searchPattern" />.
131+ /// </summary>
132+ public AndConstraint < DirectoryAssertions > HasFiles (
133+ string searchPattern ,
134+ int minimumCount ,
135+ string because = "" ,
136+ params object [ ] becauseArgs )
135137 {
136138 Execute . Assertion
137139 . WithDefaultIdentifier ( Identifier )
138140 . BecauseOf ( because , becauseArgs )
139141 . ForCondition ( Subject != null )
140142 . FailWith (
141- "You can't assert a directory having a given file if it is null." )
143+ "You can't assert a directory having files if the DirectoryInfo is null." )
142144 . Then
143145 . ForCondition ( ! string . IsNullOrEmpty ( searchPattern ) )
144146 . FailWith (
145- "You can't assert a directory having a given file if you don't pass a proper search pattern." )
147+ "You can't assert a directory having files if you don't pass a proper search pattern." )
146148 . Then
147149 . Given ( ( ) => Subject ! )
148150 . ForCondition ( directoryInfo
149- => directoryInfo . GetFiles ( searchPattern ) . Length == 1 )
151+ => directoryInfo . GetFiles ( searchPattern ) . Length >= minimumCount )
150152 . FailWith (
151- "Expected {context} {1} to contain exactly one file matching {0}{ reason}, but found {2}." ,
153+ $ "Expected {{ context}} {{1}} to contain at least { ( minimumCount == 1 ? " one file" : $ " { minimumCount } files" ) } matching {{0}}{{ reason}} , but { ( minimumCount == 1 ? "none was" : "only {2} were" ) } found .",
152154 _ => searchPattern ,
153155 directoryInfo => directoryInfo . Name ,
154156 directoryInfo => directoryInfo . GetFiles ( searchPattern ) . Length ) ;
155157
156- return new AndWhichConstraint < FileSystemAssertions , FileAssertions > (
157- new FileSystemAssertions ( Subject ! . FileSystem ) ,
158- new FileAssertions ( Subject ! . GetFiles ( searchPattern ) . Single ( ) ) ) ;
158+ return new AndConstraint < DirectoryAssertions > ( this ) ;
159159 }
160160}
0 commit comments