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); }
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)); }
public void MethodInvocationDoesNotEqualOtherObject() { var method = new Action <bool, string, PlatformID>(AMethod).Method; var args = new object[] { true, "foo", PlatformID.Win32NT }; var target = this; var equatable = new MethodInvocation(target, method, args); Assert.False(equatable.Equals(new object())); }
public void MethodInvocationDetails_CompareIdenticalMethodInvocations_AreEqualIsTrue() { var detail1 = new MethodInvocation( GetMethodInfo("SampleMethod", new[] { typeof(string) }), new object[] { "input" }); var detail2 = new MethodInvocation( GetMethodInfo("SampleMethod", new[] { typeof(string) }), new object[] { "input" }); Assert.AreEqual(true, detail1.Equals(detail2)); }
public void MethodInvocationDetails_DifferentInputValues_AreEqualIsFalse() { var detail1 = new MethodInvocation( GetMethodInfo("SampleMethod", new[] { typeof(string) }), new object[] { "input" }); var detail2 = new MethodInvocation( GetMethodInfo("SampleMethod", new[] { typeof(string) }), new object[] { "input2" }); Assert.AreEqual(false, detail1.Equals(detail2)); }
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()); }
public void MethodInvocationEqualsEvenIfContextDiffers() { var method = new Action <bool, string, PlatformID>(AMethod).Method; var args = new object[] { true, "foo", PlatformID.Win32NT }; var target = this; var equatable = new MethodInvocation(target, method, args); equatable.Context["foo"] = "bar"; var other = new MethodInvocation(target, method, args); Assert.True(equatable.Equals(other)); }