2022-01-17 16:06:20 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using AsbCloudInfrastructure.Services;
|
|
|
|
|
using AsbCloudInfrastructure.Services.Cache;
|
|
|
|
|
using Moq;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Tests.ServicesTests
|
|
|
|
|
{
|
|
|
|
|
public class UserServiceTest
|
|
|
|
|
{
|
|
|
|
|
private readonly AsbCloudDbContext context;
|
|
|
|
|
private readonly CacheDb cacheDb;
|
|
|
|
|
private readonly Mock<IUserRoleService> roleService;
|
|
|
|
|
|
|
|
|
|
public UserServiceTest()
|
|
|
|
|
{
|
|
|
|
|
context = TestHelpter.MakeTestContext();
|
|
|
|
|
cacheDb = new CacheDb();
|
|
|
|
|
roleService = new Mock<IUserRoleService>();
|
|
|
|
|
|
|
|
|
|
context.Users.RemoveRange(context.Users.Where(u => u.Id > 1));
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~UserServiceTest()
|
|
|
|
|
{
|
|
|
|
|
context.Users.RemoveRange(context.Users.Where(u => u.Id > 1));
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task InsertAsync_returns_id()
|
2022-06-15 14:57:37 +05:00
|
|
|
|
{
|
2022-01-17 16:06:20 +05:00
|
|
|
|
var service = new UserService(context, cacheDb, roleService.Object);
|
|
|
|
|
var dto = new UserExtendedDto
|
|
|
|
|
{
|
|
|
|
|
Id = 0,
|
|
|
|
|
IdCompany = 1,
|
|
|
|
|
Email = "test@test.test",
|
|
|
|
|
Login = "test",
|
|
|
|
|
Name = "test",
|
|
|
|
|
Company = new CompanyDto { Caption = "test", Id = 1 },
|
|
|
|
|
Patronymic = "test",
|
|
|
|
|
Phone = "test",
|
|
|
|
|
Position = "test",
|
|
|
|
|
Surname = "test",
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
var id = await service.InsertAsync(dto, CancellationToken.None);
|
|
|
|
|
|
|
|
|
|
Assert.NotEqual(0, id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task InsertAsync_busy_login_throws_exceprion()
|
|
|
|
|
{
|
|
|
|
|
var service = new UserService(context, cacheDb, roleService.Object);
|
|
|
|
|
var dto = new UserExtendedDto
|
|
|
|
|
{
|
|
|
|
|
Id = 5,
|
|
|
|
|
Email = "test@test.test",
|
|
|
|
|
Login = "test clone"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await service.InsertAsync(dto, CancellationToken.None);
|
|
|
|
|
await Assert.ThrowsAsync<ArgumentException>(() => service.InsertAsync(dto, CancellationToken.None));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|