@@ -73,6 +73,20 @@ public void FileAssertFile_Create_NullPattern_ThrowsInvalidOperationException()
7373 Assert . Contains ( "pattern" , exception . Message ) ;
7474 }
7575
76+ /// <summary>
77+ /// Verifies that Create throws <see cref="InvalidOperationException"/> when Pattern is blank.
78+ /// </summary>
79+ [ TestMethod ]
80+ public void FileAssertFile_Create_BlankPattern_ThrowsInvalidOperationException ( )
81+ {
82+ // Arrange
83+ var data = new FileAssertFileData { Pattern = " " } ;
84+
85+ // Act & Assert
86+ var exception = Assert . Throws < InvalidOperationException > ( ( ) => FileAssertFile . Create ( data ) ) ;
87+ Assert . Contains ( "pattern" , exception . Message ) ;
88+ }
89+
7690 /// <summary>
7791 /// Verifies that Run produces no error when there are no matching files and no constraints.
7892 /// </summary>
@@ -323,4 +337,64 @@ public void FileAssertFile_Run_TooLarge_WritesError()
323337 tempDir . Delete ( recursive : true ) ;
324338 }
325339 }
340+
341+ /// <summary>
342+ /// Verifies that Run checks size constraints against every matched file, not just the first.
343+ /// </summary>
344+ [ TestMethod ]
345+ public void FileAssertFile_Run_MultipleFiles_OneViolatesSizeConstraint_WritesError ( )
346+ {
347+ // Arrange - create two files: one large enough, one too small
348+ var tempDir = Directory . CreateTempSubdirectory ( "fileassert_test_" ) ;
349+ try
350+ {
351+ File . WriteAllText ( Path . Combine ( tempDir . FullName , "ok.txt" ) , "enough content here" ) ;
352+ File . WriteAllText ( Path . Combine ( tempDir . FullName , "small.txt" ) , string . Empty ) ;
353+ var data = new FileAssertFileData { Pattern = "*.txt" , MinSize = 5 } ;
354+ var file = FileAssertFile . Create ( data ) ;
355+ using var context = Context . Create ( [ "--silent" ] ) ;
356+
357+ // Act
358+ file . Run ( context , tempDir . FullName ) ;
359+
360+ // Assert - the small file should trigger an error
361+ Assert . AreEqual ( 1 , context . ExitCode ) ;
362+ }
363+ finally
364+ {
365+ tempDir . Delete ( recursive : true ) ;
366+ }
367+ }
368+
369+ /// <summary>
370+ /// Verifies that Run applies content rules to every matched file, not just the first.
371+ /// </summary>
372+ [ TestMethod ]
373+ public void FileAssertFile_Run_MultipleFiles_OneFailsContentRule_WritesError ( )
374+ {
375+ // Arrange - create two files: one with required content, one without
376+ var tempDir = Directory . CreateTempSubdirectory ( "fileassert_test_" ) ;
377+ try
378+ {
379+ File . WriteAllText ( Path . Combine ( tempDir . FullName , "good.txt" ) , "expected content here" ) ;
380+ File . WriteAllText ( Path . Combine ( tempDir . FullName , "bad.txt" ) , "unrelated content" ) ;
381+ var data = new FileAssertFileData
382+ {
383+ Pattern = "*.txt" ,
384+ Rules = [ new FileAssertRuleData { Contains = "expected content" } ]
385+ } ;
386+ var file = FileAssertFile . Create ( data ) ;
387+ using var context = Context . Create ( [ "--silent" ] ) ;
388+
389+ // Act
390+ file . Run ( context , tempDir . FullName ) ;
391+
392+ // Assert - the bad file should trigger an error
393+ Assert . AreEqual ( 1 , context . ExitCode ) ;
394+ }
395+ finally
396+ {
397+ tempDir . Delete ( recursive : true ) ;
398+ }
399+ }
326400}
0 commit comments