@@ -64,6 +64,7 @@ public void Register()
6464 }
6565
6666 [ TestMethod ]
67+ [ ExpectedException ( typeof ( RuntimeException ) ) ]
6768 public void RepeatInitTest ( )
6869 {
6970 var app = MakeApplication ( ) ;
@@ -106,6 +107,98 @@ public void NoBootstrapInit()
106107 } ) ;
107108 }
108109
110+ public class StopBootstrap : IBootstrap
111+ {
112+ public string value = string . Empty ;
113+ public bool stop = false ;
114+ public void Bootstrap ( )
115+ {
116+ value = "bootstrap" ;
117+ }
118+ }
119+
120+ [ TestMethod ]
121+ public void TestStopBootstrap ( )
122+ {
123+ var bootstrapStopped = new StopBootstrap ( ) { stop = true } ;
124+ var bootstrapNotStopped = new StopBootstrap ( ) ;
125+ var application = Application . New ( ) ;
126+ application . Listen < IBootstrap , object > ( ApplicationEvents . Bootstrapping , ( b ) =>
127+ {
128+ if ( ( ( StopBootstrap ) b ) . stop )
129+ {
130+ return false ;
131+ }
132+ return null ;
133+ } ) ;
134+ application . Bootstrap ( bootstrapStopped , bootstrapNotStopped ) ;
135+ Assert . AreEqual ( string . Empty , bootstrapStopped . value ) ;
136+ Assert . AreEqual ( "bootstrap" , bootstrapNotStopped . value ) ;
137+ }
138+
139+ public class StopProvider : IServiceProvider
140+ {
141+ public string value = string . Empty ;
142+ public bool stop = false ;
143+ public void Register ( )
144+ {
145+ value = "register" ;
146+ }
147+ public void Init ( )
148+ {
149+ }
150+ }
151+
152+ [ TestMethod ]
153+ public void TestStopRegisterProvider ( )
154+ {
155+ var providerStopped = new StopProvider ( ) { stop = true } ;
156+ var providerNotStopped = new StopProvider ( ) ;
157+
158+ var application = Application . New ( ) ;
159+ application . Listen < IServiceProvider , object > ( ApplicationEvents . OnRegisterProvider , ( b ) =>
160+ {
161+ if ( ( ( StopProvider ) b ) . stop )
162+ {
163+ return false ;
164+ }
165+ return null ;
166+ } ) ;
167+ application . Register ( providerStopped ) ;
168+ application . Register ( providerNotStopped ) ;
169+ Assert . AreEqual ( string . Empty , providerStopped . value ) ;
170+ Assert . AreEqual ( "register" , providerNotStopped . value ) ;
171+ }
172+
173+ [ TestMethod ]
174+ [ ExpectedException ( typeof ( RuntimeException ) ) ]
175+ public void TestInitingRegisterProvider ( )
176+ {
177+ var application = Application . New ( ) ;
178+ application . Register ( new StopProvider ( ) ) ;
179+ application . On < IServiceProvider > ( ApplicationEvents . OnIniting , ( b ) =>
180+ {
181+ application . Register ( new TestServiceProvider ( ) ) ;
182+ } ) ;
183+ application . Bootstrap ( ) ;
184+ application . Init ( ) ;
185+ }
186+
187+ [ TestMethod ]
188+ [ ExpectedException ( typeof ( RuntimeException ) ) ]
189+ public void TestTerminateRegisterProvider ( )
190+ {
191+ var application = Application . New ( ) ;
192+ application . Register ( new StopProvider ( ) ) ;
193+ application . On ( ApplicationEvents . OnTerminate , ( ) =>
194+ {
195+ application . Register ( new TestServiceProvider ( ) ) ;
196+ } ) ;
197+ application . Bootstrap ( ) ;
198+ application . Init ( ) ;
199+ application . Terminate ( ) ;
200+ }
201+
109202 /// <summary>
110203 /// 测试终止程序
111204 /// </summary>
@@ -164,7 +257,7 @@ public void TestOn()
164257 public void GetCurrentProcess ( )
165258 {
166259 var app = MakeApplication ( ) ;
167- Assert . AreEqual ( Application . StartProcess . Inited , app . Process ) ;
260+ Assert . AreEqual ( Application . StartProcess . Running , app . Process ) ;
168261 }
169262
170263 [ TestMethod ]
@@ -178,13 +271,13 @@ public void TestDebugLevel()
178271 /// 重复的引导测试
179272 /// </summary>
180273 [ TestMethod ]
274+ [ ExpectedException ( typeof ( RuntimeException ) ) ]
181275 public void RepeatBootstrap ( )
182276 {
183277 var app = new Application ( ) ;
184278 app . Bootstrap ( ) ;
185279 app . Init ( ) ;
186280 app . Bootstrap ( ) ;
187- Assert . AreEqual ( Application . StartProcess . Inited , app . Process ) ;
188281 }
189282
190283 /// <summary>
0 commit comments