refactor (readonly for static objects in tests and file-scoped namespaces
This commit is contained in:
@@ -7,19 +7,19 @@ using FluentValidation;
|
||||
using VisaApi.Fakers.Auth;
|
||||
using Xunit;
|
||||
|
||||
namespace VisaApi.Tests.Application.Validation.Auth
|
||||
{
|
||||
public class AuthDataValidatorTests
|
||||
{
|
||||
private readonly static IValidator<AuthData> validator = new AuthDataValidator();
|
||||
private readonly static AuthDataFaker faker = new();
|
||||
namespace VisaApi.Tests.Application.Validation.Auth;
|
||||
|
||||
/// <summary>
|
||||
/// Test for <see cref="AuthData"/> validator that should return validation error for invalid email
|
||||
/// </summary>
|
||||
[Fact]
|
||||
private async Task ValidateForInvalidEmailShouldReturnError()
|
||||
{
|
||||
public class AuthDataValidatorTests
|
||||
{
|
||||
private readonly static IValidator<AuthData> validator = new AuthDataValidator();
|
||||
private readonly static AuthDataFaker faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Test for <see cref="AuthData"/> validator that should return validation error for invalid email
|
||||
/// </summary>
|
||||
[Fact]
|
||||
private async Task ValidateForInvalidEmailShouldReturnError()
|
||||
{
|
||||
var authData = faker.Generate();
|
||||
authData.Email = "alsdas'dsa";
|
||||
|
||||
@@ -30,12 +30,12 @@ namespace VisaApi.Tests.Application.Validation.Auth
|
||||
.And.Contain(error => error.PropertyName == nameof(authData.Email));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test for <see cref="AuthData"/> validator that should return validation error for too long email
|
||||
/// </summary>
|
||||
[Fact]
|
||||
private async Task ValidateForLongEmailShouldReturnError()
|
||||
{
|
||||
/// <summary>
|
||||
/// Test for <see cref="AuthData"/> validator that should return validation error for too long email
|
||||
/// </summary>
|
||||
[Fact]
|
||||
private async Task ValidateForLongEmailShouldReturnError()
|
||||
{
|
||||
var authData = faker.Generate();
|
||||
var stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append('d', ConfigurationConstraints.EmailLength);
|
||||
@@ -49,12 +49,12 @@ namespace VisaApi.Tests.Application.Validation.Auth
|
||||
.And.Contain(error => error.PropertyName == nameof(authData.Email));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test for <see cref="AuthData"/> validator that should return no errors for valid email
|
||||
/// </summary>
|
||||
[Fact]
|
||||
private async Task ValidateForValidEmailShouldReturnNoError()
|
||||
{
|
||||
/// <summary>
|
||||
/// Test for <see cref="AuthData"/> validator that should return no errors for valid email
|
||||
/// </summary>
|
||||
[Fact]
|
||||
private async Task ValidateForValidEmailShouldReturnNoError()
|
||||
{
|
||||
var authData = faker.Generate();
|
||||
|
||||
var result = await validator.ValidateAsync(authData);
|
||||
@@ -63,12 +63,12 @@ namespace VisaApi.Tests.Application.Validation.Auth
|
||||
.Should().BeEmpty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test for <see cref="AuthData"/> validator that should return validation error for empty password
|
||||
/// </summary>
|
||||
[Fact]
|
||||
private async Task ValidateForEmptyPasswordShouldReturnError()
|
||||
{
|
||||
/// <summary>
|
||||
/// Test for <see cref="AuthData"/> validator that should return validation error for empty password
|
||||
/// </summary>
|
||||
[Fact]
|
||||
private async Task ValidateForEmptyPasswordShouldReturnError()
|
||||
{
|
||||
var authData = faker.Generate();
|
||||
authData.Password = string.Empty;
|
||||
|
||||
@@ -79,12 +79,12 @@ namespace VisaApi.Tests.Application.Validation.Auth
|
||||
.And.Contain(error => error.PropertyName == nameof(authData.Password));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test for <see cref="AuthData"/> validator that should return validation error for too long password
|
||||
/// </summary>
|
||||
[Fact]
|
||||
private async Task ValidateForLongPasswordShouldReturnError()
|
||||
{
|
||||
/// <summary>
|
||||
/// Test for <see cref="AuthData"/> validator that should return validation error for too long password
|
||||
/// </summary>
|
||||
[Fact]
|
||||
private async Task ValidateForLongPasswordShouldReturnError()
|
||||
{
|
||||
var authData = faker.Generate();
|
||||
var stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append('d', ConfigurationConstraints.PasswordLength + 1);
|
||||
@@ -97,12 +97,12 @@ namespace VisaApi.Tests.Application.Validation.Auth
|
||||
.And.Contain(error => error.PropertyName == nameof(authData.Password));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test for <see cref="AuthData"/> validator that should return no errors for valid password
|
||||
/// </summary>
|
||||
[Fact]
|
||||
private async Task ValidateForValidPasswordShouldReturnNoError()
|
||||
{
|
||||
/// <summary>
|
||||
/// Test for <see cref="AuthData"/> validator that should return no errors for valid password
|
||||
/// </summary>
|
||||
[Fact]
|
||||
private async Task ValidateForValidPasswordShouldReturnNoError()
|
||||
{
|
||||
var authData = faker.Generate();
|
||||
|
||||
var result = await validator.ValidateAsync(authData);
|
||||
@@ -110,5 +110,4 @@ namespace VisaApi.Tests.Application.Validation.Auth
|
||||
result.Errors.Where(error => error.PropertyName == nameof(authData.Password))
|
||||
.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,32 +11,32 @@ using VisaApi.Fakers.Users;
|
||||
using VisaApi.Tests.Infrastructure.Database;
|
||||
using Xunit;
|
||||
|
||||
namespace VisaApi.Tests.Application.Validation.Auth
|
||||
{
|
||||
[Collection(Collections.ContextUsingTestCollection)]
|
||||
public class RegisterRequestValidatorTests
|
||||
{
|
||||
private readonly static IValidator<AuthData> authDataValidator = new AuthDataValidator();
|
||||
private readonly static RegisterRequestFaker requestFaker = new();
|
||||
private readonly static UserFaker userFaker = new();
|
||||
namespace VisaApi.Tests.Application.Validation.Auth;
|
||||
|
||||
/// <summary>
|
||||
/// Creates validator from context
|
||||
/// </summary>
|
||||
/// <param name="context">db context</param>
|
||||
/// <returns>RegisterRequest validator</returns>
|
||||
private static IValidator<RegisterRequest> GetValidator(DbContext context)
|
||||
{
|
||||
[Collection(Collections.ContextUsingTestCollection)]
|
||||
public class RegisterRequestValidatorTests
|
||||
{
|
||||
private readonly static IValidator<AuthData> authDataValidator = new AuthDataValidator();
|
||||
private readonly static RegisterRequestFaker requestFaker = new();
|
||||
private readonly static UserFaker userFaker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates validator from context
|
||||
/// </summary>
|
||||
/// <param name="context">db context</param>
|
||||
/// <returns>RegisterRequest validator</returns>
|
||||
private static IValidator<RegisterRequest> GetValidator(DbContext context)
|
||||
{
|
||||
var repository = new UsersRepository(context, context);
|
||||
return new RegisterRequestValidator(repository, authDataValidator);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test for <see cref="RegisterRequest"/> validator that should throw for empty auth data
|
||||
/// </summary>
|
||||
[Fact]
|
||||
private async Task ValidateForEmptyAuthDataShouldThrow()
|
||||
{
|
||||
/// <summary>
|
||||
/// Test for <see cref="RegisterRequest"/> validator that should throw for empty auth data
|
||||
/// </summary>
|
||||
[Fact]
|
||||
private async Task ValidateForEmptyAuthDataShouldThrow()
|
||||
{
|
||||
var context = InMemoryContextProvider.GetDbContext();
|
||||
var validator = GetValidator(context);
|
||||
var request = requestFaker.Generate();
|
||||
@@ -55,12 +55,12 @@ namespace VisaApi.Tests.Application.Validation.Auth
|
||||
result.Should().NotBeNull();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test for <see cref="RegisterRequest"/> validator that should return error for used email
|
||||
/// </summary>
|
||||
[Fact]
|
||||
private async Task ValidateForUsedEmailShouldReturnError()
|
||||
{
|
||||
/// <summary>
|
||||
/// Test for <see cref="RegisterRequest"/> validator that should return error for used email
|
||||
/// </summary>
|
||||
[Fact]
|
||||
private async Task ValidateForUsedEmailShouldReturnError()
|
||||
{
|
||||
var context = InMemoryContextProvider.GetDbContext();
|
||||
var validator = GetValidator(context);
|
||||
var user = userFaker.Generate();
|
||||
@@ -76,12 +76,12 @@ namespace VisaApi.Tests.Application.Validation.Auth
|
||||
.And.HaveCount(1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test for <see cref="RegisterRequest"/> validator that should return o errors for valid requests
|
||||
/// </summary>
|
||||
[Fact]
|
||||
private async Task ValidateForValidRequestShouldReturnNoErrors()
|
||||
{
|
||||
/// <summary>
|
||||
/// Test for <see cref="RegisterRequest"/> validator that should return o errors for valid requests
|
||||
/// </summary>
|
||||
[Fact]
|
||||
private async Task ValidateForValidRequestShouldReturnNoErrors()
|
||||
{
|
||||
var context = InMemoryContextProvider.GetDbContext();
|
||||
var validator = GetValidator(context);
|
||||
var request = requestFaker.Generate();
|
||||
@@ -90,5 +90,4 @@ namespace VisaApi.Tests.Application.Validation.Auth
|
||||
|
||||
result.Errors.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user