using AsbCloudApp.Data; using AsbCloudApp.Repositories; using Moq; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using Xunit; namespace AsbCloudWebApi.Tests.ServicesTests { public class WellCompositeRepositoryTest { private readonly Mock wellCompositeRepository; private static List Data = new List { new WellCompositeDto { IdWell = 90, IdWellSrc = 4, IdWellSectionType = 2 }, new WellCompositeDto { IdWell = 90, IdWellSrc = 4, IdWellSectionType = 3 }, new WellCompositeDto { IdWell = 90, IdWellSrc = 44, IdWellSectionType = 6 }, new WellCompositeDto { IdWell = 4, IdWellSrc = 4, IdWellSectionType = 6 } }; public WellCompositeRepositoryTest() { wellCompositeRepository = new Mock(); wellCompositeRepository.Setup(x => x.GetAsync(It.IsAny(), It.IsAny())) .Returns((int idWell, CancellationToken token) => { var data = Data.Where(x => x.IdWell == idWell); return Task.FromResult(data); }); wellCompositeRepository.Setup(x => x.SaveAsync(It.IsAny(), It.IsAny>(), It.IsAny())) .Returns((int idWell, IEnumerable wellComposites, CancellationToken token) => { Data.AddRange(wellComposites); return Task.FromResult(Data.Count); }); } [Fact] public async Task GetAsync_returns_WellCompositeDto() { var data = await wellCompositeRepository.Object.GetAsync(90, CancellationToken.None); Assert.NotNull(data); } [Fact] public async Task SaveAsync() { var cnt = Data.Count; var dtos = new List { new WellCompositeDto { IdWell = 4, IdWellSrc = 44, IdWellSectionType = 6 } }; var result = await wellCompositeRepository.Object.SaveAsync(4, dtos, CancellationToken.None); Assert.True(cnt < Data.Count); } } }