public void Configuration_Returns_Same_Instance_Twice() { var environment = new Mock <IHostingEnvironment>(); environment.SetupAllProperties(); environment.SetupGet(x => x.ContentRootPath) .Returns(Directory.GetCurrentDirectory); var startup = new StartupWrapper(environment.Object); var result1 = startup.ConfigurationPublic; var result2 = startup.ConfigurationPublic; Assert.AreSame(result1, result2); Assert.AreEqual(1, startup.ConfigureConfigurationCallCount); }
public void Constructor_Saves_Environment() { var name = typeof(StartupWrapper).GetTypeInfo() .Assembly.GetName() .Name; var environment = new Mock <IHostingEnvironment>(); environment.SetupAllProperties(); var startup = new StartupWrapper(environment.Object); var result = startup.EnvironmentPublic; Assert.AreSame(environment.Object, result); Assert.AreEqual(name, result.ApplicationName); }
public void RunAsync_Calls_OnShutdown() { var environment = new Mock <IHostingEnvironment>(); environment.SetupAllProperties(); environment.Object.ContentRootPath = Directory.GetCurrentDirectory(); var startup = new StartupWrapper(environment.Object); var server = new Server <StartupWrapper>(startup); var cancelSource = new CancellationTokenSource(); // Create a new task to test the server in Exception exception = null; var thread = new Thread(() => { try { server.RunAsync(cancelSource.Token) .Wait(); } catch (Exception ex) { exception = ex; } }); thread.Start(); // Wait for a second for the server to really start Thread.Sleep(1000); // Trigger the token to exit the server cancelSource.Cancel(); // Wait for the thread to end, max: 10 seconds thread.Join(10000); // Re-throw any exception that occurred if (exception != null) { throw new Exception(exception.Message, exception); } Assert.AreEqual(1, startup.OnShutdownCallCount); }