← Back to team overview

nunit-core team mailing list archive

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
<674860@xxxxxxxxxxxxxxxxxx> 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.
>

-- 
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: Triaged

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






References