File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System . Net ;
2
+ using System . Text . Json ;
3
+ using Microsoft . AspNetCore . Mvc . Testing ;
4
+ using Xunit ;
5
+
6
+ public class ContactosTest : IClassFixture < WebApplicationFactory < Program > >
7
+ {
8
+ private readonly WebApplicationFactory < Program > _factory ;
9
+
10
+ public ContactosTest ( WebApplicationFactory < Program > factory )
11
+ {
12
+ _factory = factory ;
13
+ }
14
+
15
+ [ Fact ]
16
+ public async Task ObtenerContactos_ReturnsExpectedContactList ( )
17
+ {
18
+ // Arrange
19
+ var client = _factory . CreateClient ( ) ;
20
+
21
+ // Act
22
+ var response = await client . GetAsync ( "/obtenercontactos" ) ;
23
+
24
+ // Assert
25
+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
26
+
27
+ var responseString = await response . Content . ReadAsStringAsync ( ) ;
28
+ var contactos = JsonSerializer . Deserialize < List < string > > ( responseString , new JsonSerializerOptions
29
+ {
30
+ PropertyNameCaseInsensitive = true
31
+ } ) ;
32
+
33
+ Assert . NotNull ( contactos ) ;
34
+ Assert . Equal ( 3 , contactos . Count ) ;
35
+ Assert . Contains ( "Amin Espinoza" , contactos ) ;
36
+ Assert . Contains ( "Oscar Barajas" , contactos ) ;
37
+ Assert . Contains ( "Pepe Rodelo" , contactos ) ;
38
+ }
39
+ }
Original file line number Diff line number Diff line change 59
59
. WithName ( "GetWeatherForecast" )
60
60
. WithOpenApi ( ) ;
61
61
62
+ app . MapGet ( "/obtenercontactos" , ( ) =>
63
+ {
64
+ var contactos = new List < string > { "Amin Espinoza" , "Oscar Barajas" , "Pepe Rodelo" } ;
65
+ return contactos ;
66
+ } )
67
+ . WithName ( "ObtenerContactos" )
68
+ . WithOpenApi ( ) ;
69
+
70
+ app . Run ( ) ;
71
+
62
72
app . Run ( ) ;
63
73
64
74
record WeatherForecast ( DateOnly Date , int TemperatureC , string ? Summary )
You can’t perform that action at this time.
0 commit comments