private void _ActivityTTest() { bool isActive = false, startCondition = false, stopCondition = false; bool onJustStart = false, onJustStop = false, onJustFailStart = false, onJustFailStop = false; int p = 123; ModelActivity <int> activity = new ModelActivity <int>(); activity.RegisterActivityGetter(() => isActive); activity.RegisterStartCondition((test) => { Assert.AreEqual(p, test); return(startCondition); }); activity.RegisterStopCondition(() => stopCondition); activity.onFailStart += (test) => { Assert.AreEqual(p, test); onJustFailStart = true; }; activity.onFailStop += () => { onJustFailStop = true; }; activity.onStart += (test) => { Assert.AreEqual(p, test); onJustStart = true; isActive = true; }; activity.onStop += () => { onJustStop = true; isActive = false; }; // Test fail start onJustFailStart = false; Assert.IsFalse(activity.TryStart(p)); Assert.IsTrue(onJustFailStart); Assert.IsFalse(activity.IsActive()); Assert.IsFalse(activity.CanStart(p)); // Test success start onJustStart = false; startCondition = true; Assert.IsTrue(activity.CanStart(p)); Assert.IsTrue(activity.TryStart(p)); Assert.IsTrue(onJustStart); Assert.IsTrue(isActive); Assert.IsTrue(activity.IsActive()); // Test fail stop onJustFailStop = false; Assert.IsFalse(activity.CanStop()); Assert.IsFalse(activity.TryStop()); Assert.IsTrue(onJustFailStop); Assert.IsTrue(isActive); Assert.IsTrue(activity.IsActive()); // Test success start stopCondition = true; onJustStop = false; Assert.IsTrue(activity.CanStop()); Assert.IsTrue(activity.TryStop()); Assert.IsTrue(onJustStop); Assert.IsFalse(isActive); Assert.IsFalse(activity.IsActive()); }
public void ModelActivityTest() { bool isActive = false, startCondition = false, stopCondition = false; bool onJustStart = false, onJustStop = false, onJustFailStart = false, onJustFailStop = false; ModelActivity activity = new ModelActivity(); activity.RegisterActivityGetter(() => isActive); activity.RegisterStartCondition(() => startCondition); activity.RegisterStopCondition(() => stopCondition); activity.onFailStart += () => { onJustFailStart = true; }; activity.onFailStop += () => { onJustFailStop = true; }; activity.onStart += () => { onJustStart = true; isActive = true; }; activity.onStop += () => { onJustStop = true; isActive = false; }; // Test fail start onJustFailStart = false; Assert.IsFalse(activity.TryStart()); Assert.IsTrue(onJustFailStart); Assert.IsFalse(activity.IsActive()); Assert.IsFalse(activity.CanStart()); // Test success start onJustStart = false; startCondition = true; Assert.IsTrue(activity.CanStart()); Assert.IsTrue(activity.TryStart()); Assert.IsTrue(onJustStart); Assert.IsTrue(isActive); Assert.IsTrue(activity.IsActive()); // Test fail stop onJustFailStop = false; Assert.IsFalse(activity.CanStop()); Assert.IsFalse(activity.TryStop()); Assert.IsTrue(onJustFailStop); Assert.IsTrue(isActive); Assert.IsTrue(activity.IsActive()); // Test success start stopCondition = true; onJustStop = false; Assert.IsTrue(activity.CanStop()); Assert.IsTrue(activity.TryStop()); Assert.IsTrue(onJustStop); Assert.IsFalse(isActive); Assert.IsFalse(activity.IsActive()); _ActivityTTest(); }