コード例 #1
0
        public void RunWorkerAsync_SubscribeToOnRunWorkerCompletedEventAndWorkCancelsOperation_InvokesOnRunWorkerCompletedWithCancelSetToTrue()
        {
            // arrange
            WorkerTester tester = new WorkerTester(InitializeWorker());

            // act
            WorkerTesterResult result = tester.RunWorkerAsyncWithCancel(null);

            // assert
            Assert.IsTrue(result.OnRunWorkerComplatedEventArgs.Cancelled);
        }
コード例 #2
0
        public void RunWorkerAsync_SubscribeToOnRunWorkerCompletedEventAndRunWorkerWithoutArgument_InvokesOnRunWorkerCompletedWhenTaskFinishes()
        {
            // arrange
            WorkerTester tester = new WorkerTester(InitializeWorker());

            // act
            WorkerTesterResult result = tester.RunWorkerAsync();

            // assert
            Assert.IsTrue(result.IsRunWorkerCompletedCalled);
        }
コード例 #3
0
        public void RunWorkerAsync_SubscribeToOnRunWorkerCompletedEventAndWorkThrowsException_InvokesOnRunWorkerCompletedWithExceptionDetails()
        {
            // arrange
            WorkerTester tester = new WorkerTester(InitializeWorker());

            // act
            WorkerTesterResult result = tester.RunWorkerAsyncWithException(null);

            // assert
            Assert.That(result.OnRunWorkerComplatedEventArgs.Error, Is.InstanceOf <Exception>());
        }
コード例 #4
0
        public void RunWorkerAsync_SubscribeToOnDoWorkEventAndRunWorker_SetsCancellationPendingToFalse()
        {
            // arrange
            WorkerTester tester = new WorkerTester(InitializeWorker());

            // act
            WorkerTesterResult result = tester.RunWorkerAsync();

            // assert
            Assert.IsFalse(result.CancellationPending);
        }
コード例 #5
0
        public void RunWorkerAsync_SubscribeToOnDoWorkEvent_WhenEventIsFiredWorkerIsBusy()
        {
            // arrange
            WorkerTester tester = new WorkerTester(InitializeWorker());

            // act
            WorkerTesterResult result = tester.RunWorkerAsync();

            // assert
            Assert.IsTrue(result.IsBusy);
        }
コード例 #6
0
        public void RunWorkerAsync_SubscribeToOnDoWorkEventAndRunWorkerWithArgument_InvokesOnDoWorkEventWithSuppliedArgument(object expectedArgument)
        {
            // arrange
            WorkerTester tester = new WorkerTester(InitializeWorker());

            // act
            WorkerTesterResult result = tester.RunWorkerAsync(expectedArgument);

            // assert
            Assert.AreEqual(expectedArgument, result.DoWorkArgument);
        }
コード例 #7
0
        public void RunWorkerAsync_SubscribeToOnDoWorkEventAndRunWorkerWithoutArgument_InvokesOnDoWorkEvent()
        {
            // arrange
            WorkerTester tester = new WorkerTester(InitializeWorker());

            // act
            WorkerTesterResult result = tester.RunWorkerAsync();

            // assert
            Assert.IsTrue(result.IsDoWorkCalled);
        }
コード例 #8
0
            public WorkerTesterResult RunWorkerAsyncWithException(object argument)
            {
                WorkerTesterResult result = new WorkerTesterResult();

                worker.OnDoWork += (sender, e) =>
                {
                    throw new Exception("OnDoWork exception");
                };

                worker.OnRunWorkerCompleted += (sender, e) =>
                {
                    result.OnRunWorkerComplatedEventArgs = e;
                };

                worker.RunWorkerAsync(argument);

                return(result);
            }
コード例 #9
0
            public WorkerTesterResult RunWorkerAsyncWithCancel(object argument)
            {
                WorkerTesterResult result = new WorkerTesterResult();

                worker.OnDoWork += (sender, e) =>
                {
                    e.Cancel = true;
                };

                worker.OnRunWorkerCompleted += (sender, e) =>
                {
                    result.OnRunWorkerComplatedEventArgs = e;
                };

                worker.RunWorkerAsync(argument);

                return(result);
            }
コード例 #10
0
            public WorkerTesterResult RunWorkerAsync(object argument)
            {
                WorkerTesterResult result = new WorkerTesterResult();

                worker.OnDoWork += (sender, e) =>
                {
                    result.IsDoWorkCalled      = true;
                    result.DoWorkArgument      = e.Argument;
                    result.IsBusy              = worker.IsBusy;
                    result.CancellationPending = worker.CancellationPending;
                };

                worker.OnRunWorkerCompleted += (sender, e) =>
                {
                    result.IsRunWorkerCompletedCalled = true;
                };

                worker.RunWorkerAsync(argument);

                return(result);
            }
コード例 #11
0
            public WorkerTesterResult RunWorkerAsyncWithException(object argument)
            {
                WorkerTesterResult result = new WorkerTesterResult();

                worker.OnDoWork += (sender, e) =>
                {
                    throw new Exception("OnDoWork exception");
                };

                worker.OnRunWorkerCompleted += (sender, e) =>
                {
                    result.OnRunWorkerComplatedEventArgs = e;
                };

                worker.RunWorkerAsync(argument);

                return result;
            }
コード例 #12
0
            public WorkerTesterResult RunWorkerAsyncWithCancel(object argument)
            {
                WorkerTesterResult result = new WorkerTesterResult();

                worker.OnDoWork += (sender, e) =>
                {
                    e.Cancel = true;
                };

                worker.OnRunWorkerCompleted += (sender, e) =>
                {
                    result.OnRunWorkerComplatedEventArgs = e;
                };

                worker.RunWorkerAsync(argument);

                return result;
            }
コード例 #13
0
            public WorkerTesterResult RunWorkerAsync(object argument)
            {
                WorkerTesterResult result = new WorkerTesterResult();

                worker.OnDoWork += (sender, e) =>
                {
                    result.IsDoWorkCalled = true;
                    result.DoWorkArgument = e.Argument;
                    result.IsBusy = worker.IsBusy;
                    result.CancellationPending = worker.CancellationPending;
                };

                worker.OnRunWorkerCompleted += (sender, e) =>
                {
                    result.IsRunWorkerCompletedCalled = true;
                };

                worker.RunWorkerAsync(argument);

                return result;
            }