コード例 #1
0
        public void RegistedServices_ReceiveSuspendingEvent()
        {
            MockService service1 = new MockService();
            MockService service2 = new MockService();

            TestableLifetimeManager lifetimeManager = CreateLifetimeManager(new[] { service1, service2 });

            lifetimeManager.Suspend(new MockSuspendingEventArgs());

            Assert.Equal <string>(new string[] { "OnSuspending" }, service1.LifetimeEventCalls);
            Assert.Equal <string>(new string[] { "OnSuspending" }, service2.LifetimeEventCalls);
        }
コード例 #2
0
        public async Task RegistedServices_CausesDeferralOfSuspension()
        {
            // Create two services which will complete suspension when their tasks complete

            TaskCompletionSource <bool> tcs1 = new TaskCompletionSource <bool>();
            TaskCompletionSource <bool> tcs2 = new TaskCompletionSource <bool>();

            MockService service1 = new MockService(tcs1.Task);
            MockService service2 = new MockService(tcs2.Task);

            // Create the LifetimeManager

            TestableLifetimeManager lifetimeManager = CreateLifetimeManager(new[] { service1, service2 });

            // Suspend the LifetimeManager

            MockSuspendingEventArgs suspendingEventArgs = new MockSuspendingEventArgs();

            lifetimeManager.Suspend(suspendingEventArgs);

            // Check that the suspension is deferred

            Assert.True(suspendingEventArgs.IsDeferred);

            // Check that the suspension is deferred on completion of first service

            tcs1.SetResult(true);
            await Task.Yield();

            Assert.True(suspendingEventArgs.IsDeferred);

            // Check that the suspension is completed on completion of second service

            tcs2.SetResult(true);
            await Task.Yield();

            Assert.False(suspendingEventArgs.IsDeferred);
        }