Using() modifier missing on NUnit.Framework.Contains.Item()

Bug #674860 reported by Oliver Gramberg
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
NUnit V2
Fix Released
Medium
Charlie Poole

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);

Tags: feature

Related branches

description: updated
tags: added: feature
Changed in nunitv2:
status: New → Confirmed
importance: Undecided → Medium
assignee: nobody → Charlie Poole (charlie.poole)
milestone: none → 2.5.9
Changed in nunitv2:
status: Confirmed → Triaged
Revision history for this message
Charlie Poole (charlie.poole) wrote :

So, it appears that CollectionContainsConstraint already has Using modifier, which it inherits from CollectionItemsEqualConstraint.

Do you have a particular case that isn't working?

Revision history for this message
Charlie Poole (charlie.poole) wrote :

More info... NUnit contains tests that verify Using is working on CollectionContainsConstraint. What is probably not working is one or more of the syntactic expressions. At a glance, however, Contains.Item(...).Using(...) seems to be OK. Are you looking at the nunit 2.5.8 code?

Revision history for this message
Oliver Gramberg (oliver-gramberg) wrote :

Yes, I have 2.5.8 (as I stated at the top of the bug description.) Is there a relevant significant change in 2.5.9?

Revision history for this message
Charlie Poole (charlie.poole) wrote : Re: [Bug 674860] Re: Using() modifier missing on NUnit.Framework.Contains.Item()

No, this hasn't changed at all. It will if I can figure out just what
is not working though. :-)

See my note on the mailing list as well.

On Mon, Nov 15, 2010 at 9:06 AM, Oliver Gramberg
<email address hidden> wrote:
> Yes, I have 2.5.8 (as I stated at the top of the bug description.) Is
> there a relevant significant change in 2.5.9?
>
> --
> 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.
>

Changed in nunitv2:
status: Triaged → Fix Committed
Changed in nunitv2:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.