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:
parent
da61476a80
commit
aa5e4d12cc
24 changed files with 284 additions and 320 deletions
|
@ -25,7 +25,6 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
|
||||
using NUnit.Framework;
|
||||
using NMock2;
|
||||
|
||||
namespace Nuclex.Support.Collections {
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
|
||||
using NUnit.Framework;
|
||||
using NMock2;
|
||||
|
||||
namespace Nuclex.Support.Collections {
|
||||
|
||||
|
|
|
@ -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 {
|
|||
/// <summary>Initialization routine executed before each test is run</summary>
|
||||
[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.Clearing +=
|
||||
new EventHandler(this.mockedSubscriber.Clearing);
|
||||
this.observedCollection.Cleared +=
|
||||
new EventHandler(this.mockedSubscriber.Cleared);
|
||||
this.observedCollection.ItemAdded +=
|
||||
new EventHandler<ItemEventArgs<int>>(
|
||||
this.mockedSubscriber.ItemAdded
|
||||
);
|
||||
this.observedCollection.ItemRemoved +=
|
||||
new EventHandler<ItemEventArgs<int>>(
|
||||
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<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>
|
||||
[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 {
|
|||
/// <summary>Tests whether the ItemAdded event is fired</summary>
|
||||
[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 {
|
|||
/// <summary>Tests whether the ItemRemoved event is fired</summary>
|
||||
[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 {
|
|||
/// <summary>Tests whether items in the collection can be replaced</summary>
|
||||
[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 {
|
|||
}
|
||||
|
||||
/// <summary>Mock object factory</summary>
|
||||
private Mockery mockery;
|
||||
private MockFactory mockery;
|
||||
/// <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>
|
||||
private ObservableCollection<int> observedCollection;
|
||||
|
||||
|
|
|
@ -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 {
|
|||
/// <summary>Initialization routine executed before each test is run</summary>
|
||||
[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.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<ItemEventArgs<KeyValuePair<int, string>>>(
|
||||
this.mockedSubscriber.ItemAdded
|
||||
this.mockedSubscriber.MockObject.ItemAdded
|
||||
);
|
||||
this.observedDictionary.ItemRemoved +=
|
||||
new EventHandler<ItemEventArgs<KeyValuePair<int, string>>>(
|
||||
this.mockedSubscriber.ItemRemoved
|
||||
this.mockedSubscriber.MockObject.ItemRemoved
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -249,7 +249,7 @@ namespace Nuclex.Support.Collections {
|
|||
/// </summary>
|
||||
[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<int, string>).Add(10, "ten");
|
||||
this.mockery.VerifyAllExpectationsHaveBeenMet();
|
||||
|
||||
|
@ -264,7 +264,7 @@ namespace Nuclex.Support.Collections {
|
|||
/// </summary>
|
||||
[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<int, string>).Remove(3);
|
||||
this.mockery.VerifyAllExpectationsHaveBeenMet();
|
||||
|
||||
|
@ -287,8 +287,12 @@ namespace Nuclex.Support.Collections {
|
|||
/// </summary>
|
||||
[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<int, string>)[42] = "two and fourty";
|
||||
this.mockery.VerifyAllExpectationsHaveBeenMet();
|
||||
|
||||
|
@ -300,8 +304,12 @@ namespace Nuclex.Support.Collections {
|
|||
/// </summary>
|
||||
[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 {
|
|||
/// </summary>
|
||||
[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 {
|
|||
/// </summary>
|
||||
[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 {
|
|||
/// </summary>
|
||||
[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 {
|
|||
/// </summary>
|
||||
[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<KeyValuePair<int, string>>).Add(
|
||||
new KeyValuePair<int, string>(24, "twenty-four")
|
||||
);
|
||||
|
@ -432,8 +450,13 @@ namespace Nuclex.Support.Collections {
|
|||
/// </summary>
|
||||
[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<KeyValuePair<int, string>>).Clear();
|
||||
this.mockery.VerifyAllExpectationsHaveBeenMet();
|
||||
|
||||
|
@ -449,7 +472,11 @@ namespace Nuclex.Support.Collections {
|
|||
IEnumerator<KeyValuePair<int, string>> enumerator =
|
||||
(this.observedDictionary as ICollection<KeyValuePair<int, string>>).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<KeyValuePair<int, string>>).Remove(
|
||||
enumerator.Current
|
||||
);
|
||||
|
@ -537,9 +564,9 @@ namespace Nuclex.Support.Collections {
|
|||
}
|
||||
|
||||
/// <summary>Mock object factory</summary>
|
||||
private Mockery mockery;
|
||||
private MockFactory mockery;
|
||||
/// <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>
|
||||
private ObservableDictionary<int, string> observedDictionary;
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ using System.Collections.Generic;
|
|||
#if UNITTEST
|
||||
|
||||
using NUnit.Framework;
|
||||
using NMock2;
|
||||
|
||||
namespace Nuclex.Support.Collections {
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ using System.Collections.Generic;
|
|||
#if UNITTEST
|
||||
|
||||
using NUnit.Framework;
|
||||
using NMock2;
|
||||
|
||||
namespace Nuclex.Support.Collections {
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
|
||||
using NUnit.Framework;
|
||||
using NMock2;
|
||||
|
||||
namespace Nuclex.Support.Collections {
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
|
||||
using NUnit.Framework;
|
||||
using NMock2;
|
||||
|
||||
namespace Nuclex.Support.Collections {
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ using System.Collections.Generic;
|
|||
#if UNITTEST
|
||||
|
||||
using NUnit.Framework;
|
||||
using NMock2;
|
||||
|
||||
namespace Nuclex.Support.Collections {
|
||||
|
||||
|
|
|
@ -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 {
|
|||
/// </summary>
|
||||
[Test]
|
||||
public void TestSynchronizationOfIListWithoutICollection() {
|
||||
Mockery mockery = new Mockery();
|
||||
IList<int> mockedIList = mockery.NewMock<IList<int>>();
|
||||
StringTransformer testCollection = new StringTransformer(mockedIList);
|
||||
MockFactory mockery = new MockFactory();
|
||||
Mock<IList<int>> mockedIList = mockery.CreateMock<IList<int>>();
|
||||
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); // ;-)
|
||||
}
|
||||
|
|
|
@ -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<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>
|
||||
[Test]
|
||||
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>
|
||||
/// Verifies that the IsSynchronized property and the SyncRoot property are working
|
||||
/// on transforming read only collections based on IList<>s that do not
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue