Activity log for bug #674860

Date Who What changed Old value New value Message
2010-11-13 12:39:03 Oliver Gramberg bug added bug
2010-11-13 15:16:18 Oliver Gramberg description There is a Using() modifier on NUnit.Framework.Is.EqualTo() (I'm using v2.5.8,) but I'd like to have one on NUnit.Framework.Contains.Item(), too. Here's what you'd have to do. Make CollectionItemsEqualConstraint.comparer protected: < public abstract class CollectionItemsEqualConstraint : CollectionConstraint < { < private NUnitEqualityComparer comparer = NUnitEqualityComparer.Default; ------- > public abstract class CollectionItemsEqualConstraint : CollectionConstraint > { > protected NUnitEqualityComparer comparer = NUnitEqualityComparer.Default; Add the Using modifier to CollectionContainsConstraint: > /// <summary> > /// Flag the constraint to use the supplied Comparison object. > /// </summary> > /// <param name="comparer">The Comparison<T> object to use.</param> > /// <returns>Self.</returns> > public CollectionContainsConstraint Using<T>(Comparison<T> comparer) > { > this.comparer.ExternalComparer = EqualityAdapter.For(comparer); > return this; > } Variants go similar. Narrow the return type of Contains.Item() so the new modifier becomes accessible: > /// <summary> > /// Creates a new CollectionContainsConstraint. > /// </summary> > /// <param name="item">The item that should be found.</param> > /// <returns>A new CollectionContainsConstraint</returns> > public static CollectionContainsConstraint Item(object item) > { > return new CollectionContainsConstraint(item); > } There is a Using() modifier on NUnit.Framework.Is.EqualTo() (I'm using v2.5.8,) but I'd like to have one on NUnit.Framework.Contains.Item(), too. Here's what you'd have to do. Make CollectionItemsEqualConstraint.comparer protected: < public abstract class CollectionItemsEqualConstraint : CollectionConstraint < { < private NUnitEqualityComparer comparer = NUnitEqualityComparer.Default; ------- > public abstract class CollectionItemsEqualConstraint : CollectionConstraint > { > protected NUnitEqualityComparer comparer = NUnitEqualityComparer.Default; Add the Using modifier to CollectionContainsConstraint: > /// <summary> > /// Flag the constraint to use the supplied Comparison object. > /// </summary> > /// <param name="comparer">The Comparison<T> object to use.</param> > /// <returns>Self.</returns> > public CollectionContainsConstraint Using<T>(Comparison<T> comparer) > { > this.comparer.ExternalComparer = EqualityAdapter.For(comparer); > return this; > } Variants go similar. Narrow the return type of Contains.Item() so the new modifier becomes accessible: > /// <summary> > /// Creates a new CollectionContainsConstraint. > /// </summary> > /// <param name="item">The item that should be found.</param> > /// <returns>A new CollectionContainsConstraint</returns> > public static CollectionContainsConstraint Item(object item) > { > return new CollectionContainsConstraint(item); > } Call the supplied comparer at the appropriate time. I suggest that this should be first after comparing for null and reference equality, since it is an explicit override in the test code: > public bool ObjectsEqual(object x, object y) > { ... > if (object.ReferenceEquals(x, y)) > return true; > > if (externalComparer != null) > return externalComparer.ObjectsEqual(x, y); > > Type xType = x.GetType(); > Type yType = y.GetType(); > > if (xType.IsArray && yType.IsArray && !compareAsCollection) > return ArraysEqual((Array)x, (Array)y);
2010-11-13 15:35:08 Charlie Poole tags feature
2010-11-13 15:35:14 Charlie Poole nunitv2: status New Confirmed
2010-11-13 15:35:19 Charlie Poole nunitv2: importance Undecided Medium
2010-11-13 15:35:34 Charlie Poole nunitv2: assignee Charlie Poole (charlie.poole)
2010-11-13 15:35:52 Charlie Poole nunitv2: milestone 2.5.9
2010-11-13 21:51:10 Charlie Poole nunitv2: status Confirmed Triaged
2010-11-15 20:26:10 Charlie Poole nunitv2: status Triaged Fix Committed
2010-11-15 20:26:33 Launchpad Janitor branch linked lp:nunitv2
2010-12-15 04:29:36 Charlie Poole nunitv2: status Fix Committed Fix Released