197 lines
6.3 KiB
C#
197 lines
6.3 KiB
C#
using DOAN.Model.MES.base_;
|
|
using DOAN.Model.MES.base_.Dto;
|
|
using DOAN.Model.MES.product;
|
|
using DOAN.Model.MES.product.Dto;
|
|
using DOAN.Service.MES.product;
|
|
using DOAN.Service.MES.product.IService;
|
|
using Infrastructure.Pagination;
|
|
using Moq;
|
|
using Xunit;
|
|
|
|
namespace DOAN.Tests.MES.Product
|
|
{
|
|
/// <summary>
|
|
/// 工单服务集成测试
|
|
/// </summary>
|
|
public class ProWorkorderIntegrationTests
|
|
{
|
|
private readonly ProWorkorderService _workorderService;
|
|
private readonly Mock<IProWorkorderCoreService> _mockCoreService;
|
|
private readonly Mock<IProWorkorderQueryService> _mockQueryService;
|
|
private readonly Mock<IProWorkorderImportService> _mockImportService;
|
|
private readonly Mock<IProWorkorderExportService> _mockExportService;
|
|
private readonly Mock<IProWorkorderUtilityService> _mockUtilityService;
|
|
private readonly Mock<IProWorkorderReferenceService> _mockReferenceService;
|
|
|
|
public ProWorkorderIntegrationTests()
|
|
{
|
|
// 创建所有子Service的模拟对象
|
|
_mockCoreService = new Mock<IProWorkorderCoreService>();
|
|
_mockQueryService = new Mock<IProWorkorderQueryService>();
|
|
_mockImportService = new Mock<IProWorkorderImportService>();
|
|
_mockExportService = new Mock<IProWorkorderExportService>();
|
|
_mockUtilityService = new Mock<IProWorkorderUtilityService>();
|
|
_mockReferenceService = new Mock<IProWorkorderReferenceService>();
|
|
|
|
// 初始化主Service
|
|
_workorderService = new ProWorkorderService(
|
|
_mockCoreService.Object,
|
|
_mockQueryService.Object,
|
|
_mockImportService.Object,
|
|
_mockExportService.Object,
|
|
_mockUtilityService.Object,
|
|
_mockReferenceService.Object
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 测试工单服务集成 - 查询列表
|
|
/// </summary>
|
|
[Fact]
|
|
public void GetList_ShouldCallQueryService()
|
|
{
|
|
// Arrange
|
|
var queryDto = new ProWorkorderQueryDto
|
|
{
|
|
productionName = "集成测试产品"
|
|
};
|
|
|
|
var expectedResult = new PagedInfo<ProWorkorderDto3>
|
|
{
|
|
Total = 1,
|
|
Result = new List<ProWorkorderDto3>
|
|
{
|
|
new ProWorkorderDto3
|
|
{
|
|
productionName = "集成测试产品"
|
|
}
|
|
}
|
|
};
|
|
|
|
_mockQueryService.Setup(x => x.GetList(queryDto))
|
|
.Returns(expectedResult);
|
|
|
|
// Act
|
|
var result = _workorderService.GetList(queryDto);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(expectedResult.Total, result.Total);
|
|
Assert.Single(result.Result);
|
|
_mockQueryService.Verify(x => x.GetList(queryDto), Times.Once);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 测试工单服务集成 - 添加工单
|
|
/// </summary>
|
|
[Fact]
|
|
public void AddProWorkorder_ShouldCallCoreService()
|
|
{
|
|
// Arrange
|
|
var workorder = new ProWorkorder
|
|
{
|
|
productionName = "集成测试产品",
|
|
productionCode = "INT001"
|
|
};
|
|
|
|
var expectedWorkorder = new ProWorkorder
|
|
{
|
|
Id = "1",
|
|
productionName = "集成测试产品",
|
|
productionCode = "INT001"
|
|
};
|
|
|
|
_mockCoreService.Setup(x => x.AddProWorkorder(workorder))
|
|
.Returns(expectedWorkorder);
|
|
|
|
// Act
|
|
var result = _workorderService.AddProWorkorder(workorder);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(expectedWorkorder.Id, result.Id);
|
|
_mockCoreService.Verify(x => x.AddProWorkorder(workorder), Times.Once);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 测试工单服务集成 - 获取详情
|
|
/// </summary>
|
|
[Fact]
|
|
public void GetInfo_ShouldCallQueryService()
|
|
{
|
|
// Arrange
|
|
var workorderId = "1";
|
|
var expectedWorkorder = new ProWorkorder
|
|
{
|
|
Id = workorderId,
|
|
productionName = "集成测试产品"
|
|
};
|
|
|
|
_mockQueryService.Setup(x => x.GetInfo(workorderId))
|
|
.Returns(expectedWorkorder);
|
|
|
|
// Act
|
|
var result = _workorderService.GetInfo(workorderId);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(expectedWorkorder.Id, result.Id);
|
|
_mockQueryService.Verify(x => x.GetInfo(workorderId), Times.Once);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 测试工单服务集成 - 生成工单号
|
|
/// </summary>
|
|
[Fact]
|
|
public void Generate_workorder_ShouldCallUtilityService()
|
|
{
|
|
// Arrange
|
|
var queryDto = new ProWorkorderQueryDto2
|
|
{
|
|
productionName = "集成测试产品"
|
|
};
|
|
|
|
_mockUtilityService.Setup(x => x.Generate_workorder(queryDto))
|
|
.Returns(1);
|
|
|
|
// Act
|
|
var result = _workorderService.Generate_workorder(queryDto);
|
|
|
|
// Assert
|
|
Assert.Equal(1, result);
|
|
_mockUtilityService.Verify(x => x.Generate_workorder(queryDto), Times.Once);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 测试工单服务集成 - 获取物料信息
|
|
/// </summary>
|
|
[Fact]
|
|
public void GetMaterialInfo_ShouldCallReferenceService()
|
|
{
|
|
// Arrange
|
|
var queryDto = new BaseMaterialListQueryDto5
|
|
{
|
|
MaterialName = "集成测试物料"
|
|
};
|
|
|
|
var expectedResult = new List<BaseMaterialList>
|
|
{
|
|
new BaseMaterialList
|
|
{
|
|
MaterialName = "集成测试物料"
|
|
}
|
|
};
|
|
|
|
_mockReferenceService.Setup(x => x.GetMaterialInfo(queryDto))
|
|
.Returns(expectedResult);
|
|
|
|
// Act
|
|
var result = _workorderService.GetMaterialInfo(queryDto);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Single(result);
|
|
_mockReferenceService.Verify(x => x.GetMaterialInfo(queryDto), Times.Once);
|
|
}
|
|
}
|
|
} |