public void StartSimulationTest() { ISystemContext _context = new SystemContextFixture(); TraceSourceFixture _log = new TraceSourceFixture(); List <Tuple <string, object> > _callBackCount = new List <Tuple <string, object> >(); Range _startRange = null; int _valueChangeCount = 0; using (BoilerState _boilerState = new BoilerState(null, "browseName")) { _boilerState.RegisterVariable(new List <BaseInstanceState>(), (x, y) => { _callBackCount.Add(Tuple.Create <string, object>(String.Join("_", y), ((BaseVariableState)x).Value)); x.OnStateChanged += (q, w, e) => _valueChangeCount++; }); Range _level = _boilerState.Drum.LevelIndicator.Output.EURange.Value; _startRange = ModelExtensions.CreateRange(_level.High, _level.Low); double _startSetPoint = _boilerState.LevelController.SetPoint.Value; _boilerState.Logger = _log; _boilerState.ClearChangeMasks(_context, true); _boilerState.StartSimulation(); _boilerState.OnStateChanged += (x, y, z) => Assert.Fail(); System.Threading.Thread.Sleep(10000); Assert.AreEqual <int>(20, _callBackCount.Count); _boilerState.ClearChangeMasks(_context, true); Assert.AreEqual <Range>(_level, _boilerState.Drum.LevelIndicator.Output.EURange.Value); Assert.AreEqual <double>(_startSetPoint, _boilerState.LevelController.SetPoint.Value); } Assert.IsTrue(_log.TraceLog.Count > 10); Assert.IsTrue(_log.ErrorTraceLog.Count == 0); Assert.AreEqual <int>(20, _callBackCount.Count); Assert.IsTrue(600 < _valueChangeCount, $"_valueChangeCount = {_valueChangeCount}"); }
public void RegisterVariableTest() { TraceSourceFixture _log = new TraceSourceFixture(); using (BoilerState _boilerState = new BoilerState(null, "browseName")) { _boilerState.Logger = _log; Dictionary <string, BaseInstanceState> _vars = new Dictionary <string, BaseInstanceState>(); _boilerState.RegisterVariable(new List <BaseInstanceState>(), (x, y) => _vars.Add(String.Join("_", y), x)); foreach (KeyValuePair <string, BaseInstanceState> _item in _vars) { BaseVariableState _var = _item.Value as BaseVariableState; Assert.IsNotNull(_var); string _type = _var.Value == null ? "not set" : _var.Value.GetType().Name; Debug.WriteLine($"{_item} {_type}"); } Assert.AreEqual <int>(20, _vars.Count); } Assert.IsTrue(_log.TraceLog.Count == 0); Assert.IsTrue(_log.ErrorTraceLog.Count == 0); }