refactor (readonly for static objects in tests and file-scoped namespaces

This commit is contained in:
2024-09-22 17:34:29 +03:00
parent 1625764e0a
commit a80076e2e6
50 changed files with 1196 additions and 1246 deletions

View File

@@ -1,13 +1,12 @@
using System.Text.RegularExpressions;
namespace ApplicationLayer
namespace ApplicationLayer;
public static class Constants
{
public static class Constants
{
public readonly static Regex EnglishWordRegex = new("^[a-zA-Z]*$");
public readonly static Regex EnglishPhraseRegex = new(@"^[a-zA-Z №0-9;,\-_+=#*']*$");
public readonly static Regex PhoneNumRegex = new(@"^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$");
}
}

View File

@@ -1,9 +1,8 @@
using System.ComponentModel.DataAnnotations;
namespace ApplicationLayer.Services.AuthServices.Common
namespace ApplicationLayer.Services.AuthServices.Common;
public class AuthToken
{
public class AuthToken
{
[Required] public string Token { get; set; } = null!;
}
}

View File

@@ -1,16 +1,15 @@
using System.ComponentModel.DataAnnotations;
using Domains;
namespace ApplicationLayer.Services.Users.Models
namespace ApplicationLayer.Services.Users.Models;
/// Auth data with nullable password for making change auth data requests
public class ChangeAuthData
{
/// Auth data with nullable password for making change auth data requests
public class ChangeAuthData
{
[Required]
[MaxLength(ConfigurationConstraints.EmailLength)]
public string Email { get; set; } = null!;
[MaxLength(ConfigurationConstraints.PasswordLength)]
public string? Password { get; set; }
}
}

View File

@@ -1,10 +1,10 @@
using System.ComponentModel.DataAnnotations;
using Domains;
namespace ApplicationLayer.Services.Users.Models
namespace ApplicationLayer.Services.Users.Models;
public class UserModel
{
public class UserModel
{
/// Unique Identifier of user
[Required]
public Guid Id { get; private set; } = Guid.NewGuid();
@@ -12,5 +12,4 @@ namespace ApplicationLayer.Services.Users.Models
[Required]
[MaxLength(ConfigurationConstraints.EmailLength)]
public string Email { get; set; } = null!;
}
}

View File

@@ -1,10 +1,10 @@
using Domains;
using FluentValidation;
namespace ApplicationLayer.Services.Users.Requests.Validation
namespace ApplicationLayer.Services.Users.Requests.Validation;
public class ChangeUserAuthDataRequestValidator : AbstractValidator<ChangeUserAuthDataRequest>
{
public class ChangeUserAuthDataRequestValidator : AbstractValidator<ChangeUserAuthDataRequest>
{
public ChangeUserAuthDataRequestValidator()
{
RuleFor(r => r.UserId)
@@ -20,5 +20,4 @@ namespace ApplicationLayer.Services.Users.Requests.Validation
.MaximumLength(ConfigurationConstraints.EmailLength)
.WithMessage($"Email address length must be less than {ConfigurationConstraints.EmailLength}");
}
}
}

View File

@@ -1,4 +1,3 @@
namespace BlazorWebAssemblyVisaApiClient.Common.Exceptions
{
public class BlazorClientException(string message) : Exception(message);
}
namespace BlazorWebAssemblyVisaApiClient.Common.Exceptions;
public class BlazorClientException(string message) : Exception(message);

View File

@@ -1,4 +1,3 @@
namespace BlazorWebAssemblyVisaApiClient.Common.Exceptions
{
public class NotLoggedInException() : BlazorClientException("User is not logged in.");
}
namespace BlazorWebAssemblyVisaApiClient.Common.Exceptions;
public class NotLoggedInException() : BlazorClientException("User is not logged in.");

View File

@@ -1,10 +1,10 @@
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Components;
namespace BlazorWebAssemblyVisaApiClient
namespace BlazorWebAssemblyVisaApiClient;
public static class Constants
{
public static class Constants
{
public readonly static Regex EnglishWordRegex = new("^[a-zA-Z]*$");
public readonly static Regex EnglishPhraseRegex = new(@"^[a-z A-Z№0-9?><;,{}[\]\-_+=!@#$%\^&*|']*$");
@@ -16,5 +16,4 @@ namespace BlazorWebAssemblyVisaApiClient
public const string ApplicantRole = "Applicant";
public const string ApprovingAuthorityRole = "ApprovingAuthority";
public const string AdminRole = "Admin";
}
}

View File

@@ -3,10 +3,10 @@ using BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models;
using VisaApiClient;
using PlaceOfWorkModel = BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models.PlaceOfWorkModel;
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.AutoMapper.Profiles
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.AutoMapper.Profiles;
public class RegisterApplicantRequestProfile : Profile
{
public class RegisterApplicantRequestProfile : Profile
{
public RegisterApplicantRequestProfile()
{
CreateMap<RegisterApplicantRequestModel, RegisterApplicantRequest>(MemberList.Destination);
@@ -15,5 +15,4 @@ namespace BlazorWebAssemblyVisaApiClient.Infrastructure.AutoMapper.Profiles
CreateMap<PlaceOfWorkModel, VisaApiClient.PlaceOfWorkModel>(MemberList.Destination);
}
}
}

View File

@@ -2,13 +2,12 @@
using BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Models;
using VisaApiClient;
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.AutoMapper.Profiles
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.AutoMapper.Profiles;
public class VisaApplicationCreateRequestProfile : Profile
{
public class VisaApplicationCreateRequestProfile : Profile
{
public VisaApplicationCreateRequestProfile()
{
CreateMap<VisaApplicationCreateRequestModel, VisaApplicationCreateRequest>(MemberList.Destination);
}
}
}

View File

@@ -1,9 +1,9 @@
using System.ComponentModel.DataAnnotations;
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers;
public static class EnumExtensions
{
public static class EnumExtensions
{
public static string GetDisplayName(this Enum value)
{
var enumMembers = value.GetType().GetMembers();
@@ -14,5 +14,4 @@ namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers
var displayName = displayAttribute?.Name ?? value.ToString();
return displayName;
}
}
}

View File

@@ -1,10 +1,10 @@
using System.Text;
using FluentValidation.Results;
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers;
public static class ValidationResultExtensions
{
public static class ValidationResultExtensions
{
public static string ToErrorsString(this ValidationResult validationResult)
=> ErrorsToString(validationResult.Errors.Select(e => e.ErrorMessage));
@@ -18,5 +18,4 @@ namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers
return stringBuilder.ToString();
}
}
}

View File

@@ -1,9 +1,8 @@
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider;
public class DateTimeProvider : IDateTimeProvider
{
public class DateTimeProvider : IDateTimeProvider
{
public DateTime Now() => DateTime.Now;
public string FormattedNow() => Now().ToString("yyyy-MM-dd");
}
}

View File

@@ -1,9 +1,8 @@
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider;
public interface IDateTimeProvider
{
public interface IDateTimeProvider
{
DateTime Now();
string FormattedNow();
}
}

View File

@@ -1,6 +1,5 @@
using BlazorWebAssemblyVisaApiClient.Common.Exceptions;
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider.Exceptions
{
public class UnknownRoleException() : BlazorClientException("Unknown user role");
}
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider.Exceptions;
public class UnknownRoleException() : BlazorClientException("Unknown user role");

View File

@@ -1,9 +1,9 @@
using VisaApiClient;
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider;
public interface IUserDataProvider
{
public interface IUserDataProvider
{
public string? CurrentRole { get; }
public Action? OnRoleChanged { get; set; }
@@ -11,5 +11,4 @@ namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvide
public Task<ApplicantModel> GetApplicant();
public void UpdateCurrentRole();
}
}

View File

@@ -3,10 +3,10 @@ using System.Security.Claims;
using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider.Exceptions;
using VisaApiClient;
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider;
public class UserDataProvider(Client client) : IUserDataProvider
{
public class UserDataProvider(Client client) : IUserDataProvider
{
private readonly static JwtSecurityTokenHandler tokenHandler = new();
public string? CurrentRole { get; private set; }
@@ -49,5 +49,4 @@ namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvide
OnRoleChanged?.Invoke();
}
}
}
}

View File

@@ -1,11 +1,11 @@
using System.ComponentModel.DataAnnotations;
using VisaApiClient;
namespace BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models
namespace BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models;
/// Model of place of work with attributes required for validation to work
public class PlaceOfWorkModel
{
/// Model of place of work with attributes required for validation to work
public class PlaceOfWorkModel
{
[Required]
[StringLength(ConfigurationConstraints.PlaceOfWorkNameLength, MinimumLength = 1)]
public string Name { get; set; } = default!;
@@ -17,5 +17,4 @@ namespace BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models
[Required]
[StringLength(ConfigurationConstraints.PhoneNumberLength, MinimumLength = ConfigurationConstraints.PhoneNumberMinLength)]
public string PhoneNum { get; set; } = default!;
}
}

View File

@@ -3,11 +3,11 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using VisaApiClient;
namespace BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models
namespace BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models;
/// Model of request with attributes required for validation to work
public class RegisterApplicantRequestModel
{
/// Model of request with attributes required for validation to work
public class RegisterApplicantRequestModel
{
[Required]
[ValidateComplexType]
public RegisterRequestModel RegisterRequest { get; set; } = new();
@@ -64,5 +64,4 @@ namespace BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models
public PlaceOfWorkModel PlaceOfWork { get; set; } = new();
public bool IsNonResident { get; set; }
}
}

View File

@@ -1,13 +1,12 @@
using System.ComponentModel.DataAnnotations;
using VisaApiClient;
namespace BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models
namespace BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models;
/// Model of request with attributes required for validation to work
public class RegisterRequestModel
{
/// Model of request with attributes required for validation to work
public class RegisterRequestModel
{
[Required]
[ValidateComplexType]
public AuthData AuthData { get; set; } = new AuthData();
}
}

View File

@@ -1,10 +1,10 @@
using FluentValidation;
using VisaApiClient;
namespace BlazorWebAssemblyVisaApiClient.Validation.Auth
namespace BlazorWebAssemblyVisaApiClient.Validation.Auth;
public class ChangeUserAuthDataRequestValidator : AbstractValidator<ChangeUserAuthDataRequest>
{
public class ChangeUserAuthDataRequestValidator : AbstractValidator<ChangeUserAuthDataRequest>
{
public ChangeUserAuthDataRequestValidator()
{
RuleFor(r => r.NewAuthData)
@@ -17,5 +17,4 @@ namespace BlazorWebAssemblyVisaApiClient.Validation.Auth
.MaximumLength(ConfigurationConstraints.EmailLength)
.WithMessage($"Email address length must be less than {ConfigurationConstraints.EmailLength}");
}
}
}

View File

@@ -1,11 +1,11 @@
using System.ComponentModel.DataAnnotations;
using VisaApiClient;
namespace BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Models
namespace BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Models;
/// Model for request for data annotations validation to work
public class VisaApplicationCreateRequestModel
{
/// Model for request for data annotations validation to work
public class VisaApplicationCreateRequestModel
{
[ValidateComplexType]
public ReentryPermitModel? ReentryPermit { get; set; } = default!;
@@ -34,5 +34,4 @@ namespace BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Models
[ValidateComplexType]
public List<PastVisitModel> PastVisits { get; set; } = [];
}
}

View File

@@ -1,9 +1,9 @@
using System.Text;
namespace VisaApiClient
namespace VisaApiClient;
public class ClientBase
{
public class ClientBase
{
public AuthToken? AuthToken { get; set; }
protected Task<HttpRequestMessage> CreateHttpRequestMessageAsync(CancellationToken cancellationToken)
@@ -26,5 +26,4 @@ namespace VisaApiClient
protected async Task ProcessResponseAsync(HttpClient client, HttpResponseMessage response, CancellationToken cancellationToken)
=> await Task.CompletedTask;
}
}

View File

@@ -1,7 +1,6 @@
namespace VisaApi
namespace VisaApi;
public static class Collections
{
public static class Collections
{
public const string ContextUsingTestCollection = "ContextUsingTestCollection";
}
}

View File

@@ -3,13 +3,13 @@ using Bogus;
using Domains;
using Domains.ApplicantDomain;
namespace VisaApi.Fakers.Applicants
namespace VisaApi.Fakers.Applicants;
/// <summary>
/// Generates applicants
/// </summary>
public sealed class ApplicantFaker : Faker<Applicant>
{
/// <summary>
/// Generates applicants
/// </summary>
public sealed class ApplicantFaker : Faker<Applicant>
{
public ApplicantFaker(IDateTimeProvider dateTimeProvider)
{
RuleFor(a => a.Citizenship, f => f.Address.Country());
@@ -62,5 +62,4 @@ namespace VisaApi.Fakers.Applicants
PhoneNum = f.Phone.PhoneNumber()
});
}
}
}

View File

@@ -1,10 +1,10 @@
using ApplicationLayer.Services.Applicants.Models;
using Bogus;
namespace VisaApi.Fakers.Applicants.Requests
namespace VisaApi.Fakers.Applicants.Requests;
public sealed class NameModelFaker : Faker<NameModel>
{
public sealed class NameModelFaker : Faker<NameModel>
{
public NameModelFaker()
{
RuleFor(m => m.FirstName, f => f.Name.FirstName());
@@ -13,5 +13,4 @@ namespace VisaApi.Fakers.Applicants.Requests
RuleFor(m => m.Patronymic, f => f.Name.FirstName());
}
}
}

View File

@@ -3,10 +3,10 @@ using ApplicationLayer.Services.Applicants.Models;
using Bogus;
using Domains;
namespace VisaApi.Fakers.Applicants.Requests
namespace VisaApi.Fakers.Applicants.Requests;
public sealed class PassportModelFaker : Faker<PassportModel>
{
public sealed class PassportModelFaker : Faker<PassportModel>
{
public PassportModelFaker(IDateTimeProvider dateTimeProvider)
{
RuleFor(m => m.Issuer, f => f.Company.CompanyName());
@@ -20,5 +20,4 @@ namespace VisaApi.Fakers.Applicants.Requests
RuleFor(m => m.IssueDate,
f => f.Date.Past(4, dateTimeProvider.Now()));
}
}
}

View File

@@ -2,10 +2,10 @@ using ApplicationLayer.Services.Applicants.Models;
using Bogus;
using Domains.ApplicantDomain;
namespace VisaApi.Fakers.Applicants.Requests
namespace VisaApi.Fakers.Applicants.Requests;
public sealed class PlaceOfWorkModelFaker : Faker<PlaceOfWorkModel>
{
public sealed class PlaceOfWorkModelFaker : Faker<PlaceOfWorkModel>
{
public PlaceOfWorkModelFaker()
{
RuleFor(m => m.Name, f => f.Company.CompanyName());
@@ -21,5 +21,4 @@ namespace VisaApi.Fakers.Applicants.Requests
Building = f.Address.BuildingNumber()
});
}
}
}

View File

@@ -1,15 +1,14 @@
using ApplicationLayer.Services.AuthServices.Common;
using Bogus;
namespace VisaApi.Fakers.Auth
namespace VisaApi.Fakers.Auth;
public sealed class AuthDataFaker : Faker<AuthData>
{
public sealed class AuthDataFaker : Faker<AuthData>
{
public AuthDataFaker()
{
RuleFor(a => a.Email, f => f.Internet.Email());
RuleFor(a => a.Password, f => f.Internet.Password());
}
}
}

View File

@@ -1,15 +1,14 @@
using ApplicationLayer.Services.AuthServices.Requests;
using Bogus;
namespace VisaApi.Fakers.Auth
namespace VisaApi.Fakers.Auth;
public sealed class RegisterRequestFaker : Faker<RegisterRequest>
{
public sealed class RegisterRequestFaker : Faker<RegisterRequest>
{
private static AuthDataFaker authDataFaker = new();
public RegisterRequestFaker()
{
RuleFor(r => r.AuthData, () => authDataFaker.Generate());
}
}
}

View File

@@ -1,15 +1,14 @@
using ApplicationLayer.Services.Users.Models;
using Bogus;
namespace VisaApi.Fakers.Common
namespace VisaApi.Fakers.Common;
public sealed class ChangeAuthDataFaker : Faker<ChangeAuthData>
{
public sealed class ChangeAuthDataFaker : Faker<ChangeAuthData>
{
public ChangeAuthDataFaker()
{
RuleFor(a => a.Email, f => f.Internet.Email());
RuleFor(a => a.Password, f => f.Internet.Password());
}
}
}

View File

@@ -2,15 +2,14 @@
using Bogus;
using VisaApi.Fakers.Common;
namespace VisaApi.Fakers.Users.Requests
namespace VisaApi.Fakers.Users.Requests;
public sealed class ChangeUserAuthDataRequestFaker : Faker<ChangeUserAuthDataRequest>
{
public sealed class ChangeUserAuthDataRequestFaker : Faker<ChangeUserAuthDataRequest>
{
private static ChangeAuthDataFaker changeAuthDataFaker = new();
public ChangeUserAuthDataRequestFaker()
{
CustomInstantiator(_ => new(Guid.NewGuid(), changeAuthDataFaker.Generate()));
}
}
}

View File

@@ -1,18 +1,17 @@
using Bogus;
using Domains.Users;
namespace VisaApi.Fakers.Users
namespace VisaApi.Fakers.Users;
/// <summary>
/// Generates users
/// </summary>
public sealed class UserFaker : Faker<User>
{
/// <summary>
/// Generates users
/// </summary>
public sealed class UserFaker : Faker<User>
{
public UserFaker()
{
RuleFor(u => u.Email, f => f.Internet.Email());
RuleFor(u => u.Password, f => f.Internet.Password());
}
}
}

View File

@@ -2,13 +2,13 @@
using Bogus;
using Domains.VisaApplicationDomain;
namespace VisaApi.Fakers.VisaApplications
namespace VisaApi.Fakers.VisaApplications;
/// <summary>
/// Generates past visas
/// </summary>
public sealed class PastVisaFaker : Faker<PastVisa>
{
/// <summary>
/// Generates past visas
/// </summary>
public sealed class PastVisaFaker : Faker<PastVisa>
{
private IDateTimeProvider dateTimeProvider;
public PastVisaFaker(IDateTimeProvider dateTimeProvider)
@@ -25,5 +25,4 @@ namespace VisaApi.Fakers.VisaApplications
result.ExpirationDate = result.IssueDate.AddDays(Random.Shared.Next(1, 11));
return result;
}
}
}

View File

@@ -2,13 +2,13 @@
using Bogus;
using Domains.VisaApplicationDomain;
namespace VisaApi.Fakers.VisaApplications
namespace VisaApi.Fakers.VisaApplications;
/// <summary>
/// Generates past visas
/// </summary>
public sealed class PastVisitFaker : Faker<PastVisit>
{
/// <summary>
/// Generates past visas
/// </summary>
public sealed class PastVisitFaker : Faker<PastVisit>
{
private IDateTimeProvider dateTimeProvider;
public PastVisitFaker(IDateTimeProvider dateTimeProvider)
@@ -25,5 +25,4 @@ namespace VisaApi.Fakers.VisaApplications
result.EndDate = result.StartDate.AddDays(Random.Shared.Next(1, 11));
return result;
}
}
}

View File

@@ -2,13 +2,13 @@
using Bogus;
using Domains.VisaApplicationDomain;
namespace VisaApi.Fakers.VisaApplications
namespace VisaApi.Fakers.VisaApplications;
/// <summary>
/// Generates permissions to destination Country
/// </summary>
public sealed class PermissionToDestCountryFaker : Faker<PermissionToDestCountry>
{
/// <summary>
/// Generates permissions to destination Country
/// </summary>
public sealed class PermissionToDestCountryFaker : Faker<PermissionToDestCountry>
{
public PermissionToDestCountryFaker(IDateTimeProvider dateTimeProvider)
{
RuleFor(p => p.Issuer, f => f.Company.CompanyName());
@@ -16,5 +16,4 @@ namespace VisaApi.Fakers.VisaApplications
RuleFor(p => p.ExpirationDate,
f => f.Date.Future(4, dateTimeProvider.Now()));
}
}
}

View File

@@ -3,13 +3,13 @@ using Bogus;
using Domains;
using Domains.VisaApplicationDomain;
namespace VisaApi.Fakers.VisaApplications
namespace VisaApi.Fakers.VisaApplications;
/// <summary>
/// Generates re-entry permissions
/// </summary>
public sealed class ReentryPermitFaker : Faker<ReentryPermit>
{
/// <summary>
/// Generates re-entry permissions
/// </summary>
public sealed class ReentryPermitFaker : Faker<ReentryPermit>
{
public ReentryPermitFaker(IDateTimeProvider dateTimeProvider)
{
RuleFor(p => p.Number,
@@ -18,5 +18,4 @@ namespace VisaApi.Fakers.VisaApplications
RuleFor(p => p.ExpirationDate,
f => f.Date.Future(4, dateTimeProvider.Now()));
}
}
}

View File

@@ -4,13 +4,13 @@ using Domains;
using Domains.ApplicantDomain;
using Domains.VisaApplicationDomain;
namespace VisaApi.Fakers.VisaApplications
namespace VisaApi.Fakers.VisaApplications;
/// <summary>
/// Generates visa applications
/// </summary>
public sealed class VisaApplicationFaker : Faker<VisaApplication>
{
/// <summary>
/// Generates visa applications
/// </summary>
public sealed class VisaApplicationFaker : Faker<VisaApplication>
{
private static ReentryPermitFaker reentryPermitFaker = null!;
private static PermissionToDestCountryFaker permissionToDestCountryFaker = null!;
@@ -61,5 +61,4 @@ namespace VisaApi.Fakers.VisaApplications
return result;
}
}
}

View File

@@ -1,9 +1,8 @@
using ApplicationLayer.InfrastructureServicesInterfaces;
namespace VisaApi.Services
namespace VisaApi.Services;
public class TestDateTimeProvider : IDateTimeProvider
{
public class TestDateTimeProvider : IDateTimeProvider
{
public DateTime Now() => DateTime.Now;
}
}

View File

@@ -7,12 +7,12 @@ using FluentValidation;
using VisaApi.Fakers.Applicants.Requests;
using Xunit;
namespace VisaApi.Tests.Application.Validation.Applicants
namespace VisaApi.Tests.Application.Validation.Applicants;
public class NameModelValidatorTests
{
public class NameModelValidatorTests
{
private static IValidator<NameModel> validator = new NameModelValidator();
private static NameModelFaker faker = new();
private readonly static IValidator<NameModel> validator = new NameModelValidator();
private readonly static NameModelFaker faker = new();
/// <summary>
/// Test for <see cref="NameModel"/> validator that should throw for empty first name
@@ -167,5 +167,4 @@ namespace VisaApi.Tests.Application.Validation.Applicants
result.Errors.Should().BeEmpty();
}
}
}

View File

@@ -9,13 +9,13 @@ using VisaApi.Fakers.Applicants.Requests;
using VisaApi.Services;
using Xunit;
namespace VisaApi.Tests.Application.Validation.Applicants
namespace VisaApi.Tests.Application.Validation.Applicants;
public class PassportModelValidatorTests
{
public class PassportModelValidatorTests
{
private static IDateTimeProvider dateTimeProvider = new TestDateTimeProvider();
private static IValidator<PassportModel> validator = new PassportModelValidator(dateTimeProvider);
private static PassportModelFaker faker = new(dateTimeProvider);
private readonly static IDateTimeProvider dateTimeProvider = new TestDateTimeProvider();
private readonly static IValidator<PassportModel> validator = new PassportModelValidator(dateTimeProvider);
private readonly static PassportModelFaker faker = new(dateTimeProvider);
/// <summary>
/// Test for <see cref="PassportModel"/> validator that should return error for empty number
@@ -171,5 +171,4 @@ namespace VisaApi.Tests.Application.Validation.Applicants
result.Errors.Should().BeEmpty();
}
}
}

View File

@@ -7,12 +7,12 @@ using FluentValidation;
using VisaApi.Fakers.Applicants.Requests;
using Xunit;
namespace VisaApi.Tests.Application.Validation.Applicants
namespace VisaApi.Tests.Application.Validation.Applicants;
public class PlaceOfWorkModelValidatorTests
{
public class PlaceOfWorkModelValidatorTests
{
private static IValidator<PlaceOfWorkModel> validator = new PlaceOfWorkModelValidator();
private static PlaceOfWorkModelFaker faker = new();
private readonly static IValidator<PlaceOfWorkModel> validator = new PlaceOfWorkModelValidator();
private readonly static PlaceOfWorkModelFaker faker = new();
/// <summary>
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for empty phone num
@@ -350,5 +350,4 @@ namespace VisaApi.Tests.Application.Validation.Applicants
result.Errors.Should().BeEmpty();
}
}
}

View File

@@ -7,10 +7,10 @@ using FluentValidation;
using VisaApi.Fakers.Auth;
using Xunit;
namespace VisaApi.Tests.Application.Validation.Auth
namespace VisaApi.Tests.Application.Validation.Auth;
public class AuthDataValidatorTests
{
public class AuthDataValidatorTests
{
private readonly static IValidator<AuthData> validator = new AuthDataValidator();
private readonly static AuthDataFaker faker = new();
@@ -110,5 +110,4 @@ namespace VisaApi.Tests.Application.Validation.Auth
result.Errors.Where(error => error.PropertyName == nameof(authData.Password))
.Should().BeEmpty();
}
}
}

View File

@@ -11,11 +11,11 @@ using VisaApi.Fakers.Users;
using VisaApi.Tests.Infrastructure.Database;
using Xunit;
namespace VisaApi.Tests.Application.Validation.Auth
namespace VisaApi.Tests.Application.Validation.Auth;
[Collection(Collections.ContextUsingTestCollection)]
public class RegisterRequestValidatorTests
{
[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();
@@ -90,5 +90,4 @@ namespace VisaApi.Tests.Application.Validation.Auth
result.Errors.Should().BeEmpty();
}
}
}

View File

@@ -5,10 +5,10 @@ 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();
@@ -45,5 +45,4 @@ namespace VisaApi.Tests.Application.Validation.Users
result.IsValid.Should().BeTrue();
}
}
}

View File

@@ -2,10 +2,10 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using DbContext = Infrastructure.Database.DbContext;
namespace VisaApi.Tests.Infrastructure.Database
namespace VisaApi.Tests.Infrastructure.Database;
public static class InMemoryContextProvider
{
public static class InMemoryContextProvider
{
private static DbContextOptions<DbContext> opts = new DbContextOptionsBuilder<DbContext>()
.UseInMemoryDatabase("VisaApiDB")
.ConfigureWarnings(b => b.Ignore(InMemoryEventId.TransactionIgnoredWarning))
@@ -20,5 +20,4 @@ namespace VisaApi.Tests.Infrastructure.Database
return result;
}
}
}

View File

@@ -9,11 +9,11 @@ using VisaApi.Fakers.Users;
using VisaApi.Services;
using Xunit;
namespace VisaApi.Tests.Infrastructure.Database.Repositories
namespace VisaApi.Tests.Infrastructure.Database.Repositories;
[Collection(Collections.ContextUsingTestCollection)]
public class ApplicantsRepositoryTests
{
[Collection(Collections.ContextUsingTestCollection)]
public class ApplicantsRepositoryTests
{
private readonly static UserFaker userFaker = new();
private readonly static ApplicantFaker applicantFaker = new(GetDateTimeProvider());
@@ -151,5 +151,4 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
result.Should().Be(applicant.IsNonResident);
}
}
}

View File

@@ -1,7 +1,6 @@
using Domains.Users;
using Infrastructure.Database.Generic;
namespace VisaApi.Tests.Infrastructure.Database.Repositories.Generic
{
public class TestGenericRepository(IGenericReader reader, IGenericWriter writer) : GenericRepository<User>(reader, writer);
}
namespace VisaApi.Tests.Infrastructure.Database.Repositories.Generic;
public class TestGenericRepository(IGenericReader reader, IGenericWriter writer) : GenericRepository<User>(reader, writer);

View File

@@ -7,11 +7,11 @@ using Infrastructure.Database.Users.Repositories;
using VisaApi.Fakers.Users;
using Xunit;
namespace VisaApi.Tests.Infrastructure.Database.Repositories
namespace VisaApi.Tests.Infrastructure.Database.Repositories;
[Collection(Collections.ContextUsingTestCollection)]
public class UsersRepositoryTests
{
[Collection(Collections.ContextUsingTestCollection)]
public class UsersRepositoryTests
{
private readonly static UserFaker userFaker = new();
/// <summary> Returns <see cref="IVisaApplicationsRepository"/> </summary>
@@ -88,5 +88,4 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
result.Should().Contain(users).And.HaveSameCount(users);
}
}
}

View File

@@ -11,11 +11,11 @@ using VisaApi.Fakers.VisaApplications;
using VisaApi.Services;
using Xunit;
namespace VisaApi.Tests.Infrastructure.Database.Repositories
namespace VisaApi.Tests.Infrastructure.Database.Repositories;
[Collection(Collections.ContextUsingTestCollection)]
public class VisaApplicationsRepositoryTests
{
[Collection(Collections.ContextUsingTestCollection)]
public class VisaApplicationsRepositoryTests
{
private readonly static UserFaker userFaker = new();
private readonly static ApplicantFaker applicantFaker = new(GetDateTimeProvider());
private readonly static VisaApplicationFaker applicationFaker = new(GetDateTimeProvider());
@@ -262,5 +262,4 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
result.Should().Contain(applicationPending).And.HaveCount(1);
}
}
}