public void EqualsTest() { ProxyInstance proxy1 = new ProxyInstance(null); ProxyInstance proxy2 = new ProxyInstance(null); MethodInfo method1 = typeof(string).GetMethod("StartsWith", new Type[] { typeof(string) }), method2 = endsWith; IExpectation expectation1 = new AnyArgsExpectation(new FakeInvocation(method1), new Range(1, 1)), expectation2 = new AnyArgsExpectation(new FakeInvocation(method2), new Range(1, 1)); ProxyMethodExpectationTriplet same1 = new ProxyMethodExpectationTriplet(proxy1, method1, expectation1), same2 = new ProxyMethodExpectationTriplet(proxy1, method1, expectation1); Assert.Equal(same1, same2); Assert.Equal(same2, same1); ProxyMethodExpectationTriplet proxyDiff1 = new ProxyMethodExpectationTriplet(proxy1, method1, expectation1), proxyDiff2 = new ProxyMethodExpectationTriplet(proxy2, method1, expectation1); Assert.NotEqual(proxyDiff2, proxyDiff1); Assert.NotEqual(proxyDiff1, proxyDiff2); ProxyMethodExpectationTriplet methodDiff1 = new ProxyMethodExpectationTriplet(proxy1, method1, expectation1), methodDiff2 = new ProxyMethodExpectationTriplet(proxy1, method2, expectation1); Assert.NotEqual(methodDiff1, methodDiff2); Assert.NotEqual(methodDiff2, methodDiff1); ProxyMethodExpectationTriplet expectationDiff1 = new ProxyMethodExpectationTriplet(proxy1, method1, expectation1), expectationDiff2 = new ProxyMethodExpectationTriplet(proxy1, method1, expectation2); Assert.NotEqual(expectationDiff1, expectationDiff2); Assert.NotEqual(expectationDiff2, expectationDiff1); ProxyMethodExpectationTriplet allDiff1 = new ProxyMethodExpectationTriplet(proxy1, method1, expectation1), allDiff2 = new ProxyMethodExpectationTriplet(proxy2, method2, expectation2); Assert.NotEqual(allDiff1, allDiff2); Assert.NotEqual(allDiff2, allDiff1); }
/// <summary> /// The methods equals. /// </summary> /// <param name="method"> /// The method. /// </param> /// <param name="triplet"> /// The triplet. /// </param> /// <returns> /// The methods equals. /// </returns> private static bool MethodsEquals(MethodInfo method, ProxyMethodExpectationTriplet triplet) { if (method.IsGenericMethod == false) return triplet.Method == method; return triplet.Method.GetGenericMethodDefinition() == method.GetGenericMethodDefinition(); }
/// <summary> /// Records the specified call with the specified args on the mocked object. /// </summary> /// <param name="proxy"> /// Mocked object. /// </param> /// <param name="method"> /// Method. /// </param> /// <param name="expectation"> /// Expectation. /// </param> protected override void DoRecord(object proxy, MethodInfo method, IExpectation expectation) { Validate.IsNotNull(proxy, "proxy"); Validate.IsNotNull(method, "method"); Validate.IsNotNull(expectation, "expectation"); ProxyMethodExpectationTriplet entry = new ProxyMethodExpectationTriplet(proxy, method, expectation); recordedActions.Add(entry); }
public void ReturnSamevaluesAsInCtor() { ProxyMethodExpectationTriplet triplet = new ProxyMethodExpectationTriplet(proxy, this.endsWith, this.expectation); Assert.Equal(proxy, triplet.Proxy); Assert.Equal(endsWith, triplet.Method); Assert.Equal(expectation, triplet.Expectation); }
public void GetHashCodeReturnSameValue() { ProxyMethodExpectationTriplet triplet = new ProxyMethodExpectationTriplet(proxy, this.endsWith, this.expectation); Assert.Equal(triplet.GetHashCode(), triplet.GetHashCode()); }
public void FalseOnEqualToNull() { ProxyMethodExpectationTriplet triplet = new ProxyMethodExpectationTriplet(proxy, this.endsWith, this.expectation); Assert.False(triplet.Equals(null)); }