DD.WellWorkover.Cloud/AsbCloudWebApi.Tests/ServicesTests/DrillerServiceTest.cs

85 lines
2.5 KiB
C#
Raw Normal View History

using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services;
using AsbCloudInfrastructure.Services.Cache;
using Moq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
namespace AsbCloudWebApi.Tests.ServicesTests
{
public class DrillerServiceTest
{
private readonly AsbCloudDbContext context;
private readonly CacheDb cacheDb;
2022-05-25 20:58:29 +05:00
private Driller driller = new Driller
{
Id = 1,
Name = "Тестовый",
Patronymic = "Тест",
Surname = "Тестович"
};
private DrillerDto drillerObj = new DrillerDto
{
Id = 0,
Name = "Тестовый",
Patronymic = "Тест",
Surname = "Тестович"
};
2022-05-25 20:58:29 +05:00
private DrillerService service;
2022-05-25 20:58:29 +05:00
public DrillerServiceTest()
{
2022-05-25 20:58:29 +05:00
context = TestHelpter.MakeTestContext();
cacheDb = new CacheDb();
context.SaveChanges();
2022-05-25 20:58:29 +05:00
service = new DrillerService(context);
}
~DrillerServiceTest()
{
}
[Fact]
public async Task GetListAsync_count()
{
///Добавляем элемент
var id = await service.InsertAsync(drillerObj, CancellationToken.None);
id = await service.InsertAsync(drillerObj, CancellationToken.None);
id = await service.InsertAsync(drillerObj, CancellationToken.None);
var newCount = (await service.GetAllAsync(CancellationToken.None)).Count();
2022-05-25 20:19:08 +05:00
Assert.Equal(3, newCount);
}
[Fact]
public async Task InsertAsync_returns_id()
{
var id = await service.InsertAsync(drillerObj, CancellationToken.None);
Assert.NotEqual(0, id);
}
[Fact]
public async Task UpdateAsync_not_add_if_exists()
{
///Добавляем элемент
2022-05-25 20:58:56 +05:00
context.Drillers.Add(driller);
var oldCount = (await service.GetAllAsync(CancellationToken.None)).Count();
//Обновляем
2022-05-25 20:58:56 +05:00
drillerObj.Id = driller.Id;
drillerObj.Name = "Исправлено";
2022-06-09 13:36:14 +05:00
await service.UpdateAsync(drillerObj, CancellationToken.None);
var newCount = (await service.GetAllAsync(CancellationToken.None)).Count();
Assert.Equal(newCount, oldCount);
}
}
}