@@ -17,6 +17,8 @@ public class GetValidationExceptionsTests : DatabaseTestBaseSetup<GetValidationE
1717 private readonly List < ValidationException > _exceptionList ;
1818 private readonly Dictionary < string , string > columnToClassPropertyMapping ;
1919 private readonly Mock < PaginationService < ValidationException > > _paginationServiceMock = new ( ) ;
20+ private readonly HttpResponseData _mockHttpResponseData ;
21+
2022
2123 public GetValidationExceptionsTests ( ) : base ( ( conn , logger , transaction , command , response ) => null )
2224 {
@@ -40,6 +42,8 @@ public GetValidationExceptionsTests() : base((conn, logger, transaction, command
4042 SetupRequest ( json ) ;
4143 CreateHttpResponseMock ( ) ;
4244 SetupDataReader ( _exceptionList , columnToClassPropertyMapping ) ;
45+
46+ _mockHttpResponseData = _request . Object . CreateResponse ( ) ;
4347 }
4448
4549 [ TestMethod ]
@@ -94,4 +98,93 @@ public async Task Run_ExceptionIdIsOutOfRange_ReturnsNoContent()
9498 Assert . AreEqual ( HttpStatusCode . NoContent , result . StatusCode ) ;
9599 _validationDataMock . Verify ( v => v . GetExceptionById ( exceptionId ) , Times . Once ) ;
96100 }
101+ [ TestMethod ]
102+ public async Task Run_NoExceptionsFound_ReturnsNoContent ( )
103+ {
104+ // Arrange
105+ var exceptionId = 0 ;
106+
107+
108+ _validationDataMock . Setup ( s => s . GetAllExceptions ( false , ExceptionSort . DateCreated ) )
109+ . ReturnsAsync ( new List < ValidationException > ( ) ) ;
110+ _httpParserHelperMock . Setup ( s => s . GetQueryParameterAsInt ( It . IsAny < HttpRequestData > ( ) , "exceptionId" ) )
111+ . Returns ( 0 ) ;
112+
113+ _httpParserHelperMock . Setup ( s => s . GetQueryParameterAsInt ( It . IsAny < HttpRequestData > ( ) , "lastId" ) )
114+ . Returns ( 0 ) ;
115+
116+ _httpParserHelperMock . Setup ( s => s . GetQueryParameterAsBool (
117+ It . IsAny < HttpRequestData > ( ) ,
118+ It . Is < string > ( key => key == "todayOnly" ) ,
119+ It . IsAny < bool > ( ) ) )
120+ . Returns ( false ) ;
121+
122+ _httpParserHelperMock . Setup ( s => s . GetQueryParameterAsInt ( It . IsAny < HttpRequestData > ( ) , "orderByProperty" ) )
123+ . Returns ( ( int ) ExceptionSort . DateCreated ) ;
124+
125+ _mockHttpResponseData . StatusCode = HttpStatusCode . NoContent ;
126+
127+ _createResponseMock . Setup ( r =>
128+ r . CreateHttpResponse (
129+ HttpStatusCode . NoContent ,
130+ It . IsAny < HttpRequestData > ( ) ,
131+ It . IsAny < string > ( ) )
132+ ) . Returns ( _mockHttpResponseData ) ;
133+
134+ SetupRequestWithQueryParams ( [ ] ) ;
135+
136+ // Act
137+ var result = await _service . Run ( _request . Object ) ;
138+
139+ // Assert
140+ Assert . IsNotNull ( result ) ;
141+ Assert . AreEqual ( HttpStatusCode . NoContent , result . StatusCode ) ;
142+ _validationDataMock . Verify ( v => v . GetAllExceptions ( false , ExceptionSort . DateCreated ) , Times . Once ) ;
143+ }
144+
145+ [ TestMethod ]
146+ public async Task Run_ThrowsException_ReturnsInternalServerError ( )
147+ {
148+ // Arrange
149+ var exceptionId = 0 ;
150+
151+ // Simulate exception thrown from GetAllExceptions
152+ _validationDataMock . Setup ( s => s . GetAllExceptions ( false , ExceptionSort . DateCreated ) )
153+ . ThrowsAsync ( new Exception ( "Simulated failure" ) ) ;
154+
155+ _httpParserHelperMock . Setup ( s => s . GetQueryParameterAsInt ( It . IsAny < HttpRequestData > ( ) , "exceptionId" ) )
156+ . Returns ( exceptionId ) ;
157+
158+ _httpParserHelperMock . Setup ( s => s . GetQueryParameterAsInt ( It . IsAny < HttpRequestData > ( ) , "lastId" ) )
159+ . Returns ( 0 ) ;
160+
161+ _httpParserHelperMock . Setup ( s => s . GetQueryParameterAsBool (
162+ It . IsAny < HttpRequestData > ( ) ,
163+ It . Is < string > ( key => key == "todayOnly" ) ,
164+ It . IsAny < bool > ( ) ) )
165+ . Returns ( false ) ;
166+
167+ _httpParserHelperMock . Setup ( s => s . GetQueryParameterAsInt ( It . IsAny < HttpRequestData > ( ) , "orderByProperty" ) )
168+ . Returns ( ( int ) ExceptionSort . DateCreated ) ;
169+
170+ // Setup the mock response with expected error status code
171+ _mockHttpResponseData . StatusCode = HttpStatusCode . InternalServerError ;
172+
173+ _createResponseMock . Setup ( r =>
174+ r . CreateHttpResponse (
175+ HttpStatusCode . InternalServerError ,
176+ It . IsAny < HttpRequestData > ( ) ,
177+ It . IsAny < string > ( ) )
178+ ) . Returns ( _mockHttpResponseData ) ;
179+
180+ SetupRequestWithQueryParams ( [ ] ) ;
181+
182+ // Act
183+ var result = await _service . Run ( _request . Object ) ;
184+
185+ // Assert
186+ Assert . IsNotNull ( result ) ;
187+ Assert . AreEqual ( HttpStatusCode . InternalServerError , result . StatusCode ) ;
188+ _validationDataMock . Verify ( v => v . GetAllExceptions ( false , ExceptionSort . DateCreated ) , Times . Once ) ;
189+ }
97190}
0 commit comments