public void ConstructorRegistersInstanceWithWebHostingEnvironmentToReceiveShutdownNotifications()
 {
     IRegisteredObject registeredObject = null;
     StubHostingEnvironment.OnRegisterObject = obj => registeredObject = obj;
     var service = new TestableWebApplicationLifecycle(typeof(StubHostingEnvironment));
     Assert.Same(service, registeredObject);
 }
 public void DisposeUnregistersInstanceFromWebHostingEnvironment()
 {
     IRegisteredObject unregisteredObject = null;
     StubHostingEnvironment.OnUnregisterObject = obj => unregisteredObject = obj;
     var service = new TestableWebApplicationLifecycle(typeof(StubHostingEnvironment));
     service.Dispose();
     Assert.Same(service, unregisteredObject);
 }
        public void ConstructorRegistersInstanceWithWebHostingEnvironmentToReceiveShutdownNotifications()
        {
            IRegisteredObject registeredObject = null;

            StubHostingEnvironment.OnRegisterObject = obj => registeredObject = obj;
            var service = new TestableWebApplicationLifecycle(typeof(StubHostingEnvironment));

            Assert.AreSame(service, registeredObject);
        }
        public void DisposeUnregistersInstanceFromWebHostingEnvironment()
        {
            IRegisteredObject unregisteredObject = null;

            StubHostingEnvironment.OnUnregisterObject = obj => unregisteredObject = obj;
            var service = new TestableWebApplicationLifecycle(typeof(StubHostingEnvironment));

            service.Dispose();
            Assert.AreSame(service, unregisteredObject);
        }
        public void StopUnregistersInstanceFromWebHostingEnvironmentDuringImmediateShutdown()
        {
            IRegisteredObject unregisteredObject = null;

            StubHostingEnvironment.OnUnregisterObject = obj => unregisteredObject = obj;

            var service = new TestableWebApplicationLifecycle(typeof(StubHostingEnvironment));

            service.Stop(true);

            Assert.AreSame(service, unregisteredObject);
        }
        public void StopUnregistersInstanceFromWebHostingEnvironmentOnceAllAsyncMethodsAreCompleted()
        {
            IRegisteredObject unregisteredObject = null;

            StubHostingEnvironment.OnUnregisterObject = obj => unregisteredObject = obj;

            IRegisteredObject objectUnregisteredWhileRunningAsyncMethods = null;
            Func <Task>       asyncMethod = () =>
            {
                objectUnregisteredWhileRunningAsyncMethods = unregisteredObject;
                return(TaskEx.FromResult <object>(null));
            };

            var service = new TestableWebApplicationLifecycle(typeof(StubHostingEnvironment));

            service.Stopping += (sender, args) => args.Run(asyncMethod);

            service.Stop(false);

            Assert.IsNull(objectUnregisteredWhileRunningAsyncMethods);
            Assert.AreSame(service, unregisteredObject);
        }
        public void StopUnregistersInstanceFromWebHostingEnvironmentDuringImmediateShutdown()
        {
            IRegisteredObject unregisteredObject = null;
            StubHostingEnvironment.OnUnregisterObject = obj => unregisteredObject = obj;

            var service = new TestableWebApplicationLifecycle(typeof(StubHostingEnvironment));
            service.Stop(true);

            Assert.Same(service, unregisteredObject);
        }
        public void StopUnregistersInstanceFromWebHostingEnvironmentOnceAllAsyncMethodsAreCompleted()
        {
            IRegisteredObject unregisteredObject = null;
            StubHostingEnvironment.OnUnregisterObject = obj => unregisteredObject = obj;

            IRegisteredObject objectUnregisteredWhileRunningAsyncMethods = null;
            Func<Task> asyncMethod = () =>
            {
                objectUnregisteredWhileRunningAsyncMethods = unregisteredObject;
                return TaskEx.FromResult<object>(null);
            };

            var service = new TestableWebApplicationLifecycle(typeof(StubHostingEnvironment));
            service.Stopping += (sender, args) => args.Run(asyncMethod);

            service.Stop(false);

            Assert.Null(objectUnregisteredWhileRunningAsyncMethods);
            Assert.Same(service, unregisteredObject);
        }