comparison 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
comparison
equal deleted inserted replaced
203:4d9830a9bbb8 205:8200ab154c8a
37 public void NormalFlowTest() { 37 public void NormalFlowTest() {
38 var comp = new MockRunnableComponent(false); 38 var comp = new MockRunnableComponent(false);
39 39
40 Assert.AreEqual(ExecutionState.Created, comp.State); 40 Assert.AreEqual(ExecutionState.Created, comp.State);
41 41
42 comp.Init(); 42 comp.Initialize();
43 43
44 Assert.AreEqual(ExecutionState.Ready, comp.State); 44 Assert.AreEqual(ExecutionState.Ready, comp.State);
45 45
46 comp.Start().Join(1000); 46 comp.Start().Join(1000);
47 47
63 63
64 ShouldThrow(() => comp.Start()); 64 ShouldThrow(() => comp.Start());
65 ShouldThrow(() => comp.Stop()); 65 ShouldThrow(() => comp.Stop());
66 Assert.AreEqual(ExecutionState.Created, comp.State); 66 Assert.AreEqual(ExecutionState.Created, comp.State);
67 67
68 ShouldThrow(comp.Init); 68 ShouldThrow(comp.Initialize);
69 69
70 Assert.AreEqual(ExecutionState.Failed, comp.State); 70 Assert.AreEqual(ExecutionState.Failed, comp.State);
71 71
72 ShouldThrow(() => comp.Start()); 72 ShouldThrow(() => comp.Start());
73 ShouldThrow(() => comp.Stop()); 73 ShouldThrow(() => comp.Stop());
83 var comp = new MockRunnableComponent(false); 83 var comp = new MockRunnableComponent(false);
84 comp.Dispose(); 84 comp.Dispose();
85 85
86 ShouldThrow(() => comp.Start()); 86 ShouldThrow(() => comp.Start());
87 ShouldThrow(() => comp.Stop()); 87 ShouldThrow(() => comp.Stop());
88 ShouldThrow(comp.Init); 88 ShouldThrow(comp.Initialize);
89 89
90 Assert.AreEqual(ExecutionState.Disposed, comp.State); 90 Assert.AreEqual(ExecutionState.Disposed, comp.State);
91 }
92
93 [TestMethod]
94 public void ShouldCallDisposeOnStop() {
95 var comp = new MockRunnableComponent(true);
96
97 bool disposed = false;
98 comp.MockDispose = (disposing, error) => {
99 disposed = true;
100 };
101
102 comp.Start().Join(1000);
103 comp.Stop().Join(1000);
104
105 ShouldThrow(() => comp.Start());
106 ShouldThrow(() => comp.Stop());
107 ShouldThrow(comp.Initialize);
108
109 Assert.AreEqual(ExecutionState.Disposed, comp.State);
110 Assert.IsTrue(disposed);
111 }
112
113 [TestMethod]
114 public void ShouldNotCallDisposeOnStop() {
115 var comp = new MockRunnableComponent(true, true);
116
117 bool disposed = false;
118 comp.MockDispose = (disposing, error) => {
119 disposed = true;
120 };
121
122 comp.Start().Join(1000);
123 comp.Stop().Join(1000);
124
125 Assert.AreEqual(ExecutionState.Ready, comp.State);
126 Assert.IsFalse(disposed);
127 }
128
129 [TestMethod]
130 public void SelfDisposeOnStop() {
131 var comp = new MockRunnableComponent(true, true);
132
133 bool disposed = false;
134 Exception lastError = null;
135 comp.MockDispose = (disposing, error) => {
136 disposed = true;
137 lastError = error;
138 };
139
140 comp.Start().Join(1000);
141 comp.Stop().Join(1000);
142
143 Assert.AreEqual(ExecutionState.Ready, comp.State);
144 Assert.IsFalse(disposed);
145
146 comp.MockStop = () => {
147 comp.Dispose();
148 return Promise.Success;
149 };
150
151 comp.Start().Join(1000);
152 comp.Stop().Join(1000);
153
154 Assert.AreEqual(ExecutionState.Disposed, comp.State);
155 Assert.IsTrue(disposed);
91 } 156 }
92 157
93 [TestMethod] 158 [TestMethod]
94 public void StartCancelTest() { 159 public void StartCancelTest() {
95 var comp = new MockRunnableComponent(true) { 160 var comp = new MockRunnableComponent(true) {