refactor (readonly for static objects in tests and file-scoped namespaces
This commit is contained in:
		| @@ -5,45 +5,44 @@ using FluentValidation; | ||||
| using VisaApi.Fakers.Users.Requests; | ||||
| using Xunit; | ||||
|  | ||||
| namespace VisaApi.Tests.Application.Validation.Users | ||||
| namespace VisaApi.Tests.Application.Validation.Users; | ||||
|  | ||||
| public class ChangeUserAuthDataRequestValidationTests | ||||
| { | ||||
|     public class ChangeUserAuthDataRequestValidationTests | ||||
|     private readonly static IValidator<ChangeUserAuthDataRequest> validator = new ChangeUserAuthDataRequestValidator(); | ||||
|     private readonly static ChangeUserAuthDataRequestFaker faker = new(); | ||||
|  | ||||
|     /// <summary> | ||||
|     /// Test for <see cref="ChangeUserAuthDataRequest"/> validator that should throw exception for empty auth data | ||||
|     /// </summary> | ||||
|     [Fact] | ||||
|     private async Task ValidateForEmptyAuthDataShouldThrow() | ||||
|     { | ||||
|         private readonly static IValidator<ChangeUserAuthDataRequest> validator = new ChangeUserAuthDataRequestValidator(); | ||||
|         private readonly static ChangeUserAuthDataRequestFaker faker = new(); | ||||
|         var request = faker.Generate(); | ||||
|         request.NewAuthData = null!; | ||||
|         NullReferenceException? result = null; | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Test for <see cref="ChangeUserAuthDataRequest"/> validator that should throw exception for empty auth data | ||||
|         /// </summary> | ||||
|         [Fact] | ||||
|         private async Task ValidateForEmptyAuthDataShouldThrow() | ||||
|         try | ||||
|         { | ||||
|             var request = faker.Generate(); | ||||
|             request.NewAuthData = null!; | ||||
|             NullReferenceException? result = null; | ||||
|  | ||||
|             try | ||||
|             { | ||||
|                 await validator.ValidateAsync(request); | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 result = e as NullReferenceException; | ||||
|             } | ||||
|  | ||||
|             result.Should().NotBeNull(); | ||||
|             await validator.ValidateAsync(request); | ||||
|         } | ||||
|         catch (Exception e) | ||||
|         { | ||||
|             result = e as NullReferenceException; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Test for <see cref="ChangeUserAuthDataRequest"/> validator that should no errors for valid entity | ||||
|         /// </summary> | ||||
|         [Fact] | ||||
|         private async Task ValidateForValidShouldReturnNoErrors() | ||||
|         { | ||||
|             var request = faker.Generate(); | ||||
|             var result = await validator.ValidateAsync(request); | ||||
|  | ||||
|             result.IsValid.Should().BeTrue(); | ||||
|         } | ||||
|         result.Should().NotBeNull(); | ||||
|     } | ||||
| } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// Test for <see cref="ChangeUserAuthDataRequest"/> validator that should no errors for valid entity | ||||
|     /// </summary> | ||||
|     [Fact] | ||||
|     private async Task ValidateForValidShouldReturnNoErrors() | ||||
|     { | ||||
|         var request = faker.Generate(); | ||||
|         var result = await validator.ValidateAsync(request); | ||||
|  | ||||
|         result.IsValid.Should().BeTrue(); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user