public void AppliesToEquals()
        {
            var method   = typeof(Foo).GetMethod(nameof(object.Equals));
            var behavior = new DefaultEqualityBehavior();

            Assert.True(behavior.AppliesTo(new MethodInvocation(new Foo(), method, new object[] { new Foo() })));
        }
示例#2
0
        public void AppliesToGetHashCode()
        {
            var method   = typeof(Foo).GetMethod(nameof(object.GetHashCode)) !;
            var behavior = new DefaultEqualityBehavior();

            Assert.True(behavior.AppliesTo(MethodInvocation.Create(new Foo(), method)));
        }
        public void NotEqualsDifferentInstance()
        {
            var method   = typeof(Foo).GetMethod(nameof(object.Equals));
            var behavior = new DefaultEqualityBehavior();
            var target   = new Foo();

            var actual = (bool)behavior.Invoke(new MethodInvocation(target, method, new object[] { new Foo() }), () => null).ReturnValue;

            Assert.False(actual);
        }
示例#4
0
        public void EqualsSameInstance()
        {
            var method   = typeof(Foo).GetMethod(nameof(object.Equals));
            var behavior = new DefaultEqualityBehavior();
            var target   = new Foo();

            var actual = (bool)behavior.Execute(new MethodInvocation(target, method, new object[] { target }), () => null).ReturnValue;

            Assert.True(actual);
        }
示例#5
0
        public void NotEqualsDifferentInstance()
        {
            var method   = typeof(Foo).GetMethod(nameof(object.Equals)) !;
            var behavior = new DefaultEqualityBehavior();
            var target   = new Foo();

            var actual = (bool?)behavior.Execute(MethodInvocation.Create(target, method, new Foo()), null !).ReturnValue;

            Assert.False(actual);
        }
        public void GetsHashCode()
        {
            var method   = typeof(Foo).GetMethod(nameof(object.GetHashCode));
            var behavior = new DefaultEqualityBehavior();
            var target   = new Foo();

            var expected = target.GetHashCode();
            var actual   = (int)behavior.Invoke(new MethodInvocation(target, method, new object[0]), () => null).ReturnValue;

            Assert.Equal(expected, actual);
        }
示例#7
0
        public void GetsHashCode()
        {
            var method   = typeof(Foo).GetMethod(nameof(object.GetHashCode)) !;
            var behavior = new DefaultEqualityBehavior();
            var target   = new Foo();

            var expected = target.GetHashCode();
            var actual   = (int?)behavior.Execute(MethodInvocation.Create(target, method), null).ReturnValue;

            Assert.Equal(expected, actual);
        }
示例#8
0
        public void InvokeNextIfNotEqualsOrGetHashCode()
        {
            var method     = typeof(Foo).GetMethod(nameof(Foo.ToString));
            var behavior   = new DefaultEqualityBehavior();
            var target     = new Foo();
            var nextCalled = false;

            behavior.Execute(
                new MethodInvocation(target, method),
                () => (m, n) =>
            {
                nextCalled = true;
                return(m.CreateValueReturn(null));
            });

            Assert.True(nextCalled);
        }