Esempio n. 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();
        }
Esempio n. 2
0
        public void TestTransparentWrapping()
        {
            WeightedTransaction <TestOperation> operation1 = new WeightedTransaction <TestOperation>(
                new TestOperation()
                );
            WeightedTransaction <TestOperation> operation2 = new WeightedTransaction <TestOperation>(
                new TestOperation()
                );

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

            // Order is important due to sequential execution!
            Assert.AreSame(operation1, testQueueOperation.Children[0]);
            Assert.AreSame(operation2, testQueueOperation.Children[1]);
        }
Esempio n. 3
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();
        }
Esempio n. 4
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();
        }
Esempio n. 5
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(); }
                );
        }