44using System . Text . Json ;
55using System . Threading . Tasks ;
66using Ecommerce . Contracts . Authentication ;
7- using Ecommerce . IntegrationTests . Utils . Fixtures ;
7+ using Ecommerce . Tests . Shared ;
88using FluentAssertions ;
99using Microsoft . AspNetCore . Http ;
1010using Microsoft . AspNetCore . Mvc ;
@@ -22,64 +22,15 @@ public AuthenticationControllerTests(EcommerceWebApplicationFactoryFixture facto
2222 }
2323
2424 [ Fact ]
25- public async Task RegisterShould_ReturnErrorValidation_WhenRegisterRequestIsInvalid ( )
25+ public async Task RegisterShould_ReturnCreated_WhenRegistrationIsSuccessful ( )
2626 {
2727 // Arrange
28- var registerRequest = new RegisterRequest (
29- string . Empty ,
30- string . Empty ,
31- string . Empty ,
32- string . Empty ,
33- string . Empty ,
34- string . Empty ,
35- 0
36- ) ;
28+ var registerRequest = Utils . User . CreateRegisterRequest ( ) ;
3729
3830 // Act
3931 var response = await _httpClient . PostAsJsonAsync ( "auth/register" , registerRequest ) ;
4032
4133 // Assert
42- System . Console . WriteLine ( response ) ;
43-
44- response . StatusCode . Should ( ) . Be ( HttpStatusCode . BadRequest ) ;
45-
46- var content = await response . Content . ReadFromJsonAsync < ProblemDetails > ( ) ;
47- content . Should ( ) . NotBeNull ( ) ;
48-
49- // Assert specific error details
50- content ! . Type . Should ( ) . Be ( "ValidationException" ) ; // Use null forgiving operator as we asserted it's not null
51- content ! . Title . Should ( ) . Be ( "Validation Error" ) ;
52- content ! . Status . Should ( ) . Be ( 400 ) ;
53- content ! . Detail . Should ( ) . Be ( "One or more validation errors has occured." ) ;
54-
55- content ! . Extensions [ "errors" ] . Should ( ) . NotBeNull ( ) ;
56-
57- var errors = JsonSerializer . Deserialize < Dictionary < string , List < string > > > (
58- JsonSerializer . Serialize ( content ! . Extensions [ "errors" ] ) ,
59- new JsonSerializerOptions { PropertyNameCaseInsensitive = true , WriteIndented = true }
60- ) ;
61-
62- if ( errors is null )
63- {
64- throw new XunitException ( "Errors should not be null." ) ;
65- }
66-
67- errors . Should ( ) . ContainKey ( "FirstName" ) ;
68- errors [ "FirstName" ] . Should ( ) . Contain ( "First Name is Required" ) ;
69- errors . Should ( ) . ContainKey ( "LastName" ) ;
70- errors [ "LastName" ] . Should ( ) . Contain ( "Last Name is Required" ) ;
71- errors . Should ( ) . ContainKey ( "Email" ) ;
72- errors [ "Email" ] . Should ( ) . Contain ( "Email is required." ) ;
73- errors [ "Email" ] . Should ( ) . Contain ( "Email must be a valid format." ) ;
74- errors . Should ( ) . ContainKey ( "Password" ) ;
75- errors [ "Password" ] . Should ( ) . Contain ( "Password is required." ) ;
76- errors . Should ( ) . ContainKey ( "ConfirmPassword" ) ;
77- errors [ "ConfirmPassword" ] . Should ( ) . Contain ( "Confirmation password is required." ) ;
78- errors . Should ( ) . ContainKey ( "PhoneNumber" ) ;
79- errors [ "PhoneNumber" ] . Should ( ) . Contain ( "Phone number is required." ) ;
80-
81- System . Console . WriteLine (
82- JsonSerializer . Serialize ( content , new JsonSerializerOptions { WriteIndented = true } )
83- ) ;
34+ response . StatusCode . Should ( ) . Be ( HttpStatusCode . Created ) ;
8435 }
8536}
0 commit comments