using System; using System.Collections.Generic; using System.Linq; using System.Text; using Chefbook.HelperMethods; using NUnit.Framework; using System.Collections.ObjectModel; using System.Collections.Specialized; namespace UnitTests.HelperMethodsTests { [TestFixture] public class CollectionExtensionMethodsFixture { [Test] public void AddIfNewTest1() { List list1 = new List(); object a = new object(); list1.AddIfNewAndNotNull(a); Assert.AreEqual(1, list1.Count((item) => item == a),"Object did not appear in collection exactly once"); } [Test] public void AddIfNewTest2() { List list1 = new List(); object a = new object(); list1.AddIfNewAndNotNull(a); list1.AddIfNewAndNotNull(a); Assert.AreEqual(1, list1.Count((item) => item == a), "Object did not appear in collection exactly once"); } [Test] public void AddAndThrowTest1() { List ints = new List(); ints.Add(3); Assert.Throws(() => ints.AddAndThrowIfNullOrNotNew(3)); } [Test] public void AddAndThrowTest2() { List strings = new List(); Assert.Throws(() => strings.AddAndThrowIfNullOrNotNew(null)); } [Test] public void ModifyCollectionToMatchNewCollectionTest1() { ObservableCollection testList = new ObservableCollection(new int[] { 1, 2, 3, 4 }); List newlist = new List(new int[] { 2, 5, 4 }); var args = testList.AssertCollectionChangedFiredNTimesAndReturnArgs(() => testList.ModifyCollectionToMatchNewCollection(newlist)); Assert.True(args.Contains(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, 5), ChangedEventHelper.NotifyCollectionChangedEventArgsEqual)); Assert.True(args.Contains(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, 1), ChangedEventHelper.NotifyCollectionChangedEventArgsEqual)); Assert.True(args.Contains(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, 3), ChangedEventHelper.NotifyCollectionChangedEventArgsEqual)); } [Test] public void HasSameEntriesAsTest() { List list1 = new List(new int[] { 2, 5, 4 }); List list2 = new List(new int[] { 2, 4, 5 }); List list3 = new List(new int[] { 1, 4, 5 }); Assert.True(list1.HasSameEntriesAs(list2)); Assert.True(list2.HasSameEntriesAs(list1)); Assert.False(list2.HasSameEntriesAs(list3)); Assert.False(list3.HasSameEntriesAs(list2)); Assert.False(list1.HasSameEntriesAs(list3)); Assert.False(list3.HasSameEntriesAs(list1)); } } }