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; 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; private readonly Mock fileServiceMock; private readonly Mock userRepositoryMock; private readonly Mock wellServiceMock; private readonly Mock configurationMock; private readonly Mock emailServiceMock; private readonly Mock fileCategoryService; private readonly IEnumerable users = new List { new UserDto { Id = 1, IdCompany = 1, Name = "test", Email = "test@test.com" }, new UserDto { Id = 3, IdCompany = 1, Name = "test1", Email = "test1@test1.com" } }; public WellFinalDocumentsServiceTest() { context = TestHelpter.MakeTestContext(); context.SaveChanges(); fileServiceMock = new Mock(); userRepositoryMock = new Mock(); userRepositoryMock.Setup(x => x.GetAllAsync(CancellationToken.None)).Returns(Task.Run(() => users.Select(x => (UserExtendedDto)x))); wellServiceMock = new Mock(); configurationMock = new Mock(); emailServiceMock = new Mock(); fileCategoryService = new Mock(); 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() { var data = await service.GetByWellId(90, 1,CancellationToken.None); Assert.NotNull(data); } [Fact] public async Task GetListResponsibles_return_cnt_users() { var data = await service.GetAvailableUsersAsync(90, CancellationToken.None); Assert.NotNull(data); } [Fact] public async Task GetHistoryFileByIdCategory_return_data_hitory() { var data = await service.GetFilesHistoryByIdCategory(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); var data = await service.SaveCategoryFile(21, 10018, 78, stream, "test.txt", CancellationToken.None); Assert.Equal(21, data); } } }