Fixed unit tests that were failing due to the introdcution of the ItemReplaced event; removed NotifyCollectionResetEventArgs if no specialized collections are available

git-svn-id: file:///srv/devel/repo-conversion/nusu@257 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2012-03-01 14:05:11 +00:00
parent 2d04ad7b49
commit 13579c5162
3 changed files with 26 additions and 6 deletions

View File

@ -19,16 +19,20 @@ License along with this library
#endregion #endregion
using System; using System;
#if !NO_SPECIALIZED_COLLECTIONS
using System.Collections.Specialized; using System.Collections.Specialized;
#endif
namespace Nuclex.Support.Collections { namespace Nuclex.Support.Collections {
/// <summary>Contains fixed constants used by some collections</summary> /// <summary>Contains fixed constants used by some collections</summary>
public static class Constants { public static class Constants {
#if !NO_SPECIALIZED_COLLECTIONS
/// <summary>Fixed event args used to notify that the collection has reset</summary> /// <summary>Fixed event args used to notify that the collection has reset</summary>
public static readonly NotifyCollectionChangedEventArgs NotifyCollectionResetEventArgs = public static readonly NotifyCollectionChangedEventArgs NotifyCollectionResetEventArgs =
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset); new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);
#endif
} }

View File

@ -60,6 +60,13 @@ namespace Nuclex.Support.Collections {
/// <param name="arguments">Contains the item that is being removed</param> /// <param name="arguments">Contains the item that is being removed</param>
void ItemRemoved(object sender, ItemEventArgs<KeyValuePair<int, string>> arguments); void ItemRemoved(object sender, ItemEventArgs<KeyValuePair<int, string>> arguments);
/// <summary>Called when an item is replaced in the dictionary</summary>
/// <param name="sender">Dictionary in which an item is being replaced</param>
/// <param name="arguments">Contains the replaced item and its replacement</param>
void ItemReplaced(
object sender, ItemReplaceEventArgs<KeyValuePair<int, string>> arguments
);
} }
#endregion // interface IObservableDictionarySubscriber #endregion // interface IObservableDictionarySubscriber
@ -89,6 +96,10 @@ namespace Nuclex.Support.Collections {
new EventHandler<ItemEventArgs<KeyValuePair<int, string>>>( new EventHandler<ItemEventArgs<KeyValuePair<int, string>>>(
this.mockedSubscriber.MockObject.ItemRemoved this.mockedSubscriber.MockObject.ItemRemoved
); );
this.observedDictionary.ItemReplaced +=
new EventHandler<ItemReplaceEventArgs<KeyValuePair<int, string>>>(
this.mockedSubscriber.MockObject.ItemReplaced
);
} }
/// <summary> /// <summary>
@ -288,11 +299,9 @@ namespace Nuclex.Support.Collections {
[Test] [Test]
public void TestReplaceByIndexerViaGenericIDictionary() { public void TestReplaceByIndexerViaGenericIDictionary() {
this.mockedSubscriber.Expects.One.Method( this.mockedSubscriber.Expects.One.Method(
m => m.ItemRemoved(null, null) m => m.ItemReplaced(null, null)
).WithAnyArguments();
this.mockedSubscriber.Expects.One.Method(
m => m.ItemAdded(null, null)
).WithAnyArguments(); ).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();

View File

@ -57,6 +57,11 @@ namespace Nuclex.Support.Collections {
/// <param name="arguments">Contains the item that is being removed</param> /// <param name="arguments">Contains the item that is being removed</param>
void ItemRemoved(object sender, ItemEventArgs<int> arguments); void ItemRemoved(object sender, ItemEventArgs<int> arguments);
/// <summary>Called when an item is replaced in the dictionary</summary>
/// <param name="sender">Dictionary in which an item is being replaced</param>
/// <param name="arguments">Contains the replaced item and its replacement</param>
void ItemReplaced(object sender, ItemReplaceEventArgs<int> arguments);
} }
#endregion // interface IObservableCollectionSubscriber #endregion // interface IObservableCollectionSubscriber
@ -81,6 +86,9 @@ namespace Nuclex.Support.Collections {
this.observedList.ItemRemoved += new EventHandler<ItemEventArgs<int>>( this.observedList.ItemRemoved += new EventHandler<ItemEventArgs<int>>(
this.mockedSubscriber.MockObject.ItemRemoved this.mockedSubscriber.MockObject.ItemRemoved
); );
this.observedList.ItemReplaced += new EventHandler<ItemReplaceEventArgs<int>>(
this.mockedSubscriber.MockObject.ItemReplaced
);
} }
/// <summary>Tests whether the Clearing event is fired</summary> /// <summary>Tests whether the Clearing event is fired</summary>
@ -128,8 +136,7 @@ namespace Nuclex.Support.Collections {
this.observedList.Add(2); this.observedList.Add(2);
this.observedList.Add(3); this.observedList.Add(3);
this.mockedSubscriber.Expects.One.Method(m => m.ItemRemoved(null, null)).WithAnyArguments(); this.mockedSubscriber.Expects.One.Method(m => m.ItemReplaced(null, null)).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.observedList[1] = 4; this.observedList[1] = 4;