refactor (readonly for static objects in tests and file-scoped namespaces
This commit is contained in:
@@ -1,13 +1,12 @@
|
|||||||
using System.Text.RegularExpressions;
|
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 EnglishWordRegex = new("^[a-zA-Z]*$");
|
|
||||||
|
|
||||||
public readonly static Regex EnglishPhraseRegex = new(@"^[a-zA-Z №0-9;,\-_+=#*']*$");
|
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}$");
|
public readonly static Regex PhoneNumRegex = new(@"^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
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!;
|
||||||
{
|
}
|
||||||
[Required] public string Token { get; set; } = null!;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +1,15 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using Domains;
|
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
|
|
||||||
{
|
|
||||||
[Required]
|
|
||||||
[MaxLength(ConfigurationConstraints.EmailLength)]
|
|
||||||
public string Email { get; set; } = null!;
|
|
||||||
|
|
||||||
[MaxLength(ConfigurationConstraints.PasswordLength)]
|
/// Auth data with nullable password for making change auth data requests
|
||||||
public string? Password { get; set; }
|
public class ChangeAuthData
|
||||||
}
|
{
|
||||||
}
|
[Required]
|
||||||
|
[MaxLength(ConfigurationConstraints.EmailLength)]
|
||||||
|
public string Email { get; set; } = null!;
|
||||||
|
|
||||||
|
[MaxLength(ConfigurationConstraints.PasswordLength)]
|
||||||
|
public string? Password { get; set; }
|
||||||
|
}
|
||||||
@@ -1,16 +1,15 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using Domains;
|
using Domains;
|
||||||
|
|
||||||
namespace ApplicationLayer.Services.Users.Models
|
namespace ApplicationLayer.Services.Users.Models;
|
||||||
{
|
|
||||||
public class UserModel
|
|
||||||
{
|
|
||||||
/// Unique Identifier of user
|
|
||||||
[Required]
|
|
||||||
public Guid Id { get; private set; } = Guid.NewGuid();
|
|
||||||
|
|
||||||
[Required]
|
public class UserModel
|
||||||
[MaxLength(ConfigurationConstraints.EmailLength)]
|
{
|
||||||
public string Email { get; set; } = null!;
|
/// Unique Identifier of user
|
||||||
}
|
[Required]
|
||||||
}
|
public Guid Id { get; private set; } = Guid.NewGuid();
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[MaxLength(ConfigurationConstraints.EmailLength)]
|
||||||
|
public string Email { get; set; } = null!;
|
||||||
|
}
|
||||||
@@ -1,24 +1,23 @@
|
|||||||
using Domains;
|
using Domains;
|
||||||
using FluentValidation;
|
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()
|
||||||
{
|
{
|
||||||
public ChangeUserAuthDataRequestValidator()
|
RuleFor(r => r.UserId)
|
||||||
{
|
.NotEmpty();
|
||||||
RuleFor(r => r.UserId)
|
|
||||||
.NotEmpty();
|
|
||||||
|
|
||||||
RuleFor(r => r.NewAuthData)
|
RuleFor(r => r.NewAuthData)
|
||||||
.NotEmpty();
|
.NotEmpty();
|
||||||
|
|
||||||
RuleFor(r => r.NewAuthData.Email)
|
RuleFor(r => r.NewAuthData.Email)
|
||||||
.NotEmpty()
|
.NotEmpty()
|
||||||
.EmailAddress()
|
.EmailAddress()
|
||||||
.WithMessage("Email should be valid")
|
.WithMessage("Email should be valid")
|
||||||
.MaximumLength(ConfigurationConstraints.EmailLength)
|
.MaximumLength(ConfigurationConstraints.EmailLength)
|
||||||
.WithMessage($"Email address length must be less than {ConfigurationConstraints.EmailLength}");
|
.WithMessage($"Email address length must be less than {ConfigurationConstraints.EmailLength}");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
namespace BlazorWebAssemblyVisaApiClient.Common.Exceptions
|
namespace BlazorWebAssemblyVisaApiClient.Common.Exceptions;
|
||||||
{
|
|
||||||
public class BlazorClientException(string message) : Exception(message);
|
public class BlazorClientException(string message) : Exception(message);
|
||||||
}
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
namespace BlazorWebAssemblyVisaApiClient.Common.Exceptions
|
namespace BlazorWebAssemblyVisaApiClient.Common.Exceptions;
|
||||||
{
|
|
||||||
public class NotLoggedInException() : BlazorClientException("User is not logged in.");
|
public class NotLoggedInException() : BlazorClientException("User is not logged in.");
|
||||||
}
|
|
||||||
@@ -1,20 +1,19 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Microsoft.AspNetCore.Components;
|
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 EnglishWordRegex = new("^[a-zA-Z]*$");
|
|
||||||
|
|
||||||
public readonly static Regex EnglishPhraseRegex = new(@"^[a-z A-Z№0-9?><;,{}[\]\-_+=!@#$%\^&*|']*$");
|
public readonly static Regex EnglishPhraseRegex = new(@"^[a-z A-Z№0-9?><;,{}[\]\-_+=!@#$%\^&*|']*$");
|
||||||
|
|
||||||
public readonly static Regex PhoneNumRegex = new(@"^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$");
|
public readonly static Regex PhoneNumRegex = new(@"^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$");
|
||||||
|
|
||||||
public readonly static MarkupString RequiredFieldMarkup = (MarkupString)"<span style=\"color: red;\">*</span>";
|
public readonly static MarkupString RequiredFieldMarkup = (MarkupString)"<span style=\"color: red;\">*</span>";
|
||||||
|
|
||||||
public const string ApplicantRole = "Applicant";
|
public const string ApplicantRole = "Applicant";
|
||||||
public const string ApprovingAuthorityRole = "ApprovingAuthority";
|
public const string ApprovingAuthorityRole = "ApprovingAuthority";
|
||||||
public const string AdminRole = "Admin";
|
public const string AdminRole = "Admin";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -3,17 +3,16 @@ using BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models;
|
|||||||
using VisaApiClient;
|
using VisaApiClient;
|
||||||
using PlaceOfWorkModel = BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models.PlaceOfWorkModel;
|
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()
|
||||||
{
|
{
|
||||||
public RegisterApplicantRequestProfile()
|
|
||||||
{
|
|
||||||
CreateMap<RegisterApplicantRequestModel, RegisterApplicantRequest>(MemberList.Destination);
|
CreateMap<RegisterApplicantRequestModel, RegisterApplicantRequest>(MemberList.Destination);
|
||||||
|
|
||||||
CreateMap<RegisterRequestModel, RegisterRequest>(MemberList.Destination);
|
CreateMap<RegisterRequestModel, RegisterRequest>(MemberList.Destination);
|
||||||
|
|
||||||
CreateMap<PlaceOfWorkModel, VisaApiClient.PlaceOfWorkModel>(MemberList.Destination);
|
CreateMap<PlaceOfWorkModel, VisaApiClient.PlaceOfWorkModel>(MemberList.Destination);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -2,13 +2,12 @@
|
|||||||
using BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Models;
|
using BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Models;
|
||||||
using VisaApiClient;
|
using VisaApiClient;
|
||||||
|
|
||||||
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.AutoMapper.Profiles
|
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.AutoMapper.Profiles;
|
||||||
|
|
||||||
|
public class VisaApplicationCreateRequestProfile : Profile
|
||||||
{
|
{
|
||||||
public class VisaApplicationCreateRequestProfile : Profile
|
public VisaApplicationCreateRequestProfile()
|
||||||
{
|
{
|
||||||
public VisaApplicationCreateRequestProfile()
|
|
||||||
{
|
|
||||||
CreateMap<VisaApplicationCreateRequestModel, VisaApplicationCreateRequest>(MemberList.Destination);
|
CreateMap<VisaApplicationCreateRequestModel, VisaApplicationCreateRequest>(MemberList.Destination);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
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)
|
||||||
{
|
{
|
||||||
public static string GetDisplayName(this Enum value)
|
|
||||||
{
|
|
||||||
var enumMembers = value.GetType().GetMembers();
|
var enumMembers = value.GetType().GetMembers();
|
||||||
var member = enumMembers.First(info => info.Name == value.ToString());
|
var member = enumMembers.First(info => info.Name == value.ToString());
|
||||||
var displayAttribute = (DisplayAttribute?)member
|
var displayAttribute = (DisplayAttribute?)member
|
||||||
@@ -14,5 +14,4 @@ namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers
|
|||||||
var displayName = displayAttribute?.Name ?? value.ToString();
|
var displayName = displayAttribute?.Name ?? value.ToString();
|
||||||
return displayName;
|
return displayName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using FluentValidation.Results;
|
using FluentValidation.Results;
|
||||||
|
|
||||||
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers
|
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers;
|
||||||
{
|
|
||||||
public static class ValidationResultExtensions
|
|
||||||
{
|
|
||||||
public static string ToErrorsString(this ValidationResult validationResult)
|
|
||||||
=> ErrorsToString(validationResult.Errors.Select(e => e.ErrorMessage));
|
|
||||||
|
|
||||||
private static string ErrorsToString(IEnumerable<string> errors)
|
public static class ValidationResultExtensions
|
||||||
{
|
{
|
||||||
|
public static string ToErrorsString(this ValidationResult validationResult)
|
||||||
|
=> ErrorsToString(validationResult.Errors.Select(e => e.ErrorMessage));
|
||||||
|
|
||||||
|
private static string ErrorsToString(IEnumerable<string> errors)
|
||||||
|
{
|
||||||
var stringBuilder = new StringBuilder();
|
var stringBuilder = new StringBuilder();
|
||||||
foreach (var error in errors)
|
foreach (var error in errors)
|
||||||
{
|
{
|
||||||
@@ -18,5 +18,4 @@ namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers
|
|||||||
|
|
||||||
return stringBuilder.ToString();
|
return stringBuilder.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider
|
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider;
|
||||||
{
|
|
||||||
public class DateTimeProvider : IDateTimeProvider
|
|
||||||
{
|
|
||||||
public DateTime Now() => DateTime.Now;
|
|
||||||
|
|
||||||
public string FormattedNow() => Now().ToString("yyyy-MM-dd");
|
public class DateTimeProvider : IDateTimeProvider
|
||||||
}
|
{
|
||||||
}
|
public DateTime Now() => DateTime.Now;
|
||||||
|
|
||||||
|
public string FormattedNow() => Now().ToString("yyyy-MM-dd");
|
||||||
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider
|
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider;
|
||||||
{
|
|
||||||
public interface IDateTimeProvider
|
|
||||||
{
|
|
||||||
DateTime Now();
|
|
||||||
|
|
||||||
string FormattedNow();
|
public interface IDateTimeProvider
|
||||||
}
|
{
|
||||||
}
|
DateTime Now();
|
||||||
|
|
||||||
|
string FormattedNow();
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
using BlazorWebAssemblyVisaApiClient.Common.Exceptions;
|
using BlazorWebAssemblyVisaApiClient.Common.Exceptions;
|
||||||
|
|
||||||
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider.Exceptions
|
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider.Exceptions;
|
||||||
{
|
|
||||||
public class UnknownRoleException() : BlazorClientException("Unknown user role");
|
public class UnknownRoleException() : BlazorClientException("Unknown user role");
|
||||||
}
|
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
using VisaApiClient;
|
using VisaApiClient;
|
||||||
|
|
||||||
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider
|
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider;
|
||||||
|
|
||||||
|
public interface IUserDataProvider
|
||||||
{
|
{
|
||||||
public interface IUserDataProvider
|
public string? CurrentRole { get; }
|
||||||
{
|
|
||||||
public string? CurrentRole { get; }
|
|
||||||
|
|
||||||
public Action? OnRoleChanged { get; set; }
|
public Action? OnRoleChanged { get; set; }
|
||||||
|
|
||||||
public Task<ApplicantModel> GetApplicant();
|
public Task<ApplicantModel> GetApplicant();
|
||||||
|
|
||||||
public void UpdateCurrentRole();
|
public void UpdateCurrentRole();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -3,23 +3,23 @@ using System.Security.Claims;
|
|||||||
using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider.Exceptions;
|
using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider.Exceptions;
|
||||||
using VisaApiClient;
|
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; }
|
||||||
|
|
||||||
|
public Action? OnRoleChanged { get; set; }
|
||||||
|
|
||||||
|
public async Task<ApplicantModel> GetApplicant()
|
||||||
{
|
{
|
||||||
private readonly static JwtSecurityTokenHandler tokenHandler = new();
|
|
||||||
|
|
||||||
public string? CurrentRole { get; private set; }
|
|
||||||
|
|
||||||
public Action? OnRoleChanged { get; set; }
|
|
||||||
|
|
||||||
public async Task<ApplicantModel> GetApplicant()
|
|
||||||
{
|
|
||||||
return await client.GetApplicantAsync();
|
return await client.GetApplicantAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateCurrentRole()
|
public void UpdateCurrentRole()
|
||||||
{
|
{
|
||||||
var role = CurrentRole;
|
var role = CurrentRole;
|
||||||
|
|
||||||
if (client.AuthToken is null)
|
if (client.AuthToken is null)
|
||||||
@@ -49,5 +49,4 @@ namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvide
|
|||||||
OnRoleChanged?.Invoke();
|
OnRoleChanged?.Invoke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,21 +1,20 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using VisaApiClient;
|
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
|
[Required]
|
||||||
public class PlaceOfWorkModel
|
[StringLength(ConfigurationConstraints.PlaceOfWorkNameLength, MinimumLength = 1)]
|
||||||
{
|
public string Name { get; set; } = default!;
|
||||||
[Required]
|
|
||||||
[StringLength(ConfigurationConstraints.PlaceOfWorkNameLength, MinimumLength = 1)]
|
|
||||||
public string Name { get; set; } = default!;
|
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[ValidateComplexType]
|
[ValidateComplexType]
|
||||||
public AddressModel Address { get; set; } = new AddressModel();
|
public AddressModel Address { get; set; } = new AddressModel();
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[StringLength(ConfigurationConstraints.PhoneNumberLength, MinimumLength = ConfigurationConstraints.PhoneNumberMinLength)]
|
[StringLength(ConfigurationConstraints.PhoneNumberLength, MinimumLength = ConfigurationConstraints.PhoneNumberMinLength)]
|
||||||
public string PhoneNum { get; set; } = default!;
|
public string PhoneNum { get; set; } = default!;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -3,66 +3,65 @@ using Newtonsoft.Json;
|
|||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
using VisaApiClient;
|
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
|
[Required]
|
||||||
public class RegisterApplicantRequestModel
|
[ValidateComplexType]
|
||||||
{
|
public RegisterRequestModel RegisterRequest { get; set; } = new();
|
||||||
[Required]
|
|
||||||
[ValidateComplexType]
|
|
||||||
public RegisterRequestModel RegisterRequest { get; set; } = new();
|
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[ValidateComplexType]
|
[ValidateComplexType]
|
||||||
public NameModel ApplicantName { get; set; } = new();
|
public NameModel ApplicantName { get; set; } = new();
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[ValidateComplexType]
|
[ValidateComplexType]
|
||||||
public PassportModel Passport { get; set; } = new();
|
public PassportModel Passport { get; set; } = new();
|
||||||
|
|
||||||
[Required(AllowEmptyStrings = true)]
|
[Required(AllowEmptyStrings = true)]
|
||||||
public DateTimeOffset BirthDate { get; set; }
|
public DateTimeOffset BirthDate { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[StringLength(70, MinimumLength = 1)]
|
[StringLength(70, MinimumLength = 1)]
|
||||||
public string CityOfBirth { get; set; } = default!;
|
public string CityOfBirth { get; set; } = default!;
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[StringLength(70, MinimumLength = 1)]
|
[StringLength(70, MinimumLength = 1)]
|
||||||
public string CountryOfBirth { get; set; } = default!;
|
public string CountryOfBirth { get; set; } = default!;
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[StringLength(30, MinimumLength = 1)]
|
[StringLength(30, MinimumLength = 1)]
|
||||||
public string Citizenship { get; set; } = default!;
|
public string Citizenship { get; set; } = default!;
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[StringLength(30, MinimumLength = 1)]
|
[StringLength(30, MinimumLength = 1)]
|
||||||
public string CitizenshipByBirth { get; set; } = default!;
|
public string CitizenshipByBirth { get; set; } = default!;
|
||||||
|
|
||||||
[Required(AllowEmptyStrings = true)]
|
[Required(AllowEmptyStrings = true)]
|
||||||
[JsonConverter(typeof(StringEnumConverter))]
|
[JsonConverter(typeof(StringEnumConverter))]
|
||||||
public Gender Gender { get; set; }
|
public Gender Gender { get; set; }
|
||||||
|
|
||||||
[Required(AllowEmptyStrings = true)]
|
[Required(AllowEmptyStrings = true)]
|
||||||
[JsonConverter(typeof(StringEnumConverter))]
|
[JsonConverter(typeof(StringEnumConverter))]
|
||||||
public MaritalStatus MaritalStatus { get; set; }
|
public MaritalStatus MaritalStatus { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[ValidateComplexType]
|
[ValidateComplexType]
|
||||||
public NameModel FatherName { get; set; } = new();
|
public NameModel FatherName { get; set; } = new();
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[ValidateComplexType]
|
[ValidateComplexType]
|
||||||
public NameModel MotherName { get; set; } = new();
|
public NameModel MotherName { get; set; } = new();
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[StringLength(50, MinimumLength = 1)]
|
[StringLength(50, MinimumLength = 1)]
|
||||||
public string JobTitle { get; set; } = default!;
|
public string JobTitle { get; set; } = default!;
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[ValidateComplexType]
|
[ValidateComplexType]
|
||||||
public PlaceOfWorkModel PlaceOfWork { get; set; } = new();
|
public PlaceOfWorkModel PlaceOfWork { get; set; } = new();
|
||||||
|
|
||||||
public bool IsNonResident { get; set; }
|
public bool IsNonResident { get; set; }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using VisaApiClient;
|
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
|
[Required]
|
||||||
public class RegisterRequestModel
|
[ValidateComplexType]
|
||||||
{
|
public AuthData AuthData { get; set; } = new AuthData();
|
||||||
[Required]
|
}
|
||||||
[ValidateComplexType]
|
|
||||||
public AuthData AuthData { get; set; } = new AuthData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
using VisaApiClient;
|
using VisaApiClient;
|
||||||
|
|
||||||
namespace BlazorWebAssemblyVisaApiClient.Validation.Auth
|
namespace BlazorWebAssemblyVisaApiClient.Validation.Auth;
|
||||||
|
|
||||||
|
public class ChangeUserAuthDataRequestValidator : AbstractValidator<ChangeUserAuthDataRequest>
|
||||||
{
|
{
|
||||||
public class ChangeUserAuthDataRequestValidator : AbstractValidator<ChangeUserAuthDataRequest>
|
public ChangeUserAuthDataRequestValidator()
|
||||||
{
|
{
|
||||||
public ChangeUserAuthDataRequestValidator()
|
|
||||||
{
|
|
||||||
RuleFor(r => r.NewAuthData)
|
RuleFor(r => r.NewAuthData)
|
||||||
.NotEmpty();
|
.NotEmpty();
|
||||||
|
|
||||||
@@ -17,5 +17,4 @@ namespace BlazorWebAssemblyVisaApiClient.Validation.Auth
|
|||||||
.MaximumLength(ConfigurationConstraints.EmailLength)
|
.MaximumLength(ConfigurationConstraints.EmailLength)
|
||||||
.WithMessage($"Email address length must be less than {ConfigurationConstraints.EmailLength}");
|
.WithMessage($"Email address length must be less than {ConfigurationConstraints.EmailLength}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,38 +1,37 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using VisaApiClient;
|
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
|
[ValidateComplexType]
|
||||||
public class VisaApplicationCreateRequestModel
|
public ReentryPermitModel? ReentryPermit { get; set; } = default!;
|
||||||
{
|
|
||||||
[ValidateComplexType]
|
|
||||||
public ReentryPermitModel? ReentryPermit { get; set; } = default!;
|
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[MaxLength(ConfigurationConstraints.CountryNameLength)]
|
[MaxLength(ConfigurationConstraints.CountryNameLength)]
|
||||||
public string DestinationCountry { get; set; } = default!;
|
public string DestinationCountry { get; set; } = default!;
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public VisaCategory VisaCategory { get; set; }
|
public VisaCategory VisaCategory { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public bool IsForGroup { get; set; }
|
public bool IsForGroup { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public RequestedNumberOfEntries RequestedNumberOfEntries { get; set; }
|
public RequestedNumberOfEntries RequestedNumberOfEntries { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[Range(0, ConfigurationConstraints.MaxValidDays)]
|
[Range(0, ConfigurationConstraints.MaxValidDays)]
|
||||||
public int ValidDaysRequested { get; set; }
|
public int ValidDaysRequested { get; set; }
|
||||||
|
|
||||||
[ValidateComplexType]
|
[ValidateComplexType]
|
||||||
public List<PastVisaModel> PastVisas { get; set; } = [];
|
public List<PastVisaModel> PastVisas { get; set; } = [];
|
||||||
|
|
||||||
[ValidateComplexType]
|
[ValidateComplexType]
|
||||||
public PermissionToDestCountryModel? PermissionToDestCountry { get; set; } = default!;
|
public PermissionToDestCountryModel? PermissionToDestCountry { get; set; } = default!;
|
||||||
|
|
||||||
[ValidateComplexType]
|
[ValidateComplexType]
|
||||||
public List<PastVisitModel> PastVisits { get; set; } = [];
|
public List<PastVisitModel> PastVisits { get; set; } = [];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace VisaApiClient
|
namespace VisaApiClient;
|
||||||
{
|
|
||||||
public class ClientBase
|
|
||||||
{
|
|
||||||
public AuthToken? AuthToken { get; set; }
|
|
||||||
|
|
||||||
protected Task<HttpRequestMessage> CreateHttpRequestMessageAsync(CancellationToken cancellationToken)
|
public class ClientBase
|
||||||
{
|
{
|
||||||
|
public AuthToken? AuthToken { get; set; }
|
||||||
|
|
||||||
|
protected Task<HttpRequestMessage> CreateHttpRequestMessageAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
var msg = new HttpRequestMessage();
|
var msg = new HttpRequestMessage();
|
||||||
|
|
||||||
msg.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", AuthToken?.Token);
|
msg.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", AuthToken?.Token);
|
||||||
@@ -16,15 +16,14 @@ namespace VisaApiClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected async Task PrepareRequestAsync(HttpClient client, HttpRequestMessage request, string url, CancellationToken cancellationToken)
|
protected async Task PrepareRequestAsync(HttpClient client, HttpRequestMessage request, string url, CancellationToken cancellationToken)
|
||||||
=> await Task.CompletedTask;
|
=> await Task.CompletedTask;
|
||||||
|
|
||||||
protected async Task PrepareRequestAsync(HttpClient client, HttpRequestMessage request, StringBuilder urlBuilder, CancellationToken cancellationToken)
|
protected async Task PrepareRequestAsync(HttpClient client, HttpRequestMessage request, StringBuilder urlBuilder, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
await Task.CompletedTask;
|
await Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async Task ProcessResponseAsync(HttpClient client, HttpResponseMessage response, CancellationToken cancellationToken)
|
protected async Task ProcessResponseAsync(HttpClient client, HttpResponseMessage response, CancellationToken cancellationToken)
|
||||||
=> await Task.CompletedTask;
|
=> await Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
namespace VisaApi
|
namespace VisaApi;
|
||||||
|
|
||||||
|
public static class Collections
|
||||||
{
|
{
|
||||||
public static class Collections
|
public const string ContextUsingTestCollection = "ContextUsingTestCollection";
|
||||||
{
|
}
|
||||||
public const string ContextUsingTestCollection = "ContextUsingTestCollection";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,15 +3,15 @@ using Bogus;
|
|||||||
using Domains;
|
using Domains;
|
||||||
using Domains.ApplicantDomain;
|
using Domains.ApplicantDomain;
|
||||||
|
|
||||||
namespace VisaApi.Fakers.Applicants
|
namespace VisaApi.Fakers.Applicants;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates applicants
|
||||||
|
/// </summary>
|
||||||
|
public sealed class ApplicantFaker : Faker<Applicant>
|
||||||
{
|
{
|
||||||
/// <summary>
|
public ApplicantFaker(IDateTimeProvider dateTimeProvider)
|
||||||
/// Generates applicants
|
|
||||||
/// </summary>
|
|
||||||
public sealed class ApplicantFaker : Faker<Applicant>
|
|
||||||
{
|
{
|
||||||
public ApplicantFaker(IDateTimeProvider dateTimeProvider)
|
|
||||||
{
|
|
||||||
RuleFor(a => a.Citizenship, f => f.Address.Country());
|
RuleFor(a => a.Citizenship, f => f.Address.Country());
|
||||||
|
|
||||||
RuleFor(a => a.Gender, f => f.Random.Enum<Gender>());
|
RuleFor(a => a.Gender, f => f.Random.Enum<Gender>());
|
||||||
@@ -62,5 +62,4 @@ namespace VisaApi.Fakers.Applicants
|
|||||||
PhoneNum = f.Phone.PhoneNumber()
|
PhoneNum = f.Phone.PhoneNumber()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,17 +1,16 @@
|
|||||||
using ApplicationLayer.Services.Applicants.Models;
|
using ApplicationLayer.Services.Applicants.Models;
|
||||||
using Bogus;
|
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()
|
||||||
{
|
{
|
||||||
public NameModelFaker()
|
|
||||||
{
|
|
||||||
RuleFor(m => m.FirstName, f => f.Name.FirstName());
|
RuleFor(m => m.FirstName, f => f.Name.FirstName());
|
||||||
|
|
||||||
RuleFor(m => m.Surname, f => f.Name.LastName());
|
RuleFor(m => m.Surname, f => f.Name.LastName());
|
||||||
|
|
||||||
RuleFor(m => m.Patronymic, f => f.Name.FirstName());
|
RuleFor(m => m.Patronymic, f => f.Name.FirstName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -3,12 +3,12 @@ using ApplicationLayer.Services.Applicants.Models;
|
|||||||
using Bogus;
|
using Bogus;
|
||||||
using Domains;
|
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)
|
||||||
{
|
{
|
||||||
public PassportModelFaker(IDateTimeProvider dateTimeProvider)
|
|
||||||
{
|
|
||||||
RuleFor(m => m.Issuer, f => f.Company.CompanyName());
|
RuleFor(m => m.Issuer, f => f.Company.CompanyName());
|
||||||
|
|
||||||
RuleFor(m => m.Number,
|
RuleFor(m => m.Number,
|
||||||
@@ -20,5 +20,4 @@ namespace VisaApi.Fakers.Applicants.Requests
|
|||||||
RuleFor(m => m.IssueDate,
|
RuleFor(m => m.IssueDate,
|
||||||
f => f.Date.Past(4, dateTimeProvider.Now()));
|
f => f.Date.Past(4, dateTimeProvider.Now()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -2,12 +2,12 @@ using ApplicationLayer.Services.Applicants.Models;
|
|||||||
using Bogus;
|
using Bogus;
|
||||||
using Domains.ApplicantDomain;
|
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()
|
||||||
{
|
{
|
||||||
public PlaceOfWorkModelFaker()
|
|
||||||
{
|
|
||||||
RuleFor(m => m.Name, f => f.Company.CompanyName());
|
RuleFor(m => m.Name, f => f.Company.CompanyName());
|
||||||
|
|
||||||
RuleFor(m => m.PhoneNum, f => f.Phone.PhoneNumber("###########"));
|
RuleFor(m => m.PhoneNum, f => f.Phone.PhoneNumber("###########"));
|
||||||
@@ -21,5 +21,4 @@ namespace VisaApi.Fakers.Applicants.Requests
|
|||||||
Building = f.Address.BuildingNumber()
|
Building = f.Address.BuildingNumber()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
using ApplicationLayer.Services.AuthServices.Common;
|
using ApplicationLayer.Services.AuthServices.Common;
|
||||||
using Bogus;
|
using Bogus;
|
||||||
|
|
||||||
namespace VisaApi.Fakers.Auth
|
namespace VisaApi.Fakers.Auth;
|
||||||
|
|
||||||
|
public sealed class AuthDataFaker : Faker<AuthData>
|
||||||
{
|
{
|
||||||
public sealed class AuthDataFaker : Faker<AuthData>
|
public AuthDataFaker()
|
||||||
{
|
{
|
||||||
public AuthDataFaker()
|
|
||||||
{
|
|
||||||
RuleFor(a => a.Email, f => f.Internet.Email());
|
RuleFor(a => a.Email, f => f.Internet.Email());
|
||||||
|
|
||||||
RuleFor(a => a.Password, f => f.Internet.Password());
|
RuleFor(a => a.Password, f => f.Internet.Password());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
using ApplicationLayer.Services.AuthServices.Requests;
|
using ApplicationLayer.Services.AuthServices.Requests;
|
||||||
using Bogus;
|
using Bogus;
|
||||||
|
|
||||||
namespace VisaApi.Fakers.Auth
|
namespace VisaApi.Fakers.Auth;
|
||||||
{
|
|
||||||
public sealed class RegisterRequestFaker : Faker<RegisterRequest>
|
|
||||||
{
|
|
||||||
private static AuthDataFaker authDataFaker = new();
|
|
||||||
|
|
||||||
public RegisterRequestFaker()
|
public sealed class RegisterRequestFaker : Faker<RegisterRequest>
|
||||||
{
|
{
|
||||||
|
private static AuthDataFaker authDataFaker = new();
|
||||||
|
|
||||||
|
public RegisterRequestFaker()
|
||||||
|
{
|
||||||
RuleFor(r => r.AuthData, () => authDataFaker.Generate());
|
RuleFor(r => r.AuthData, () => authDataFaker.Generate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
using ApplicationLayer.Services.Users.Models;
|
using ApplicationLayer.Services.Users.Models;
|
||||||
using Bogus;
|
using Bogus;
|
||||||
|
|
||||||
namespace VisaApi.Fakers.Common
|
namespace VisaApi.Fakers.Common;
|
||||||
|
|
||||||
|
public sealed class ChangeAuthDataFaker : Faker<ChangeAuthData>
|
||||||
{
|
{
|
||||||
public sealed class ChangeAuthDataFaker : Faker<ChangeAuthData>
|
public ChangeAuthDataFaker()
|
||||||
{
|
{
|
||||||
public ChangeAuthDataFaker()
|
|
||||||
{
|
|
||||||
RuleFor(a => a.Email, f => f.Internet.Email());
|
RuleFor(a => a.Email, f => f.Internet.Email());
|
||||||
|
|
||||||
RuleFor(a => a.Password, f => f.Internet.Password());
|
RuleFor(a => a.Password, f => f.Internet.Password());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -2,15 +2,14 @@
|
|||||||
using Bogus;
|
using Bogus;
|
||||||
using VisaApi.Fakers.Common;
|
using VisaApi.Fakers.Common;
|
||||||
|
|
||||||
namespace VisaApi.Fakers.Users.Requests
|
namespace VisaApi.Fakers.Users.Requests;
|
||||||
{
|
|
||||||
public sealed class ChangeUserAuthDataRequestFaker : Faker<ChangeUserAuthDataRequest>
|
|
||||||
{
|
|
||||||
private static ChangeAuthDataFaker changeAuthDataFaker = new();
|
|
||||||
|
|
||||||
public ChangeUserAuthDataRequestFaker()
|
public sealed class ChangeUserAuthDataRequestFaker : Faker<ChangeUserAuthDataRequest>
|
||||||
{
|
{
|
||||||
|
private static ChangeAuthDataFaker changeAuthDataFaker = new();
|
||||||
|
|
||||||
|
public ChangeUserAuthDataRequestFaker()
|
||||||
|
{
|
||||||
CustomInstantiator(_ => new(Guid.NewGuid(), changeAuthDataFaker.Generate()));
|
CustomInstantiator(_ => new(Guid.NewGuid(), changeAuthDataFaker.Generate()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,18 +1,17 @@
|
|||||||
using Bogus;
|
using Bogus;
|
||||||
using Domains.Users;
|
using Domains.Users;
|
||||||
|
|
||||||
namespace VisaApi.Fakers.Users
|
namespace VisaApi.Fakers.Users;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates users
|
||||||
|
/// </summary>
|
||||||
|
public sealed class UserFaker : Faker<User>
|
||||||
{
|
{
|
||||||
/// <summary>
|
public UserFaker()
|
||||||
/// Generates users
|
|
||||||
/// </summary>
|
|
||||||
public sealed class UserFaker : Faker<User>
|
|
||||||
{
|
{
|
||||||
public UserFaker()
|
|
||||||
{
|
|
||||||
RuleFor(u => u.Email, f => f.Internet.Email());
|
RuleFor(u => u.Email, f => f.Internet.Email());
|
||||||
|
|
||||||
RuleFor(u => u.Password, f => f.Internet.Password());
|
RuleFor(u => u.Password, f => f.Internet.Password());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -2,28 +2,27 @@
|
|||||||
using Bogus;
|
using Bogus;
|
||||||
using Domains.VisaApplicationDomain;
|
using Domains.VisaApplicationDomain;
|
||||||
|
|
||||||
namespace VisaApi.Fakers.VisaApplications
|
namespace VisaApi.Fakers.VisaApplications;
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Generates past visas
|
|
||||||
/// </summary>
|
|
||||||
public sealed class PastVisaFaker : Faker<PastVisa>
|
|
||||||
{
|
|
||||||
private IDateTimeProvider dateTimeProvider;
|
|
||||||
|
|
||||||
public PastVisaFaker(IDateTimeProvider dateTimeProvider)
|
/// <summary>
|
||||||
{
|
/// Generates past visas
|
||||||
|
/// </summary>
|
||||||
|
public sealed class PastVisaFaker : Faker<PastVisa>
|
||||||
|
{
|
||||||
|
private IDateTimeProvider dateTimeProvider;
|
||||||
|
|
||||||
|
public PastVisaFaker(IDateTimeProvider dateTimeProvider)
|
||||||
|
{
|
||||||
this.dateTimeProvider = dateTimeProvider;
|
this.dateTimeProvider = dateTimeProvider;
|
||||||
|
|
||||||
RuleFor(pv => pv.Name, f => f.Random.Words());
|
RuleFor(pv => pv.Name, f => f.Random.Words());
|
||||||
}
|
}
|
||||||
|
|
||||||
public PastVisa GenerateValid()
|
public PastVisa GenerateValid()
|
||||||
{
|
{
|
||||||
var result = Generate();
|
var result = Generate();
|
||||||
result.IssueDate = dateTimeProvider.Now().AddDays(Random.Shared.Next(11, 900));
|
result.IssueDate = dateTimeProvider.Now().AddDays(Random.Shared.Next(11, 900));
|
||||||
result.ExpirationDate = result.IssueDate.AddDays(Random.Shared.Next(1, 11));
|
result.ExpirationDate = result.IssueDate.AddDays(Random.Shared.Next(1, 11));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -2,28 +2,27 @@
|
|||||||
using Bogus;
|
using Bogus;
|
||||||
using Domains.VisaApplicationDomain;
|
using Domains.VisaApplicationDomain;
|
||||||
|
|
||||||
namespace VisaApi.Fakers.VisaApplications
|
namespace VisaApi.Fakers.VisaApplications;
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Generates past visas
|
|
||||||
/// </summary>
|
|
||||||
public sealed class PastVisitFaker : Faker<PastVisit>
|
|
||||||
{
|
|
||||||
private IDateTimeProvider dateTimeProvider;
|
|
||||||
|
|
||||||
public PastVisitFaker(IDateTimeProvider dateTimeProvider)
|
/// <summary>
|
||||||
{
|
/// Generates past visas
|
||||||
|
/// </summary>
|
||||||
|
public sealed class PastVisitFaker : Faker<PastVisit>
|
||||||
|
{
|
||||||
|
private IDateTimeProvider dateTimeProvider;
|
||||||
|
|
||||||
|
public PastVisitFaker(IDateTimeProvider dateTimeProvider)
|
||||||
|
{
|
||||||
this.dateTimeProvider = dateTimeProvider;
|
this.dateTimeProvider = dateTimeProvider;
|
||||||
|
|
||||||
RuleFor(pv => pv.DestinationCountry, f => f.Address.Country());
|
RuleFor(pv => pv.DestinationCountry, f => f.Address.Country());
|
||||||
}
|
}
|
||||||
|
|
||||||
public PastVisit GenerateValid()
|
public PastVisit GenerateValid()
|
||||||
{
|
{
|
||||||
var result = Generate();
|
var result = Generate();
|
||||||
result.StartDate = dateTimeProvider.Now().AddDays(Random.Shared.Next(11, 900));
|
result.StartDate = dateTimeProvider.Now().AddDays(Random.Shared.Next(11, 900));
|
||||||
result.EndDate = result.StartDate.AddDays(Random.Shared.Next(1, 11));
|
result.EndDate = result.StartDate.AddDays(Random.Shared.Next(1, 11));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -2,19 +2,18 @@
|
|||||||
using Bogus;
|
using Bogus;
|
||||||
using Domains.VisaApplicationDomain;
|
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>
|
public PermissionToDestCountryFaker(IDateTimeProvider dateTimeProvider)
|
||||||
/// Generates permissions to destination Country
|
|
||||||
/// </summary>
|
|
||||||
public sealed class PermissionToDestCountryFaker : Faker<PermissionToDestCountry>
|
|
||||||
{
|
{
|
||||||
public PermissionToDestCountryFaker(IDateTimeProvider dateTimeProvider)
|
|
||||||
{
|
|
||||||
RuleFor(p => p.Issuer, f => f.Company.CompanyName());
|
RuleFor(p => p.Issuer, f => f.Company.CompanyName());
|
||||||
|
|
||||||
RuleFor(p => p.ExpirationDate,
|
RuleFor(p => p.ExpirationDate,
|
||||||
f => f.Date.Future(4, dateTimeProvider.Now()));
|
f => f.Date.Future(4, dateTimeProvider.Now()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -3,20 +3,19 @@ using Bogus;
|
|||||||
using Domains;
|
using Domains;
|
||||||
using Domains.VisaApplicationDomain;
|
using Domains.VisaApplicationDomain;
|
||||||
|
|
||||||
namespace VisaApi.Fakers.VisaApplications
|
namespace VisaApi.Fakers.VisaApplications;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates re-entry permissions
|
||||||
|
/// </summary>
|
||||||
|
public sealed class ReentryPermitFaker : Faker<ReentryPermit>
|
||||||
{
|
{
|
||||||
/// <summary>
|
public ReentryPermitFaker(IDateTimeProvider dateTimeProvider)
|
||||||
/// Generates re-entry permissions
|
|
||||||
/// </summary>
|
|
||||||
public sealed class ReentryPermitFaker : Faker<ReentryPermit>
|
|
||||||
{
|
{
|
||||||
public ReentryPermitFaker(IDateTimeProvider dateTimeProvider)
|
|
||||||
{
|
|
||||||
RuleFor(p => p.Number,
|
RuleFor(p => p.Number,
|
||||||
f => f.Random.String(ConfigurationConstraints.ReentryPermitNumberLength, 'a', 'z'));
|
f => f.Random.String(ConfigurationConstraints.ReentryPermitNumberLength, 'a', 'z'));
|
||||||
|
|
||||||
RuleFor(p => p.ExpirationDate,
|
RuleFor(p => p.ExpirationDate,
|
||||||
f => f.Date.Future(4, dateTimeProvider.Now()));
|
f => f.Date.Future(4, dateTimeProvider.Now()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -4,18 +4,18 @@ using Domains;
|
|||||||
using Domains.ApplicantDomain;
|
using Domains.ApplicantDomain;
|
||||||
using Domains.VisaApplicationDomain;
|
using Domains.VisaApplicationDomain;
|
||||||
|
|
||||||
namespace VisaApi.Fakers.VisaApplications
|
namespace VisaApi.Fakers.VisaApplications;
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Generates visa applications
|
|
||||||
/// </summary>
|
|
||||||
public sealed class VisaApplicationFaker : Faker<VisaApplication>
|
|
||||||
{
|
|
||||||
private static ReentryPermitFaker reentryPermitFaker = null!;
|
|
||||||
private static PermissionToDestCountryFaker permissionToDestCountryFaker = null!;
|
|
||||||
|
|
||||||
public VisaApplicationFaker(IDateTimeProvider dateTimeProvider)
|
/// <summary>
|
||||||
{
|
/// Generates visa applications
|
||||||
|
/// </summary>
|
||||||
|
public sealed class VisaApplicationFaker : Faker<VisaApplication>
|
||||||
|
{
|
||||||
|
private static ReentryPermitFaker reentryPermitFaker = null!;
|
||||||
|
private static PermissionToDestCountryFaker permissionToDestCountryFaker = null!;
|
||||||
|
|
||||||
|
public VisaApplicationFaker(IDateTimeProvider dateTimeProvider)
|
||||||
|
{
|
||||||
reentryPermitFaker = new(dateTimeProvider);
|
reentryPermitFaker = new(dateTimeProvider);
|
||||||
permissionToDestCountryFaker = new(dateTimeProvider);
|
permissionToDestCountryFaker = new(dateTimeProvider);
|
||||||
var pastVisaFaker = new PastVisaFaker(dateTimeProvider);
|
var pastVisaFaker = new PastVisaFaker(dateTimeProvider);
|
||||||
@@ -44,8 +44,8 @@ namespace VisaApi.Fakers.VisaApplications
|
|||||||
f => f.Random.Int(1, ConfigurationConstraints.MaxValidDays));
|
f => f.Random.Int(1, ConfigurationConstraints.MaxValidDays));
|
||||||
}
|
}
|
||||||
|
|
||||||
public VisaApplication GenerateValid(Applicant applicant)
|
public VisaApplication GenerateValid(Applicant applicant)
|
||||||
{
|
{
|
||||||
var result = Generate();
|
var result = Generate();
|
||||||
|
|
||||||
result.ApplicantId = applicant.Id;
|
result.ApplicantId = applicant.Id;
|
||||||
@@ -61,5 +61,4 @@ namespace VisaApi.Fakers.VisaApplications
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
using ApplicationLayer.InfrastructureServicesInterfaces;
|
using ApplicationLayer.InfrastructureServicesInterfaces;
|
||||||
|
|
||||||
namespace VisaApi.Services
|
namespace VisaApi.Services;
|
||||||
|
|
||||||
|
public class TestDateTimeProvider : IDateTimeProvider
|
||||||
{
|
{
|
||||||
public class TestDateTimeProvider : IDateTimeProvider
|
public DateTime Now() => DateTime.Now;
|
||||||
{
|
}
|
||||||
public DateTime Now() => DateTime.Now;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,165 +7,164 @@ using FluentValidation;
|
|||||||
using VisaApi.Fakers.Applicants.Requests;
|
using VisaApi.Fakers.Applicants.Requests;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace VisaApi.Tests.Application.Validation.Applicants
|
namespace VisaApi.Tests.Application.Validation.Applicants;
|
||||||
|
|
||||||
|
public class NameModelValidatorTests
|
||||||
{
|
{
|
||||||
public class NameModelValidatorTests
|
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
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForEmptyFirstNameShouldThrow()
|
||||||
{
|
{
|
||||||
private static IValidator<NameModel> validator = new NameModelValidator();
|
var name = faker.Generate();
|
||||||
private static NameModelFaker faker = new();
|
name.FirstName = null!;
|
||||||
|
|
||||||
/// <summary>
|
var result = await validator.ValidateAsync(name);
|
||||||
/// Test for <see cref="NameModel"/> validator that should throw for empty first name
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForEmptyFirstNameShouldThrow()
|
|
||||||
{
|
|
||||||
var name = faker.Generate();
|
|
||||||
name.FirstName = null!;
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(name);
|
result.Errors.Where(error => error.PropertyName == nameof(name.FirstName))
|
||||||
|
.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(name.FirstName))
|
/// <summary>
|
||||||
.Should().HaveCount(1);
|
/// Test for <see cref="NameModel"/> validator that should throw for empty surname
|
||||||
}
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForEmptySurnameShouldThrow()
|
||||||
|
{
|
||||||
|
var name = faker.Generate();
|
||||||
|
name.Surname = null!;
|
||||||
|
|
||||||
/// <summary>
|
var result = await validator.ValidateAsync(name);
|
||||||
/// Test for <see cref="NameModel"/> validator that should throw for empty surname
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForEmptySurnameShouldThrow()
|
|
||||||
{
|
|
||||||
var name = faker.Generate();
|
|
||||||
name.Surname = null!;
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(name);
|
result.Errors.Where(error => error.PropertyName == nameof(name.Surname))
|
||||||
|
.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(name.Surname))
|
/// <summary>
|
||||||
.Should().HaveCount(1);
|
/// Test for <see cref="NameModel"/> validator that should return no errors for empty patronymic
|
||||||
}
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForEmptyPatronymicShouldReturnNoErrors()
|
||||||
|
{
|
||||||
|
var name = faker.Generate();
|
||||||
|
name.Patronymic = null;
|
||||||
|
|
||||||
/// <summary>
|
var result = await validator.ValidateAsync(name);
|
||||||
/// Test for <see cref="NameModel"/> validator that should return no errors for empty patronymic
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForEmptyPatronymicShouldReturnNoErrors()
|
|
||||||
{
|
|
||||||
var name = faker.Generate();
|
|
||||||
name.Patronymic = null;
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(name);
|
result.Errors.Where(error => error.PropertyName == nameof(name.Patronymic))
|
||||||
|
.Should().BeEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(name.Patronymic))
|
/// <summary>
|
||||||
.Should().BeEmpty();
|
/// Test for <see cref="NameModel"/> validator that should return error for too long first name
|
||||||
}
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForLongFirstNameShouldReturnError()
|
||||||
|
{
|
||||||
|
var name = faker.Generate();
|
||||||
|
var stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.Append('h', ConfigurationConstraints.NameLength + 1);
|
||||||
|
name.FirstName = stringBuilder.ToString();
|
||||||
|
|
||||||
/// <summary>
|
var result = await validator.ValidateAsync(name);
|
||||||
/// Test for <see cref="NameModel"/> validator that should return error for too long first name
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForLongFirstNameShouldReturnError()
|
|
||||||
{
|
|
||||||
var name = faker.Generate();
|
|
||||||
var stringBuilder = new StringBuilder();
|
|
||||||
stringBuilder.Append('h', ConfigurationConstraints.NameLength + 1);
|
|
||||||
name.FirstName = stringBuilder.ToString();
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(name);
|
result.Errors.Where(error => error.PropertyName == nameof(name.FirstName))
|
||||||
|
.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(name.FirstName))
|
/// <summary>
|
||||||
.Should().HaveCount(1);
|
/// Test for <see cref="NameModel"/> validator that should return error for too long surname
|
||||||
}
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForLongSurnameShouldReturnError()
|
||||||
|
{
|
||||||
|
var name = faker.Generate();
|
||||||
|
var stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.Append('h', ConfigurationConstraints.NameLength + 1);
|
||||||
|
name.Surname = stringBuilder.ToString();
|
||||||
|
|
||||||
/// <summary>
|
var result = await validator.ValidateAsync(name);
|
||||||
/// Test for <see cref="NameModel"/> validator that should return error for too long surname
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForLongSurnameShouldReturnError()
|
|
||||||
{
|
|
||||||
var name = faker.Generate();
|
|
||||||
var stringBuilder = new StringBuilder();
|
|
||||||
stringBuilder.Append('h', ConfigurationConstraints.NameLength + 1);
|
|
||||||
name.Surname = stringBuilder.ToString();
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(name);
|
result.Errors.Where(error => error.PropertyName == nameof(name.Surname))
|
||||||
|
.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(name.Surname))
|
/// <summary>
|
||||||
.Should().HaveCount(1);
|
/// Test for <see cref="NameModel"/> validator that should return error for too long patronymic
|
||||||
}
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForLongPatronymicShouldReturnError()
|
||||||
|
{
|
||||||
|
var name = faker.Generate();
|
||||||
|
var stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.Append('h', ConfigurationConstraints.NameLength + 1);
|
||||||
|
name.Patronymic = stringBuilder.ToString();
|
||||||
|
|
||||||
/// <summary>
|
var result = await validator.ValidateAsync(name);
|
||||||
/// Test for <see cref="NameModel"/> validator that should return error for too long patronymic
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForLongPatronymicShouldReturnError()
|
|
||||||
{
|
|
||||||
var name = faker.Generate();
|
|
||||||
var stringBuilder = new StringBuilder();
|
|
||||||
stringBuilder.Append('h', ConfigurationConstraints.NameLength + 1);
|
|
||||||
name.Patronymic = stringBuilder.ToString();
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(name);
|
result.Errors.Where(error => error.PropertyName == nameof(name.Patronymic))
|
||||||
|
.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(name.Patronymic))
|
/// <summary>
|
||||||
.Should().HaveCount(1);
|
/// Test for <see cref="NameModel"/> validator that should return error for not valid firstname
|
||||||
}
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForNotValidFirstNameShouldReturnError()
|
||||||
|
{
|
||||||
|
var name = faker.Generate();
|
||||||
|
name.FirstName = "&&7!**|";
|
||||||
|
|
||||||
/// <summary>
|
var result = await validator.ValidateAsync(name);
|
||||||
/// Test for <see cref="NameModel"/> validator that should return error for not valid firstname
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForNotValidFirstNameShouldReturnError()
|
|
||||||
{
|
|
||||||
var name = faker.Generate();
|
|
||||||
name.FirstName = "&&7!**|";
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(name);
|
result.Errors.Where(error => error.PropertyName == nameof(name.FirstName))
|
||||||
|
.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(name.FirstName))
|
/// <summary>
|
||||||
.Should().HaveCount(1);
|
/// Test for <see cref="NameModel"/> validator that should return error for not valid surname
|
||||||
}
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForNotValidSurnameShouldReturnError()
|
||||||
|
{
|
||||||
|
var name = faker.Generate();
|
||||||
|
name.Surname = "&&7!**|";
|
||||||
|
|
||||||
/// <summary>
|
var result = await validator.ValidateAsync(name);
|
||||||
/// Test for <see cref="NameModel"/> validator that should return error for not valid surname
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForNotValidSurnameShouldReturnError()
|
|
||||||
{
|
|
||||||
var name = faker.Generate();
|
|
||||||
name.Surname = "&&7!**|";
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(name);
|
result.Errors.Where(error => error.PropertyName == nameof(name.Surname))
|
||||||
|
.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(name.Surname))
|
/// <summary>
|
||||||
.Should().HaveCount(1);
|
/// Test for <see cref="NameModel"/> validator that should return error for not valid patronymic
|
||||||
}
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForNotValidPatronymicShouldReturnError()
|
||||||
|
{
|
||||||
|
var name = faker.Generate();
|
||||||
|
name.Patronymic = "&&7!**|";
|
||||||
|
|
||||||
/// <summary>
|
var result = await validator.ValidateAsync(name);
|
||||||
/// Test for <see cref="NameModel"/> validator that should return error for not valid patronymic
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForNotValidPatronymicShouldReturnError()
|
|
||||||
{
|
|
||||||
var name = faker.Generate();
|
|
||||||
name.Patronymic = "&&7!**|";
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(name);
|
result.Errors.Where(error => error.PropertyName == nameof(name.Patronymic))
|
||||||
|
.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(name.Patronymic))
|
/// <summary>
|
||||||
.Should().HaveCount(1);
|
/// Test for <see cref="NameModel"/> validator that should return no errors for valid name
|
||||||
}
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForValidNameShouldReturnNoErrors()
|
||||||
|
{
|
||||||
|
var name = faker.Generate();
|
||||||
|
|
||||||
/// <summary>
|
var result = await validator.ValidateAsync(name);
|
||||||
/// Test for <see cref="NameModel"/> validator that should return no errors for valid name
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForValidNameShouldReturnNoErrors()
|
|
||||||
{
|
|
||||||
var name = faker.Generate();
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(name);
|
result.Errors.Should().BeEmpty();
|
||||||
|
|
||||||
result.Errors.Should().BeEmpty();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,167 +9,166 @@ using VisaApi.Fakers.Applicants.Requests;
|
|||||||
using VisaApi.Services;
|
using VisaApi.Services;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace VisaApi.Tests.Application.Validation.Applicants
|
namespace VisaApi.Tests.Application.Validation.Applicants;
|
||||||
|
|
||||||
|
public class PassportModelValidatorTests
|
||||||
{
|
{
|
||||||
public class PassportModelValidatorTests
|
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
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForEmptyNumberShouldReturnError()
|
||||||
{
|
{
|
||||||
private static IDateTimeProvider dateTimeProvider = new TestDateTimeProvider();
|
var model = faker.Generate();
|
||||||
private static IValidator<PassportModel> validator = new PassportModelValidator(dateTimeProvider);
|
model.Number = string.Empty;
|
||||||
private static PassportModelFaker faker = new(dateTimeProvider);
|
|
||||||
|
|
||||||
/// <summary>
|
var result = await validator.ValidateAsync(model);
|
||||||
/// Test for <see cref="PassportModel"/> validator that should return error for empty number
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForEmptyNumberShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
model.Number = string.Empty;
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
result.Errors.Where(error => error.PropertyName == nameof(model.Number))
|
||||||
|
.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(model.Number))
|
/// <summary>
|
||||||
.Should().HaveCount(1);
|
/// Test for <see cref="PassportModel"/> validator that should return error for too long number
|
||||||
}
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForLongNumberShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
var stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.Append('d', ConfigurationConstraints.PassportNumberLength + 1);
|
||||||
|
model.Number = stringBuilder.ToString();
|
||||||
|
|
||||||
/// <summary>
|
var result = await validator.ValidateAsync(model);
|
||||||
/// Test for <see cref="PassportModel"/> validator that should return error for too long number
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForLongNumberShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
var stringBuilder = new StringBuilder();
|
|
||||||
stringBuilder.Append('d', ConfigurationConstraints.PassportNumberLength + 1);
|
|
||||||
model.Number = stringBuilder.ToString();
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
result.Errors.Where(error => error.PropertyName == nameof(model.Number))
|
||||||
|
.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(model.Number))
|
/// <summary>
|
||||||
.Should().HaveCount(1);
|
/// Test for <see cref="PassportModel"/> validator that should return error for not valid number
|
||||||
}
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForNotValidNumberShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
model.Number = "&?%$24asd\\]|";
|
||||||
|
|
||||||
/// <summary>
|
var result = await validator.ValidateAsync(model);
|
||||||
/// Test for <see cref="PassportModel"/> validator that should return error for not valid number
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForNotValidNumberShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
model.Number = "&?%$24asd\\]|";
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
result.Errors.Where(error => error.PropertyName == nameof(model.Number))
|
||||||
|
.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(model.Number))
|
/// <summary>
|
||||||
.Should().HaveCount(1);
|
/// Test for <see cref="PassportModel"/> validator that should return error for empty issuer
|
||||||
}
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForEmptyIssuerShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
model.Issuer = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
var result = await validator.ValidateAsync(model);
|
||||||
/// Test for <see cref="PassportModel"/> validator that should return error for empty issuer
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForEmptyIssuerShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
model.Issuer = string.Empty;
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
result.Errors.Where(error => error.PropertyName == nameof(model.Issuer))
|
||||||
|
.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(model.Issuer))
|
/// <summary>
|
||||||
.Should().HaveCount(1);
|
/// Test for <see cref="PassportModel"/> validator that should return error for too long issuer
|
||||||
}
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForLongIssuerShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
var stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.Append('d', ConfigurationConstraints.IssuerNameLength + 1);
|
||||||
|
model.Issuer = stringBuilder.ToString();
|
||||||
|
|
||||||
/// <summary>
|
var result = await validator.ValidateAsync(model);
|
||||||
/// Test for <see cref="PassportModel"/> validator that should return error for too long issuer
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForLongIssuerShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
var stringBuilder = new StringBuilder();
|
|
||||||
stringBuilder.Append('d', ConfigurationConstraints.IssuerNameLength + 1);
|
|
||||||
model.Issuer = stringBuilder.ToString();
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
result.Errors.Where(error => error.PropertyName == nameof(model.Issuer))
|
||||||
|
.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(model.Issuer))
|
/// <summary>
|
||||||
.Should().HaveCount(1);
|
/// Test for <see cref="PassportModel"/> validator that should return error for not valid issuer
|
||||||
}
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForNotValidIssuerShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
model.Issuer = "&?%$24asd\\]|";
|
||||||
|
|
||||||
/// <summary>
|
var result = await validator.ValidateAsync(model);
|
||||||
/// Test for <see cref="PassportModel"/> validator that should return error for not valid issuer
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForNotValidIssuerShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
model.Issuer = "&?%$24asd\\]|";
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
result.Errors.Where(error => error.PropertyName == nameof(model.Issuer))
|
||||||
|
.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(model.Issuer))
|
/// <summary>
|
||||||
.Should().HaveCount(1);
|
/// Test for <see cref="PassportModel"/> validator that should return error for expired passport
|
||||||
}
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForExpiredPassportShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
model.ExpirationDate = dateTimeProvider.Now().AddDays(-10);
|
||||||
|
model.IssueDate = model.ExpirationDate.AddDays(-10);
|
||||||
|
|
||||||
/// <summary>
|
var result = await validator.ValidateAsync(model);
|
||||||
/// Test for <see cref="PassportModel"/> validator that should return error for expired passport
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForExpiredPassportShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
model.ExpirationDate = dateTimeProvider.Now().AddDays(-10);
|
|
||||||
model.IssueDate = model.ExpirationDate.AddDays(-10);
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
result.Errors.Where(error => error.PropertyName == nameof(model.ExpirationDate))
|
||||||
|
.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(model.ExpirationDate))
|
/// <summary>
|
||||||
.Should().HaveCount(1);
|
/// Test for <see cref="PassportModel"/> validator that should return error for passport from future
|
||||||
}
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForPassportFromFutureShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
model.ExpirationDate = dateTimeProvider.Now().AddDays(10);
|
||||||
|
model.IssueDate = model.ExpirationDate.AddDays(-3);
|
||||||
|
|
||||||
/// <summary>
|
var result = await validator.ValidateAsync(model);
|
||||||
/// Test for <see cref="PassportModel"/> validator that should return error for passport from future
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForPassportFromFutureShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
model.ExpirationDate = dateTimeProvider.Now().AddDays(10);
|
|
||||||
model.IssueDate = model.ExpirationDate.AddDays(-3);
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
result.Errors.Where(error => error.PropertyName == nameof(model.IssueDate))
|
||||||
|
.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(model.IssueDate))
|
/// <summary>
|
||||||
.Should().HaveCount(1);
|
/// Test for <see cref="PassportModel"/> validator that should return error for passport that expired before issue
|
||||||
}
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForPassportExpiredBeforeIssueShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
model.ExpirationDate = dateTimeProvider.Now().AddDays(10);
|
||||||
|
model.IssueDate = model.ExpirationDate.AddDays(3);
|
||||||
|
|
||||||
/// <summary>
|
var result = await validator.ValidateAsync(model);
|
||||||
/// Test for <see cref="PassportModel"/> validator that should return error for passport that expired before issue
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForPassportExpiredBeforeIssueShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
model.ExpirationDate = dateTimeProvider.Now().AddDays(10);
|
|
||||||
model.IssueDate = model.ExpirationDate.AddDays(3);
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
result.Errors.Where(error => error.PropertyName == nameof(model.IssueDate))
|
||||||
|
.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(model.IssueDate))
|
/// <summary>
|
||||||
.Should().HaveCount(1);
|
/// Test for <see cref="PassportModel"/> validator that should return no errors for valid passport
|
||||||
}
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForValidPassportShouldReturnNoErrors()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
|
||||||
/// <summary>
|
var result = await validator.ValidateAsync(model);
|
||||||
/// Test for <see cref="PassportModel"/> validator that should return no errors for valid passport
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForValidPassportShouldReturnNoErrors()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
result.Errors.Should().BeEmpty();
|
||||||
|
|
||||||
result.Errors.Should().BeEmpty();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,348 +7,347 @@ using FluentValidation;
|
|||||||
using VisaApi.Fakers.Applicants.Requests;
|
using VisaApi.Fakers.Applicants.Requests;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace VisaApi.Tests.Application.Validation.Applicants
|
namespace VisaApi.Tests.Application.Validation.Applicants;
|
||||||
|
|
||||||
|
public class PlaceOfWorkModelValidatorTests
|
||||||
{
|
{
|
||||||
public class PlaceOfWorkModelValidatorTests
|
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
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForEmptyPhoneNumShouldReturnError()
|
||||||
{
|
{
|
||||||
private static IValidator<PlaceOfWorkModel> validator = new PlaceOfWorkModelValidator();
|
var model = faker.Generate();
|
||||||
private static PlaceOfWorkModelFaker faker = new();
|
model.PhoneNum = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
var result = await validator.ValidateAsync(model);
|
||||||
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for empty phone num
|
|
||||||
/// </summary>
|
result.Errors.Where(error => error.PropertyName == nameof(model.PhoneNum))
|
||||||
[Fact]
|
.Should().NotBeEmpty();
|
||||||
private async Task ValidateForEmptyPhoneNumShouldReturnError()
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for long phone num
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForLongPhoneNumShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
var stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.Append('8', ConfigurationConstraints.PhoneNumberLength + 1);
|
||||||
|
model.PhoneNum = stringBuilder.ToString();
|
||||||
|
|
||||||
|
var result = await validator.ValidateAsync(model);
|
||||||
|
|
||||||
|
result.Errors.Where(error => error.PropertyName == nameof(model.PhoneNum))
|
||||||
|
.Should().NotBeEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for short phone num
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForShortPhoneNumShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
var stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.Append('8', ConfigurationConstraints.PhoneNumberMinLength - 1);
|
||||||
|
model.PhoneNum = stringBuilder.ToString();
|
||||||
|
|
||||||
|
var result = await validator.ValidateAsync(model);
|
||||||
|
|
||||||
|
result.Errors.Where(error => error.PropertyName == nameof(model.PhoneNum))
|
||||||
|
.Should()
|
||||||
|
.HaveCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for not valid phone num
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForNotValidPhoneNumShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
var stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.Append('a', ConfigurationConstraints.PhoneNumberMinLength);
|
||||||
|
model.PhoneNum = stringBuilder.ToString();
|
||||||
|
|
||||||
|
var result = await validator.ValidateAsync(model);
|
||||||
|
|
||||||
|
result.Errors.Where(error => error.PropertyName == nameof(model.PhoneNum))
|
||||||
|
.Should()
|
||||||
|
.HaveCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test for <see cref="PlaceOfWorkModel"/> validator that should throw exception for null address
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForEmptyAddressShouldThrow()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
model.Address = null!;
|
||||||
|
NullReferenceException? result = null;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var model = faker.Generate();
|
await validator.ValidateAsync(model);
|
||||||
model.PhoneNum = string.Empty;
|
}
|
||||||
|
catch (Exception e)
|
||||||
var result = await validator.ValidateAsync(model);
|
{
|
||||||
|
result = e as NullReferenceException;
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(model.PhoneNum))
|
|
||||||
.Should().NotBeEmpty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
result.Should().NotBeNull();
|
||||||
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for long phone num
|
}
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForLongPhoneNumShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
var stringBuilder = new StringBuilder();
|
|
||||||
stringBuilder.Append('8', ConfigurationConstraints.PhoneNumberLength + 1);
|
|
||||||
model.PhoneNum = stringBuilder.ToString();
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
/// <summary>
|
||||||
|
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for empty Country
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForEmptyCountryShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
model.Address.Country = "";
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(model.PhoneNum))
|
var result = await validator.ValidateAsync(model);
|
||||||
.Should().NotBeEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
result.Errors.Where(error => error.PropertyName == "Address.Country")
|
||||||
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for short phone num
|
.Should().HaveCount(1);
|
||||||
/// </summary>
|
}
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForShortPhoneNumShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
var stringBuilder = new StringBuilder();
|
|
||||||
stringBuilder.Append('8', ConfigurationConstraints.PhoneNumberMinLength - 1);
|
|
||||||
model.PhoneNum = stringBuilder.ToString();
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
/// <summary>
|
||||||
|
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for too long Country
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForLongCountryShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
var stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.Append('a', ConfigurationConstraints.CountryNameLength + 1);
|
||||||
|
model.Address.Country = stringBuilder.ToString();
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(model.PhoneNum))
|
var result = await validator.ValidateAsync(model);
|
||||||
.Should()
|
|
||||||
.HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
result.Errors.Where(error => error.PropertyName == "Address.Country")
|
||||||
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for not valid phone num
|
.Should().HaveCount(1);
|
||||||
/// </summary>
|
}
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForNotValidPhoneNumShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
var stringBuilder = new StringBuilder();
|
|
||||||
stringBuilder.Append('a', ConfigurationConstraints.PhoneNumberMinLength);
|
|
||||||
model.PhoneNum = stringBuilder.ToString();
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
/// <summary>
|
||||||
|
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for not valid Country
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForNotValidCountryShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
model.Address.Country = "|&%";
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(model.PhoneNum))
|
var result = await validator.ValidateAsync(model);
|
||||||
.Should()
|
|
||||||
.HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
result.Errors.Where(error => error.PropertyName == "Address.Country")
|
||||||
/// Test for <see cref="PlaceOfWorkModel"/> validator that should throw exception for null address
|
.Should().HaveCount(1);
|
||||||
/// </summary>
|
}
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForEmptyAddressShouldThrow()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
model.Address = null!;
|
|
||||||
NullReferenceException? result = null;
|
|
||||||
|
|
||||||
try
|
/// <summary>
|
||||||
{
|
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for empty City
|
||||||
await validator.ValidateAsync(model);
|
/// </summary>
|
||||||
}
|
[Fact]
|
||||||
catch (Exception e)
|
private async Task ValidateForEmptyCityShouldReturnError()
|
||||||
{
|
{
|
||||||
result = e as NullReferenceException;
|
var model = faker.Generate();
|
||||||
}
|
model.Address.City = "";
|
||||||
|
|
||||||
result.Should().NotBeNull();
|
var result = await validator.ValidateAsync(model);
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
result.Errors.Where(error => error.PropertyName == "Address.City")
|
||||||
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for empty Country
|
.Should().HaveCount(1);
|
||||||
/// </summary>
|
}
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForEmptyCountryShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
model.Address.Country = "";
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
/// <summary>
|
||||||
|
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for too long city
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForLongCityShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
var stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.Append('a', ConfigurationConstraints.CityNameLength + 1);
|
||||||
|
model.Address.City = stringBuilder.ToString();
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == "Address.Country")
|
var result = await validator.ValidateAsync(model);
|
||||||
.Should().HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
result.Errors.Where(error => error.PropertyName == "Address.City")
|
||||||
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for too long Country
|
.Should().HaveCount(1);
|
||||||
/// </summary>
|
}
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForLongCountryShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
var stringBuilder = new StringBuilder();
|
|
||||||
stringBuilder.Append('a', ConfigurationConstraints.CountryNameLength + 1);
|
|
||||||
model.Address.Country = stringBuilder.ToString();
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
/// <summary>
|
||||||
|
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for not valid city
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForNotValidCityShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
model.Address.City = "|&%";
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == "Address.Country")
|
var result = await validator.ValidateAsync(model);
|
||||||
.Should().HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
result.Errors.Where(error => error.PropertyName == "Address.City")
|
||||||
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for not valid Country
|
.Should().HaveCount(1);
|
||||||
/// </summary>
|
}
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForNotValidCountryShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
model.Address.Country = "|&%";
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
/// <summary>
|
||||||
|
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for empty street
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForEmptyStreetShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
model.Address.Street = "";
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == "Address.Country")
|
var result = await validator.ValidateAsync(model);
|
||||||
.Should().HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
result.Errors.Where(error => error.PropertyName == "Address.Street")
|
||||||
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for empty City
|
.Should().HaveCount(1);
|
||||||
/// </summary>
|
}
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForEmptyCityShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
model.Address.City = "";
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
/// <summary>
|
||||||
|
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for too long street
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForLongStreetShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
var stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.Append('a', ConfigurationConstraints.StreetNameLength + 1);
|
||||||
|
model.Address.Street = stringBuilder.ToString();
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == "Address.City")
|
var result = await validator.ValidateAsync(model);
|
||||||
.Should().HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
result.Errors.Where(error => error.PropertyName == "Address.Street")
|
||||||
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for too long city
|
.Should().HaveCount(1);
|
||||||
/// </summary>
|
}
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForLongCityShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
var stringBuilder = new StringBuilder();
|
|
||||||
stringBuilder.Append('a', ConfigurationConstraints.CityNameLength + 1);
|
|
||||||
model.Address.City = stringBuilder.ToString();
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
/// <summary>
|
||||||
|
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for not valid street
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForNotValidStreetShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
model.Address.Street = "|&%";
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == "Address.City")
|
var result = await validator.ValidateAsync(model);
|
||||||
.Should().HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
result.Errors.Where(error => error.PropertyName == "Address.Street")
|
||||||
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for not valid city
|
.Should().HaveCount(1);
|
||||||
/// </summary>
|
}
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForNotValidCityShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
model.Address.City = "|&%";
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
/// <summary>
|
||||||
|
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for empty building /// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForEmptyBuildingShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
model.Address.Building = "";
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == "Address.City")
|
var result = await validator.ValidateAsync(model);
|
||||||
.Should().HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
result.Errors.Where(error => error.PropertyName == "Address.Building")
|
||||||
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for empty street
|
.Should().HaveCount(1);
|
||||||
/// </summary>
|
}
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForEmptyStreetShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
model.Address.Street = "";
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
/// <summary>
|
||||||
|
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for too long building
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForLongBuildingShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
var stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.Append('a', ConfigurationConstraints.BuildingNumberLength + 1);
|
||||||
|
model.Address.Building = stringBuilder.ToString();
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == "Address.Street")
|
var result = await validator.ValidateAsync(model);
|
||||||
.Should().HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
result.Errors.Where(error => error.PropertyName == "Address.Building")
|
||||||
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for too long street
|
.Should().HaveCount(1);
|
||||||
/// </summary>
|
}
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForLongStreetShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
var stringBuilder = new StringBuilder();
|
|
||||||
stringBuilder.Append('a', ConfigurationConstraints.StreetNameLength + 1);
|
|
||||||
model.Address.Street = stringBuilder.ToString();
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
/// <summary>
|
||||||
|
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for not valid building
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForNotValidBuildingShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
model.Address.Building = "|&%";
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == "Address.Street")
|
var result = await validator.ValidateAsync(model);
|
||||||
.Should().HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
result.Errors.Where(error => error.PropertyName == "Address.Building")
|
||||||
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for not valid street
|
.Should().HaveCount(1);
|
||||||
/// </summary>
|
}
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForNotValidStreetShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
model.Address.Street = "|&%";
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
/// <summary>
|
||||||
|
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for empty name
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForEmptyNameShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
model.Name = "";
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == "Address.Street")
|
var result = await validator.ValidateAsync(model);
|
||||||
.Should().HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
result.Errors.Where(error => error.PropertyName == nameof(model.Name))
|
||||||
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for empty building /// </summary>
|
.Should().HaveCount(1);
|
||||||
[Fact]
|
}
|
||||||
private async Task ValidateForEmptyBuildingShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
model.Address.Building = "";
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
/// <summary>
|
||||||
|
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for too long name
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForTooLongNameShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
var stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.Append('g', ConfigurationConstraints.PlaceOfWorkNameLength + 1);
|
||||||
|
model.Name = stringBuilder.ToString();
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == "Address.Building")
|
var result = await validator.ValidateAsync(model);
|
||||||
.Should().HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
result.Errors.Where(error => error.PropertyName == nameof(model.Name))
|
||||||
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for too long building
|
.Should().HaveCount(1);
|
||||||
/// </summary>
|
}
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForLongBuildingShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
var stringBuilder = new StringBuilder();
|
|
||||||
stringBuilder.Append('a', ConfigurationConstraints.BuildingNumberLength + 1);
|
|
||||||
model.Address.Building = stringBuilder.ToString();
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
/// <summary>
|
||||||
|
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for not valid name
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForNotValidNameShouldReturnError()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
model.Name = "@$%&|";
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == "Address.Building")
|
var result = await validator.ValidateAsync(model);
|
||||||
.Should().HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
result.Errors.Where(error => error.PropertyName == nameof(model.Name))
|
||||||
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for not valid building
|
.Should().HaveCount(1);
|
||||||
/// </summary>
|
}
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForNotValidBuildingShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
model.Address.Building = "|&%";
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
/// <summary>
|
||||||
|
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return no errors for valid model
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task ValidateForValidShouldReturnNoErrors()
|
||||||
|
{
|
||||||
|
var model = faker.Generate();
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == "Address.Building")
|
var result = await validator.ValidateAsync(model);
|
||||||
.Should().HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
result.Errors.Should().BeEmpty();
|
||||||
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for empty name
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForEmptyNameShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
model.Name = "";
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(model.Name))
|
|
||||||
.Should().HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for too long name
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForTooLongNameShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
var stringBuilder = new StringBuilder();
|
|
||||||
stringBuilder.Append('g', ConfigurationConstraints.PlaceOfWorkNameLength + 1);
|
|
||||||
model.Name = stringBuilder.ToString();
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(model.Name))
|
|
||||||
.Should().HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return error for not valid name
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForNotValidNameShouldReturnError()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
model.Name = "@$%&|";
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
|
||||||
|
|
||||||
result.Errors.Where(error => error.PropertyName == nameof(model.Name))
|
|
||||||
.Should().HaveCount(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Test for <see cref="PlaceOfWorkModel"/> validator that should return no errors for valid model
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForValidShouldReturnNoErrors()
|
|
||||||
{
|
|
||||||
var model = faker.Generate();
|
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(model);
|
|
||||||
|
|
||||||
result.Errors.Should().BeEmpty();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,19 +7,19 @@ using FluentValidation;
|
|||||||
using VisaApi.Fakers.Auth;
|
using VisaApi.Fakers.Auth;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace VisaApi.Tests.Application.Validation.Auth
|
namespace VisaApi.Tests.Application.Validation.Auth;
|
||||||
{
|
|
||||||
public class AuthDataValidatorTests
|
|
||||||
{
|
|
||||||
private readonly static IValidator<AuthData> validator = new AuthDataValidator();
|
|
||||||
private readonly static AuthDataFaker faker = new();
|
|
||||||
|
|
||||||
/// <summary>
|
public class AuthDataValidatorTests
|
||||||
/// Test for <see cref="AuthData"/> validator that should return validation error for invalid email
|
{
|
||||||
/// </summary>
|
private readonly static IValidator<AuthData> validator = new AuthDataValidator();
|
||||||
[Fact]
|
private readonly static AuthDataFaker faker = new();
|
||||||
private async Task ValidateForInvalidEmailShouldReturnError()
|
|
||||||
{
|
/// <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();
|
var authData = faker.Generate();
|
||||||
authData.Email = "alsdas'dsa";
|
authData.Email = "alsdas'dsa";
|
||||||
|
|
||||||
@@ -30,12 +30,12 @@ namespace VisaApi.Tests.Application.Validation.Auth
|
|||||||
.And.Contain(error => error.PropertyName == nameof(authData.Email));
|
.And.Contain(error => error.PropertyName == nameof(authData.Email));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="AuthData"/> validator that should return validation error for too long email
|
/// Test for <see cref="AuthData"/> validator that should return validation error for too long email
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task ValidateForLongEmailShouldReturnError()
|
private async Task ValidateForLongEmailShouldReturnError()
|
||||||
{
|
{
|
||||||
var authData = faker.Generate();
|
var authData = faker.Generate();
|
||||||
var stringBuilder = new StringBuilder();
|
var stringBuilder = new StringBuilder();
|
||||||
stringBuilder.Append('d', ConfigurationConstraints.EmailLength);
|
stringBuilder.Append('d', ConfigurationConstraints.EmailLength);
|
||||||
@@ -49,12 +49,12 @@ namespace VisaApi.Tests.Application.Validation.Auth
|
|||||||
.And.Contain(error => error.PropertyName == nameof(authData.Email));
|
.And.Contain(error => error.PropertyName == nameof(authData.Email));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="AuthData"/> validator that should return no errors for valid email
|
/// Test for <see cref="AuthData"/> validator that should return no errors for valid email
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task ValidateForValidEmailShouldReturnNoError()
|
private async Task ValidateForValidEmailShouldReturnNoError()
|
||||||
{
|
{
|
||||||
var authData = faker.Generate();
|
var authData = faker.Generate();
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(authData);
|
var result = await validator.ValidateAsync(authData);
|
||||||
@@ -63,12 +63,12 @@ namespace VisaApi.Tests.Application.Validation.Auth
|
|||||||
.Should().BeEmpty();
|
.Should().BeEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="AuthData"/> validator that should return validation error for empty password
|
/// Test for <see cref="AuthData"/> validator that should return validation error for empty password
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task ValidateForEmptyPasswordShouldReturnError()
|
private async Task ValidateForEmptyPasswordShouldReturnError()
|
||||||
{
|
{
|
||||||
var authData = faker.Generate();
|
var authData = faker.Generate();
|
||||||
authData.Password = string.Empty;
|
authData.Password = string.Empty;
|
||||||
|
|
||||||
@@ -79,12 +79,12 @@ namespace VisaApi.Tests.Application.Validation.Auth
|
|||||||
.And.Contain(error => error.PropertyName == nameof(authData.Password));
|
.And.Contain(error => error.PropertyName == nameof(authData.Password));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="AuthData"/> validator that should return validation error for too long password
|
/// Test for <see cref="AuthData"/> validator that should return validation error for too long password
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task ValidateForLongPasswordShouldReturnError()
|
private async Task ValidateForLongPasswordShouldReturnError()
|
||||||
{
|
{
|
||||||
var authData = faker.Generate();
|
var authData = faker.Generate();
|
||||||
var stringBuilder = new StringBuilder();
|
var stringBuilder = new StringBuilder();
|
||||||
stringBuilder.Append('d', ConfigurationConstraints.PasswordLength + 1);
|
stringBuilder.Append('d', ConfigurationConstraints.PasswordLength + 1);
|
||||||
@@ -97,12 +97,12 @@ namespace VisaApi.Tests.Application.Validation.Auth
|
|||||||
.And.Contain(error => error.PropertyName == nameof(authData.Password));
|
.And.Contain(error => error.PropertyName == nameof(authData.Password));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="AuthData"/> validator that should return no errors for valid password
|
/// Test for <see cref="AuthData"/> validator that should return no errors for valid password
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task ValidateForValidPasswordShouldReturnNoError()
|
private async Task ValidateForValidPasswordShouldReturnNoError()
|
||||||
{
|
{
|
||||||
var authData = faker.Generate();
|
var authData = faker.Generate();
|
||||||
|
|
||||||
var result = await validator.ValidateAsync(authData);
|
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))
|
result.Errors.Where(error => error.PropertyName == nameof(authData.Password))
|
||||||
.Should().BeEmpty();
|
.Should().BeEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -11,32 +11,32 @@ using VisaApi.Fakers.Users;
|
|||||||
using VisaApi.Tests.Infrastructure.Database;
|
using VisaApi.Tests.Infrastructure.Database;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace VisaApi.Tests.Application.Validation.Auth
|
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();
|
|
||||||
|
|
||||||
/// <summary>
|
[Collection(Collections.ContextUsingTestCollection)]
|
||||||
/// Creates validator from context
|
public class RegisterRequestValidatorTests
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="context">db context</param>
|
private readonly static IValidator<AuthData> authDataValidator = new AuthDataValidator();
|
||||||
/// <returns>RegisterRequest validator</returns>
|
private readonly static RegisterRequestFaker requestFaker = new();
|
||||||
private static IValidator<RegisterRequest> GetValidator(DbContext context)
|
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);
|
var repository = new UsersRepository(context, context);
|
||||||
return new RegisterRequestValidator(repository, authDataValidator);
|
return new RegisterRequestValidator(repository, authDataValidator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="RegisterRequest"/> validator that should throw for empty auth data
|
/// Test for <see cref="RegisterRequest"/> validator that should throw for empty auth data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task ValidateForEmptyAuthDataShouldThrow()
|
private async Task ValidateForEmptyAuthDataShouldThrow()
|
||||||
{
|
{
|
||||||
var context = InMemoryContextProvider.GetDbContext();
|
var context = InMemoryContextProvider.GetDbContext();
|
||||||
var validator = GetValidator(context);
|
var validator = GetValidator(context);
|
||||||
var request = requestFaker.Generate();
|
var request = requestFaker.Generate();
|
||||||
@@ -55,12 +55,12 @@ namespace VisaApi.Tests.Application.Validation.Auth
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="RegisterRequest"/> validator that should return error for used email
|
/// Test for <see cref="RegisterRequest"/> validator that should return error for used email
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task ValidateForUsedEmailShouldReturnError()
|
private async Task ValidateForUsedEmailShouldReturnError()
|
||||||
{
|
{
|
||||||
var context = InMemoryContextProvider.GetDbContext();
|
var context = InMemoryContextProvider.GetDbContext();
|
||||||
var validator = GetValidator(context);
|
var validator = GetValidator(context);
|
||||||
var user = userFaker.Generate();
|
var user = userFaker.Generate();
|
||||||
@@ -76,12 +76,12 @@ namespace VisaApi.Tests.Application.Validation.Auth
|
|||||||
.And.HaveCount(1);
|
.And.HaveCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="RegisterRequest"/> validator that should return o errors for valid requests
|
/// Test for <see cref="RegisterRequest"/> validator that should return o errors for valid requests
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task ValidateForValidRequestShouldReturnNoErrors()
|
private async Task ValidateForValidRequestShouldReturnNoErrors()
|
||||||
{
|
{
|
||||||
var context = InMemoryContextProvider.GetDbContext();
|
var context = InMemoryContextProvider.GetDbContext();
|
||||||
var validator = GetValidator(context);
|
var validator = GetValidator(context);
|
||||||
var request = requestFaker.Generate();
|
var request = requestFaker.Generate();
|
||||||
@@ -90,5 +90,4 @@ namespace VisaApi.Tests.Application.Validation.Auth
|
|||||||
|
|
||||||
result.Errors.Should().BeEmpty();
|
result.Errors.Should().BeEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -5,45 +5,44 @@ using FluentValidation;
|
|||||||
using VisaApi.Fakers.Users.Requests;
|
using VisaApi.Fakers.Users.Requests;
|
||||||
using Xunit;
|
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();
|
var request = faker.Generate();
|
||||||
private readonly static ChangeUserAuthDataRequestFaker faker = new();
|
request.NewAuthData = null!;
|
||||||
|
NullReferenceException? result = null;
|
||||||
|
|
||||||
/// <summary>
|
try
|
||||||
/// Test for <see cref="ChangeUserAuthDataRequest"/> validator that should throw exception for empty auth data
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task ValidateForEmptyAuthDataShouldThrow()
|
|
||||||
{
|
{
|
||||||
var request = faker.Generate();
|
await validator.ValidateAsync(request);
|
||||||
request.NewAuthData = null!;
|
}
|
||||||
NullReferenceException? result = null;
|
catch (Exception e)
|
||||||
|
{
|
||||||
try
|
result = e as NullReferenceException;
|
||||||
{
|
|
||||||
await validator.ValidateAsync(request);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
result = e as NullReferenceException;
|
|
||||||
}
|
|
||||||
|
|
||||||
result.Should().NotBeNull();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
result.Should().NotBeNull();
|
||||||
/// 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/// <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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,17 +2,17 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||||
using DbContext = Infrastructure.Database.DbContext;
|
using DbContext = Infrastructure.Database.DbContext;
|
||||||
|
|
||||||
namespace VisaApi.Tests.Infrastructure.Database
|
namespace VisaApi.Tests.Infrastructure.Database;
|
||||||
{
|
|
||||||
public static class InMemoryContextProvider
|
|
||||||
{
|
|
||||||
private static DbContextOptions<DbContext> opts = new DbContextOptionsBuilder<DbContext>()
|
|
||||||
.UseInMemoryDatabase("VisaApiDB")
|
|
||||||
.ConfigureWarnings(b => b.Ignore(InMemoryEventId.TransactionIgnoredWarning))
|
|
||||||
.Options;
|
|
||||||
|
|
||||||
public static DbContext GetDbContext()
|
public static class InMemoryContextProvider
|
||||||
{
|
{
|
||||||
|
private static DbContextOptions<DbContext> opts = new DbContextOptionsBuilder<DbContext>()
|
||||||
|
.UseInMemoryDatabase("VisaApiDB")
|
||||||
|
.ConfigureWarnings(b => b.Ignore(InMemoryEventId.TransactionIgnoredWarning))
|
||||||
|
.Options;
|
||||||
|
|
||||||
|
public static DbContext GetDbContext()
|
||||||
|
{
|
||||||
var result = new DbContext(opts);
|
var result = new DbContext(opts);
|
||||||
|
|
||||||
result.Database.EnsureDeleted();
|
result.Database.EnsureDeleted();
|
||||||
@@ -20,5 +20,4 @@ namespace VisaApi.Tests.Infrastructure.Database
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -9,29 +9,29 @@ using VisaApi.Fakers.Users;
|
|||||||
using VisaApi.Services;
|
using VisaApi.Services;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
namespace VisaApi.Tests.Infrastructure.Database.Repositories;
|
||||||
|
|
||||||
|
[Collection(Collections.ContextUsingTestCollection)]
|
||||||
|
public class ApplicantsRepositoryTests
|
||||||
{
|
{
|
||||||
[Collection(Collections.ContextUsingTestCollection)]
|
private readonly static UserFaker userFaker = new();
|
||||||
public class ApplicantsRepositoryTests
|
private readonly static ApplicantFaker applicantFaker = new(GetDateTimeProvider());
|
||||||
|
|
||||||
|
/// <summary> Returns <see cref="IApplicantsRepository"/> </summary>
|
||||||
|
/// <param name="context"> Database context </param>
|
||||||
|
/// <returns>Repository</returns>
|
||||||
|
private static IApplicantsRepository GetRepository(DbContext context)
|
||||||
|
=> new ApplicantsRepository(context, context);
|
||||||
|
|
||||||
|
/// <summary> Returns <see cref="IDateTimeProvider"/> </summary>
|
||||||
|
private static IDateTimeProvider GetDateTimeProvider() => new TestDateTimeProvider();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test for <see cref="IApplicantsRepository.FindByUserIdAsync"/> method that should throw exception for not existing entity
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task FindByUserIdForNotExistingShouldThrow()
|
||||||
{
|
{
|
||||||
private readonly static UserFaker userFaker = new();
|
|
||||||
private readonly static ApplicantFaker applicantFaker = new(GetDateTimeProvider());
|
|
||||||
|
|
||||||
/// <summary> Returns <see cref="IApplicantsRepository"/> </summary>
|
|
||||||
/// <param name="context"> Database context </param>
|
|
||||||
/// <returns>Repository</returns>
|
|
||||||
private static IApplicantsRepository GetRepository(DbContext context)
|
|
||||||
=> new ApplicantsRepository(context, context);
|
|
||||||
|
|
||||||
/// <summary> Returns <see cref="IDateTimeProvider"/> </summary>
|
|
||||||
private static IDateTimeProvider GetDateTimeProvider() => new TestDateTimeProvider();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Test for <see cref="IApplicantsRepository.FindByUserIdAsync"/> method that should throw exception for not existing entity
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task FindByUserIdForNotExistingShouldThrow()
|
|
||||||
{
|
|
||||||
await using var context = InMemoryContextProvider.GetDbContext();
|
await using var context = InMemoryContextProvider.GetDbContext();
|
||||||
var repository = GetRepository(context);
|
var repository = GetRepository(context);
|
||||||
ApplicantNotFoundByUserIdException? result = null;
|
ApplicantNotFoundByUserIdException? result = null;
|
||||||
@@ -48,12 +48,12 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="IApplicantsRepository.FindByUserIdAsync"/> method that should return existing entity
|
/// Test for <see cref="IApplicantsRepository.FindByUserIdAsync"/> method that should return existing entity
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task FindByUserIdForExistingShouldReturnApplicant()
|
private async Task FindByUserIdForExistingShouldReturnApplicant()
|
||||||
{
|
{
|
||||||
await using var context = InMemoryContextProvider.GetDbContext();
|
await using var context = InMemoryContextProvider.GetDbContext();
|
||||||
var repository = GetRepository(context);
|
var repository = GetRepository(context);
|
||||||
var user = userFaker.Generate();
|
var user = userFaker.Generate();
|
||||||
@@ -68,12 +68,12 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
|||||||
result.Should().BeEquivalentTo(applicant);
|
result.Should().BeEquivalentTo(applicant);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="IApplicantsRepository.GetApplicantIdByUserId"/> method that should throw exception for not existing entity
|
/// Test for <see cref="IApplicantsRepository.GetApplicantIdByUserId"/> method that should throw exception for not existing entity
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task GetApplicantIdByUserIdForNotExistingShouldThrow()
|
private async Task GetApplicantIdByUserIdForNotExistingShouldThrow()
|
||||||
{
|
{
|
||||||
await using var context = InMemoryContextProvider.GetDbContext();
|
await using var context = InMemoryContextProvider.GetDbContext();
|
||||||
var repository = GetRepository(context);
|
var repository = GetRepository(context);
|
||||||
ApplicantNotFoundByUserIdException? result = null;
|
ApplicantNotFoundByUserIdException? result = null;
|
||||||
@@ -90,12 +90,12 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="IApplicantsRepository.GetApplicantIdByUserId"/> method that should return existing entity's identifier
|
/// Test for <see cref="IApplicantsRepository.GetApplicantIdByUserId"/> method that should return existing entity's identifier
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task GetApplicantIdByUserIdForExistingShouldReturnApplicant()
|
private async Task GetApplicantIdByUserIdForExistingShouldReturnApplicant()
|
||||||
{
|
{
|
||||||
await using var context = InMemoryContextProvider.GetDbContext();
|
await using var context = InMemoryContextProvider.GetDbContext();
|
||||||
var repository = GetRepository(context);
|
var repository = GetRepository(context);
|
||||||
var user = userFaker.Generate();
|
var user = userFaker.Generate();
|
||||||
@@ -110,12 +110,12 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
|||||||
result.Should().Be(applicant.Id);
|
result.Should().Be(applicant.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="IApplicantsRepository.IsApplicantNonResidentByUserId"/> method that should throw exception for not existing entity
|
/// Test for <see cref="IApplicantsRepository.IsApplicantNonResidentByUserId"/> method that should throw exception for not existing entity
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task IsApplicantNonResidentByUserIdForNotExistingShouldThrow()
|
private async Task IsApplicantNonResidentByUserIdForNotExistingShouldThrow()
|
||||||
{
|
{
|
||||||
await using var context = InMemoryContextProvider.GetDbContext();
|
await using var context = InMemoryContextProvider.GetDbContext();
|
||||||
var repository = GetRepository(context);
|
var repository = GetRepository(context);
|
||||||
ApplicantNotFoundByUserIdException? result = null;
|
ApplicantNotFoundByUserIdException? result = null;
|
||||||
@@ -132,12 +132,12 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="IApplicantsRepository.IsApplicantNonResidentByUserId"/> method that should return existing entity's IsNonResident property
|
/// Test for <see cref="IApplicantsRepository.IsApplicantNonResidentByUserId"/> method that should return existing entity's IsNonResident property
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task IsApplicantNonResidentByUserIdForExistingShouldReturnApplicant()
|
private async Task IsApplicantNonResidentByUserIdForExistingShouldReturnApplicant()
|
||||||
{
|
{
|
||||||
await using var context = InMemoryContextProvider.GetDbContext();
|
await using var context = InMemoryContextProvider.GetDbContext();
|
||||||
var repository = GetRepository(context);
|
var repository = GetRepository(context);
|
||||||
var user = userFaker.Generate();
|
var user = userFaker.Generate();
|
||||||
@@ -151,5 +151,4 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
|||||||
|
|
||||||
result.Should().Be(applicant.IsNonResident);
|
result.Should().Be(applicant.IsNonResident);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
using Domains.Users;
|
using Domains.Users;
|
||||||
using Infrastructure.Database.Generic;
|
using Infrastructure.Database.Generic;
|
||||||
|
|
||||||
namespace VisaApi.Tests.Infrastructure.Database.Repositories.Generic
|
namespace VisaApi.Tests.Infrastructure.Database.Repositories.Generic;
|
||||||
{
|
|
||||||
public class TestGenericRepository(IGenericReader reader, IGenericWriter writer) : GenericRepository<User>(reader, writer);
|
public class TestGenericRepository(IGenericReader reader, IGenericWriter writer) : GenericRepository<User>(reader, writer);
|
||||||
}
|
|
||||||
@@ -7,25 +7,25 @@ using Infrastructure.Database.Users.Repositories;
|
|||||||
using VisaApi.Fakers.Users;
|
using VisaApi.Fakers.Users;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
namespace VisaApi.Tests.Infrastructure.Database.Repositories;
|
||||||
|
|
||||||
|
[Collection(Collections.ContextUsingTestCollection)]
|
||||||
|
public class UsersRepositoryTests
|
||||||
{
|
{
|
||||||
[Collection(Collections.ContextUsingTestCollection)]
|
private readonly static UserFaker userFaker = new();
|
||||||
public class UsersRepositoryTests
|
|
||||||
|
/// <summary> Returns <see cref="IVisaApplicationsRepository"/> </summary>
|
||||||
|
/// <param name="context"> Database context </param>
|
||||||
|
/// <returns>Repository</returns>
|
||||||
|
private static IUsersRepository GetRepository(DbContext context)
|
||||||
|
=> new UsersRepository(context, context);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test for <see cref="IUsersRepository.FindByEmailAsync"/> method that should return null for not existing email
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task FindByEmailForNotExistingShouldReturnNull()
|
||||||
{
|
{
|
||||||
private readonly static UserFaker userFaker = new();
|
|
||||||
|
|
||||||
/// <summary> Returns <see cref="IVisaApplicationsRepository"/> </summary>
|
|
||||||
/// <param name="context"> Database context </param>
|
|
||||||
/// <returns>Repository</returns>
|
|
||||||
private static IUsersRepository GetRepository(DbContext context)
|
|
||||||
=> new UsersRepository(context, context);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Test for <see cref="IUsersRepository.FindByEmailAsync"/> method that should return null for not existing email
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task FindByEmailForNotExistingShouldReturnNull()
|
|
||||||
{
|
|
||||||
await using var context = InMemoryContextProvider.GetDbContext();
|
await using var context = InMemoryContextProvider.GetDbContext();
|
||||||
var repository = GetRepository(context);
|
var repository = GetRepository(context);
|
||||||
|
|
||||||
@@ -34,12 +34,12 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
|||||||
result.Should().BeNull();
|
result.Should().BeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="IUsersRepository.FindByEmailAsync"/> method that should return entity for existing email
|
/// Test for <see cref="IUsersRepository.FindByEmailAsync"/> method that should return entity for existing email
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task FindByEmailForExistingShouldReturnEntity()
|
private async Task FindByEmailForExistingShouldReturnEntity()
|
||||||
{
|
{
|
||||||
await using var context = InMemoryContextProvider.GetDbContext();
|
await using var context = InMemoryContextProvider.GetDbContext();
|
||||||
var repository = GetRepository(context);
|
var repository = GetRepository(context);
|
||||||
var user = userFaker.Generate();
|
var user = userFaker.Generate();
|
||||||
@@ -51,12 +51,12 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
|||||||
result.Should().Be(user);
|
result.Should().Be(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="IUsersRepository.GetAllOfRoleAsync"/> method that should return empty from empty db
|
/// Test for <see cref="IUsersRepository.GetAllOfRoleAsync"/> method that should return empty from empty db
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task GetAllOfRoleForEmptyShouldReturnEmpty()
|
private async Task GetAllOfRoleForEmptyShouldReturnEmpty()
|
||||||
{
|
{
|
||||||
await using var context = InMemoryContextProvider.GetDbContext();
|
await using var context = InMemoryContextProvider.GetDbContext();
|
||||||
var repository = GetRepository(context);
|
var repository = GetRepository(context);
|
||||||
|
|
||||||
@@ -65,12 +65,12 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
|||||||
result.Should().BeEmpty();
|
result.Should().BeEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="IUsersRepository.GetAllOfRoleAsync"/> method that should return entities from not empty db
|
/// Test for <see cref="IUsersRepository.GetAllOfRoleAsync"/> method that should return entities from not empty db
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task GetAllOfRoleForNotEmptyShouldReturnEntities()
|
private async Task GetAllOfRoleForNotEmptyShouldReturnEntities()
|
||||||
{
|
{
|
||||||
await using var context = InMemoryContextProvider.GetDbContext();
|
await using var context = InMemoryContextProvider.GetDbContext();
|
||||||
var repository = GetRepository(context);
|
var repository = GetRepository(context);
|
||||||
var users = new List<User>();
|
var users = new List<User>();
|
||||||
@@ -88,5 +88,4 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
|||||||
|
|
||||||
result.Should().Contain(users).And.HaveSameCount(users);
|
result.Should().Contain(users).And.HaveSameCount(users);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -11,30 +11,30 @@ using VisaApi.Fakers.VisaApplications;
|
|||||||
using VisaApi.Services;
|
using VisaApi.Services;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
namespace VisaApi.Tests.Infrastructure.Database.Repositories;
|
||||||
|
|
||||||
|
[Collection(Collections.ContextUsingTestCollection)]
|
||||||
|
public class VisaApplicationsRepositoryTests
|
||||||
{
|
{
|
||||||
[Collection(Collections.ContextUsingTestCollection)]
|
private readonly static UserFaker userFaker = new();
|
||||||
public class VisaApplicationsRepositoryTests
|
private readonly static ApplicantFaker applicantFaker = new(GetDateTimeProvider());
|
||||||
|
private readonly static VisaApplicationFaker applicationFaker = new(GetDateTimeProvider());
|
||||||
|
|
||||||
|
/// <summary> Returns <see cref="IVisaApplicationsRepository"/> </summary>
|
||||||
|
/// <param name="context"> Database context </param>
|
||||||
|
/// <returns>Repository</returns>
|
||||||
|
private static IVisaApplicationsRepository GetRepository(DbContext context)
|
||||||
|
=> new VisaApplicationsRepository(context, context);
|
||||||
|
|
||||||
|
/// <summary> Returns <see cref="IDateTimeProvider"/> </summary>
|
||||||
|
private static IDateTimeProvider GetDateTimeProvider() => new TestDateTimeProvider();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test for <see cref="IVisaApplicationsRepository.GetOfApplicantAsync"/> method that should return empty if no applications added
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
private async Task GetOfApplicantForEmptyShouldReturnEmpty()
|
||||||
{
|
{
|
||||||
private readonly static UserFaker userFaker = new();
|
|
||||||
private readonly static ApplicantFaker applicantFaker = new(GetDateTimeProvider());
|
|
||||||
private readonly static VisaApplicationFaker applicationFaker = new(GetDateTimeProvider());
|
|
||||||
|
|
||||||
/// <summary> Returns <see cref="IVisaApplicationsRepository"/> </summary>
|
|
||||||
/// <param name="context"> Database context </param>
|
|
||||||
/// <returns>Repository</returns>
|
|
||||||
private static IVisaApplicationsRepository GetRepository(DbContext context)
|
|
||||||
=> new VisaApplicationsRepository(context, context);
|
|
||||||
|
|
||||||
/// <summary> Returns <see cref="IDateTimeProvider"/> </summary>
|
|
||||||
private static IDateTimeProvider GetDateTimeProvider() => new TestDateTimeProvider();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Test for <see cref="IVisaApplicationsRepository.GetOfApplicantAsync"/> method that should return empty if no applications added
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
private async Task GetOfApplicantForEmptyShouldReturnEmpty()
|
|
||||||
{
|
|
||||||
await using var context = InMemoryContextProvider.GetDbContext();
|
await using var context = InMemoryContextProvider.GetDbContext();
|
||||||
var repository = GetRepository(context);
|
var repository = GetRepository(context);
|
||||||
var user = userFaker.Generate();
|
var user = userFaker.Generate();
|
||||||
@@ -49,12 +49,12 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
|||||||
result.Should().BeEmpty();
|
result.Should().BeEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="IVisaApplicationsRepository.GetOfApplicantAsync"/> method that should return added entities
|
/// Test for <see cref="IVisaApplicationsRepository.GetOfApplicantAsync"/> method that should return added entities
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task GetOfApplicantForExistingShouldReturnEntities()
|
private async Task GetOfApplicantForExistingShouldReturnEntities()
|
||||||
{
|
{
|
||||||
await using var context = InMemoryContextProvider.GetDbContext();
|
await using var context = InMemoryContextProvider.GetDbContext();
|
||||||
var repository = GetRepository(context);
|
var repository = GetRepository(context);
|
||||||
var user = userFaker.Generate();
|
var user = userFaker.Generate();
|
||||||
@@ -77,12 +77,12 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
|||||||
result.Should().Contain(applications).And.HaveSameCount(applications);
|
result.Should().Contain(applications).And.HaveSameCount(applications);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="IVisaApplicationsRepository.GetByApplicantAndApplicationIdAsync"/> method that should throw exception for not existing entities
|
/// Test for <see cref="IVisaApplicationsRepository.GetByApplicantAndApplicationIdAsync"/> method that should throw exception for not existing entities
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task GetApplicantIdByUserIdForNotExistingShouldThrow()
|
private async Task GetApplicantIdByUserIdForNotExistingShouldThrow()
|
||||||
{
|
{
|
||||||
await using var context = InMemoryContextProvider.GetDbContext();
|
await using var context = InMemoryContextProvider.GetDbContext();
|
||||||
var repository = GetRepository(context);
|
var repository = GetRepository(context);
|
||||||
ApplicationNotFoundByApplicantAndApplicationIdException? result = null;
|
ApplicationNotFoundByApplicantAndApplicationIdException? result = null;
|
||||||
@@ -101,12 +101,12 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="IVisaApplicationsRepository.GetByApplicantAndApplicationIdAsync"/> method that should throw exception for not existing applicant
|
/// Test for <see cref="IVisaApplicationsRepository.GetByApplicantAndApplicationIdAsync"/> method that should throw exception for not existing applicant
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task GetApplicantIdByUserIdForNotExistingApplicantShouldThrow()
|
private async Task GetApplicantIdByUserIdForNotExistingApplicantShouldThrow()
|
||||||
{
|
{
|
||||||
await using var context = InMemoryContextProvider.GetDbContext();
|
await using var context = InMemoryContextProvider.GetDbContext();
|
||||||
var repository = GetRepository(context);
|
var repository = GetRepository(context);
|
||||||
var user = userFaker.Generate();
|
var user = userFaker.Generate();
|
||||||
@@ -132,12 +132,12 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="IVisaApplicationsRepository.GetByApplicantAndApplicationIdAsync"/> method that should throw exception for not existing application
|
/// Test for <see cref="IVisaApplicationsRepository.GetByApplicantAndApplicationIdAsync"/> method that should throw exception for not existing application
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task GetApplicantIdByUserIdForNotExistingApplicationShouldThrow()
|
private async Task GetApplicantIdByUserIdForNotExistingApplicationShouldThrow()
|
||||||
{
|
{
|
||||||
await using var context = InMemoryContextProvider.GetDbContext();
|
await using var context = InMemoryContextProvider.GetDbContext();
|
||||||
var repository = GetRepository(context);
|
var repository = GetRepository(context);
|
||||||
var user = userFaker.Generate();
|
var user = userFaker.Generate();
|
||||||
@@ -161,13 +161,13 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="IVisaApplicationsRepository.GetByApplicantAndApplicationIdAsync"/> method
|
/// Test for <see cref="IVisaApplicationsRepository.GetByApplicantAndApplicationIdAsync"/> method
|
||||||
/// that should throw exception for not accessible application
|
/// that should throw exception for not accessible application
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task GetApplicantIdByUserIdForNotAccessibleApplicationShouldThrow()
|
private async Task GetApplicantIdByUserIdForNotAccessibleApplicationShouldThrow()
|
||||||
{
|
{
|
||||||
await using var context = InMemoryContextProvider.GetDbContext();
|
await using var context = InMemoryContextProvider.GetDbContext();
|
||||||
var repository = GetRepository(context);
|
var repository = GetRepository(context);
|
||||||
var user = userFaker.Generate();
|
var user = userFaker.Generate();
|
||||||
@@ -198,13 +198,13 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="IVisaApplicationsRepository.GetByApplicantAndApplicationIdAsync"/> method
|
/// Test for <see cref="IVisaApplicationsRepository.GetByApplicantAndApplicationIdAsync"/> method
|
||||||
/// that should return application for valid identifiers
|
/// that should return application for valid identifiers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task GetApplicantIdByUserIdForValidIdsShouldReturnApplication()
|
private async Task GetApplicantIdByUserIdForValidIdsShouldReturnApplication()
|
||||||
{
|
{
|
||||||
await using var context = InMemoryContextProvider.GetDbContext();
|
await using var context = InMemoryContextProvider.GetDbContext();
|
||||||
var repository = GetRepository(context);
|
var repository = GetRepository(context);
|
||||||
var user = userFaker.Generate();
|
var user = userFaker.Generate();
|
||||||
@@ -222,12 +222,12 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
|||||||
result.Should().Be(application);
|
result.Should().Be(application);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="IVisaApplicationsRepository.GetPendingApplicationsAsync"/> method that should return empty from empty db
|
/// Test for <see cref="IVisaApplicationsRepository.GetPendingApplicationsAsync"/> method that should return empty from empty db
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task GetPendingApplicationsForEmptyShouldReturnEmpty()
|
private async Task GetPendingApplicationsForEmptyShouldReturnEmpty()
|
||||||
{
|
{
|
||||||
await using var context = InMemoryContextProvider.GetDbContext();
|
await using var context = InMemoryContextProvider.GetDbContext();
|
||||||
var repository = GetRepository(context);
|
var repository = GetRepository(context);
|
||||||
|
|
||||||
@@ -236,12 +236,12 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
|||||||
result.Should().BeEmpty();
|
result.Should().BeEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for <see cref="IVisaApplicationsRepository.GetPendingApplicationsAsync"/> method that should return pending applications from not empty db
|
/// Test for <see cref="IVisaApplicationsRepository.GetPendingApplicationsAsync"/> method that should return pending applications from not empty db
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
private async Task GetPendingApplicationsForExistingShouldReturnExistingPending()
|
private async Task GetPendingApplicationsForExistingShouldReturnExistingPending()
|
||||||
{
|
{
|
||||||
await using var context = InMemoryContextProvider.GetDbContext();
|
await using var context = InMemoryContextProvider.GetDbContext();
|
||||||
var repository = GetRepository(context);
|
var repository = GetRepository(context);
|
||||||
var user = userFaker.Generate();
|
var user = userFaker.Generate();
|
||||||
@@ -262,5 +262,4 @@ namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
|||||||
|
|
||||||
result.Should().Contain(applicationPending).And.HaveCount(1);
|
result.Should().Contain(applicationPending).And.HaveCount(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user