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

178 lines
6.1 KiB
C#
Raw Normal View History

2022-06-15 14:57:37 +05:00
using AsbCloudApp.Services;
2022-01-27 09:38:52 +05:00
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services;
2022-06-15 14:57:37 +05:00
using Moq;
2022-01-27 09:38:52 +05:00
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
namespace AsbCloudWebApi.Tests.ServicesTests;
public class ClusterServiceTest
{
private readonly AsbCloudDbContext context;
private readonly Mock<IWellService> wellService;
2022-01-27 09:38:52 +05:00
private readonly List<Deposit> deposits = new()
{
new Deposit { Id = 1, Caption = "Test deposit 1" },
new Deposit { Id = 2, Caption = "Test deposit 2" },
new Deposit { Id = 3, Caption = "Test deposit 3" },
new Deposit { Id = 4, Caption = "Test deposit 4" }
2022-01-27 09:38:52 +05:00
};
2022-06-15 14:57:37 +05:00
2022-01-27 09:38:52 +05:00
private readonly List<Cluster> clusters = new()
{
new Cluster { Id = 1, Caption = "Test cluster 1", IdDeposit = 1, Timezone = new SimpleTimezone()},
new Cluster { Id = 2, Caption = "Test cluster 2", IdDeposit = 1, Timezone = new SimpleTimezone() },
new Cluster { Id = 3, Caption = "Test cluster 3", IdDeposit = 2, Timezone = new SimpleTimezone() },
new Cluster { Id = 4, Caption = "Test cluster 4", IdDeposit = 2, Timezone = new SimpleTimezone() }
2022-01-27 09:38:52 +05:00
};
2022-06-15 14:57:37 +05:00
2022-01-27 09:38:52 +05:00
private readonly List<Well> wells = new()
{
new Well { Id = 1, Caption = "Test well 1", IdCluster = 1 },
new Well { Id = 2, Caption = "Test well 2", IdCluster = 2 },
new Well { Id = 3, Caption = "Test well 3", IdCluster = 1 },
new Well { Id = 4, Caption = "Test well 4", IdCluster = 2 }
};
2022-06-15 14:57:37 +05:00
private readonly List<CompanyType> companiesTypes = new()
{
new CompanyType { Id = 1, Caption = "test company type"}
2022-01-27 09:38:52 +05:00
};
2022-06-15 14:57:37 +05:00
2022-01-27 09:38:52 +05:00
private readonly List<Company> companies = new()
{
new Company { Id = 1, Caption = "Test company 1", IdCompanyType = 1},
new Company { Id = 2, Caption = "Test company 2", IdCompanyType = 1}
2022-01-27 09:38:52 +05:00
};
2022-06-15 14:57:37 +05:00
2022-01-27 09:38:52 +05:00
private readonly List<RelationCompanyWell> relations = new()
{
new RelationCompanyWell { IdCompany = 1, IdWell = 1 },
new RelationCompanyWell { IdCompany = 1, IdWell = 2 },
new RelationCompanyWell { IdCompany = 2, IdWell = 2 }
};
2022-06-15 14:57:37 +05:00
private readonly List<WellSectionType> wellSectionTypes = new()
{
new WellSectionType { Id = 1, Caption = "Test well section type 1" }
};
private readonly List<DrillParams> drillParams = new()
{
new DrillParams {Id = 1, IdWell = 1, IdWellSectionType = 1},
new DrillParams {Id = 2, IdWell = 2, IdWellSectionType = 1}
2022-01-27 09:38:52 +05:00
};
2022-06-15 14:57:37 +05:00
2022-01-27 09:38:52 +05:00
public ClusterServiceTest()
{
2022-11-15 17:44:48 +05:00
context = TestHelpter.MakeRealTestContext();
2022-01-27 09:38:52 +05:00
wellService = new Mock<IWellService>();
context.Deposits.RemoveRange(context.Deposits);
context.Clusters.RemoveRange(context.Clusters);
context.Wells.RemoveRange(context.Wells);
context.CompaniesTypes.RemoveRange(context.CompaniesTypes);
context.Companies.RemoveRange(context.Companies);
context.RelationCompaniesWells.RemoveRange(context.RelationCompaniesWells);
context.WellSectionTypes.RemoveRange(context.WellSectionTypes);
context.DrillParams.RemoveRange(context.DrillParams);
2022-06-15 14:57:37 +05:00
if (context.ChangeTracker.HasChanges())
context.SaveChanges();
2022-01-27 09:38:52 +05:00
context.Deposits.AddRange(deposits);
context.Clusters.AddRange(clusters);
context.Wells.AddRange(wells);
context.CompaniesTypes.AddRange(companiesTypes);
2022-01-27 09:38:52 +05:00
context.Companies.AddRange(companies);
context.RelationCompaniesWells.AddRange(relations);
context.WellSectionTypes.AddRange(wellSectionTypes);
context.DrillParams.AddRange(drillParams);
2022-01-27 09:38:52 +05:00
context.SaveChanges();
}
2022-06-15 14:57:37 +05:00
2022-01-27 09:38:52 +05:00
~ClusterServiceTest()
{
context.Deposits.RemoveRange(context.Deposits);
context.Clusters.RemoveRange(context.Clusters);
context.Wells.RemoveRange(context.Wells);
context.CompaniesTypes.RemoveRange(context.CompaniesTypes);
context.Companies.RemoveRange(context.Companies);
context.RelationCompaniesWells.RemoveRange(context.RelationCompaniesWells);
2022-01-27 09:38:52 +05:00
context.SaveChanges();
}
[Fact]
public async Task GetDepositsAsync_returns_one_deposit()
2022-06-15 14:57:37 +05:00
{
2022-01-27 09:38:52 +05:00
var service = new ClusterService(context, wellService.Object);
var dtos = await service.GetDepositsAsync(1);
2022-02-21 12:04:26 +05:00
Assert.Single(dtos);
2022-01-27 09:38:52 +05:00
}
2022-06-15 14:57:37 +05:00
2022-01-27 09:38:52 +05:00
[Fact]
public async Task GetDepositsAsync_returns_one_deposit_with_two_clusters()
2022-06-15 14:57:37 +05:00
{
2022-01-27 09:38:52 +05:00
var service = new ClusterService(context, wellService.Object);
var dtos = await service.GetDepositsAsync(1);
Assert.Equal(2, dtos.FirstOrDefault()?.Clusters.Count());
}
[Fact]
public async Task GetDrillParamsAsync_returns_depositDtos()
2022-06-15 14:57:37 +05:00
{
2022-01-27 09:38:52 +05:00
var service = new ClusterService(context, wellService.Object);
var dtos = await service.GetDepositsDrillParamsAsync(1);
Assert.True(dtos.Any());
}
2022-06-15 14:57:37 +05:00
2022-01-27 09:38:52 +05:00
[Fact]
public async Task GetDrillParamsAsync_returns_one_deposit()
2022-06-15 14:57:37 +05:00
{
2022-01-27 09:38:52 +05:00
var service = new ClusterService(context, wellService.Object);
var dtos = await service.GetDepositsDrillParamsAsync(1);
2022-02-21 12:04:26 +05:00
Assert.Single(dtos);
2022-01-27 09:38:52 +05:00
}
2022-06-15 14:57:37 +05:00
2022-01-27 09:38:52 +05:00
[Fact]
public async Task GetDrillParamsAsync_returns_one_deposit_with_two_clusters()
2022-06-15 14:57:37 +05:00
{
2022-01-27 09:38:52 +05:00
var service = new ClusterService(context, wellService.Object);
var dtos = await service.GetDepositsDrillParamsAsync(1);
Assert.Equal(2, dtos.FirstOrDefault()?.Clusters.Count());
}
2022-06-15 14:57:37 +05:00
2022-01-27 09:38:52 +05:00
[Fact]
public async Task GetClustersAsync_returns_two_dtos()
2022-06-15 14:57:37 +05:00
{
2022-01-27 09:38:52 +05:00
var service = new ClusterService(context, wellService.Object);
var dtos = await service.GetClustersAsync(1);
Assert.Equal(2, dtos.Count());
2022-01-27 09:38:52 +05:00
}
2022-06-15 14:57:37 +05:00
2022-01-27 09:38:52 +05:00
[Fact]
public async Task GetClustersAsync_with_deposit_returns_two_clusters()
2022-06-15 14:57:37 +05:00
{
2022-01-27 09:38:52 +05:00
var service = new ClusterService(context, wellService.Object);
2022-06-15 14:57:37 +05:00
var dtos = await service.GetClustersAsync(1, 1);
Assert.Equal(2, dtos.Count());
}
2022-06-15 14:57:37 +05:00
[Fact]
public async Task GetWellsAsync_returns_one_well_by_cluster_and_company()
2022-06-15 14:57:37 +05:00
{
var service = new ClusterService(context, wellService.Object);
2022-06-15 14:57:37 +05:00
var dtos = await service.GetWellsAsync(1, 1);
2022-01-27 09:38:52 +05:00
2022-02-21 12:04:26 +05:00
Assert.Single(dtos);
2022-01-27 09:38:52 +05:00
}
2022-06-15 14:57:37 +05:00
2022-01-27 09:38:52 +05:00
}