@@ -5,13 +5,17 @@ public class RequiredValidatorTests
55 private readonly RequiredValidator < TestModel , string > _stringValidator ;
66 private readonly RequiredValidator < TestModel , int > _intValidator ;
77 private readonly RequiredValidator < TestModel , int ? > _nullableIntValidator ;
8+ private readonly RequiredValidator < TestModel , bool > _boolValidator ;
9+ private readonly RequiredValidator < TestModel , bool ? > _nullableBoolValidator ;
810 private readonly IServiceProvider _services ;
911
1012 public RequiredValidatorTests ( )
1113 {
1214 _stringValidator = new RequiredValidator < TestModel , string > ( "Field is required" ) ;
1315 _intValidator = new RequiredValidator < TestModel , int > ( "Field is required" ) ;
1416 _nullableIntValidator = new RequiredValidator < TestModel , int ? > ( "Field is required" ) ;
17+ _boolValidator = new RequiredValidator < TestModel , bool > ( "Field is required" ) ;
18+ _nullableBoolValidator = new RequiredValidator < TestModel , bool ? > ( "Field is required" ) ;
1519 _services = A . Fake < IServiceProvider > ( ) ;
1620 }
1721
@@ -99,6 +103,76 @@ public async Task ValidateAsync_Int_Should_Pass_When_NonZero()
99103 result . ErrorMessage . ShouldBeNull ( ) ;
100104 }
101105
106+ [ Fact ]
107+ public async Task ValidateAsync_Bool_Should_Fail_When_False ( )
108+ {
109+ // Arrange
110+ var model = new TestModel ( ) ;
111+
112+ // Act
113+ var result = await _boolValidator . ValidateAsync ( model , false , _services ) ;
114+
115+ // Assert
116+ result . IsValid . ShouldBeFalse ( ) ;
117+ result . ErrorMessage . ShouldBe ( "Field is required" ) ;
118+ }
119+
120+ [ Fact ]
121+ public async Task ValidateAsync_Bool_Should_Pass_When_True ( )
122+ {
123+ // Arrange
124+ var model = new TestModel ( ) ;
125+
126+ // Act
127+ var result = await _boolValidator . ValidateAsync ( model , true , _services ) ;
128+
129+ // Assert
130+ result . IsValid . ShouldBeTrue ( ) ;
131+ result . ErrorMessage . ShouldBeNull ( ) ;
132+ }
133+
134+ [ Fact ]
135+ public async Task ValidateAsync_NullableBool_Should_Fail_When_Null ( )
136+ {
137+ // Arrange
138+ var model = new TestModel ( ) ;
139+
140+ // Act
141+ var result = await _nullableBoolValidator . ValidateAsync ( model , null , _services ) ;
142+
143+ // Assert
144+ result . IsValid . ShouldBeFalse ( ) ;
145+ result . ErrorMessage . ShouldBe ( "Field is required" ) ;
146+ }
147+
148+ [ Fact ]
149+ public async Task ValidateAsync_NullableBool_Should_Fail_When_False ( )
150+ {
151+ // Arrange
152+ var model = new TestModel ( ) ;
153+
154+ // Act
155+ var result = await _nullableBoolValidator . ValidateAsync ( model , false , _services ) ;
156+
157+ // Assert
158+ result . IsValid . ShouldBeFalse ( ) ;
159+ result . ErrorMessage . ShouldBe ( "Field is required" ) ;
160+ }
161+
162+ [ Fact ]
163+ public async Task ValidateAsync_NullableBool_Should_Pass_When_True ( )
164+ {
165+ // Arrange
166+ var model = new TestModel ( ) ;
167+
168+ // Act
169+ var result = await _nullableBoolValidator . ValidateAsync ( model , true , _services ) ;
170+
171+ // Assert
172+ result . IsValid . ShouldBeTrue ( ) ;
173+ result . ErrorMessage . ShouldBeNull ( ) ;
174+ }
175+
102176 [ Fact ]
103177 public async Task ValidateAsync_NullableInt_Should_Fail_When_Null ( )
104178 {
0 commit comments