Test implementation of IProgressErrorNotifier
Inheritance: IProgressErrorNotifier
コード例 #1
0
 public void TestCleanup()
 {
     this.errorNotifier    = null;
     this.serviceProvider  = null;
     this.testSubject      = null;
     this.threadingService = null;
 }
        public void ErrorNotificationMananger_EndToEnd()
        {
            ConfigurableErrorNotifier testNotifier = new ConfigurableErrorNotifier();

            // Should not throw
            this.Notify();

            // Add notifier
            this.testSubject.AddNotifier(testNotifier);
            this.Notify();
            testNotifier.AssertExcepections(1);

            // Cleanup
            this.testSubject.RemoveNotifier(testNotifier);

            // Add same notifier multiple times (no op)
            this.testSubject.AddNotifier(testNotifier);
            testNotifier.Reset();
            this.Notify();
            testNotifier.AssertExcepections(1);

            // Remove single instance
            this.testSubject.RemoveNotifier(testNotifier);
            testNotifier.Reset();
            this.Notify();
            testNotifier.AssertExcepections(0);

            // Remove non existing instance
            this.testSubject.RemoveNotifier(testNotifier);
            testNotifier.Reset();
            this.Notify();
            testNotifier.AssertExcepections(0);
        }
        public void ErrorNotificationMananger_EndToEnd()
        {
            ConfigurableErrorNotifier testNotifier = new ConfigurableErrorNotifier();

            // Should not throw
            this.Notify();

            // Add notifier
            this.testSubject.AddNotifier(testNotifier);
            this.Notify();
            testNotifier.Exceptions.Should().HaveCount(1);

            // Cleanup
            this.testSubject.RemoveNotifier(testNotifier);

            // Add same notifier multiple times (no op)
            this.testSubject.AddNotifier(testNotifier);
            testNotifier.Reset();
            this.Notify();
            testNotifier.Exceptions.Should().HaveCount(1);

            // Remove single instance
            this.testSubject.RemoveNotifier(testNotifier);
            testNotifier.Reset();
            this.Notify();
            testNotifier.Exceptions.Should().BeEmpty();

            // Remove non existing instance
            this.testSubject.RemoveNotifier(testNotifier);
            testNotifier.Reset();
            this.Notify();
            testNotifier.Exceptions.Should().BeEmpty();
        }
 public void TestCleanup()
 {
     this.errorNotifier = null;
     this.serviceProvider = null;
     this.testSubject = null;
     this.threadingService = null;
 }
コード例 #5
0
        private ProgressEventsVerifier InitializeTestSubjectWithTestErrorHandling(params ProgressStepDefinition[] definitions)
        {
            // Replace the error handler
            this.errorNotifier = SequentialProgressControllerHelper.InitializeWithTestErrorHandling(this.testSubject, definitions);
            ProgressEventsVerifier verifier = null;

            this.threadingService.RunInUIContext(() => verifier = new ProgressEventsVerifier(this.testSubject));
            return(verifier);
        }
        /// <summary>
        /// The <see cref="ProgressControllerStep"/> which are used by default will swallow the assert exceptions
        /// which means that investigating why something is failing requires more time and effort.
        /// This extension method will record the first <see cref="UnitTestAssertException"/> which was thrown during
        /// execution and will rethrow it on a way that will allow the test to fail and see the original stack
        /// that caused the test failure (on Finished event)
        /// </summary>
        /// <param name="controller">The controller to configure</param>
        /// <returns>The notifier that was used for configuration of the assert exception</returns>
        public static ConfigurableErrorNotifier ConfigureToThrowAssertExceptions(SequentialProgressController controller)
        {
            Assert.IsNotNull(controller, "Controller argument is required");
            Assert.IsNotNull(controller.Steps, "Controller needs to be initialized");

            ConfigurableErrorNotifier errorHandler = new ConfigurableErrorNotifier();

            controller.ErrorNotificationManager.AddNotifier(errorHandler);

            UnitTestAssertException originalException = null;

            // Controller.Finished is executed out of the awaitable state machine and on the calling (UI) thread
            // which means that at this point the test runtime engine will be able to catch it and fail the test
            EventHandler <ProgressControllerFinishedEventArgs> onFinished = null;

            onFinished = (s, e) =>
            {
                // Need to register on the UI thread
                VsThreadingHelper.RunTask(controller, Microsoft.VisualStudio.Shell.VsTaskRunContext.UIThreadNormalPriority, () =>
                {
                    controller.Finished -= onFinished;
                }).Wait();

                // Satisfy the sequential controller verification code
                e.Handled();

                if (originalException != null)
                {
                    Assert.AreEqual(ProgressControllerResult.Failed, e.Result, "Expected to be failed since the assert failed which causes an exception");
                    throw new RestoredUnitTestAssertException(originalException.Message, originalException);
                }
            };

            // Need to register on the UI thread
            VsThreadingHelper.RunTask(controller, Microsoft.VisualStudio.Shell.VsTaskRunContext.UIThreadNormalPriority, () =>
            {
                controller.Finished += onFinished;
            }).Wait();

            errorHandler.NotifyAction = (e) =>
            {
                // Only the first one
                if (originalException == null)
                {
                    originalException = e as UnitTestAssertException;
                }
            };
            return(errorHandler);
        }
        /// <summary>
        /// The <see cref="ProgressControllerStep"/> which are used by default will swallow the assert exceptions
        /// which means that investigating why something is failing requires more time and effort.
        /// This extension method will record the first <see cref="UnitTestAssertException"/> which was thrown during 
        /// execution and will rethrow it on a way that will allow the test to fail and see the original stack
        /// that caused the test failure (on Finished event)
        /// </summary>
        /// <param name="controller">The controller to configure</param>
        /// <returns>The notifier that was used for configuration of the assert exception</returns>
        public static ConfigurableErrorNotifier ConfigureToThrowAssertExceptions(SequentialProgressController controller)
        {
            Assert.IsNotNull(controller, "Controller argument is required");
            Assert.IsNotNull(controller.Steps, "Controller needs to be initialized");

            ConfigurableErrorNotifier errorHandler = new ConfigurableErrorNotifier();
            controller.ErrorNotificationManager.AddNotifier(errorHandler);

            UnitTestAssertException originalException = null;

            // Controller.Finished is executed out of the awaitable state machine and on the calling (UI) thread
            // which means that at this point the test runtime engine will be able to catch it and fail the test 
            EventHandler<ProgressControllerFinishedEventArgs> onFinished = null;
            onFinished = (s, e) =>
            {
                // Need to register on the UI thread
                VsThreadingHelper.RunTask(controller, Microsoft.VisualStudio.Shell.VsTaskRunContext.UIThreadNormalPriority, () =>
                {
                    controller.Finished -= onFinished;
                }).Wait();

                // Satisfy the sequential controller verification code
                e.Handled();

                if (originalException != null)
                {
                    Assert.AreEqual(ProgressControllerResult.Failed, e.Result, "Expected to be failed since the assert failed which causes an exception");
                    throw new RestoredUnitTestAssertException(originalException.Message, originalException);
                }
            };

            // Need to register on the UI thread
            VsThreadingHelper.RunTask(controller, Microsoft.VisualStudio.Shell.VsTaskRunContext.UIThreadNormalPriority, () =>
            {
                controller.Finished += onFinished;
            }).Wait();

            errorHandler.NotifyAction = (e) =>
            {
                // Only the first one
                if (originalException == null)
                {
                    originalException = e as UnitTestAssertException;
                }
            };
            return errorHandler;
        }
 private ProgressEventsVerifier InitializeTestSubjectWithTestErrorHandling(params ProgressStepDefinition[] definitions)
 {
     // Replace the error handler
     this.errorNotifier = SequentialProgressControllerHelper.InitializeWithTestErrorHandling(this.testSubject, definitions);
     ProgressEventsVerifier verifier = null;
     this.threadingService.RunInUIContext(() => verifier = new ProgressEventsVerifier(this.testSubject));
     return verifier;
 }