chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
I think I found a bug with AndArgumentsMatch. Here's the production code:

    public class Edge1
    {
        public int FirstVert
        { get; set; }
        public int SecondVert
        { get; set; }

        public Edge1(int firstVert, int secondVert)
        {
            FirstVert = firstVert;
            SecondVert = secondVert;
        }

        public static bool operator ==(Edge1 e1, Edge1 e2)
        {
            return Equals(e1, e2);
        }

        public static bool operator !=(Edge1 e1, Edge1 e2)
        {
            return !Equals(e1, e2);
        }

        public override bool Equals(object obj)
        {
            Edge1 otherEdge = (Edge1)obj;
            return (FirstVert == otherEdge.FirstVert && SecondVert == otherEdge.SecondVert)
                || (FirstVert == otherEdge.SecondVert && SecondVert == otherEdge.FirstVert);

        }

        public override int GetHashCode()
        {
            return FirstVert.GetHashCode() ^ SecondVert.GetHashCode();
        }
        public class Edge1Comparer:IComparer<Edge1>
        {
            public int Compare(Edge1 x, Edge1 y)

            {
                return GetRanking(x) - GetRanking(y);
            }

            public int GetRanking(Edge1 x)
            {
                throw new NotImplementedException();
            }
        }
    }


And here's the test code:
        [Test]
        public void Edge1Test()
        {

            var edge1 = new Edge1(1,2);
            Edge1.Edge1Comparer comparer = Isolate.Fake.Instance<Edge1>();
            Isolate.WhenCalled(()=>comparer.Compare(null, null))
                .CallOriginal();



            Isolate.WhenCalled((Edge1 edge) => comparer.GetRanking(edge))
                .AndArgumentsMatch(edge => edge == edge1)
                .WillReturn(1);
        }


The test code will crash at the line AndArgumentsMatch with the following message:
failed: TypeMock.TypeMockException :
*** All argument matching parameters should be used on the same method.
at hd.a()
at hd.a(Int32& A_0)
at f4.d()
at da.a(Boolean A_0)
at de.b(Boolean A_0)
at ic.c(Boolean A_0)
at ic.a(Object A_0, Boolean A_1, Func`1 A_2, Action A_3, Action A_4, Action A_5)
at ic.c(Object A_0)


But if you remove the Equals and GetHashCode override, then the test can pass.
________
Kissing advice advice
asked by nsoonhui (59.1k points)

1 Answer

0 votes
Hi Soon Hui,

Thank you for a good repro.

The problem is that we compare the values passed as arguments and overriding the compare method has uncovered a bug we have.

I managed to solve this bug and it would be part of the upcoming release of Typemock Isolator.

I'll send you a patch with this fix so you can verify that it was solved.
answered by dhelper (11.9k points)
...