203 lines
6.5 KiB
C#
203 lines
6.5 KiB
C#
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);
|
||
}
|
||
}
|
||
}
|