Beispiel #1
0
        public void TestWeightedSequentialExecution()
        {
            TestOperation operation1 = new TestOperation();
            TestOperation operation2 = new TestOperation();

            OperationQueue <TestOperation> testQueueOperation =
                new OperationQueue <TestOperation>(
                    new WeightedTransaction <TestOperation>[] {
                new WeightedTransaction <TestOperation>(operation1, 0.5f),
                new WeightedTransaction <TestOperation>(operation2, 2.0f)
            }
                    );

            Mock <IOperationQueueSubscriber> mockedSubscriber = mockSubscriber(testQueueOperation);

            testQueueOperation.Start();

            mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With(
                new NMock.Matchers.TypeMatcher(typeof(OperationQueue <TestOperation>)),
                new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.1f))
                );

            operation1.ChangeProgress(0.5f);

            mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With(
                new NMock.Matchers.TypeMatcher(typeof(OperationQueue <TestOperation>)),
                new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.2f))
                );

            operation1.SetEnded();

            this.mockery.VerifyAllExpectationsHaveBeenMet();
        }
Beispiel #2
0
        public void TestSequentialExecution()
        {
            TestOperation operation1 = new TestOperation();
            TestOperation operation2 = new TestOperation();

            OperationQueue <TestOperation> testQueueOperation =
                new OperationQueue <TestOperation>(
                    new TestOperation[] { operation1, operation2 }
                    );

            IOperationQueueSubscriber mockedSubscriber = mockSubscriber(testQueueOperation);

            testQueueOperation.Start();

            Expect.Once.On(mockedSubscriber).
            Method("ProgressChanged").
            With(
                new Matcher[] {
                new NMock2.Matchers.TypeMatcher(typeof(OperationQueue <TestOperation>)),
                new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.25f))
            }
                );

            operation1.ChangeProgress(0.5f);

            Expect.Once.On(mockedSubscriber).
            Method("ProgressChanged").
            With(
                new Matcher[] {
                new NMock2.Matchers.TypeMatcher(typeof(OperationQueue <TestOperation>)),
                new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.5f))
            }
                );

            operation1.SetEnded();

            this.mockery.VerifyAllExpectationsHaveBeenMet();
        }
Beispiel #3
0
        public void TestEndPropagation()
        {
            TestOperation operation1 = new TestOperation();
            TestOperation operation2 = new TestOperation();

            OperationQueue <TestOperation> testQueueOperation =
                new OperationQueue <TestOperation>(
                    new TestOperation[] {
                operation1,
                operation2
            }
                    );

            testQueueOperation.Start();

            Assert.IsFalse(testQueueOperation.Ended);
            operation1.SetEnded();
            Assert.IsFalse(testQueueOperation.Ended);
            operation2.SetEnded();
            Assert.IsTrue(testQueueOperation.Ended);

            testQueueOperation.Join();
        }
Beispiel #4
0
        public void TestExceptionPropagation()
        {
            TestOperation operation1 = new TestOperation();
            TestOperation operation2 = new TestOperation();

            OperationQueue <TestOperation> testQueueOperation =
                new OperationQueue <TestOperation>(
                    new TestOperation[] {
                operation1,
                operation2
            }
                    );

            testQueueOperation.Start();

            Assert.IsFalse(testQueueOperation.Ended);
            operation1.SetEnded();
            Assert.IsFalse(testQueueOperation.Ended);
            operation2.SetEnded(new AbortedException("Hello World"));

            Assert.Throws <AbortedException>(
                delegate() { testQueueOperation.Join(); }
                );
        }