Upgraded unit tests to NMock 3.0

git-svn-id: file:///srv/devel/repo-conversion/nusu@214 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2011-03-08 20:36:43 +00:00
parent da61476a80
commit aa5e4d12cc
24 changed files with 284 additions and 320 deletions

View File

@ -40,8 +40,8 @@
<AssemblyOriginatorKeyFile>..\Foundation.snk</AssemblyOriginatorKeyFile> <AssemblyOriginatorKeyFile>..\Foundation.snk</AssemblyOriginatorKeyFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="NMock2"> <Reference Include="NMock.StrongNamed">
<HintPath>..\References\nmock\net-4.0\NMock2.dll</HintPath> <HintPath>..\References\nmock\net-4.0\NMock.StrongNamed.dll</HintPath>
</Reference> </Reference>
<Reference Include="nunit.framework, Version=2.5.5.10112, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> <Reference Include="nunit.framework, Version=2.5.5.10112, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>

View File

@ -25,7 +25,6 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using NUnit.Framework; using NUnit.Framework;
using NMock2;
namespace Nuclex.Support.Collections { namespace Nuclex.Support.Collections {

View File

@ -24,7 +24,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using NUnit.Framework; using NUnit.Framework;
using NMock2;
namespace Nuclex.Support.Collections { namespace Nuclex.Support.Collections {

View File

@ -24,7 +24,7 @@ using System.Collections.Generic;
#if UNITTEST #if UNITTEST
using NUnit.Framework; using NUnit.Framework;
using NMock2; using NMock;
namespace Nuclex.Support.Collections { namespace Nuclex.Support.Collections {
@ -64,30 +64,30 @@ namespace Nuclex.Support.Collections {
/// <summary>Initialization routine executed before each test is run</summary> /// <summary>Initialization routine executed before each test is run</summary>
[SetUp] [SetUp]
public void Setup() { public void Setup() {
this.mockery = new Mockery(); this.mockery = new MockFactory();
this.mockedSubscriber = this.mockery.NewMock<IObservableCollectionSubscriber>(); this.mockedSubscriber = this.mockery.CreateMock<IObservableCollectionSubscriber>();
this.observedCollection = new ObservableCollection<int>(); this.observedCollection = new ObservableCollection<int>();
this.observedCollection.Clearing += this.observedCollection.Clearing += new EventHandler(
new EventHandler(this.mockedSubscriber.Clearing); this.mockedSubscriber.MockObject.Clearing
this.observedCollection.Cleared +=
new EventHandler(this.mockedSubscriber.Cleared);
this.observedCollection.ItemAdded +=
new EventHandler<ItemEventArgs<int>>(
this.mockedSubscriber.ItemAdded
); );
this.observedCollection.ItemRemoved += this.observedCollection.Cleared += new EventHandler(
new EventHandler<ItemEventArgs<int>>( this.mockedSubscriber.MockObject.Cleared
this.mockedSubscriber.ItemRemoved );
this.observedCollection.ItemAdded += new EventHandler<ItemEventArgs<int>>(
this.mockedSubscriber.MockObject.ItemAdded
);
this.observedCollection.ItemRemoved += new EventHandler<ItemEventArgs<int>>(
this.mockedSubscriber.MockObject.ItemRemoved
); );
} }
/// <summary>Tests whether the Clearing event is fired</summary> /// <summary>Tests whether the Clearing event is fired</summary>
[Test] [Test]
public void TestClearingEvent() { public void TestClearingEvent() {
Expect.Once.On(this.mockedSubscriber).Method("Clearing").WithAnyArguments(); this.mockedSubscriber.Expects.One.Method(m => m.Clearing(null, null)).WithAnyArguments();
Expect.Once.On(this.mockedSubscriber).Method("Cleared").WithAnyArguments(); this.mockedSubscriber.Expects.One.Method(m => m.Cleared(null, null)).WithAnyArguments();
this.observedCollection.Clear(); this.observedCollection.Clear();
this.mockery.VerifyAllExpectationsHaveBeenMet(); this.mockery.VerifyAllExpectationsHaveBeenMet();
@ -96,7 +96,7 @@ namespace Nuclex.Support.Collections {
/// <summary>Tests whether the ItemAdded event is fired</summary> /// <summary>Tests whether the ItemAdded event is fired</summary>
[Test] [Test]
public void TestItemAddedEvent() { 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); this.observedCollection.Add(123);
@ -106,11 +106,11 @@ namespace Nuclex.Support.Collections {
/// <summary>Tests whether the ItemRemoved event is fired</summary> /// <summary>Tests whether the ItemRemoved event is fired</summary>
[Test] [Test]
public void TestItemRemovedEvent() { 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); 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); this.observedCollection.Remove(123);
@ -120,14 +120,16 @@ namespace Nuclex.Support.Collections {
/// <summary>Tests whether items in the collection can be replaced</summary> /// <summary>Tests whether items in the collection can be replaced</summary>
[Test] [Test]
public void TestItemReplacement() { 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(1);
this.observedCollection.Add(2); this.observedCollection.Add(2);
this.observedCollection.Add(3); this.observedCollection.Add(3);
Expect.Once.On(this.mockedSubscriber).Method("ItemRemoved").WithAnyArguments(); this.mockedSubscriber.Expects.One.Method(m => m.ItemRemoved(null, null)).WithAnyArguments();
Expect.Once.On(this.mockedSubscriber).Method("ItemAdded").WithAnyArguments(); this.mockedSubscriber.Expects.One.Method(m => m.ItemAdded(null, null)).WithAnyArguments();
// Replace the middle item with something else // Replace the middle item with something else
this.observedCollection[1] = 4; this.observedCollection[1] = 4;
@ -150,9 +152,9 @@ namespace Nuclex.Support.Collections {
} }
/// <summary>Mock object factory</summary> /// <summary>Mock object factory</summary>
private Mockery mockery; private MockFactory mockery;
/// <summary>The mocked observable collection subscriber</summary> /// <summary>The mocked observable collection subscriber</summary>
private IObservableCollectionSubscriber mockedSubscriber; private Mock<IObservableCollectionSubscriber> mockedSubscriber;
/// <summary>An observable collection to which a mock will be subscribed</summary> /// <summary>An observable collection to which a mock will be subscribed</summary>
private ObservableCollection<int> observedCollection; private ObservableCollection<int> observedCollection;

View File

@ -27,7 +27,7 @@ using System.IO;
using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization.Formatters.Binary;
using NUnit.Framework; using NUnit.Framework;
using NMock2; using NMock;
namespace Nuclex.Support.Collections { namespace Nuclex.Support.Collections {
@ -67,9 +67,9 @@ namespace Nuclex.Support.Collections {
/// <summary>Initialization routine executed before each test is run</summary> /// <summary>Initialization routine executed before each test is run</summary>
[SetUp] [SetUp]
public void Setup() { public void Setup() {
this.mockery = new Mockery(); this.mockery = new MockFactory();
this.mockedSubscriber = this.mockery.NewMock<IObservableDictionarySubscriber>(); this.mockedSubscriber = this.mockery.CreateMock<IObservableDictionarySubscriber>();
this.observedDictionary = new ObservableDictionary<int, string>(); this.observedDictionary = new ObservableDictionary<int, string>();
this.observedDictionary.Add(1, "one"); this.observedDictionary.Add(1, "one");
@ -78,16 +78,16 @@ namespace Nuclex.Support.Collections {
this.observedDictionary.Add(42, "forty-two"); this.observedDictionary.Add(42, "forty-two");
this.observedDictionary.Clearing += this.observedDictionary.Clearing +=
new EventHandler(this.mockedSubscriber.Clearing); new EventHandler(this.mockedSubscriber.MockObject.Clearing);
this.observedDictionary.Cleared += this.observedDictionary.Cleared +=
new EventHandler(this.mockedSubscriber.Cleared); new EventHandler(this.mockedSubscriber.MockObject.Cleared);
this.observedDictionary.ItemAdded += this.observedDictionary.ItemAdded +=
new EventHandler<ItemEventArgs<KeyValuePair<int, string>>>( new EventHandler<ItemEventArgs<KeyValuePair<int, string>>>(
this.mockedSubscriber.ItemAdded this.mockedSubscriber.MockObject.ItemAdded
); );
this.observedDictionary.ItemRemoved += this.observedDictionary.ItemRemoved +=
new EventHandler<ItemEventArgs<KeyValuePair<int, string>>>( new EventHandler<ItemEventArgs<KeyValuePair<int, string>>>(
this.mockedSubscriber.ItemRemoved this.mockedSubscriber.MockObject.ItemRemoved
); );
} }
@ -249,7 +249,7 @@ namespace Nuclex.Support.Collections {
/// </summary> /// </summary>
[Test] [Test]
public void TestAddViaGenericIDictionary() { 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<int, string>).Add(10, "ten"); (this.observedDictionary as IDictionary<int, string>).Add(10, "ten");
this.mockery.VerifyAllExpectationsHaveBeenMet(); this.mockery.VerifyAllExpectationsHaveBeenMet();
@ -264,7 +264,7 @@ namespace Nuclex.Support.Collections {
/// </summary> /// </summary>
[Test] [Test]
public void TestRemoveViaGenericIDictionary() { 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<int, string>).Remove(3); (this.observedDictionary as IDictionary<int, string>).Remove(3);
this.mockery.VerifyAllExpectationsHaveBeenMet(); this.mockery.VerifyAllExpectationsHaveBeenMet();
@ -287,8 +287,12 @@ namespace Nuclex.Support.Collections {
/// </summary> /// </summary>
[Test] [Test]
public void TestReplaceByIndexerViaGenericIDictionary() { public void TestReplaceByIndexerViaGenericIDictionary() {
Expect.Once.On(this.mockedSubscriber).Method("ItemRemoved").WithAnyArguments(); this.mockedSubscriber.Expects.One.Method(
Expect.Once.On(this.mockedSubscriber).Method("ItemAdded").WithAnyArguments(); m => m.ItemRemoved(null, null)
).WithAnyArguments();
this.mockedSubscriber.Expects.One.Method(
m => m.ItemAdded(null, null)
).WithAnyArguments();
(this.observedDictionary as IDictionary<int, string>)[42] = "two and fourty"; (this.observedDictionary as IDictionary<int, string>)[42] = "two and fourty";
this.mockery.VerifyAllExpectationsHaveBeenMet(); this.mockery.VerifyAllExpectationsHaveBeenMet();
@ -300,8 +304,12 @@ namespace Nuclex.Support.Collections {
/// </summary> /// </summary>
[Test] [Test]
public void TestClearViaIDictionary() { public void TestClearViaIDictionary() {
Expect.Once.On(this.mockedSubscriber).Method("Clearing").WithAnyArguments(); this.mockedSubscriber.Expects.One.Method(
Expect.Once.On(this.mockedSubscriber).Method("Cleared").WithAnyArguments(); m => m.Clearing(null, null)
).WithAnyArguments();
this.mockedSubscriber.Expects.One.Method(
m => m.Cleared(null, null)
).WithAnyArguments();
(this.observedDictionary as IDictionary).Clear(); (this.observedDictionary as IDictionary).Clear();
this.mockery.VerifyAllExpectationsHaveBeenMet(); this.mockery.VerifyAllExpectationsHaveBeenMet();
@ -313,7 +321,9 @@ namespace Nuclex.Support.Collections {
/// </summary> /// </summary>
[Test] [Test]
public void TestAddViaIDictionary() { 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.observedDictionary as IDictionary).Add(24, "twenty-four");
this.mockery.VerifyAllExpectationsHaveBeenMet(); this.mockery.VerifyAllExpectationsHaveBeenMet();
@ -380,7 +390,7 @@ namespace Nuclex.Support.Collections {
/// </summary> /// </summary>
[Test] [Test]
public void TestRemoveViaIDictionary() { 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.observedDictionary as IDictionary).Remove(3);
this.mockery.VerifyAllExpectationsHaveBeenMet(); this.mockery.VerifyAllExpectationsHaveBeenMet();
@ -401,8 +411,13 @@ namespace Nuclex.Support.Collections {
/// </summary> /// </summary>
[Test] [Test]
public void TestReplaceByIndexerViaIDictionary() { public void TestReplaceByIndexerViaIDictionary() {
Expect.Once.On(this.mockedSubscriber).Method("ItemRemoved").WithAnyArguments(); this.mockedSubscriber.Expects.One.Method(
Expect.Once.On(this.mockedSubscriber).Method("ItemAdded").WithAnyArguments(); 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.observedDictionary as IDictionary)[42] = "two and fourty";
this.mockery.VerifyAllExpectationsHaveBeenMet(); this.mockery.VerifyAllExpectationsHaveBeenMet();
@ -415,7 +430,10 @@ namespace Nuclex.Support.Collections {
/// </summary> /// </summary>
[Test] [Test]
public void TestAddViaGenericICollection() { 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<KeyValuePair<int, string>>).Add( (this.observedDictionary as ICollection<KeyValuePair<int, string>>).Add(
new KeyValuePair<int, string>(24, "twenty-four") new KeyValuePair<int, string>(24, "twenty-four")
); );
@ -432,8 +450,13 @@ namespace Nuclex.Support.Collections {
/// </summary> /// </summary>
[Test] [Test]
public void TestClearViaGenericICollection() { public void TestClearViaGenericICollection() {
Expect.Once.On(this.mockedSubscriber).Method("Clearing").WithAnyArguments(); this.mockedSubscriber.Expects.One.Method(
Expect.Once.On(this.mockedSubscriber).Method("Cleared").WithAnyArguments(); m => m.Clearing(null, null)
).WithAnyArguments();
this.mockedSubscriber.Expects.One.Method(
m => m.Cleared(null, null)
).WithAnyArguments();
(this.observedDictionary as ICollection<KeyValuePair<int, string>>).Clear(); (this.observedDictionary as ICollection<KeyValuePair<int, string>>).Clear();
this.mockery.VerifyAllExpectationsHaveBeenMet(); this.mockery.VerifyAllExpectationsHaveBeenMet();
@ -449,7 +472,11 @@ namespace Nuclex.Support.Collections {
IEnumerator<KeyValuePair<int, string>> enumerator = IEnumerator<KeyValuePair<int, string>> enumerator =
(this.observedDictionary as ICollection<KeyValuePair<int, string>>).GetEnumerator(); (this.observedDictionary as ICollection<KeyValuePair<int, string>>).GetEnumerator();
enumerator.MoveNext(); 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<KeyValuePair<int, string>>).Remove( (this.observedDictionary as ICollection<KeyValuePair<int, string>>).Remove(
enumerator.Current enumerator.Current
); );
@ -537,9 +564,9 @@ namespace Nuclex.Support.Collections {
} }
/// <summary>Mock object factory</summary> /// <summary>Mock object factory</summary>
private Mockery mockery; private MockFactory mockery;
/// <summary>The mocked observable collection subscriber</summary> /// <summary>The mocked observable collection subscriber</summary>
private IObservableDictionarySubscriber mockedSubscriber; private Mock<IObservableDictionarySubscriber> mockedSubscriber;
/// <summary>An observable dictionary to which a mock will be subscribed</summary> /// <summary>An observable dictionary to which a mock will be subscribed</summary>
private ObservableDictionary<int, string> observedDictionary; private ObservableDictionary<int, string> observedDictionary;

View File

@ -24,7 +24,6 @@ using System.Collections.Generic;
#if UNITTEST #if UNITTEST
using NUnit.Framework; using NUnit.Framework;
using NMock2;
namespace Nuclex.Support.Collections { namespace Nuclex.Support.Collections {

View File

@ -24,7 +24,6 @@ using System.Collections.Generic;
#if UNITTEST #if UNITTEST
using NUnit.Framework; using NUnit.Framework;
using NMock2;
namespace Nuclex.Support.Collections { namespace Nuclex.Support.Collections {

View File

@ -24,7 +24,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using NUnit.Framework; using NUnit.Framework;
using NMock2;
namespace Nuclex.Support.Collections { namespace Nuclex.Support.Collections {

View File

@ -24,7 +24,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using NUnit.Framework; using NUnit.Framework;
using NMock2;
namespace Nuclex.Support.Collections { namespace Nuclex.Support.Collections {

View File

@ -24,7 +24,6 @@ using System.Collections.Generic;
#if UNITTEST #if UNITTEST
using NUnit.Framework; using NUnit.Framework;
using NMock2;
namespace Nuclex.Support.Collections { namespace Nuclex.Support.Collections {

View File

@ -25,7 +25,7 @@ using System.Collections.Generic;
#if UNITTEST #if UNITTEST
using NUnit.Framework; using NUnit.Framework;
using NMock2; using NMock;
namespace Nuclex.Support.Collections { namespace Nuclex.Support.Collections {
@ -477,13 +477,13 @@ namespace Nuclex.Support.Collections {
/// </summary> /// </summary>
[Test] [Test]
public void TestSynchronizationOfIListWithoutICollection() { public void TestSynchronizationOfIListWithoutICollection() {
Mockery mockery = new Mockery(); MockFactory mockery = new MockFactory();
IList<int> mockedIList = mockery.NewMock<IList<int>>(); Mock<IList<int>> mockedIList = mockery.CreateMock<IList<int>>();
StringTransformer testCollection = new StringTransformer(mockedIList); StringTransformer testCollection = new StringTransformer(mockedIList.MockObject);
if(!(testCollection as ICollection).IsSynchronized) { if(!(testCollection as ICollection).IsSynchronized) {
lock((testCollection as ICollection).SyncRoot) { 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; int count = testCollection.Count;
Assert.AreEqual(12345, count); // ;-) Assert.AreEqual(12345, count); // ;-)
} }

View File

@ -25,7 +25,6 @@ using System.Collections.Generic;
#if UNITTEST #if UNITTEST
using NUnit.Framework; using NUnit.Framework;
using NMock2;
namespace Nuclex.Support.Collections { namespace Nuclex.Support.Collections {
@ -76,6 +75,35 @@ namespace Nuclex.Support.Collections {
#endregion // class Dummy #endregion // class Dummy
#region class ListWithoutICollection
private class ListWithoutICollection : IList<WeakReference<Dummy>> {
public int IndexOf(WeakReference<Dummy> item) { throw new NotImplementedException(); }
public void Insert(int index, WeakReference<Dummy> item) {
throw new NotImplementedException();
}
public void RemoveAt(int index) { throw new NotImplementedException(); }
public WeakReference<Dummy> this[int index] {
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
public void Add(WeakReference<Dummy> item) { throw new NotImplementedException(); }
public void Clear() { throw new NotImplementedException(); }
public bool Contains(WeakReference<Dummy> item) { throw new NotImplementedException(); }
public void CopyTo(WeakReference<Dummy>[] array, int arrayIndex) {
throw new NotImplementedException();
}
public int Count { get { return 12345; } }
public bool IsReadOnly { get { throw new NotImplementedException(); } }
public bool Remove(WeakReference<Dummy> item) { throw new NotImplementedException(); }
public IEnumerator<WeakReference<Dummy>> GetEnumerator() {
throw new NotImplementedException();
}
IEnumerator IEnumerable.GetEnumerator() { throw new NotImplementedException(); }
}
#endregion // class ListWithoutICollection
/// <summary>Verifies that the constructor of the weak collection is working</summary> /// <summary>Verifies that the constructor of the weak collection is working</summary>
[Test] [Test]
public void TestConstructor() { public void TestConstructor() {
@ -592,31 +620,6 @@ namespace Nuclex.Support.Collections {
} }
} }
private class ListWithoutICollection : IList<WeakReference<Dummy>> {
public int IndexOf(WeakReference<Dummy> item) { throw new NotImplementedException(); }
public void Insert(int index, WeakReference<Dummy> item) {
throw new NotImplementedException();
}
public void RemoveAt(int index) { throw new NotImplementedException(); }
public WeakReference<Dummy> this[int index] {
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
public void Add(WeakReference<Dummy> item) { throw new NotImplementedException(); }
public void Clear() { throw new NotImplementedException(); }
public bool Contains(WeakReference<Dummy> item) { throw new NotImplementedException(); }
public void CopyTo(WeakReference<Dummy>[] array, int arrayIndex) {
throw new NotImplementedException();
}
public int Count { get { return 12345; } }
public bool IsReadOnly { get { throw new NotImplementedException(); } }
public bool Remove(WeakReference<Dummy> item) { throw new NotImplementedException(); }
public IEnumerator<WeakReference<Dummy>> GetEnumerator() {
throw new NotImplementedException();
}
IEnumerator IEnumerable.GetEnumerator() { throw new NotImplementedException(); }
}
/// <summary> /// <summary>
/// Verifies that the IsSynchronized property and the SyncRoot property are working /// Verifies that the IsSynchronized property and the SyncRoot property are working
/// on transforming read only collections based on IList&lt;&gt;s that do not /// on transforming read only collections based on IList&lt;&gt;s that do not

View File

@ -26,7 +26,7 @@ using System.Reflection;
#if UNITTEST #if UNITTEST
using NUnit.Framework; using NUnit.Framework;
using NMock2; using NMock;
namespace Nuclex.Support.Plugins { namespace Nuclex.Support.Plugins {
@ -141,12 +141,12 @@ namespace Nuclex.Support.Plugins {
/// </summary> /// </summary>
[Test] [Test]
public void TestAssemblyLoadedEvent() { public void TestAssemblyLoadedEvent() {
Mockery mockery = new Mockery(); MockFactory mockery = new MockFactory();
PluginRepository testRepository = new PluginRepository(); PluginRepository testRepository = new PluginRepository();
IAssemblyLoadedSubscriber subscriber = mockSubscriber(mockery, testRepository); Mock<IAssemblyLoadedSubscriber> 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()); Assembly self = Assembly.GetAssembly(GetType());
testRepository.AddAssembly(self); testRepository.AddAssembly(self);
@ -202,14 +202,14 @@ namespace Nuclex.Support.Plugins {
/// <param name="mockery">Mockery to create an event subscriber in</param> /// <param name="mockery">Mockery to create an event subscriber in</param>
/// <param name="repository">Repository to subscribe the mocked subscriber to</param> /// <param name="repository">Repository to subscribe the mocked subscriber to</param>
/// <returns>The mocked event subscriber</returns> /// <returns>The mocked event subscriber</returns>
private static IAssemblyLoadedSubscriber mockSubscriber( private static Mock<IAssemblyLoadedSubscriber> mockSubscriber(
Mockery mockery, PluginRepository repository MockFactory mockery, PluginRepository repository
) { ) {
IAssemblyLoadedSubscriber mockedSubscriber = Mock<IAssemblyLoadedSubscriber> mockedSubscriber =
mockery.NewMock<IAssemblyLoadedSubscriber>(); mockery.CreateMock<IAssemblyLoadedSubscriber>();
repository.AssemblyLoaded += new AssemblyLoadEventHandler( repository.AssemblyLoaded += new AssemblyLoadEventHandler(
mockedSubscriber.AssemblyLoaded mockedSubscriber.MockObject.AssemblyLoaded
); );
return mockedSubscriber; return mockedSubscriber;

View File

@ -26,7 +26,6 @@ using System.IO;
using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization.Formatters.Binary;
using NUnit.Framework; using NUnit.Framework;
using NMock2;
namespace Nuclex.Support.Scheduling { namespace Nuclex.Support.Scheduling {
@ -58,7 +57,6 @@ namespace Nuclex.Support.Scheduling {
Assert.AreSame(inner, testException.InnerException); Assert.AreSame(inner, testException.InnerException);
} }
/// <summary> /// <summary>
/// Test whether the exception can be serialized /// Test whether the exception can be serialized
/// </summary> /// </summary>

View File

@ -25,9 +25,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization.Formatters.Binary;
using NUnit.Framework; using NUnit.Framework;
using NMock2;
namespace Nuclex.Support.Scheduling { namespace Nuclex.Support.Scheduling {

View File

@ -25,7 +25,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using NUnit.Framework; using NUnit.Framework;
using NMock2; using NMock;
using Nuclex.Support.Tracking; using Nuclex.Support.Tracking;
@ -166,7 +166,7 @@ namespace Nuclex.Support.Scheduling {
/// <summary>Initialization routine executed before each test is run</summary> /// <summary>Initialization routine executed before each test is run</summary>
[SetUp] [SetUp]
public void Setup() { public void Setup() {
this.mockery = new Mockery(); this.mockery = new MockFactory();
} }
/// <summary>Validates that the queue executes operations sequentially</summary> /// <summary>Validates that the queue executes operations sequentially</summary>
@ -180,26 +180,22 @@ namespace Nuclex.Support.Scheduling {
new TestOperation[] { operation1, operation2 } new TestOperation[] { operation1, operation2 }
); );
IOperationQueueSubscriber mockedSubscriber = mockSubscriber(testQueueOperation); Mock<IOperationQueueSubscriber> mockedSubscriber = mockSubscriber(testQueueOperation);
testQueueOperation.Start(); testQueueOperation.Start();
Expect.Once.On(mockedSubscriber). mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With(
Method("ProgressChanged").
With(
new Matcher[] { new Matcher[] {
new NMock2.Matchers.TypeMatcher(typeof(OperationQueue<TestOperation>)), new NMock.Matchers.TypeMatcher(typeof(OperationQueue<TestOperation>)),
new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.25f)) new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.25f))
} }
); );
operation1.ChangeProgress(0.5f); operation1.ChangeProgress(0.5f);
Expect.Once.On(mockedSubscriber). mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With(
Method("ProgressChanged").
With(
new Matcher[] { new Matcher[] {
new NMock2.Matchers.TypeMatcher(typeof(OperationQueue<TestOperation>)), new NMock.Matchers.TypeMatcher(typeof(OperationQueue<TestOperation>)),
new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.5f)) new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.5f))
} }
); );
@ -226,28 +222,20 @@ namespace Nuclex.Support.Scheduling {
} }
); );
IOperationQueueSubscriber mockedSubscriber = mockSubscriber(testQueueOperation); Mock<IOperationQueueSubscriber> mockedSubscriber = mockSubscriber(testQueueOperation);
testQueueOperation.Start(); testQueueOperation.Start();
Expect.Once.On(mockedSubscriber). mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With(
Method("ProgressChanged"). new NMock.Matchers.TypeMatcher(typeof(OperationQueue<TestOperation>)),
With(
new Matcher[] {
new NMock2.Matchers.TypeMatcher(typeof(OperationQueue<TestOperation>)),
new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.1f)) new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.1f))
}
); );
operation1.ChangeProgress(0.5f); operation1.ChangeProgress(0.5f);
Expect.Once.On(mockedSubscriber). mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With(
Method("ProgressChanged"). new NMock.Matchers.TypeMatcher(typeof(OperationQueue<TestOperation>)),
With(
new Matcher[] {
new NMock2.Matchers.TypeMatcher(typeof(OperationQueue<TestOperation>)),
new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.2f)) new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.2f))
}
); );
operation1.SetEnded(); operation1.SetEnded();
@ -341,19 +329,19 @@ namespace Nuclex.Support.Scheduling {
/// <summary>Mocks a subscriber for the events of an operation</summary> /// <summary>Mocks a subscriber for the events of an operation</summary>
/// <param name="operation">Operation to mock an event subscriber for</param> /// <param name="operation">Operation to mock an event subscriber for</param>
/// <returns>The mocked event subscriber</returns> /// <returns>The mocked event subscriber</returns>
private IOperationQueueSubscriber mockSubscriber(Operation operation) { private Mock<IOperationQueueSubscriber> mockSubscriber(Operation operation) {
IOperationQueueSubscriber mockedSubscriber = Mock<IOperationQueueSubscriber> mockedSubscriber =
this.mockery.NewMock<IOperationQueueSubscriber>(); this.mockery.CreateMock<IOperationQueueSubscriber>();
operation.AsyncEnded += new EventHandler(mockedSubscriber.Ended); operation.AsyncEnded += new EventHandler(mockedSubscriber.MockObject.Ended);
(operation as IProgressReporter).AsyncProgressChanged += (operation as IProgressReporter).AsyncProgressChanged +=
new EventHandler<ProgressReportEventArgs>(mockedSubscriber.ProgressChanged); new EventHandler<ProgressReportEventArgs>(mockedSubscriber.MockObject.ProgressChanged);
return mockedSubscriber; return mockedSubscriber;
} }
/// <summary>Mock object factory</summary> /// <summary>Mock object factory</summary>
private Mockery mockery; private MockFactory mockery;
} }

View File

@ -27,7 +27,6 @@ using System.Runtime.Serialization.Formatters.Binary;
using System.Threading; using System.Threading;
using NUnit.Framework; using NUnit.Framework;
using NMock2;
namespace Nuclex.Support.Scheduling { namespace Nuclex.Support.Scheduling {

View File

@ -27,7 +27,6 @@ using System.Runtime.Serialization.Formatters.Binary;
using NUnit.Framework; using NUnit.Framework;
using NMock2;
namespace Nuclex.Support.Scheduling { namespace Nuclex.Support.Scheduling {

View File

@ -25,7 +25,7 @@ using System.Threading;
#if UNITTEST #if UNITTEST
using NUnit.Framework; using NUnit.Framework;
using NMock2; using NMock;
namespace Nuclex.Support.Tracking { namespace Nuclex.Support.Tracking {
@ -85,7 +85,7 @@ namespace Nuclex.Support.Tracking {
/// <summary>Initialization routine executed before each test is run</summary> /// <summary>Initialization routine executed before each test is run</summary>
[SetUp] [SetUp]
public void Setup() { public void Setup() {
this.mockery = new Mockery(); this.mockery = new MockFactory();
} }
/// <summary>Verifies that the constructor of the observation wrapper works</summary> /// <summary>Verifies that the constructor of the observation wrapper works</summary>
@ -95,23 +95,23 @@ namespace Nuclex.Support.Tracking {
Transaction.EndedDummy Transaction.EndedDummy
); );
IObservationSubscriber subscriber = this.mockery.NewMock<IObservationSubscriber>(); Mock<IObservationSubscriber> subscriber = this.mockery.CreateMock<IObservationSubscriber>();
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 // This should no be called because otherwise, the 'Ended' event would be raised
// to the transaction group before all transactions have been added into // to the transaction group before all transactions have been added into
// the internal list, leading to an early ending or even multiple endings. // 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( using(
ObservedWeightedTransaction<Transaction> test = ObservedWeightedTransaction<Transaction> test =
new ObservedWeightedTransaction<Transaction>( new ObservedWeightedTransaction<Transaction>(
testTransaction, testTransaction,
new ObservedWeightedTransaction<Transaction>.ReportDelegate( new ObservedWeightedTransaction<Transaction>.ReportDelegate(
subscriber.ProgressUpdated subscriber.MockObject.ProgressUpdated
), ),
new ObservedWeightedTransaction<Transaction>.ReportDelegate( new ObservedWeightedTransaction<Transaction>.ReportDelegate(
subscriber.Ended subscriber.MockObject.Ended
) )
) )
) { ) {
@ -129,20 +129,20 @@ namespace Nuclex.Support.Tracking {
new FunkyTransaction() new FunkyTransaction()
); );
IObservationSubscriber subscriber = this.mockery.NewMock<IObservationSubscriber>(); Mock<IObservationSubscriber> subscriber = this.mockery.CreateMock<IObservationSubscriber>();
Expect.AtLeast(0).On(subscriber).Method("ProgressUpdated"); subscriber.Expects.AtLeast(0).Method(m => m.ProgressUpdated());
Expect.Once.On(subscriber).Method("Ended"); subscriber.Expects.One.Method(m => m.Ended());
using( using(
ObservedWeightedTransaction<Transaction> test = ObservedWeightedTransaction<Transaction> test =
new ObservedWeightedTransaction<Transaction>( new ObservedWeightedTransaction<Transaction>(
testTransaction, testTransaction,
new ObservedWeightedTransaction<Transaction>.ReportDelegate( new ObservedWeightedTransaction<Transaction>.ReportDelegate(
subscriber.ProgressUpdated subscriber.MockObject.ProgressUpdated
), ),
new ObservedWeightedTransaction<Transaction>.ReportDelegate( new ObservedWeightedTransaction<Transaction>.ReportDelegate(
subscriber.Ended subscriber.MockObject.Ended
) )
) )
) { ) {
@ -151,7 +151,7 @@ namespace Nuclex.Support.Tracking {
} }
/// <summary>Mock object factory</summary> /// <summary>Mock object factory</summary>
private Mockery mockery; private MockFactory mockery;
} }

View File

@ -25,7 +25,6 @@ using System.Threading;
#if UNITTEST #if UNITTEST
using NUnit.Framework; using NUnit.Framework;
using NMock2;
namespace Nuclex.Support.Tracking { namespace Nuclex.Support.Tracking {

View File

@ -25,7 +25,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using NUnit.Framework; using NUnit.Framework;
using NMock2; using NMock;
namespace Nuclex.Support.Tracking { namespace Nuclex.Support.Tracking {
@ -161,28 +161,28 @@ namespace Nuclex.Support.Tracking {
/// <summary>Initialization routine executed before each test is run</summary> /// <summary>Initialization routine executed before each test is run</summary>
[SetUp] [SetUp]
public void Setup() { public void Setup() {
this.mockery = new Mockery(); this.mockery = new MockFactory();
} }
/// <summary>Validates that the tracker properly sums the progress</summary> /// <summary>Validates that the tracker properly sums the progress</summary>
[Test] [Test]
public void TestSummedProgress() { public void TestSummedProgress() {
using(ProgressTracker tracker = new ProgressTracker()) { using(ProgressTracker tracker = new ProgressTracker()) {
IProgressTrackerSubscriber mockedSubscriber = mockSubscriber(tracker); Mock<IProgressTrackerSubscriber> mockedSubscriber = mockSubscriber(tracker);
TestTransaction test1 = new TestTransaction(); TestTransaction test1 = new TestTransaction();
TestTransaction test2 = new TestTransaction(); TestTransaction test2 = new TestTransaction();
// Step 1 // 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 // Since the progress is already at 0, these redundant reports are optional
Expect.Between(0, 2).On(mockedSubscriber).Method("ProgressChanged").With( mockedSubscriber.Expects.Between(0, 2).Method(m => m.ProgressChanged(null, null)).With(
new Matcher[] { new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)),
new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)),
new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f)) new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f))
}
); );
tracker.Track(test1); tracker.Track(test1);
@ -191,11 +191,9 @@ namespace Nuclex.Support.Tracking {
// Step 2 // Step 2
{ {
Expect.Once.On(mockedSubscriber).Method("ProgressChanged").With( mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With(
new Matcher[] { new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)),
new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)),
new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.25f)) new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.25f))
}
); );
test1.ChangeProgress(0.5f); test1.ChangeProgress(0.5f);
@ -216,26 +214,22 @@ namespace Nuclex.Support.Tracking {
[Test] [Test]
public void TestDelayedRemoval() { public void TestDelayedRemoval() {
using(ProgressTracker tracker = new ProgressTracker()) { using(ProgressTracker tracker = new ProgressTracker()) {
IProgressTrackerSubscriber mockedSubscriber = mockSubscriber(tracker); Mock<IProgressTrackerSubscriber> mockedSubscriber = mockSubscriber(tracker);
TestTransaction test1 = new TestTransaction(); TestTransaction test1 = new TestTransaction();
TestTransaction test2 = new TestTransaction(); TestTransaction test2 = new TestTransaction();
// Step 1 // Step 1
{ {
Expect.Once.On(mockedSubscriber). mockedSubscriber.Expects.One.Method(
Method("IdleStateChanged"). m => m.IdleStateChanged(null, null)
WithAnyArguments(); ).WithAnyArguments();
// This is optional. The tracker's progress is currently 0, so there's no need // This is optional. The tracker's progress is currently 0, so there's no need
// to send out superfluous progress reports. // to send out superfluous progress reports.
Expect.Between(0, 2).On(mockedSubscriber). mockedSubscriber.Expects.Between(0, 2).Method(m => m.ProgressChanged(null, null)).With(
Method("ProgressChanged"). new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)),
With(
new Matcher[] {
new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)),
new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f)) new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f))
}
); );
tracker.Track(test1); tracker.Track(test1);
@ -244,13 +238,9 @@ namespace Nuclex.Support.Tracking {
// Step 2 // Step 2
{ {
Expect.Once.On(mockedSubscriber). mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With(
Method("ProgressChanged"). new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)),
With(
new Matcher[] {
new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)),
new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.25f)) new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.25f))
}
); );
// Total progress should be 0.25 after this call (two transactions, one with // Total progress should be 0.25 after this call (two transactions, one with
@ -260,13 +250,9 @@ namespace Nuclex.Support.Tracking {
// Step 3 // Step 3
{ {
Expect.Once.On(mockedSubscriber). mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With(
Method("ProgressChanged"). new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)),
With(
new Matcher[] {
new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)),
new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.75f)) new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.75f))
}
); );
// Total progress should be 0.75 after this call (one transaction at 100%, // Total progress should be 0.75 after this call (one transaction at 100%,
@ -277,18 +263,14 @@ namespace Nuclex.Support.Tracking {
// Step 4 // Step 4
{ {
Expect.Once.On(mockedSubscriber). mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With(
Method("ProgressChanged"). new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)),
With(
new Matcher[] {
new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)),
new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(1.0f)) new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(1.0f))
}
); );
Expect.Once.On(mockedSubscriber). mockedSubscriber.Expects.One.Method(
Method("IdleStateChanged"). m => m.IdleStateChanged(null, null)
WithAnyArguments(); ).WithAnyArguments();
test1.End(); test1.End();
} }
@ -304,10 +286,14 @@ namespace Nuclex.Support.Tracking {
[Test] [Test]
public void TestSoleEndedTransaction() { public void TestSoleEndedTransaction() {
using(ProgressTracker tracker = new ProgressTracker()) { using(ProgressTracker tracker = new ProgressTracker()) {
IProgressTrackerSubscriber mockedSubscriber = mockSubscriber(tracker); Mock<IProgressTrackerSubscriber> mockedSubscriber = mockSubscriber(tracker);
Expect.Never.On(mockedSubscriber).Method("IdleStateChanged").WithAnyArguments(); mockedSubscriber.Expects.No.Method(
Expect.Never.On(mockedSubscriber).Method("ProgressChanged").WithAnyArguments(); m => m.IdleStateChanged(null, null)
).WithAnyArguments();
mockedSubscriber.Expects.No.Method(
m => m.ProgressChanged(null, null)
).WithAnyArguments();
tracker.Track(Transaction.EndedDummy); tracker.Track(Transaction.EndedDummy);
} }
@ -322,23 +308,19 @@ namespace Nuclex.Support.Tracking {
[Test] [Test]
public void TestEndedTransaction() { public void TestEndedTransaction() {
using(ProgressTracker tracker = new ProgressTracker()) { using(ProgressTracker tracker = new ProgressTracker()) {
IProgressTrackerSubscriber mockedSubscriber = mockSubscriber(tracker); Mock<IProgressTrackerSubscriber> mockedSubscriber = mockSubscriber(tracker);
TestTransaction test1 = new TestTransaction(); TestTransaction test1 = new TestTransaction();
// Step 1 // Step 1
{ {
Expect.Once.On(mockedSubscriber). mockedSubscriber.Expects.One.Method(
Method("IdleStateChanged"). m => m.IdleStateChanged(null, null)
WithAnyArguments(); ).WithAnyArguments();
Expect.Between(0, 1).On(mockedSubscriber). mockedSubscriber.Expects.AtMost(1).Method(m => m.ProgressChanged(null, null)).With(
Method("ProgressChanged"). new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)),
With(
new Matcher[] {
new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)),
new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f)) new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f))
}
); );
tracker.Track(test1); tracker.Track(test1);
@ -346,13 +328,9 @@ namespace Nuclex.Support.Tracking {
// Step 2 // Step 2
{ {
Expect.Once.On(mockedSubscriber). mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With(
Method("ProgressChanged"). new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)),
With(
new Matcher[] {
new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)),
new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.5f)) new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.5f))
}
); );
tracker.Track(Transaction.EndedDummy); tracker.Track(Transaction.EndedDummy);
@ -360,18 +338,14 @@ namespace Nuclex.Support.Tracking {
// Step 3 // Step 3
{ {
Expect.Once.On(mockedSubscriber). mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With(
Method("ProgressChanged"). new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)),
With(
new Matcher[] {
new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)),
new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(1.0f)) new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(1.0f))
}
); );
Expect.Once.On(mockedSubscriber). mockedSubscriber.Expects.One.Method(
Method("IdleStateChanged"). m => m.IdleStateChanged(null, null)
WithAnyArguments(); ).WithAnyArguments();
test1.End(); test1.End();
} }
@ -512,21 +486,21 @@ namespace Nuclex.Support.Tracking {
/// <summary>Mocks a subscriber for the events of a tracker</summary> /// <summary>Mocks a subscriber for the events of a tracker</summary>
/// <param name="tracker">Tracker to mock an event subscriber for</param> /// <param name="tracker">Tracker to mock an event subscriber for</param>
/// <returns>The mocked event subscriber</returns> /// <returns>The mocked event subscriber</returns>
private IProgressTrackerSubscriber mockSubscriber(ProgressTracker tracker) { private Mock<IProgressTrackerSubscriber> mockSubscriber(ProgressTracker tracker) {
IProgressTrackerSubscriber mockedSubscriber = Mock<IProgressTrackerSubscriber> mockedSubscriber =
this.mockery.NewMock<IProgressTrackerSubscriber>(); this.mockery.CreateMock<IProgressTrackerSubscriber>();
tracker.AsyncIdleStateChanged += tracker.AsyncIdleStateChanged +=
new EventHandler<IdleStateEventArgs>(mockedSubscriber.IdleStateChanged); new EventHandler<IdleStateEventArgs>(mockedSubscriber.MockObject.IdleStateChanged);
tracker.AsyncProgressChanged += tracker.AsyncProgressChanged +=
new EventHandler<ProgressReportEventArgs>(mockedSubscriber.ProgressChanged); new EventHandler<ProgressReportEventArgs>(mockedSubscriber.MockObject.ProgressChanged);
return mockedSubscriber; return mockedSubscriber;
} }
/// <summary>Mock object factory</summary> /// <summary>Mock object factory</summary>
private Mockery mockery; private MockFactory mockery;
} }

View File

@ -27,7 +27,6 @@ using System.IO;
using Nuclex.Support.Scheduling; using Nuclex.Support.Scheduling;
using NUnit.Framework; using NUnit.Framework;
using NMock2;
namespace Nuclex.Support.Tracking { namespace Nuclex.Support.Tracking {

View File

@ -26,7 +26,7 @@ using System.IO;
using System.Threading; using System.Threading;
using NUnit.Framework; using NUnit.Framework;
using NMock2; using NMock;
namespace Nuclex.Support.Tracking { namespace Nuclex.Support.Tracking {
@ -105,7 +105,7 @@ namespace Nuclex.Support.Tracking {
/// <summary>Initialization routine executed before each test is run</summary> /// <summary>Initialization routine executed before each test is run</summary>
[SetUp] [SetUp]
public void Setup() { public void Setup() {
this.mockery = new Mockery(); this.mockery = new MockFactory();
} }
/// <summary> /// <summary>
@ -128,10 +128,8 @@ namespace Nuclex.Support.Tracking {
public void TestEndedEventAfterSubscription() { public void TestEndedEventAfterSubscription() {
TestTransaction test = new TestTransaction(); TestTransaction test = new TestTransaction();
ITransactionSubscriber mockedSubscriber = mockSubscriber(test); Mock<ITransactionSubscriber> mockedSubscriber = mockSubscriber(test);
Expect.Once.On(mockedSubscriber). mockedSubscriber.Expects.One.Method(m => m.Ended(null, null)).WithAnyArguments();
Method("Ended").
WithAnyArguments();
test.End(); test.End();
@ -147,14 +145,12 @@ namespace Nuclex.Support.Tracking {
TestTransaction test = new TestTransaction(); TestTransaction test = new TestTransaction();
test.End(); test.End();
ITransactionSubscriber mockedSubscriber = Mock<ITransactionSubscriber> mockedSubscriber =
this.mockery.NewMock<ITransactionSubscriber>(); this.mockery.CreateMock<ITransactionSubscriber>();
Expect.Once.On(mockedSubscriber). mockedSubscriber.Expects.One.Method(m => m.Ended(null, null)).WithAnyArguments();
Method("Ended").
WithAnyArguments();
test.AsyncEnded += new EventHandler(mockedSubscriber.Ended); test.AsyncEnded += new EventHandler(mockedSubscriber.MockObject.Ended);
this.mockery.VerifyAllExpectationsHaveBeenMet(); this.mockery.VerifyAllExpectationsHaveBeenMet();
} }
@ -221,10 +217,10 @@ namespace Nuclex.Support.Tracking {
TestTransaction monitored = new TestTransaction(); TestTransaction monitored = new TestTransaction();
UnsubscribingTransaction test = new UnsubscribingTransaction(monitored); UnsubscribingTransaction test = new UnsubscribingTransaction(monitored);
ITransactionSubscriber mockedSubscriber = mockSubscriber(monitored); Mock<ITransactionSubscriber> mockedSubscriber = mockSubscriber(monitored);
try { try {
Expect.Once.On(mockedSubscriber).Method("Ended").WithAnyArguments(); mockedSubscriber.Expects.One.Method(m => m.Ended(null, null)).WithAnyArguments();
monitored.End(); monitored.End();
this.mockery.VerifyAllExpectationsHaveBeenMet(); this.mockery.VerifyAllExpectationsHaveBeenMet();
} }
@ -236,17 +232,17 @@ namespace Nuclex.Support.Tracking {
/// <summary>Mocks a subscriber for the events of a transaction</summary> /// <summary>Mocks a subscriber for the events of a transaction</summary>
/// <param name="transaction">Transaction to mock an event subscriber for</param> /// <param name="transaction">Transaction to mock an event subscriber for</param>
/// <returns>The mocked event subscriber</returns> /// <returns>The mocked event subscriber</returns>
private ITransactionSubscriber mockSubscriber(Transaction transaction) { private Mock<ITransactionSubscriber> mockSubscriber(Transaction transaction) {
ITransactionSubscriber mockedSubscriber = Mock<ITransactionSubscriber> mockedSubscriber =
this.mockery.NewMock<ITransactionSubscriber>(); this.mockery.CreateMock<ITransactionSubscriber>();
transaction.AsyncEnded += new EventHandler(mockedSubscriber.Ended); transaction.AsyncEnded += new EventHandler(mockedSubscriber.MockObject.Ended);
return mockedSubscriber; return mockedSubscriber;
} }
/// <summary>Mock object factory</summary> /// <summary>Mock object factory</summary>
private Mockery mockery; private MockFactory mockery;
} }

View File

@ -26,7 +26,7 @@ using System.Threading;
#if UNITTEST #if UNITTEST
using NUnit.Framework; using NUnit.Framework;
using NMock2; using NMock;
namespace Nuclex.Support.Tracking { namespace Nuclex.Support.Tracking {
@ -190,7 +190,7 @@ namespace Nuclex.Support.Tracking {
/// <summary>Initialization routine executed before each test is run</summary> /// <summary>Initialization routine executed before each test is run</summary>
[SetUp] [SetUp]
public void Setup() { public void Setup() {
this.mockery = new Mockery(); this.mockery = new MockFactory();
} }
/// <summary>Validates that the transaction group correctly sums the progress</summary> /// <summary>Validates that the transaction group correctly sums the progress</summary>
@ -202,15 +202,11 @@ namespace Nuclex.Support.Tracking {
new TestTransaction[] { new TestTransaction(), new TestTransaction() } new TestTransaction[] { new TestTransaction(), new TestTransaction() }
) )
) { ) {
ITransactionGroupSubscriber mockedSubscriber = mockSubscriber(testTransactionGroup); Mock<ITransactionGroupSubscriber> mockedSubscriber = mockSubscriber(testTransactionGroup);
Expect.Once.On(mockedSubscriber). mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With(
Method("ProgressChanged"). new NMock.Matchers.TypeMatcher(typeof(TransactionGroup<TestTransaction>)),
With(
new Matcher[] {
new NMock2.Matchers.TypeMatcher(typeof(TransactionGroup<TestTransaction>)),
new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.25f)) new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.25f))
}
); );
testTransactionGroup.Children[0].Transaction.ChangeProgress(0.5f); testTransactionGroup.Children[0].Transaction.ChangeProgress(0.5f);
@ -231,26 +227,18 @@ namespace Nuclex.Support.Tracking {
} }
) )
) { ) {
ITransactionGroupSubscriber mockedSubscriber = mockSubscriber(testTransactionGroup); Mock<ITransactionGroupSubscriber> mockedSubscriber = mockSubscriber(testTransactionGroup);
Expect.Once.On(mockedSubscriber). mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With(
Method("ProgressChanged"). new NMock.Matchers.TypeMatcher(typeof(TransactionGroup<TestTransaction>)),
With(
new Matcher[] {
new NMock2.Matchers.TypeMatcher(typeof(TransactionGroup<TestTransaction>)),
new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.5f / 3.0f)) new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.5f / 3.0f))
}
); );
testTransactionGroup.Children[0].Transaction.ChangeProgress(0.5f); testTransactionGroup.Children[0].Transaction.ChangeProgress(0.5f);
Expect.Once.On(mockedSubscriber). mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With(
Method("ProgressChanged"). new NMock.Matchers.TypeMatcher(typeof(TransactionGroup<TestTransaction>)),
With(
new Matcher[] {
new NMock2.Matchers.TypeMatcher(typeof(TransactionGroup<TestTransaction>)),
new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.5f)) new ProgressUpdateEventArgsMatcher(new ProgressReportEventArgs(0.5f))
}
); );
testTransactionGroup.Children[1].Transaction.ChangeProgress(0.5f); testTransactionGroup.Children[1].Transaction.ChangeProgress(0.5f);
@ -271,15 +259,15 @@ namespace Nuclex.Support.Tracking {
new TestTransaction[] { new TestTransaction(), new TestTransaction() } new TestTransaction[] { new TestTransaction(), new TestTransaction() }
) )
) { ) {
ITransactionGroupSubscriber mockedSubscriber = mockSubscriber(testTransactionGroup); Mock<ITransactionGroupSubscriber> mockedSubscriber = mockSubscriber(testTransactionGroup);
Expect.Exactly(2).On(mockedSubscriber). mockedSubscriber.Expects.Exactly(2).Method(
Method("ProgressChanged"). m => m.ProgressChanged(null, null)
WithAnyArguments(); ).WithAnyArguments();
Expect.Once.On(mockedSubscriber). mockedSubscriber.Expects.One.Method(
Method("Ended"). m => m.Ended(null, null)
WithAnyArguments(); ).WithAnyArguments();
testTransactionGroup.Children[0].Transaction.End(); testTransactionGroup.Children[0].Transaction.End();
testTransactionGroup.Children[1].Transaction.End(); testTransactionGroup.Children[1].Transaction.End();
@ -300,15 +288,16 @@ namespace Nuclex.Support.Tracking {
new TestTransaction[] { new TestTransaction() } new TestTransaction[] { new TestTransaction() }
) )
) { ) {
ITransactionGroupSubscriber mockedSubscriber = mockSubscriber(testTransactionGroup); Mock<ITransactionGroupSubscriber> mockedSubscriber = mockSubscriber(testTransactionGroup);
Expect.Once.On(mockedSubscriber). mockedSubscriber.Expects.One.Method(
Method("ProgressChanged"). m => m.ProgressChanged(null, null)
WithAnyArguments(); ).WithAnyArguments();
mockedSubscriber.Expects.One.Method(
m => m.Ended(null, null)
).WithAnyArguments();
Expect.Once.On(mockedSubscriber).
Method("Ended").
WithAnyArguments();
testTransactionGroup.Children[0].Transaction.End(); testTransactionGroup.Children[0].Transaction.End();
@ -376,19 +365,19 @@ namespace Nuclex.Support.Tracking {
/// <summary>Mocks a subscriber for the events of a transaction</summary> /// <summary>Mocks a subscriber for the events of a transaction</summary>
/// <param name="transaction">Transaction to mock an event subscriber for</param> /// <param name="transaction">Transaction to mock an event subscriber for</param>
/// <returns>The mocked event subscriber</returns> /// <returns>The mocked event subscriber</returns>
private ITransactionGroupSubscriber mockSubscriber(Transaction transaction) { private Mock<ITransactionGroupSubscriber> mockSubscriber(Transaction transaction) {
ITransactionGroupSubscriber mockedSubscriber = Mock<ITransactionGroupSubscriber> mockedSubscriber =
this.mockery.NewMock<ITransactionGroupSubscriber>(); this.mockery.CreateMock<ITransactionGroupSubscriber>();
transaction.AsyncEnded += new EventHandler(mockedSubscriber.Ended); transaction.AsyncEnded += new EventHandler(mockedSubscriber.MockObject.Ended);
(transaction as IProgressReporter).AsyncProgressChanged += (transaction as IProgressReporter).AsyncProgressChanged +=
new EventHandler<ProgressReportEventArgs>(mockedSubscriber.ProgressChanged); new EventHandler<ProgressReportEventArgs>(mockedSubscriber.MockObject.ProgressChanged);
return mockedSubscriber; return mockedSubscriber;
} }
/// <summary>Mock object factory</summary> /// <summary>Mock object factory</summary>
private Mockery mockery; private MockFactory mockery;
} }