public void TestSingleDegrader() { var degrader = new Degrader("All"); var monitorPowerSupply = new PowerSupplyMonitor(degrader); _capabilityPowerSupply = new Capability(degrader, "Power Supply"); var monitorActuator = new ActuatorMonitor(degrader); _capabilityActuator = new Capability(degrader, "Actuator"); _capabilitySystem = new Capability(degrader, "System"); degrader.AddDefaultRules(monitorPowerSupply.TotalFailure, _capabilityPowerSupply); degrader.AddDefaultRules(monitorActuator.TotalFailure, _capabilityActuator); degrader.AddDefaultRules(_capabilityPowerSupply, _capabilityActuator); degrader.AddDefaultRules(_capabilityActuator, _capabilitySystem); degrader.AddTrigger(_capabilitySystem, x => Console.WriteLine($"- System: {Capabilities.Convert(x.Current)}")); GiveStatus(); Console.WriteLine("Pass Power Supply..."); monitorPowerSupply.MakeOk(); GiveStatus(); Console.WriteLine("Pass Power Actuator..."); monitorActuator.MakeOk(); GiveStatus(); Assert.That(_capabilitySystem.Current, Is.EqualTo(Capabilities.Full)); }
public void TestDegrader() { var degraderPowerSupply = new Degrader("Power Supply"); var monitorPowerSupply = new PowerSupplyMonitor(degraderPowerSupply); _capabilityPowerSupply = new Capability(degraderPowerSupply, "Power Supply"); var degraderActuator = new Degrader("Actuator"); var monitorActuator = new ActuatorMonitor(degraderActuator); _capabilityActuator = new Capability(degraderActuator, "Actuator"); var degraderSystem = new Degrader("System"); _capabilitySystem = new Capability(degraderSystem, "System"); degraderPowerSupply.AddDefaultRules(monitorPowerSupply.TotalFailure, _capabilityPowerSupply); degraderPowerSupply.AddRuleForUnknown(monitorPowerSupply.LimitedCurrent, _capabilityPowerSupply); degraderPowerSupply.AddRule(monitorPowerSupply.LimitedCurrent, MonitoringResult.NOK, _capabilityPowerSupply, Capabilities.Limited); degraderActuator.AddDefaultRules(monitorActuator.TotalFailure, _capabilityActuator); degraderActuator.AddDefaultRules(_capabilityPowerSupply, _capabilityActuator); degraderActuator.AddRule(_capabilityPowerSupply, Capabilities.Limited, _capabilityActuator, Capabilities.Limited); degraderSystem.AddRule(_capabilityActuator, Capabilities.Failed, _capabilitySystem, Capabilities.Failed); degraderSystem.AddRule(_capabilityActuator, Capabilities.Limited, _capabilitySystem, Capabilities.Limited); degraderSystem.AddTrigger(_capabilitySystem, x => Console.WriteLine($"- System: {Capabilities.Convert(x.Current)}")); GiveStatus(); Console.WriteLine("Pass Power Supply..."); monitorPowerSupply.MakeOk(); GiveStatus(); Console.WriteLine("Pass Power Actuator..."); monitorActuator.MakeOk(); GiveStatus(); Console.WriteLine("Injecting Power Supply Failure..."); monitorPowerSupply.InjectTotalFailure(); GiveStatus(); Console.WriteLine("Rehealing Power Supply Failure..."); monitorPowerSupply.MakeOk(); GiveStatus(); Console.WriteLine("Injecting Limited Power Supply Failure..."); monitorPowerSupply.InjectLimitedCurrentFailure(); GiveStatus(); Console.WriteLine("Rehealing Power Supply Failure..."); monitorPowerSupply.MakeOk(); GiveStatus(); Console.WriteLine("Injecting Actuator Failure..."); monitorActuator.InjectTotalFailure(); GiveStatus(); Console.WriteLine("Rehealing Actuator Failure..."); monitorActuator.MakeOk(); GiveStatus(); Console.WriteLine("Injecting Power Supply + Actuator Failure..."); monitorActuator.InjectTotalFailure(); monitorPowerSupply.InjectTotalFailure(); GiveStatus(); Console.WriteLine("Rehealing Actuator Failure..."); monitorActuator.MakeOk(); GiveStatus(); Console.WriteLine("Rehealing Power Supply Failure..."); monitorPowerSupply.MakeOk(); GiveStatus(); Assert.That(_capabilitySystem.Current, Is.EqualTo(Capabilities.Full)); }