using Xunit; using YZWater.Core.Models; using YZWater.Core.Services; namespace YZWater.Core.Tests.Services; /// /// ISA-18.2 报警管理 + 数据缺口 单元测试(搁置状态、配置默认值、缺口时长计算) /// public class AlarmManagementTests { [Fact] public void Shelve_ShouldMarkConditionAsShelved() { var service = AlarmService.Instance; service.Shelve("TestTank_High", 30, "Tester"); Assert.True(service.IsShelved("TestTank_High")); Assert.Contains(service.GetShelvedAlarms(), s => s.ConditionId == "TestTank_High"); service.Unshelve("TestTank_High", "Tester"); Assert.False(service.IsShelved("TestTank_High")); } [Fact] public void Shelve_InvalidArgs_ShouldBeIgnored() { var service = AlarmService.Instance; service.Shelve("TestTank_Invalid", 0); Assert.False(service.IsShelved("TestTank_Invalid")); } [Fact] public void IsShelved_UnknownCondition_ShouldBeFalse() { Assert.False(AlarmService.Instance.IsShelved("NoSuchCondition")); } [Fact] public void AlarmManagementConfig_Defaults() { var config = new AlarmManagementConfig(); Assert.True(config.EnableFloodSuppression); Assert.Equal(6, config.FloodRaiseThreshold); Assert.Equal(60, config.FloodWindowSeconds); Assert.True(config.EnableFirstOut); Assert.Equal(5, config.FirstOutWindowSeconds); Assert.Equal(30, config.DefaultShelveMinutes); } [Fact] public void SystemConfig_ShouldExposeAlarmSection() { var config = new SystemConfig(); Assert.NotNull(config.Alarm); Assert.Equal(6, config.Alarm.FloodRaiseThreshold); } [Fact] public void DataGapRecord_OpenGap_DurationTextUsesNow() { var gap = new DataGapRecord { StartTime = DateTime.Now.AddMinutes(-5) }; Assert.True(gap.IsOpen); Assert.Contains("m", gap.DurationText); } [Fact] public void DataGapRecord_ClosedGap_DurationTextUsesRange() { var start = new DateTime(2026, 9, 25, 10, 0, 0); var gap = new DataGapRecord { StartTime = start, EndTime = start.AddMinutes(30) }; Assert.False(gap.IsOpen); Assert.Equal("30m 0s", gap.DurationText); } }