From aa5e4d12ccb8859dfab29cdb6f468dbf289c40c8 Mon Sep 17 00:00:00 2001 From: Markus Ewald Date: Tue, 8 Mar 2011 20:36:43 +0000 Subject: [PATCH] Upgraded unit tests to NMock 3.0 git-svn-id: file:///srv/devel/repo-conversion/nusu@214 d2e56fa2-650e-0410-a79f-9358c0239efd --- Nuclex.Support (net-4.0).csproj | 4 +- Source/Collections/Deque.Test.cs | 1 - Source/Collections/ItemEventArgs.Test.cs | 1 - .../Collections/ObservableCollection.Test.cs | 52 +++--- .../Collections/ObservableDictionary.Test.cs | 73 +++++--- Source/Collections/Parentable.Test.cs | 1 - .../Collections/ParentingCollection.Test.cs | 1 - Source/Collections/Pool.Test.cs | 1 - Source/Collections/PriorityItemPair.Test.cs | 1 - Source/Collections/ReverseComparer.Test.cs | 1 - .../TransformingReadOnlyCollection.Test.cs | 10 +- Source/Collections/WeakCollection.Test.cs | 55 +++--- Source/Plugins/PluginRepository.Test.cs | 18 +- Source/Scheduling/AbortedException.Test.cs | 2 - Source/Scheduling/Operation.Test.cs | 2 - Source/Scheduling/OperationQueue.Test.cs | 72 ++++---- .../ThreadCallbackOperation.Test.cs | 1 - Source/Scheduling/ThreadOperation.Test.cs | 1 - .../ObservedWeightedTransaction.Test.cs | 26 +-- ...ightedTransactionWrapperCollection.Test.cs | 1 - Source/Tracking/ProgressTracker.Test.cs | 160 ++++++++---------- Source/Tracking/Request.Test.cs | 1 - Source/Tracking/Transaction.Test.cs | 34 ++-- Source/Tracking/TransactionGroup.Test.cs | 85 ++++------ 24 files changed, 284 insertions(+), 320 deletions(-) diff --git a/Nuclex.Support (net-4.0).csproj b/Nuclex.Support (net-4.0).csproj index b5cf861..e2b6e6f 100644 --- a/Nuclex.Support (net-4.0).csproj +++ b/Nuclex.Support (net-4.0).csproj @@ -40,8 +40,8 @@ ..\Foundation.snk - - ..\References\nmock\net-4.0\NMock2.dll + + ..\References\nmock\net-4.0\NMock.StrongNamed.dll False diff --git a/Source/Collections/Deque.Test.cs b/Source/Collections/Deque.Test.cs index 953b6e7..fa3651a 100644 --- a/Source/Collections/Deque.Test.cs +++ b/Source/Collections/Deque.Test.cs @@ -25,7 +25,6 @@ using System.Collections; using System.Collections.Generic; using NUnit.Framework; -using NMock2; namespace Nuclex.Support.Collections { diff --git a/Source/Collections/ItemEventArgs.Test.cs b/Source/Collections/ItemEventArgs.Test.cs index e4e5819..427410c 100644 --- a/Source/Collections/ItemEventArgs.Test.cs +++ b/Source/Collections/ItemEventArgs.Test.cs @@ -24,7 +24,6 @@ using System; using System.Collections.Generic; using NUnit.Framework; -using NMock2; namespace Nuclex.Support.Collections { diff --git a/Source/Collections/ObservableCollection.Test.cs b/Source/Collections/ObservableCollection.Test.cs index cf97425..cc1f98d 100644 --- a/Source/Collections/ObservableCollection.Test.cs +++ b/Source/Collections/ObservableCollection.Test.cs @@ -24,7 +24,7 @@ using System.Collections.Generic; #if UNITTEST using NUnit.Framework; -using NMock2; +using NMock; namespace Nuclex.Support.Collections { @@ -64,30 +64,30 @@ namespace Nuclex.Support.Collections { /// Initialization routine executed before each test is run [SetUp] public void Setup() { - this.mockery = new Mockery(); + this.mockery = new MockFactory(); - this.mockedSubscriber = this.mockery.NewMock(); + this.mockedSubscriber = this.mockery.CreateMock(); this.observedCollection = new ObservableCollection(); - this.observedCollection.Clearing += - new EventHandler(this.mockedSubscriber.Clearing); - this.observedCollection.Cleared += - new EventHandler(this.mockedSubscriber.Cleared); - this.observedCollection.ItemAdded += - new EventHandler>( - this.mockedSubscriber.ItemAdded - ); - this.observedCollection.ItemRemoved += - new EventHandler>( - this.mockedSubscriber.ItemRemoved - ); + this.observedCollection.Clearing += new EventHandler( + this.mockedSubscriber.MockObject.Clearing + ); + this.observedCollection.Cleared += new EventHandler( + this.mockedSubscriber.MockObject.Cleared + ); + this.observedCollection.ItemAdded += new EventHandler>( + this.mockedSubscriber.MockObject.ItemAdded + ); + this.observedCollection.ItemRemoved += new EventHandler>( + this.mockedSubscriber.MockObject.ItemRemoved + ); } /// Tests whether the Clearing event is fired [Test] public void TestClearingEvent() { - Expect.Once.On(this.mockedSubscriber).Method("Clearing").WithAnyArguments(); - Expect.Once.On(this.mockedSubscriber).Method("Cleared").WithAnyArguments(); + this.mockedSubscriber.Expects.One.Method(m => m.Clearing(null, null)).WithAnyArguments(); + this.mockedSubscriber.Expects.One.Method(m => m.Cleared(null, null)).WithAnyArguments(); this.observedCollection.Clear(); this.mockery.VerifyAllExpectationsHaveBeenMet(); @@ -96,7 +96,7 @@ namespace Nuclex.Support.Collections { /// Tests whether the ItemAdded event is fired [Test] public void TestItemAddedEvent() { - Expect.Once.On(this.mockedSubscriber).Method("ItemAdded").WithAnyArguments(); + this.mockedSubscriber.Expects.One.Method(m => m.ItemAdded(null, null)).WithAnyArguments(); this.observedCollection.Add(123); @@ -106,11 +106,11 @@ namespace Nuclex.Support.Collections { /// Tests whether the ItemRemoved event is fired [Test] public void TestItemRemovedEvent() { - Expect.Once.On(this.mockedSubscriber).Method("ItemAdded").WithAnyArguments(); + this.mockedSubscriber.Expects.One.Method(m => m.ItemAdded(null, null)).WithAnyArguments(); this.observedCollection.Add(123); - Expect.Once.On(this.mockedSubscriber).Method("ItemRemoved").WithAnyArguments(); + this.mockedSubscriber.Expects.One.Method(m => m.ItemRemoved(null, null)).WithAnyArguments(); this.observedCollection.Remove(123); @@ -120,14 +120,16 @@ namespace Nuclex.Support.Collections { /// Tests whether items in the collection can be replaced [Test] public void TestItemReplacement() { - Expect.Exactly(3).On(this.mockedSubscriber).Method("ItemAdded").WithAnyArguments(); + this.mockedSubscriber.Expects.Exactly(3).Method( + m => m.ItemAdded(null, null) + ).WithAnyArguments(); this.observedCollection.Add(1); this.observedCollection.Add(2); this.observedCollection.Add(3); - Expect.Once.On(this.mockedSubscriber).Method("ItemRemoved").WithAnyArguments(); - Expect.Once.On(this.mockedSubscriber).Method("ItemAdded").WithAnyArguments(); + this.mockedSubscriber.Expects.One.Method(m => m.ItemRemoved(null, null)).WithAnyArguments(); + this.mockedSubscriber.Expects.One.Method(m => m.ItemAdded(null, null)).WithAnyArguments(); // Replace the middle item with something else this.observedCollection[1] = 4; @@ -150,9 +152,9 @@ namespace Nuclex.Support.Collections { } /// Mock object factory - private Mockery mockery; + private MockFactory mockery; /// The mocked observable collection subscriber - private IObservableCollectionSubscriber mockedSubscriber; + private Mock mockedSubscriber; /// An observable collection to which a mock will be subscribed private ObservableCollection observedCollection; diff --git a/Source/Collections/ObservableDictionary.Test.cs b/Source/Collections/ObservableDictionary.Test.cs index b98411f..b0a39fb 100644 --- a/Source/Collections/ObservableDictionary.Test.cs +++ b/Source/Collections/ObservableDictionary.Test.cs @@ -27,7 +27,7 @@ using System.IO; using System.Runtime.Serialization.Formatters.Binary; using NUnit.Framework; -using NMock2; +using NMock; namespace Nuclex.Support.Collections { @@ -67,9 +67,9 @@ namespace Nuclex.Support.Collections { /// Initialization routine executed before each test is run [SetUp] public void Setup() { - this.mockery = new Mockery(); + this.mockery = new MockFactory(); - this.mockedSubscriber = this.mockery.NewMock(); + this.mockedSubscriber = this.mockery.CreateMock(); this.observedDictionary = new ObservableDictionary(); this.observedDictionary.Add(1, "one"); @@ -78,16 +78,16 @@ namespace Nuclex.Support.Collections { this.observedDictionary.Add(42, "forty-two"); this.observedDictionary.Clearing += - new EventHandler(this.mockedSubscriber.Clearing); + new EventHandler(this.mockedSubscriber.MockObject.Clearing); this.observedDictionary.Cleared += - new EventHandler(this.mockedSubscriber.Cleared); + new EventHandler(this.mockedSubscriber.MockObject.Cleared); this.observedDictionary.ItemAdded += new EventHandler>>( - this.mockedSubscriber.ItemAdded + this.mockedSubscriber.MockObject.ItemAdded ); this.observedDictionary.ItemRemoved += new EventHandler>>( - this.mockedSubscriber.ItemRemoved + this.mockedSubscriber.MockObject.ItemRemoved ); } @@ -249,7 +249,7 @@ namespace Nuclex.Support.Collections { /// [Test] public void TestAddViaGenericIDictionary() { - Expect.Once.On(this.mockedSubscriber).Method("ItemAdded").WithAnyArguments(); + this.mockedSubscriber.Expects.One.Method(m => m.ItemAdded(null, null)).WithAnyArguments(); (this.observedDictionary as IDictionary).Add(10, "ten"); this.mockery.VerifyAllExpectationsHaveBeenMet(); @@ -264,7 +264,7 @@ namespace Nuclex.Support.Collections { /// [Test] public void TestRemoveViaGenericIDictionary() { - Expect.Once.On(this.mockedSubscriber).Method("ItemRemoved").WithAnyArguments(); + this.mockedSubscriber.Expects.One.Method(m => m.ItemRemoved(null, null)).WithAnyArguments(); (this.observedDictionary as IDictionary).Remove(3); this.mockery.VerifyAllExpectationsHaveBeenMet(); @@ -287,8 +287,12 @@ namespace Nuclex.Support.Collections { /// [Test] public void TestReplaceByIndexerViaGenericIDictionary() { - Expect.Once.On(this.mockedSubscriber).Method("ItemRemoved").WithAnyArguments(); - Expect.Once.On(this.mockedSubscriber).Method("ItemAdded").WithAnyArguments(); + this.mockedSubscriber.Expects.One.Method( + m => m.ItemRemoved(null, null) + ).WithAnyArguments(); + this.mockedSubscriber.Expects.One.Method( + m => m.ItemAdded(null, null) + ).WithAnyArguments(); (this.observedDictionary as IDictionary)[42] = "two and fourty"; this.mockery.VerifyAllExpectationsHaveBeenMet(); @@ -300,8 +304,12 @@ namespace Nuclex.Support.Collections { /// [Test] public void TestClearViaIDictionary() { - Expect.Once.On(this.mockedSubscriber).Method("Clearing").WithAnyArguments(); - Expect.Once.On(this.mockedSubscriber).Method("Cleared").WithAnyArguments(); + this.mockedSubscriber.Expects.One.Method( + m => m.Clearing(null, null) + ).WithAnyArguments(); + this.mockedSubscriber.Expects.One.Method( + m => m.Cleared(null, null) + ).WithAnyArguments(); (this.observedDictionary as IDictionary).Clear(); this.mockery.VerifyAllExpectationsHaveBeenMet(); @@ -313,7 +321,9 @@ namespace Nuclex.Support.Collections { /// [Test] public void TestAddViaIDictionary() { - Expect.Once.On(this.mockedSubscriber).Method("ItemAdded").WithAnyArguments(); + this.mockedSubscriber.Expects.One.Method( + m => m.ItemAdded(null, null) + ).WithAnyArguments(); (this.observedDictionary as IDictionary).Add(24, "twenty-four"); this.mockery.VerifyAllExpectationsHaveBeenMet(); @@ -380,7 +390,7 @@ namespace Nuclex.Support.Collections { /// [Test] public void TestRemoveViaIDictionary() { - Expect.Once.On(this.mockedSubscriber).Method("ItemRemoved").WithAnyArguments(); + this.mockedSubscriber.Expects.One.Method(m => m.ItemRemoved(null, null)).WithAnyArguments(); (this.observedDictionary as IDictionary).Remove(3); this.mockery.VerifyAllExpectationsHaveBeenMet(); @@ -401,8 +411,13 @@ namespace Nuclex.Support.Collections { /// [Test] public void TestReplaceByIndexerViaIDictionary() { - Expect.Once.On(this.mockedSubscriber).Method("ItemRemoved").WithAnyArguments(); - Expect.Once.On(this.mockedSubscriber).Method("ItemAdded").WithAnyArguments(); + this.mockedSubscriber.Expects.One.Method( + m => m.ItemRemoved(null, null) + ).WithAnyArguments(); + this.mockedSubscriber.Expects.One.Method( + m => m.ItemAdded(null, null) + ).WithAnyArguments(); + (this.observedDictionary as IDictionary)[42] = "two and fourty"; this.mockery.VerifyAllExpectationsHaveBeenMet(); @@ -415,7 +430,10 @@ namespace Nuclex.Support.Collections { /// [Test] public void TestAddViaGenericICollection() { - Expect.Once.On(this.mockedSubscriber).Method("ItemAdded").WithAnyArguments(); + this.mockedSubscriber.Expects.One.Method( + m => m.ItemAdded(null, null) + ).WithAnyArguments(); + (this.observedDictionary as ICollection>).Add( new KeyValuePair(24, "twenty-four") ); @@ -432,8 +450,13 @@ namespace Nuclex.Support.Collections { /// [Test] public void TestClearViaGenericICollection() { - Expect.Once.On(this.mockedSubscriber).Method("Clearing").WithAnyArguments(); - Expect.Once.On(this.mockedSubscriber).Method("Cleared").WithAnyArguments(); + this.mockedSubscriber.Expects.One.Method( + m => m.Clearing(null, null) + ).WithAnyArguments(); + this.mockedSubscriber.Expects.One.Method( + m => m.Cleared(null, null) + ).WithAnyArguments(); + (this.observedDictionary as ICollection>).Clear(); this.mockery.VerifyAllExpectationsHaveBeenMet(); @@ -449,7 +472,11 @@ namespace Nuclex.Support.Collections { IEnumerator> enumerator = (this.observedDictionary as ICollection>).GetEnumerator(); enumerator.MoveNext(); - Expect.Once.On(this.mockedSubscriber).Method("ItemRemoved").WithAnyArguments(); + + this.mockedSubscriber.Expects.One.Method( + m => m.ItemRemoved(null, null) + ).WithAnyArguments(); + (this.observedDictionary as ICollection>).Remove( enumerator.Current ); @@ -537,9 +564,9 @@ namespace Nuclex.Support.Collections { } /// Mock object factory - private Mockery mockery; + private MockFactory mockery; /// The mocked observable collection subscriber - private IObservableDictionarySubscriber mockedSubscriber; + private Mock mockedSubscriber; /// An observable dictionary to which a mock will be subscribed private ObservableDictionary observedDictionary; diff --git a/Source/Collections/Parentable.Test.cs b/Source/Collections/Parentable.Test.cs index fda570f..ef69480 100644 --- a/Source/Collections/Parentable.Test.cs +++ b/Source/Collections/Parentable.Test.cs @@ -24,7 +24,6 @@ using System.Collections.Generic; #if UNITTEST using NUnit.Framework; -using NMock2; namespace Nuclex.Support.Collections { diff --git a/Source/Collections/ParentingCollection.Test.cs b/Source/Collections/ParentingCollection.Test.cs index bf0e6ff..6d78c09 100644 --- a/Source/Collections/ParentingCollection.Test.cs +++ b/Source/Collections/ParentingCollection.Test.cs @@ -24,7 +24,6 @@ using System.Collections.Generic; #if UNITTEST using NUnit.Framework; -using NMock2; namespace Nuclex.Support.Collections { diff --git a/Source/Collections/Pool.Test.cs b/Source/Collections/Pool.Test.cs index 06a17c1..f58ed97 100644 --- a/Source/Collections/Pool.Test.cs +++ b/Source/Collections/Pool.Test.cs @@ -24,7 +24,6 @@ using System; using System.Collections.Generic; using NUnit.Framework; -using NMock2; namespace Nuclex.Support.Collections { diff --git a/Source/Collections/PriorityItemPair.Test.cs b/Source/Collections/PriorityItemPair.Test.cs index da804eb..b357ecd 100644 --- a/Source/Collections/PriorityItemPair.Test.cs +++ b/Source/Collections/PriorityItemPair.Test.cs @@ -24,7 +24,6 @@ using System; using System.Collections.Generic; using NUnit.Framework; -using NMock2; namespace Nuclex.Support.Collections { diff --git a/Source/Collections/ReverseComparer.Test.cs b/Source/Collections/ReverseComparer.Test.cs index 4fc7849..65b61f6 100644 --- a/Source/Collections/ReverseComparer.Test.cs +++ b/Source/Collections/ReverseComparer.Test.cs @@ -24,7 +24,6 @@ using System.Collections.Generic; #if UNITTEST using NUnit.Framework; -using NMock2; namespace Nuclex.Support.Collections { diff --git a/Source/Collections/TransformingReadOnlyCollection.Test.cs b/Source/Collections/TransformingReadOnlyCollection.Test.cs index 0c247e8..9243e40 100644 --- a/Source/Collections/TransformingReadOnlyCollection.Test.cs +++ b/Source/Collections/TransformingReadOnlyCollection.Test.cs @@ -25,7 +25,7 @@ using System.Collections.Generic; #if UNITTEST using NUnit.Framework; -using NMock2; +using NMock; namespace Nuclex.Support.Collections { @@ -477,13 +477,13 @@ namespace Nuclex.Support.Collections { /// [Test] public void TestSynchronizationOfIListWithoutICollection() { - Mockery mockery = new Mockery(); - IList mockedIList = mockery.NewMock>(); - StringTransformer testCollection = new StringTransformer(mockedIList); + MockFactory mockery = new MockFactory(); + Mock> mockedIList = mockery.CreateMock>(); + StringTransformer testCollection = new StringTransformer(mockedIList.MockObject); if(!(testCollection as ICollection).IsSynchronized) { lock((testCollection as ICollection).SyncRoot) { - Expect.Once.On(mockedIList).GetProperty("Count").Will(Return.Value(12345)); + mockedIList.Expects.One.GetProperty(p => p.Count).WillReturn(12345); int count = testCollection.Count; Assert.AreEqual(12345, count); // ;-) } diff --git a/Source/Collections/WeakCollection.Test.cs b/Source/Collections/WeakCollection.Test.cs index b3e268f..7429816 100644 --- a/Source/Collections/WeakCollection.Test.cs +++ b/Source/Collections/WeakCollection.Test.cs @@ -25,7 +25,6 @@ using System.Collections.Generic; #if UNITTEST using NUnit.Framework; -using NMock2; namespace Nuclex.Support.Collections { @@ -76,6 +75,35 @@ namespace Nuclex.Support.Collections { #endregion // class Dummy + #region class ListWithoutICollection + + private class ListWithoutICollection : IList> { + public int IndexOf(WeakReference item) { throw new NotImplementedException(); } + public void Insert(int index, WeakReference item) { + throw new NotImplementedException(); + } + public void RemoveAt(int index) { throw new NotImplementedException(); } + public WeakReference this[int index] { + get { throw new NotImplementedException(); } + set { throw new NotImplementedException(); } + } + public void Add(WeakReference item) { throw new NotImplementedException(); } + public void Clear() { throw new NotImplementedException(); } + public bool Contains(WeakReference item) { throw new NotImplementedException(); } + public void CopyTo(WeakReference[] array, int arrayIndex) { + throw new NotImplementedException(); + } + public int Count { get { return 12345; } } + public bool IsReadOnly { get { throw new NotImplementedException(); } } + public bool Remove(WeakReference item) { throw new NotImplementedException(); } + public IEnumerator> GetEnumerator() { + throw new NotImplementedException(); + } + IEnumerator IEnumerable.GetEnumerator() { throw new NotImplementedException(); } + } + + #endregion // class ListWithoutICollection + /// Verifies that the constructor of the weak collection is working [Test] public void TestConstructor() { @@ -592,31 +620,6 @@ namespace Nuclex.Support.Collections { } } - private class ListWithoutICollection : IList> { - public int IndexOf(WeakReference item) { throw new NotImplementedException(); } - public void Insert(int index, WeakReference item) { - throw new NotImplementedException(); - } - public void RemoveAt(int index) { throw new NotImplementedException(); } - public WeakReference this[int index] { - get { throw new NotImplementedException(); } - set { throw new NotImplementedException(); } - } - public void Add(WeakReference item) { throw new NotImplementedException(); } - public void Clear() { throw new NotImplementedException(); } - public bool Contains(WeakReference item) { throw new NotImplementedException(); } - public void CopyTo(WeakReference[] array, int arrayIndex) { - throw new NotImplementedException(); - } - public int Count { get { return 12345; } } - public bool IsReadOnly { get { throw new NotImplementedException(); } } - public bool Remove(WeakReference item) { throw new NotImplementedException(); } - public IEnumerator> GetEnumerator() { - throw new NotImplementedException(); - } - IEnumerator IEnumerable.GetEnumerator() { throw new NotImplementedException(); } - } - /// /// Verifies that the IsSynchronized property and the SyncRoot property are working /// on transforming read only collections based on IList<>s that do not diff --git a/Source/Plugins/PluginRepository.Test.cs b/Source/Plugins/PluginRepository.Test.cs index 29aa80c..ac464ec 100644 --- a/Source/Plugins/PluginRepository.Test.cs +++ b/Source/Plugins/PluginRepository.Test.cs @@ -26,7 +26,7 @@ using System.Reflection; #if UNITTEST using NUnit.Framework; -using NMock2; +using NMock; namespace Nuclex.Support.Plugins { @@ -141,12 +141,12 @@ namespace Nuclex.Support.Plugins { /// [Test] public void TestAssemblyLoadedEvent() { - Mockery mockery = new Mockery(); + MockFactory mockery = new MockFactory(); PluginRepository testRepository = new PluginRepository(); - IAssemblyLoadedSubscriber subscriber = mockSubscriber(mockery, testRepository); + Mock subscriber = mockSubscriber(mockery, testRepository); - Expect.Once.On(subscriber).Method("AssemblyLoaded").WithAnyArguments(); + subscriber.Expects.One.Method(m => m.AssemblyLoaded(null, null)).WithAnyArguments(); Assembly self = Assembly.GetAssembly(GetType()); testRepository.AddAssembly(self); @@ -202,14 +202,14 @@ namespace Nuclex.Support.Plugins { /// Mockery to create an event subscriber in /// Repository to subscribe the mocked subscriber to /// The mocked event subscriber - private static IAssemblyLoadedSubscriber mockSubscriber( - Mockery mockery, PluginRepository repository + private static Mock mockSubscriber( + MockFactory mockery, PluginRepository repository ) { - IAssemblyLoadedSubscriber mockedSubscriber = - mockery.NewMock(); + Mock mockedSubscriber = + mockery.CreateMock(); repository.AssemblyLoaded += new AssemblyLoadEventHandler( - mockedSubscriber.AssemblyLoaded + mockedSubscriber.MockObject.AssemblyLoaded ); return mockedSubscriber; diff --git a/Source/Scheduling/AbortedException.Test.cs b/Source/Scheduling/AbortedException.Test.cs index 4511a8c..0881b15 100644 --- a/Source/Scheduling/AbortedException.Test.cs +++ b/Source/Scheduling/AbortedException.Test.cs @@ -26,7 +26,6 @@ using System.IO; using System.Runtime.Serialization.Formatters.Binary; using NUnit.Framework; -using NMock2; namespace Nuclex.Support.Scheduling { @@ -58,7 +57,6 @@ namespace Nuclex.Support.Scheduling { Assert.AreSame(inner, testException.InnerException); } - /// /// Test whether the exception can be serialized /// diff --git a/Source/Scheduling/Operation.Test.cs b/Source/Scheduling/Operation.Test.cs index 00a1e39..e493bbf 100644 --- a/Source/Scheduling/Operation.Test.cs +++ b/Source/Scheduling/Operation.Test.cs @@ -25,9 +25,7 @@ using System.Collections.Generic; using System.IO; using System.Runtime.Serialization.Formatters.Binary; - using NUnit.Framework; -using NMock2; namespace Nuclex.Support.Scheduling { diff --git a/Source/Scheduling/OperationQueue.Test.cs b/Source/Scheduling/OperationQueue.Test.cs index 052ea67..15e0b6b 100644 --- a/Source/Scheduling/OperationQueue.Test.cs +++ b/Source/Scheduling/OperationQueue.Test.cs @@ -25,7 +25,7 @@ using System.Collections.Generic; using System.IO; using NUnit.Framework; -using NMock2; +using NMock; using Nuclex.Support.Tracking; @@ -166,7 +166,7 @@ namespace Nuclex.Support.Scheduling { /// Initialization routine executed before each test is run [SetUp] public void Setup() { - this.mockery = new Mockery(); + this.mockery = new MockFactory(); } /// Validates that the queue executes operations sequentially @@ -180,29 +180,25 @@ namespace Nuclex.Support.Scheduling { new TestOperation[] { operation1, operation2 } ); - IOperationQueueSubscriber mockedSubscriber = mockSubscriber(testQueueOperation); + Mock mockedSubscriber = mockSubscriber(testQueueOperation); testQueueOperation.Start(); - Expect.Once.On(mockedSubscriber). - Method("ProgressChanged"). - With( - new Matcher[] { - new NMock2.Matchers.TypeMatcher(typeof(OperationQueue)), - new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.25f)) - } - ); + mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With( + new Matcher[] { + new NMock.Matchers.TypeMatcher(typeof(OperationQueue)), + 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)), - new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.5f)) - } - ); + mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With( + new Matcher[] { + new NMock.Matchers.TypeMatcher(typeof(OperationQueue)), + new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.5f)) + } + ); operation1.SetEnded(); @@ -226,29 +222,21 @@ namespace Nuclex.Support.Scheduling { } ); - IOperationQueueSubscriber mockedSubscriber = mockSubscriber(testQueueOperation); + Mock mockedSubscriber = mockSubscriber(testQueueOperation); testQueueOperation.Start(); - Expect.Once.On(mockedSubscriber). - Method("ProgressChanged"). - With( - new Matcher[] { - new NMock2.Matchers.TypeMatcher(typeof(OperationQueue)), - new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.1f)) - } - ); + mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With( + new NMock.Matchers.TypeMatcher(typeof(OperationQueue)), + 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)), - new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.2f)) - } - ); + mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With( + new NMock.Matchers.TypeMatcher(typeof(OperationQueue)), + new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.2f)) + ); operation1.SetEnded(); @@ -341,19 +329,19 @@ namespace Nuclex.Support.Scheduling { /// Mocks a subscriber for the events of an operation /// Operation to mock an event subscriber for /// The mocked event subscriber - private IOperationQueueSubscriber mockSubscriber(Operation operation) { - IOperationQueueSubscriber mockedSubscriber = - this.mockery.NewMock(); + private Mock mockSubscriber(Operation operation) { + Mock mockedSubscriber = + this.mockery.CreateMock(); - operation.AsyncEnded += new EventHandler(mockedSubscriber.Ended); + operation.AsyncEnded += new EventHandler(mockedSubscriber.MockObject.Ended); (operation as IProgressReporter).AsyncProgressChanged += - new EventHandler(mockedSubscriber.ProgressChanged); + new EventHandler(mockedSubscriber.MockObject.ProgressChanged); return mockedSubscriber; } /// Mock object factory - private Mockery mockery; + private MockFactory mockery; } diff --git a/Source/Scheduling/ThreadCallbackOperation.Test.cs b/Source/Scheduling/ThreadCallbackOperation.Test.cs index 270aa8f..44ecf1e 100644 --- a/Source/Scheduling/ThreadCallbackOperation.Test.cs +++ b/Source/Scheduling/ThreadCallbackOperation.Test.cs @@ -27,7 +27,6 @@ using System.Runtime.Serialization.Formatters.Binary; using System.Threading; using NUnit.Framework; -using NMock2; namespace Nuclex.Support.Scheduling { diff --git a/Source/Scheduling/ThreadOperation.Test.cs b/Source/Scheduling/ThreadOperation.Test.cs index 969d52d..0558509 100644 --- a/Source/Scheduling/ThreadOperation.Test.cs +++ b/Source/Scheduling/ThreadOperation.Test.cs @@ -27,7 +27,6 @@ using System.Runtime.Serialization.Formatters.Binary; using NUnit.Framework; -using NMock2; namespace Nuclex.Support.Scheduling { diff --git a/Source/Tracking/Internal/ObservedWeightedTransaction.Test.cs b/Source/Tracking/Internal/ObservedWeightedTransaction.Test.cs index 309ad49..338ef2b 100644 --- a/Source/Tracking/Internal/ObservedWeightedTransaction.Test.cs +++ b/Source/Tracking/Internal/ObservedWeightedTransaction.Test.cs @@ -25,7 +25,7 @@ using System.Threading; #if UNITTEST using NUnit.Framework; -using NMock2; +using NMock; namespace Nuclex.Support.Tracking { @@ -85,7 +85,7 @@ namespace Nuclex.Support.Tracking { /// Initialization routine executed before each test is run [SetUp] public void Setup() { - this.mockery = new Mockery(); + this.mockery = new MockFactory(); } /// Verifies that the constructor of the observation wrapper works @@ -95,23 +95,23 @@ namespace Nuclex.Support.Tracking { Transaction.EndedDummy ); - IObservationSubscriber subscriber = this.mockery.NewMock(); + Mock subscriber = this.mockery.CreateMock(); - Expect.AtLeast(0).On(subscriber).Method("ProgressUpdated"); + subscriber.Expects.AtLeast(0).Method(m => m.ProgressUpdated()); // This should no be called because otherwise, the 'Ended' event would be raised // to the transaction group before all transactions have been added into // the internal list, leading to an early ending or even multiple endings. - Expect.Never.On(subscriber).Method("Ended"); + subscriber.Expects.No.Method(m => m.Ended()); using( ObservedWeightedTransaction test = new ObservedWeightedTransaction( testTransaction, new ObservedWeightedTransaction.ReportDelegate( - subscriber.ProgressUpdated + subscriber.MockObject.ProgressUpdated ), new ObservedWeightedTransaction.ReportDelegate( - subscriber.Ended + subscriber.MockObject.Ended ) ) ) { @@ -129,20 +129,20 @@ namespace Nuclex.Support.Tracking { new FunkyTransaction() ); - IObservationSubscriber subscriber = this.mockery.NewMock(); + Mock subscriber = this.mockery.CreateMock(); - Expect.AtLeast(0).On(subscriber).Method("ProgressUpdated"); - Expect.Once.On(subscriber).Method("Ended"); + subscriber.Expects.AtLeast(0).Method(m => m.ProgressUpdated()); + subscriber.Expects.One.Method(m => m.Ended()); using( ObservedWeightedTransaction test = new ObservedWeightedTransaction( testTransaction, new ObservedWeightedTransaction.ReportDelegate( - subscriber.ProgressUpdated + subscriber.MockObject.ProgressUpdated ), new ObservedWeightedTransaction.ReportDelegate( - subscriber.Ended + subscriber.MockObject.Ended ) ) ) { @@ -151,7 +151,7 @@ namespace Nuclex.Support.Tracking { } /// Mock object factory - private Mockery mockery; + private MockFactory mockery; } diff --git a/Source/Tracking/Internal/WeightedTransactionWrapperCollection.Test.cs b/Source/Tracking/Internal/WeightedTransactionWrapperCollection.Test.cs index 0eb53d7..30e441b 100644 --- a/Source/Tracking/Internal/WeightedTransactionWrapperCollection.Test.cs +++ b/Source/Tracking/Internal/WeightedTransactionWrapperCollection.Test.cs @@ -25,7 +25,6 @@ using System.Threading; #if UNITTEST using NUnit.Framework; -using NMock2; namespace Nuclex.Support.Tracking { diff --git a/Source/Tracking/ProgressTracker.Test.cs b/Source/Tracking/ProgressTracker.Test.cs index c26b561..49d4be9 100644 --- a/Source/Tracking/ProgressTracker.Test.cs +++ b/Source/Tracking/ProgressTracker.Test.cs @@ -25,7 +25,7 @@ using System.Collections.Generic; using System.IO; using NUnit.Framework; -using NMock2; +using NMock; namespace Nuclex.Support.Tracking { @@ -161,28 +161,28 @@ namespace Nuclex.Support.Tracking { /// Initialization routine executed before each test is run [SetUp] public void Setup() { - this.mockery = new Mockery(); + this.mockery = new MockFactory(); } /// Validates that the tracker properly sums the progress [Test] public void TestSummedProgress() { using(ProgressTracker tracker = new ProgressTracker()) { - IProgressTrackerSubscriber mockedSubscriber = mockSubscriber(tracker); + Mock mockedSubscriber = mockSubscriber(tracker); TestTransaction test1 = new TestTransaction(); TestTransaction test2 = new TestTransaction(); // Step 1 { - Expect.Once.On(mockedSubscriber).Method("IdleStateChanged").WithAnyArguments(); + mockedSubscriber.Expects.One.Method( + m => m.IdleStateChanged(null, null) + ).WithAnyArguments(); // Since the progress is already at 0, these redundant reports are optional - Expect.Between(0, 2).On(mockedSubscriber).Method("ProgressChanged").With( - new Matcher[] { - new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)), - new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f)) - } + mockedSubscriber.Expects.Between(0, 2).Method(m => m.ProgressChanged(null, null)).With( + new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)), + new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f)) ); tracker.Track(test1); @@ -191,11 +191,9 @@ namespace Nuclex.Support.Tracking { // Step 2 { - Expect.Once.On(mockedSubscriber).Method("ProgressChanged").With( - new Matcher[] { - new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)), - new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.25f)) - } + mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With( + new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)), + new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.25f)) ); test1.ChangeProgress(0.5f); @@ -216,27 +214,23 @@ namespace Nuclex.Support.Tracking { [Test] public void TestDelayedRemoval() { using(ProgressTracker tracker = new ProgressTracker()) { - IProgressTrackerSubscriber mockedSubscriber = mockSubscriber(tracker); + Mock mockedSubscriber = mockSubscriber(tracker); TestTransaction test1 = new TestTransaction(); TestTransaction test2 = new TestTransaction(); // Step 1 { - Expect.Once.On(mockedSubscriber). - Method("IdleStateChanged"). - WithAnyArguments(); + mockedSubscriber.Expects.One.Method( + m => m.IdleStateChanged(null, null) + ).WithAnyArguments(); // This is optional. The tracker's progress is currently 0, so there's no need // to send out superfluous progress reports. - Expect.Between(0, 2).On(mockedSubscriber). - Method("ProgressChanged"). - With( - new Matcher[] { - new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)), - new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f)) - } - ); + mockedSubscriber.Expects.Between(0, 2).Method(m => m.ProgressChanged(null, null)).With( + new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)), + new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f)) + ); tracker.Track(test1); tracker.Track(test2); @@ -244,14 +238,10 @@ namespace Nuclex.Support.Tracking { // Step 2 { - Expect.Once.On(mockedSubscriber). - Method("ProgressChanged"). - With( - new Matcher[] { - new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)), - new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.25f)) - } - ); + mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With( + new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)), + new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.25f)) + ); // Total progress should be 0.25 after this call (two transactions, one with // 0% progress and one with 50% progress) @@ -260,14 +250,10 @@ namespace Nuclex.Support.Tracking { // Step 3 { - Expect.Once.On(mockedSubscriber). - Method("ProgressChanged"). - With( - new Matcher[] { - new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)), - new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.75f)) - } - ); + mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With( + new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)), + new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.75f)) + ); // Total progress should be 0.75 after this call (one transaction at 100%, // the other one at 50%). If the second transaction would be removed by the tracker, @@ -277,18 +263,14 @@ namespace Nuclex.Support.Tracking { // Step 4 { - Expect.Once.On(mockedSubscriber). - Method("ProgressChanged"). - With( - new Matcher[] { - new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)), - new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(1.0f)) - } - ); + mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With( + new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)), + new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(1.0f)) + ); - Expect.Once.On(mockedSubscriber). - Method("IdleStateChanged"). - WithAnyArguments(); + mockedSubscriber.Expects.One.Method( + m => m.IdleStateChanged(null, null) + ).WithAnyArguments(); test1.End(); } @@ -304,10 +286,14 @@ namespace Nuclex.Support.Tracking { [Test] public void TestSoleEndedTransaction() { using(ProgressTracker tracker = new ProgressTracker()) { - IProgressTrackerSubscriber mockedSubscriber = mockSubscriber(tracker); + Mock mockedSubscriber = mockSubscriber(tracker); - Expect.Never.On(mockedSubscriber).Method("IdleStateChanged").WithAnyArguments(); - Expect.Never.On(mockedSubscriber).Method("ProgressChanged").WithAnyArguments(); + mockedSubscriber.Expects.No.Method( + m => m.IdleStateChanged(null, null) + ).WithAnyArguments(); + mockedSubscriber.Expects.No.Method( + m => m.ProgressChanged(null, null) + ).WithAnyArguments(); tracker.Track(Transaction.EndedDummy); } @@ -322,56 +308,44 @@ namespace Nuclex.Support.Tracking { [Test] public void TestEndedTransaction() { using(ProgressTracker tracker = new ProgressTracker()) { - IProgressTrackerSubscriber mockedSubscriber = mockSubscriber(tracker); + Mock mockedSubscriber = mockSubscriber(tracker); TestTransaction test1 = new TestTransaction(); // Step 1 { - Expect.Once.On(mockedSubscriber). - Method("IdleStateChanged"). - WithAnyArguments(); + mockedSubscriber.Expects.One.Method( + m => m.IdleStateChanged(null, null) + ).WithAnyArguments(); - Expect.Between(0, 1).On(mockedSubscriber). - Method("ProgressChanged"). - With( - new Matcher[] { - new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)), - new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f)) - } - ); + mockedSubscriber.Expects.AtMost(1).Method(m => m.ProgressChanged(null, null)).With( + new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)), + new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f)) + ); tracker.Track(test1); } // Step 2 { - Expect.Once.On(mockedSubscriber). - Method("ProgressChanged"). - With( - new Matcher[] { - new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)), - new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.5f)) - } - ); + mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With( + new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)), + new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.5f)) + ); tracker.Track(Transaction.EndedDummy); } // Step 3 { - Expect.Once.On(mockedSubscriber). - Method("ProgressChanged"). - With( - new Matcher[] { - new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)), - new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(1.0f)) - } - ); + mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With( + new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)), + new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(1.0f)) + ); - Expect.Once.On(mockedSubscriber). - Method("IdleStateChanged"). - WithAnyArguments(); + mockedSubscriber.Expects.One.Method( + m => m.IdleStateChanged(null, null) + ).WithAnyArguments(); test1.End(); } @@ -512,21 +486,21 @@ namespace Nuclex.Support.Tracking { /// Mocks a subscriber for the events of a tracker /// Tracker to mock an event subscriber for /// The mocked event subscriber - private IProgressTrackerSubscriber mockSubscriber(ProgressTracker tracker) { - IProgressTrackerSubscriber mockedSubscriber = - this.mockery.NewMock(); + private Mock mockSubscriber(ProgressTracker tracker) { + Mock mockedSubscriber = + this.mockery.CreateMock(); tracker.AsyncIdleStateChanged += - new EventHandler(mockedSubscriber.IdleStateChanged); + new EventHandler(mockedSubscriber.MockObject.IdleStateChanged); tracker.AsyncProgressChanged += - new EventHandler(mockedSubscriber.ProgressChanged); + new EventHandler(mockedSubscriber.MockObject.ProgressChanged); return mockedSubscriber; } /// Mock object factory - private Mockery mockery; + private MockFactory mockery; } diff --git a/Source/Tracking/Request.Test.cs b/Source/Tracking/Request.Test.cs index ec25558..f97f642 100644 --- a/Source/Tracking/Request.Test.cs +++ b/Source/Tracking/Request.Test.cs @@ -27,7 +27,6 @@ using System.IO; using Nuclex.Support.Scheduling; using NUnit.Framework; -using NMock2; namespace Nuclex.Support.Tracking { diff --git a/Source/Tracking/Transaction.Test.cs b/Source/Tracking/Transaction.Test.cs index dc71d47..abc2f63 100644 --- a/Source/Tracking/Transaction.Test.cs +++ b/Source/Tracking/Transaction.Test.cs @@ -26,7 +26,7 @@ using System.IO; using System.Threading; using NUnit.Framework; -using NMock2; +using NMock; namespace Nuclex.Support.Tracking { @@ -105,7 +105,7 @@ namespace Nuclex.Support.Tracking { /// Initialization routine executed before each test is run [SetUp] public void Setup() { - this.mockery = new Mockery(); + this.mockery = new MockFactory(); } /// @@ -128,10 +128,8 @@ namespace Nuclex.Support.Tracking { public void TestEndedEventAfterSubscription() { TestTransaction test = new TestTransaction(); - ITransactionSubscriber mockedSubscriber = mockSubscriber(test); - Expect.Once.On(mockedSubscriber). - Method("Ended"). - WithAnyArguments(); + Mock mockedSubscriber = mockSubscriber(test); + mockedSubscriber.Expects.One.Method(m => m.Ended(null, null)).WithAnyArguments(); test.End(); @@ -147,14 +145,12 @@ namespace Nuclex.Support.Tracking { TestTransaction test = new TestTransaction(); test.End(); - ITransactionSubscriber mockedSubscriber = - this.mockery.NewMock(); + Mock mockedSubscriber = + this.mockery.CreateMock(); - Expect.Once.On(mockedSubscriber). - Method("Ended"). - WithAnyArguments(); + mockedSubscriber.Expects.One.Method(m => m.Ended(null, null)).WithAnyArguments(); - test.AsyncEnded += new EventHandler(mockedSubscriber.Ended); + test.AsyncEnded += new EventHandler(mockedSubscriber.MockObject.Ended); this.mockery.VerifyAllExpectationsHaveBeenMet(); } @@ -221,10 +217,10 @@ namespace Nuclex.Support.Tracking { TestTransaction monitored = new TestTransaction(); UnsubscribingTransaction test = new UnsubscribingTransaction(monitored); - ITransactionSubscriber mockedSubscriber = mockSubscriber(monitored); + Mock mockedSubscriber = mockSubscriber(monitored); try { - Expect.Once.On(mockedSubscriber).Method("Ended").WithAnyArguments(); + mockedSubscriber.Expects.One.Method(m => m.Ended(null, null)).WithAnyArguments(); monitored.End(); this.mockery.VerifyAllExpectationsHaveBeenMet(); } @@ -236,17 +232,17 @@ namespace Nuclex.Support.Tracking { /// Mocks a subscriber for the events of a transaction /// Transaction to mock an event subscriber for /// The mocked event subscriber - private ITransactionSubscriber mockSubscriber(Transaction transaction) { - ITransactionSubscriber mockedSubscriber = - this.mockery.NewMock(); + private Mock mockSubscriber(Transaction transaction) { + Mock mockedSubscriber = + this.mockery.CreateMock(); - transaction.AsyncEnded += new EventHandler(mockedSubscriber.Ended); + transaction.AsyncEnded += new EventHandler(mockedSubscriber.MockObject.Ended); return mockedSubscriber; } /// Mock object factory - private Mockery mockery; + private MockFactory mockery; } diff --git a/Source/Tracking/TransactionGroup.Test.cs b/Source/Tracking/TransactionGroup.Test.cs index 5a87704..d77a8e9 100644 --- a/Source/Tracking/TransactionGroup.Test.cs +++ b/Source/Tracking/TransactionGroup.Test.cs @@ -26,7 +26,7 @@ using System.Threading; #if UNITTEST using NUnit.Framework; -using NMock2; +using NMock; namespace Nuclex.Support.Tracking { @@ -190,7 +190,7 @@ namespace Nuclex.Support.Tracking { /// Initialization routine executed before each test is run [SetUp] public void Setup() { - this.mockery = new Mockery(); + this.mockery = new MockFactory(); } /// Validates that the transaction group correctly sums the progress @@ -202,16 +202,12 @@ namespace Nuclex.Support.Tracking { new TestTransaction[] { new TestTransaction(), new TestTransaction() } ) ) { - ITransactionGroupSubscriber mockedSubscriber = mockSubscriber(testTransactionGroup); + Mock mockedSubscriber = mockSubscriber(testTransactionGroup); - Expect.Once.On(mockedSubscriber). - Method("ProgressChanged"). - With( - new Matcher[] { - new NMock2.Matchers.TypeMatcher(typeof(TransactionGroup)), - new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.25f)) - } - ); + mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With( + new NMock.Matchers.TypeMatcher(typeof(TransactionGroup)), + new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.25f)) + ); testTransactionGroup.Children[0].Transaction.ChangeProgress(0.5f); @@ -231,27 +227,19 @@ namespace Nuclex.Support.Tracking { } ) ) { - ITransactionGroupSubscriber mockedSubscriber = mockSubscriber(testTransactionGroup); + Mock mockedSubscriber = mockSubscriber(testTransactionGroup); - Expect.Once.On(mockedSubscriber). - Method("ProgressChanged"). - With( - new Matcher[] { - new NMock2.Matchers.TypeMatcher(typeof(TransactionGroup)), - new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.5f / 3.0f)) - } - ); + mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With( + new NMock.Matchers.TypeMatcher(typeof(TransactionGroup)), + 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)), - new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.5f)) - } - ); + mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With( + new NMock.Matchers.TypeMatcher(typeof(TransactionGroup)), + new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.5f)) + ); testTransactionGroup.Children[1].Transaction.ChangeProgress(0.5f); @@ -271,15 +259,15 @@ namespace Nuclex.Support.Tracking { new TestTransaction[] { new TestTransaction(), new TestTransaction() } ) ) { - ITransactionGroupSubscriber mockedSubscriber = mockSubscriber(testTransactionGroup); + Mock mockedSubscriber = mockSubscriber(testTransactionGroup); - Expect.Exactly(2).On(mockedSubscriber). - Method("ProgressChanged"). - WithAnyArguments(); + mockedSubscriber.Expects.Exactly(2).Method( + m => m.ProgressChanged(null, null) + ).WithAnyArguments(); - Expect.Once.On(mockedSubscriber). - Method("Ended"). - WithAnyArguments(); + mockedSubscriber.Expects.One.Method( + m => m.Ended(null, null) + ).WithAnyArguments(); testTransactionGroup.Children[0].Transaction.End(); testTransactionGroup.Children[1].Transaction.End(); @@ -300,15 +288,16 @@ namespace Nuclex.Support.Tracking { new TestTransaction[] { new TestTransaction() } ) ) { - ITransactionGroupSubscriber mockedSubscriber = mockSubscriber(testTransactionGroup); + Mock mockedSubscriber = mockSubscriber(testTransactionGroup); - Expect.Once.On(mockedSubscriber). - Method("ProgressChanged"). - WithAnyArguments(); + mockedSubscriber.Expects.One.Method( + m => m.ProgressChanged(null, null) + ).WithAnyArguments(); + + mockedSubscriber.Expects.One.Method( + m => m.Ended(null, null) + ).WithAnyArguments(); - Expect.Once.On(mockedSubscriber). - Method("Ended"). - WithAnyArguments(); testTransactionGroup.Children[0].Transaction.End(); @@ -376,19 +365,19 @@ namespace Nuclex.Support.Tracking { /// Mocks a subscriber for the events of a transaction /// Transaction to mock an event subscriber for /// The mocked event subscriber - private ITransactionGroupSubscriber mockSubscriber(Transaction transaction) { - ITransactionGroupSubscriber mockedSubscriber = - this.mockery.NewMock(); + private Mock mockSubscriber(Transaction transaction) { + Mock mockedSubscriber = + this.mockery.CreateMock(); - transaction.AsyncEnded += new EventHandler(mockedSubscriber.Ended); + transaction.AsyncEnded += new EventHandler(mockedSubscriber.MockObject.Ended); (transaction as IProgressReporter).AsyncProgressChanged += - new EventHandler(mockedSubscriber.ProgressChanged); + new EventHandler(mockedSubscriber.MockObject.ProgressChanged); return mockedSubscriber; } /// Mock object factory - private Mockery mockery; + private MockFactory mockery; }