@@ -16,18 +16,23 @@ public async Task GetTodoByIdAsync_Returns_BadRequest_When_Id_Is_Empty()
16
16
// Arrange
17
17
var mediatorMock = new Mock < IMediator > ( ) ;
18
18
var emptyId = Guid . Empty ;
19
- var expectedBadRequest = TypedResults . BadRequest < ValidationErrorDto > (
20
- new ValidationErrorDto (
21
- [ new ValidationErrorItem ( "id" , "id must not be an empty guid." ) ]
22
- ) ) ;
19
+ var expectedBadRequest = new ValidationErrorDto (
20
+ [ new ValidationErrorItem ( "id" , "id must not be an empty guid." ) ]
21
+ ) ;
23
22
24
23
// Act
25
- var result = await TodoEndpoints . GetTodoByIdAsync ( emptyId , mediatorMock . Object ) ;
24
+ var response = await TodoEndpoints . GetTodoByIdAsync ( emptyId , mediatorMock . Object ) ;
26
25
27
26
// Assert
28
- Assert . IsType < Results < BadRequest < ValidationErrorDto > , NotFound , Ok < TodoDto > > > ( result ) ;
29
- var badrequest = ( BadRequest < ValidationErrorDto > ) result . Result ;
30
- Assert . NotNull ( badrequest ) ;
27
+ Assert . IsType < Results < BadRequest < ValidationErrorDto > , NotFound , Ok < TodoDto > > > ( response ) ;
28
+
29
+ var result = ( BadRequest < ValidationErrorDto > ) response . Result ;
30
+ Assert . NotNull ( result ) ;
31
+ Assert . Equal ( StatusCodes . Status400BadRequest , result . StatusCode ) ;
32
+
33
+ var value = Assert . IsType < ValidationErrorDto > ( result . Value ) ;
34
+ Assert . True ( value . ValidationErrors . Any ( ) ) ;
35
+ Assert . Equal ( expectedBadRequest . ValidationErrors . FirstOrDefault ( ) , value . ValidationErrors . FirstOrDefault ( ) ) ;
31
36
}
32
37
33
38
[ Fact ]
@@ -40,13 +45,14 @@ public async Task GetTodoByIdAsync_Returns_NotFound_When_Todo_Not_Found()
40
45
. ReturnsAsync ( new List < TodoDto > ( ) ) ;
41
46
42
47
// Act
43
- var result = await TodoEndpoints . GetTodoByIdAsync ( nonExistentId , mediatorMock . Object ) ;
48
+ var response = await TodoEndpoints . GetTodoByIdAsync ( nonExistentId , mediatorMock . Object ) ;
44
49
45
50
// Assert
46
- Assert . IsType < Results < BadRequest < ValidationErrorDto > , NotFound , Ok < TodoDto > > > ( result ) ;
47
- var notFoundResult = ( NotFound ) result . Result ;
48
-
49
- Assert . NotNull ( notFoundResult ) ;
51
+ Assert . IsType < Results < BadRequest < ValidationErrorDto > , NotFound , Ok < TodoDto > > > ( response ) ;
52
+
53
+ var result = ( NotFound ) response . Result ;
54
+ Assert . NotNull ( result ) ;
55
+ Assert . Equal ( StatusCodes . Status404NotFound , result . StatusCode ) ;
50
56
}
51
57
52
58
[ Fact ]
@@ -55,21 +61,22 @@ public async Task GetTodoByIdAsync_Returns_Ok_When_Todo_Found()
55
61
// Arrange
56
62
var mediatorMock = new Mock < IMediator > ( ) ;
57
63
var existingId = Guid . NewGuid ( ) ; // Assuming this id exists
58
- var todoDto = new TodoDto ( existingId , "" , false ) ; // Assuming todo with this id exists
64
+ var todoDto = new TodoDto ( existingId , "Test name " , false ) ; // Assuming todo with this id exists
59
65
60
66
mediatorMock . Setup ( m => m . Send ( It . IsAny < GetAllTodosQuery > ( ) , CancellationToken . None ) )
61
67
. ReturnsAsync ( new List < TodoDto > ( ) {
62
68
todoDto
63
69
} ) ;
64
70
65
71
// Act
66
- var result = await TodoEndpoints . GetTodoByIdAsync ( existingId , mediatorMock . Object ) ;
72
+ var response = await TodoEndpoints . GetTodoByIdAsync ( existingId , mediatorMock . Object ) ;
67
73
68
74
// Assert
69
- Assert . IsType < Results < BadRequest < ValidationErrorDto > , NotFound , Ok < TodoDto > > > ( result ) ;
70
- var okResult = ( Ok < TodoDto > ) result . Result ;
71
-
72
- Assert . NotNull ( okResult ) ;
73
- Assert . Equal ( todoDto , okResult . Value ) ;
75
+ Assert . IsType < Results < BadRequest < ValidationErrorDto > , NotFound , Ok < TodoDto > > > ( response ) ;
76
+
77
+ var result = ( Ok < TodoDto > ) response . Result ;
78
+ Assert . NotNull ( result ) ;
79
+ Assert . Equal ( StatusCodes . Status200OK , result . StatusCode ) ;
80
+ Assert . Equal ( todoDto , result . Value ) ;
74
81
}
75
82
}
0 commit comments