** Branch linked: lp:nunitv2 -- Using() modifier missing on NUnit.Framework.Contains.Item() https://bugs.launchpad.net/bugs/674860 You received this bug notification because you are a member of NUnit Developers, which is subscribed to NUnit V2.
Status in NUnit V2 Test Framework: Fix Committed Bug 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); > } 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); _______________________________________________ Mailing list: https://launchpad.net/~nunit-core Post to : nunit-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~nunit-core More help : https://help.launchpad.net/ListHelp