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