diff Implab.Test/RunnableComponentTests.cs @ 205:8200ab154c8a v2

Added ResetState to RunnableComponent to reset in case of failure Added StateChanged event to IRunnable Renamed Promise.SUCCESS -> Promise.Success Added Promise.FromException Renamed Bundle -> PromiseAll in PromiseExtensions
author cin
date Tue, 25 Oct 2016 17:40:33 +0300
parents 4d9830a9bbb8
children 7d07503621fe
line wrap: on
line diff
--- a/Implab.Test/RunnableComponentTests.cs	Tue Oct 18 17:49:54 2016 +0300
+++ b/Implab.Test/RunnableComponentTests.cs	Tue Oct 25 17:40:33 2016 +0300
@@ -39,7 +39,7 @@
 
             Assert.AreEqual(ExecutionState.Created, comp.State);
 
-            comp.Init();
+            comp.Initialize();
 
             Assert.AreEqual(ExecutionState.Ready, comp.State);
 
@@ -65,7 +65,7 @@
             ShouldThrow(() => comp.Stop());
             Assert.AreEqual(ExecutionState.Created, comp.State);
 
-            ShouldThrow(comp.Init);
+            ShouldThrow(comp.Initialize);
 
             Assert.AreEqual(ExecutionState.Failed, comp.State);
 
@@ -85,12 +85,77 @@
 
             ShouldThrow(() => comp.Start());
             ShouldThrow(() => comp.Stop());
-            ShouldThrow(comp.Init);
+            ShouldThrow(comp.Initialize);
 
             Assert.AreEqual(ExecutionState.Disposed, comp.State);
         }
 
         [TestMethod]
+        public void ShouldCallDisposeOnStop() {
+            var comp = new MockRunnableComponent(true);
+
+            bool disposed = false;
+            comp.MockDispose = (disposing, error) => {
+                disposed = true;
+            };
+
+            comp.Start().Join(1000);
+            comp.Stop().Join(1000);
+
+            ShouldThrow(() => comp.Start());
+            ShouldThrow(() => comp.Stop());
+            ShouldThrow(comp.Initialize);
+
+            Assert.AreEqual(ExecutionState.Disposed, comp.State);
+            Assert.IsTrue(disposed);
+        }
+
+        [TestMethod]
+        public void ShouldNotCallDisposeOnStop() {
+            var comp = new MockRunnableComponent(true, true);
+
+            bool disposed = false;
+            comp.MockDispose = (disposing, error) => {
+                disposed = true;
+            };
+
+            comp.Start().Join(1000);
+            comp.Stop().Join(1000);
+
+            Assert.AreEqual(ExecutionState.Ready, comp.State);
+            Assert.IsFalse(disposed);
+        }
+
+        [TestMethod]
+        public void SelfDisposeOnStop() {
+            var comp = new MockRunnableComponent(true, true);
+
+            bool disposed = false;
+            Exception lastError = null;
+            comp.MockDispose = (disposing, error) => {
+                disposed = true;
+                lastError = error;
+            };
+
+            comp.Start().Join(1000);
+            comp.Stop().Join(1000);
+
+            Assert.AreEqual(ExecutionState.Ready, comp.State);
+            Assert.IsFalse(disposed);
+
+            comp.MockStop = () => {
+                comp.Dispose();
+                return Promise.Success;
+            };
+
+            comp.Start().Join(1000);
+            comp.Stop().Join(1000);
+
+            Assert.AreEqual(ExecutionState.Disposed, comp.State);
+            Assert.IsTrue(disposed);
+        }
+
+        [TestMethod]
         public void StartCancelTest() {
             var comp = new MockRunnableComponent(true) {
                 MockStart = () => PromiseHelper.Sleep(100000, 0)