示例#1
0
        /// <summary>Mocks a subscriber for the events of an operation</summary>
        /// <param name="operation">Operation to mock an event subscriber for</param>
        /// <returns>The mocked event subscriber</returns>
        private IOperationQueueSubscriber mockSubscriber(Operation operation)
        {
            IOperationQueueSubscriber mockedSubscriber =
                this.mockery.NewMock <IOperationQueueSubscriber>();

            operation.AsyncEnded += new EventHandler(mockedSubscriber.Ended);
            (operation as IProgressReporter).AsyncProgressChanged +=
                new EventHandler <ProgressReportEventArgs>(mockedSubscriber.ProgressChanged);

            return(mockedSubscriber);
        }
示例#2
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)
            }
                    );

            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.1f))
            }
                );

            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.2f))
            }
                );

            operation1.SetEnded();

            this.mockery.VerifyAllExpectationsHaveBeenMet();
        }