Example #1
0
        public void MethodInvocationEqualsByTargetMethodArgs()
        {
            var method = new Action <bool, string, PlatformID>(AMethod).Method;
            var args   = new object[] { true, "foo", PlatformID.Win32NT };
            var target = this;

            IStructuralEquatable equatable = new MethodInvocation(target, method, args);
            IStructuralEquatable other     = new MethodInvocation(target, method, args);

            Assert.True(equatable.Equals(other));
            Assert.True(equatable.Equals(other, EqualityComparer <object> .Default));
            Assert.Equal(equatable.GetHashCode(), other.GetHashCode());
            Assert.Equal(equatable.GetHashCode(EqualityComparer <object> .Default), other.GetHashCode(EqualityComparer <object> .Default));
        }
Example #2
0
        public void EqualIfTargetMethodAndArgumentsMatch()
        {
            var doThis  = new MethodInvocation(this, typeof(MethodInvocationTests).GetMethod(nameof(Do)));
            var doThiss = new MethodInvocation(this, typeof(MethodInvocationTests).GetMethod(nameof(Do)));

            Assert.Equal((object)doThis, doThiss);
            Assert.Equal(doThis, doThiss);
            Assert.Equal(doThis.GetHashCode(), doThiss.GetHashCode());
            Assert.True(doThis.Equals(doThiss));
            Assert.True(doThis.Equals((object)doThiss));

            var doOther = new MethodInvocation(new MethodInvocationTests(), typeof(MethodInvocationTests).GetMethod(nameof(Do)));

            Assert.NotEqual(doThis, doOther);

            var doInt5  = new MethodInvocation(this, typeof(MethodInvocationTests).GetMethod(nameof(DoWithInt)), 5);
            var doInt5s = new MethodInvocation(this, typeof(MethodInvocationTests).GetMethod(nameof(DoWithInt)), 5);

            Assert.NotEqual(doThis, doInt5);
            Assert.Equal(doInt5, doInt5s);
            Assert.Equal(doInt5.GetHashCode(), doInt5s.GetHashCode());

            var doInt6 = new MethodInvocation(this, typeof(MethodInvocationTests).GetMethod(nameof(DoWithInt)), 6);

            Assert.NotEqual(doInt5, doInt6);
        }
Example #3
0
        public void MethodInvocationEqualsByTargetMethodArgs()
        {
            var method = new Action <bool, string, PlatformID>(AMethod).Method;
            var args   = new object[] { true, "foo", PlatformID.Win32NT };
            var target = this;

            IEquatable <IMethodInvocation> equatable = new MethodInvocation(target, method, args);
            IEquatable <IMethodInvocation> other     = new MethodInvocation(target, method, args);

            Assert.True(equatable.Equals(other));
            Assert.Equal(equatable.GetHashCode(), other.GetHashCode());
        }