Started validation tests
This commit is contained in:
@@ -7,6 +7,9 @@ namespace ApplicationLayer.Services.Users.Requests.Validation
|
||||
{
|
||||
public ChangeUserAuthDataRequestValidator()
|
||||
{
|
||||
RuleFor(r => r.UserId)
|
||||
.NotEmpty();
|
||||
|
||||
RuleFor(r => r.NewAuthData)
|
||||
.NotEmpty();
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using ApplicationLayer.Services.Users.Models;
|
||||
using Bogus;
|
||||
|
||||
namespace VisaApi.Fakers.Common
|
||||
{
|
||||
public sealed class ChangeAuthDataFaker : Faker<ChangeAuthData>
|
||||
{
|
||||
public ChangeAuthDataFaker()
|
||||
{
|
||||
RuleFor(a => a.Email, f => f.Internet.Email());
|
||||
|
||||
RuleFor(a => a.Password, f => f.Internet.Password());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using ApplicationLayer.Services.Users.Requests;
|
||||
using Bogus;
|
||||
using VisaApi.Fakers.Common;
|
||||
|
||||
namespace VisaApi.Fakers.Users.Requests
|
||||
{
|
||||
public sealed class ChangeUserAuthDataRequestFaker : Faker<ChangeUserAuthDataRequest>
|
||||
{
|
||||
private static ChangeAuthDataFaker changeAuthDataFaker = new();
|
||||
|
||||
public ChangeUserAuthDataRequestFaker()
|
||||
{
|
||||
CustomInstantiator(_ => new(Guid.NewGuid(), changeAuthDataFaker.Generate()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using Bogus;
|
||||
using Domains.Users;
|
||||
|
||||
namespace VisaApi.Fakers.Common
|
||||
namespace VisaApi.Fakers.Users
|
||||
{
|
||||
/// <summary>
|
||||
/// Generates users
|
||||
@@ -0,0 +1,37 @@
|
||||
using ApplicationLayer.Services.Users.Requests;
|
||||
using ApplicationLayer.Services.Users.Requests.Validation;
|
||||
using FluentAssertions;
|
||||
using FluentValidation;
|
||||
using VisaApi.Fakers.Users.Requests;
|
||||
using Xunit;
|
||||
|
||||
namespace VisaApi.Tests.Application.Validation.Users
|
||||
{
|
||||
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 return validation error for empty auth data
|
||||
/// </summary>
|
||||
[Fact]
|
||||
private async Task ValidateForEmptyAuthDataShouldReturnError()
|
||||
{
|
||||
var request = faker.Generate();
|
||||
request.NewAuthData = null!;
|
||||
NullReferenceException? result = null;
|
||||
|
||||
try
|
||||
{
|
||||
await validator.ValidateAsync(request);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
result = e as NullReferenceException;
|
||||
}
|
||||
|
||||
result.Should().NotBeNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using Infrastructure.Database;
|
||||
using Infrastructure.Database.Applicants.Repositories;
|
||||
using Infrastructure.Database.Applicants.Repositories.Exceptions;
|
||||
using VisaApi.Fakers.Applicants;
|
||||
using VisaApi.Fakers.Common;
|
||||
using VisaApi.Fakers.Users;
|
||||
using VisaApi.Services;
|
||||
using Xunit;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using Domains.Users;
|
||||
using FluentAssertions;
|
||||
using Infrastructure.Database;
|
||||
using Infrastructure.Database.Users.Repositories;
|
||||
using VisaApi.Fakers.Common;
|
||||
using VisaApi.Fakers.Users;
|
||||
using Xunit;
|
||||
|
||||
namespace VisaApi.Tests.Infrastructure.Database.Repositories
|
||||
|
||||
@@ -6,7 +6,7 @@ using Infrastructure.Database;
|
||||
using Infrastructure.Database.VisaApplications.Repositories;
|
||||
using Infrastructure.Database.VisaApplications.Repositories.Exceptions;
|
||||
using VisaApi.Fakers.Applicants;
|
||||
using VisaApi.Fakers.Common;
|
||||
using VisaApi.Fakers.Users;
|
||||
using VisaApi.Fakers.VisaApplications;
|
||||
using VisaApi.Services;
|
||||
using Xunit;
|
||||
|
||||
Reference in New Issue
Block a user