修复探测器的订阅与获取
This commit is contained in:
@@ -3,6 +3,9 @@ using Prism.Events;
|
||||
using System;
|
||||
using System.Windows;
|
||||
using XP.Common.Logging.Interfaces;
|
||||
using XP.Hardware.Detector.Abstractions.Enums;
|
||||
using XP.Hardware.Detector.Abstractions.Events;
|
||||
using XP.Hardware.Detector.Services;
|
||||
using XP.Hardware.MotionControl.Abstractions;
|
||||
using XP.Hardware.MotionControl.Abstractions.Enums;
|
||||
using XP.Hardware.MotionControl.Abstractions.Events;
|
||||
@@ -25,6 +28,7 @@ namespace XplorePlane.Tests.Services
|
||||
private readonly Mock<IRaySourceService> _mockRaySource;
|
||||
private readonly Mock<IMotionSystem> _mockMotionSystem;
|
||||
private readonly Mock<IMotionControlService> _mockMotionControlService;
|
||||
private readonly Mock<IDetectorService> _mockDetectorService;
|
||||
private readonly Mock<ILinearAxis> _mockStageX;
|
||||
private readonly Mock<ILinearAxis> _mockStageY;
|
||||
private readonly Mock<ILinearAxis> _mockSourceZ;
|
||||
@@ -48,6 +52,7 @@ namespace XplorePlane.Tests.Services
|
||||
_mockRaySource = new Mock<IRaySourceService>();
|
||||
_mockMotionSystem = new Mock<IMotionSystem>();
|
||||
_mockMotionControlService = new Mock<IMotionControlService>();
|
||||
_mockDetectorService = new Mock<IDetectorService>();
|
||||
_mockStageX = CreateLinearAxis(AxisId.StageX, 0);
|
||||
_mockStageY = CreateLinearAxis(AxisId.StageY, 0);
|
||||
_mockSourceZ = CreateLinearAxis(AxisId.SourceZ, 0);
|
||||
@@ -70,12 +75,24 @@ namespace XplorePlane.Tests.Services
|
||||
.Setup(x => x.GetCurrentGeometry())
|
||||
.Returns((0d, 0d, 1d));
|
||||
|
||||
// DetectorService:GetInfo 在未初始化时抛出,模拟此行为
|
||||
_mockDetectorService
|
||||
.Setup(x => x.GetInfo())
|
||||
.Throws(new InvalidOperationException("探测器未初始化"));
|
||||
_mockDetectorService
|
||||
.SetupGet(x => x.Status)
|
||||
.Returns(DetectorStatus.Uninitialized);
|
||||
_mockDetectorService
|
||||
.SetupGet(x => x.IsConnected)
|
||||
.Returns(false);
|
||||
|
||||
_mockLogger.Setup(l => l.ForModule<AppStateService>()).Returns(_mockLogger.Object);
|
||||
|
||||
_service = new AppStateService(
|
||||
_mockRaySource.Object,
|
||||
_mockMotionSystem.Object,
|
||||
_mockMotionControlService.Object,
|
||||
_mockDetectorService.Object,
|
||||
_eventAggregator,
|
||||
_mockLogger.Object);
|
||||
}
|
||||
@@ -188,6 +205,57 @@ namespace XplorePlane.Tests.Services
|
||||
Assert.Equal(222.2, _service.MotionState.FDD);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StatusChangedEvent_Acquiring_SyncsDetectorState()
|
||||
{
|
||||
// 模拟探测器进入采集状态
|
||||
_mockDetectorService.SetupGet(x => x.Status).Returns(DetectorStatus.Acquiring);
|
||||
_mockDetectorService.Setup(x => x.GetInfo()).Throws(new InvalidOperationException());
|
||||
|
||||
_eventAggregator.GetEvent<StatusChangedEvent>()
|
||||
.Publish(DetectorStatus.Acquiring);
|
||||
|
||||
// 等待后台线程处理(BackgroundThread 订阅)
|
||||
System.Threading.Thread.Sleep(100);
|
||||
|
||||
Assert.True(_service.DetectorState.IsConnected);
|
||||
Assert.True(_service.DetectorState.IsAcquiring);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StatusChangedEvent_Uninitialized_SyncsDetectorStateDisconnected()
|
||||
{
|
||||
_eventAggregator.GetEvent<StatusChangedEvent>()
|
||||
.Publish(DetectorStatus.Uninitialized);
|
||||
|
||||
System.Threading.Thread.Sleep(100);
|
||||
|
||||
Assert.False(_service.DetectorState.IsConnected);
|
||||
Assert.False(_service.DetectorState.IsAcquiring);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ImageCapturedEvent_UpdatesLatestDetectorFrame()
|
||||
{
|
||||
Assert.Null(_service.LatestDetectorFrame);
|
||||
|
||||
var args = new XP.Hardware.Detector.Abstractions.ImageCapturedEventArgs
|
||||
{
|
||||
ImageData = new ushort[4],
|
||||
Width = 2,
|
||||
Height = 2,
|
||||
FrameNumber = 1,
|
||||
CaptureTime = DateTime.UtcNow
|
||||
};
|
||||
|
||||
_eventAggregator.GetEvent<ImageCapturedEvent>().Publish(args);
|
||||
|
||||
// 等待后台线程处理
|
||||
System.Threading.Thread.Sleep(100);
|
||||
|
||||
Assert.Same(args, _service.LatestDetectorFrame);
|
||||
}
|
||||
|
||||
private static Mock<ILinearAxis> CreateLinearAxis(AxisId axisId, double position)
|
||||
{
|
||||
var axis = new Mock<ILinearAxis>();
|
||||
|
||||
Reference in New Issue
Block a user