@@ -77,6 +77,55 @@ string uriScheme
7777 await Task . Delay ( 1000 ) . ConfigureAwait ( false ) ;
7878 await fixture . StopAsync ( ) . ConfigureAwait ( false ) ;
7979 }
80+
81+ /// <summary>
82+ /// Start a server fixture, stop it and restart it.
83+ /// </summary>
84+ [ Test ]
85+ public async Task StartAndRestartServerAsync ( )
86+ {
87+ IServiceCollection services = new ServiceCollection ( )
88+ . AddConfigurationServices ( )
89+ . AddServerServices ( )
90+ . AddSingleton < IStandardServer , StandardServer > ( ) ;
91+
92+ IServiceProvider serviceProvider = services . BuildServiceProvider ( ) ;
93+
94+ var fixture = new ServerFixture < IStandardServer > (
95+ serviceProvider . GetRequiredService < IStandardServer > ( ) ,
96+ serviceProvider . GetRequiredService < IApplicationInstance > ( ) ) ;
97+ Assert . NotNull ( fixture ) ;
98+ fixture . UriScheme = Utils . UriSchemeOpcTcp ;
99+
100+ IStandardServer server = await fixture . StartAsync ( TestContext . Out ) . ConfigureAwait ( false ) ;
101+ fixture . SetTraceOutput ( TestContext . Out ) ;
102+ Assert . NotNull ( server ) ;
103+
104+ Assert . AreEqual ( server . CurrentInstance . Initialized , true ) ;
105+ Assert . AreEqual ( server . CurrentState , ServerState . Running ) ;
106+
107+ await Task . Delay ( 1000 ) . ConfigureAwait ( false ) ;
108+ await fixture . StopAsync ( ) . ConfigureAwait ( false ) ;
109+
110+ uint ? exceptionStatusCode1 = NUnit . Framework . Assert . Throws < ServiceResultException > ( delegate { bool result = server . CurrentInstance . Initialized ; } ) ? . StatusCode ;
111+ Assert . AreEqual ( exceptionStatusCode1 , StatusCodes . BadServerHalted ) ;
112+
113+ await Task . Delay ( 1000 ) . ConfigureAwait ( false ) ;
114+
115+ IStandardServer server2 = await fixture . StartAsync ( TestContext . Out ) . ConfigureAwait ( false ) ;
116+ Assert . NotNull ( server2 ) ;
117+
118+ Assert . AreEqual ( server . CurrentInstance . Initialized , true ) ;
119+ Assert . AreEqual ( server . CurrentState , ServerState . Running ) ;
120+
121+ await Task . Delay ( 1000 ) . ConfigureAwait ( false ) ;
122+ await fixture . StopAsync ( ) . ConfigureAwait ( false ) ;
123+
124+ await Task . Delay ( 1000 ) . ConfigureAwait ( false ) ;
125+
126+ uint ? exceptionStatusCode2 = NUnit . Framework . Assert . Throws < ServiceResultException > ( delegate { bool result = server . CurrentInstance . Initialized ; } ) ? . StatusCode ;
127+ Assert . AreEqual ( exceptionStatusCode2 , StatusCodes . BadServerHalted ) ;
128+ }
80129 #endregion
81130 }
82131}
0 commit comments