feat: 添加工单管理服务及相关测试
refactor: 重构工单服务接口和实现 test: 添加工单服务的单元测试和集成测试
This commit is contained in:
202
DOAN.Tests/MES/Product/ProWorkorderQueryServiceTests.cs
Normal file
202
DOAN.Tests/MES/Product/ProWorkorderQueryServiceTests.cs
Normal file
@@ -0,0 +1,202 @@
|
||||
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 ProWorkorderQueryServiceTests
|
||||
{
|
||||
private readonly IProWorkorderQueryService _queryService;
|
||||
private readonly Mock<ProWorkorderQueryService> _mockQueryService;
|
||||
|
||||
public ProWorkorderQueryServiceTests()
|
||||
{
|
||||
// 由于ProWorkorderQueryService继承自BaseService,需要模拟依赖
|
||||
// 这里使用Moq创建模拟对象
|
||||
_mockQueryService = new Mock<ProWorkorderQueryService>();
|
||||
_queryService = _mockQueryService.Object;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试查询生产工单列表
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetList_ShouldReturnPagedWorkorders()
|
||||
{
|
||||
// Arrange
|
||||
var queryDto = new ProWorkorderQueryDto
|
||||
{
|
||||
productionName = "测试产品",
|
||||
productionCode = "TEST001"
|
||||
};
|
||||
|
||||
var expectedResult = new PagedInfo<ProWorkorderDto3>
|
||||
{
|
||||
Total = 1,
|
||||
Result = new List<ProWorkorderDto3>
|
||||
{
|
||||
new ProWorkorderDto3
|
||||
{
|
||||
productionName = "测试产品",
|
||||
productionCode = "TEST001"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_mockQueryService.Setup(x => x.GetList(It.IsAny<ProWorkorderQueryDto>()))
|
||||
.Returns(expectedResult);
|
||||
|
||||
// Act
|
||||
var result = _queryService.GetList(queryDto);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(expectedResult.Total, result.Total);
|
||||
Assert.Single(result.Result);
|
||||
Assert.Equal(expectedResult.Result[0].productionName, result.Result[0].productionName);
|
||||
Assert.Equal(expectedResult.Result[0].productionCode, result.Result[0].productionCode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试获取工单无校验
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetList_NOCheck_ShouldReturnPagedWorkorders()
|
||||
{
|
||||
// Arrange
|
||||
var queryDto = new ProWorkorderQueryDto
|
||||
{
|
||||
productionName = "测试产品",
|
||||
productionCode = "TEST001"
|
||||
};
|
||||
|
||||
var expectedResult = new PagedInfo<ProWorkorderDto>
|
||||
{
|
||||
Total = 1,
|
||||
Result = new List<ProWorkorderDto>
|
||||
{
|
||||
new ProWorkorderDto
|
||||
{
|
||||
productionName = "测试产品",
|
||||
productionCode = "TEST001"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_mockQueryService.Setup(x => x.GetList_NOCheck(It.IsAny<ProWorkorderQueryDto>()))
|
||||
.Returns(expectedResult);
|
||||
|
||||
// Act
|
||||
var result = _queryService.GetList_NOCheck(queryDto);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(expectedResult.Total, result.Total);
|
||||
Assert.Single(result.Result);
|
||||
Assert.Equal(expectedResult.Result[0].productionName, result.Result[0].productionName);
|
||||
Assert.Equal(expectedResult.Result[0].productionCode, result.Result[0].productionCode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试获取工单详情
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetInfo_ShouldReturnWorkorder()
|
||||
{
|
||||
// Arrange
|
||||
var workorderId = "1";
|
||||
var expectedWorkorder = new ProWorkorder
|
||||
{
|
||||
Id = workorderId,
|
||||
productionName = "测试产品",
|
||||
productionCode = "TEST001"
|
||||
};
|
||||
|
||||
_mockQueryService.Setup(x => x.GetInfo(It.IsAny<string>()))
|
||||
.Returns(expectedWorkorder);
|
||||
|
||||
// Act
|
||||
var result = _queryService.GetInfo(workorderId);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(expectedWorkorder.Id, result.Id);
|
||||
Assert.Equal(expectedWorkorder.productionName, result.productionName);
|
||||
Assert.Equal(expectedWorkorder.productionCode, result.productionCode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试获取工单进度跟踪列表
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetWorkorderTraceProgressList_ShouldReturnPagedProgress()
|
||||
{
|
||||
// Arrange
|
||||
var queryDto = new ProWorkorderQueryDto
|
||||
{
|
||||
productionName = "测试产品"
|
||||
};
|
||||
|
||||
var expectedResult = new PagedInfo<ProWorkorderTranceProgressDto>
|
||||
{
|
||||
Total = 1,
|
||||
Result = new List<ProWorkorderTranceProgressDto>
|
||||
{
|
||||
new ProWorkorderTranceProgressDto
|
||||
{
|
||||
productionName = "测试产品"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_mockQueryService.Setup(x => x.GetWorkorderTraceProgressList(It.IsAny<ProWorkorderQueryDto>()))
|
||||
.Returns(expectedResult);
|
||||
|
||||
// Act
|
||||
var result = _queryService.GetWorkorderTraceProgressList(queryDto);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(expectedResult.Total, result.Total);
|
||||
Assert.Single(result.Result);
|
||||
Assert.Equal(expectedResult.Result[0].productionName, result.Result[0].productionName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试查询BOM及其所需数量
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void SearchBOMNum_ShouldReturnBomList()
|
||||
{
|
||||
// Arrange
|
||||
var workorderNum = "WO001";
|
||||
var expectedResult = new List<WorkOrderBom>
|
||||
{
|
||||
new WorkOrderBom
|
||||
{
|
||||
PartId = "1",
|
||||
PartName = "测试部件"
|
||||
}
|
||||
};
|
||||
|
||||
_mockQueryService.Setup(x => x.SearchBOMNum(It.IsAny<string>()))
|
||||
.Returns(expectedResult);
|
||||
|
||||
// Act
|
||||
var result = _queryService.SearchBOMNum(workorderNum);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Single(result);
|
||||
Assert.Equal(expectedResult[0].PartId, result[0].PartId);
|
||||
Assert.Equal(expectedResult[0].PartName, result[0].PartName);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user