/// <summary>Mocks a subscriber for the events of a transaction</summary> /// <param name="transaction">Transaction to mock an event subscriber for</param> /// <returns>The mocked event subscriber</returns> private ITransactionGroupSubscriber mockSubscriber(Transaction transaction) { ITransactionGroupSubscriber mockedSubscriber = this.mockery.NewMock <ITransactionGroupSubscriber>(); transaction.AsyncEnded += new EventHandler(mockedSubscriber.Ended); (transaction as IProgressReporter).AsyncProgressChanged += new EventHandler <ProgressReportEventArgs>(mockedSubscriber.ProgressChanged); return(mockedSubscriber); }
public void TestWeightedSummedProgress() { using ( TransactionGroup <TestTransaction> testTransactionGroup = new TransactionGroup <TestTransaction>( new WeightedTransaction <TestTransaction>[] { new WeightedTransaction <TestTransaction>(new TestTransaction(), 1.0f), new WeightedTransaction <TestTransaction>(new TestTransaction(), 2.0f) } ) ) { ITransactionGroupSubscriber mockedSubscriber = mockSubscriber(testTransactionGroup); Expect.Once.On(mockedSubscriber). Method("ProgressChanged"). With( new Matcher[] { new NMock2.Matchers.TypeMatcher(typeof(TransactionGroup <TestTransaction>)), new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.5f / 3.0f)) } ); testTransactionGroup.Children[0].Transaction.ChangeProgress(0.5f); Expect.Once.On(mockedSubscriber). Method("ProgressChanged"). With( new Matcher[] { new NMock2.Matchers.TypeMatcher(typeof(TransactionGroup <TestTransaction>)), new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.5f)) } ); testTransactionGroup.Children[1].Transaction.ChangeProgress(0.5f); this.mockery.VerifyAllExpectationsHaveBeenMet(); } }
public void TestEndedEventWithSingleTransaction() { using ( TransactionGroup <TestTransaction> testTransactionGroup = new TransactionGroup <TestTransaction>( new TestTransaction[] { new TestTransaction() } ) ) { ITransactionGroupSubscriber mockedSubscriber = mockSubscriber(testTransactionGroup); Expect.Once.On(mockedSubscriber). Method("ProgressChanged"). WithAnyArguments(); Expect.Once.On(mockedSubscriber). Method("Ended"). WithAnyArguments(); testTransactionGroup.Children[0].Transaction.End(); this.mockery.VerifyAllExpectationsHaveBeenMet(); } }