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

102 lines
3.5 KiB
C#
Raw Normal View History

using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services;
using Microsoft.Extensions.Configuration;
using Moq;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
using System.IO;
2022-09-05 09:59:14 +05:00
using System.Collections.Generic;
using System.Linq;
using AsbCloudApp.Repositories;
using AsbCloudInfrastructure.Repository;
namespace AsbCloudWebApi.Tests.ServicesTests
{
public class WellFinalDocumentsServiceTest
{
private readonly AsbCloudDbContext context;
private WellFinalDocumentsService service;
2022-10-06 14:37:03 +05:00
private readonly Mock<FileService> fileServiceMock;
private readonly Mock<IUserRepository> userRepositoryMock;
private readonly Mock<IWellService> wellServiceMock;
private readonly Mock<IConfiguration> configurationMock;
private readonly Mock<IEmailService> emailServiceMock;
private readonly Mock<IFileCategoryService> fileCategoryService;
private readonly IEnumerable<UserDto> users = new List<UserDto> {
new UserDto {
2022-09-05 09:59:14 +05:00
Id = 1,
IdCompany = 1,
Name = "test",
Email = "test@test.com"
},
new UserDto {
2022-09-05 09:59:14 +05:00
Id = 3,
IdCompany = 1,
Name = "test1",
Email = "test1@test1.com"
}
};
public WellFinalDocumentsServiceTest()
{
2022-11-15 17:44:48 +05:00
context = TestHelpter.MakeRealTestContext();
context.SaveChanges();
2022-10-06 14:37:03 +05:00
fileServiceMock = new Mock<FileService>();
userRepositoryMock = new Mock<IUserRepository>();
userRepositoryMock.Setup(x => x.GetAllAsync(CancellationToken.None)).Returns(Task.Run(() => users.Select(x => (UserExtendedDto)x)));
2022-09-05 09:59:14 +05:00
wellServiceMock = new Mock<IWellService>();
configurationMock = new Mock<IConfiguration>();
emailServiceMock = new Mock<IEmailService>();
fileCategoryService = new Mock<IFileCategoryService>();
service = new WellFinalDocumentsService(
context: context,
fileService: fileServiceMock.Object,
userRepository: userRepositoryMock.Object,
wellService: wellServiceMock.Object,
configuration: configurationMock.Object,
emailService: emailServiceMock.Object,
fileCategoryService: fileCategoryService.Object);
}
~WellFinalDocumentsServiceTest()
{
}
[Fact]
public async Task GetWellFinalDocument_return_collection_rows()
{
2022-11-23 17:21:47 +05:00
var data = await service.GetByWellIdAsync(90, 1,CancellationToken.None);
Assert.NotNull(data);
}
[Fact]
public async Task GetListResponsibles_return_cnt_users()
{
var data = await service.GetAvailableUsersAsync(90, CancellationToken.None);
2022-09-05 09:59:14 +05:00
Assert.NotNull(data);
}
[Fact]
public async Task GetHistoryFileByIdCategory_return_data_hitory()
{
2022-11-23 17:21:47 +05:00
var data = await service.GetFilesHistoryByIdCategoryAsync(90, 10018, CancellationToken.None);
Assert.NotNull(data);
}
[Fact]
public async Task SaveCategoryFile_return_id_edit_record()
{
var stream = new FileStream("D:\\test\\test.txt", FileMode.Open);
2022-11-23 17:21:47 +05:00
var data = await service.SaveCategoryFileAsync(21, 10018, 78, stream, "test.txt", CancellationToken.None);
Assert.Equal(21, data);
}
}
}