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

81 lines
2.6 KiB
C#
Raw Normal View History

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<IWellCompositeRepository> wellCompositeRepository;
private static List<WellCompositeDto> Data = new List<WellCompositeDto> {
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<IWellCompositeRepository>();
wellCompositeRepository.Setup(x => x.GetAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
.Returns((int idWell, CancellationToken token) => {
var data = Data.Where(x => x.IdWell == idWell);
return Task.FromResult(data);
});
wellCompositeRepository.Setup(x => x.SaveAsync(It.IsAny<int>(), It.IsAny<IEnumerable<WellCompositeDto>>(), It.IsAny<CancellationToken>()))
.Returns((int idWell, IEnumerable<WellCompositeDto> 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<WellCompositeDto> {
new WellCompositeDto {
IdWell = 4,
IdWellSrc = 44,
IdWellSectionType = 6
}
};
var result = await wellCompositeRepository.Object.SaveAsync(4, dtos, CancellationToken.None);
Assert.True(cnt < Data.Count);
}
}
}