public void CtorValueReturnedInProperties() { object mockProxy = new object(); // mock for the mocked, he he ProxyMethodPair pair = new ProxyMethodPair(mockProxy, endsWith); Assert.Same(mockProxy, pair.Proxy); Assert.Same(endsWith, pair.Method); }
public void NotEqualIfNotSameMethod() { ProxyInstance mockProxy = new ProxyInstance(null); ProxyMethodPair pair1 = new ProxyMethodPair(mockProxy, endsWith); ProxyMethodPair pair2 = new ProxyMethodPair(mockProxy, startsWith); Assert.NotEqual(pair1, pair2); Assert.NotEqual(pair2, pair1); //make sure that it works both ways }
public void EqualsToAnotherProxy() { ProxyInstance mockProxy = new ProxyInstance(null); ProxyMethodPair pair1 = new ProxyMethodPair(mockProxy, endsWith); ProxyMethodPair pair2 = new ProxyMethodPair(mockProxy, endsWith); Assert.Equal(pair1, pair2); Assert.Equal(pair2, pair1); //make sure that it works both ways }
public void NotEqualToNull() { ProxyInstance mockProxy = new ProxyInstance(null); ProxyMethodPair pair1 = new ProxyMethodPair(mockProxy, endsWith); Assert.False(pair1.Equals(null)); }
/// <summary> /// The try replace repeatable expectation. /// </summary> /// <param name="method"> /// The method. /// </param> /// <param name="newExpectation"> /// The new expectation. /// </param> /// <param name="oldExpectation"> /// The old expectation. /// </param> /// <param name="proxy"> /// The proxy. /// </param> /// <returns> /// The try replace repeatable expectation. /// </returns> private bool TryReplaceRepeatableExpectation(MethodInfo method, IExpectation newExpectation, IExpectation oldExpectation, object proxy) { ProxyMethodPair pair = new ProxyMethodPair(proxy, method); if (repeatableMethods.ContainsKey(pair)) { ExpectationsList expectationsList = repeatableMethods[pair]; int indexOf = expectationsList.IndexOf(oldExpectation); if (indexOf != -1) { expectationsList[indexOf] = newExpectation; return true; } } return false; }
/// <summary> /// Remove the all repeatable expectations for proxy. /// </summary> /// <param name="proxy"> /// Mocked object. /// </param> public void RemoveAllRepeatableExpectationsForProxy(object proxy) { ProxyMethodPair[] keys = new ProxyMethodPair[repeatableMethods.Keys.Count]; repeatableMethods.Keys.CopyTo(keys, 0); foreach (ProxyMethodPair pair in keys) { if (MockedObjectsEquality.Instance.Equals(pair.Proxy, proxy)) repeatableMethods.Remove(pair); } }
/// <summary> /// This check the methods that were setup using the SetupResult.For() /// or LastCall.Repeat.Any() and that bypass the whole expectation model. /// </summary> /// <param name="proxy"> /// The proxy. /// </param> /// <param name="method"> /// The method. /// </param> /// <param name="args"> /// The args. /// </param> public IExpectation GetRepeatableExpectation(object proxy, MethodInfo method, object[] args) { ProxyMethodPair pair = new ProxyMethodPair(proxy, method); if (repeatableMethods.ContainsKey(pair) == false) return null; ExpectationsList list = repeatableMethods[pair]; foreach (IExpectation expectation in list) { if (expectation.IsExpected(args)) { expectation.AddActualCall(); if (expectation.RepeatableOption == RepeatableOption.Never) { string errMsg = string.Format("{0} Expected #{1}, Actual #{2}.", expectation.ErrorMessage, expectation.Expected, expectation.ActualCallsCount); ExpectationViolationException exception = new ExpectationViolationException(errMsg); MockRepository.SetExceptionToBeThrownOnVerify(proxy, exception); throw exception; } return expectation; } } return null; }
/// <summary> /// Set the expectation so it can repeat any number of times. /// </summary> /// <param name="proxy"> /// The proxy. /// </param> /// <param name="method"> /// The method. /// </param> /// <param name="expectation"> /// The expectation. /// </param> public void AddToRepeatableMethods(object proxy, MethodInfo method, IExpectation expectation) { // Just to get an error if I make a mistake and try to add a normal // method to the speical repeat method Debug.Assert(expectation.RepeatableOption != RepeatableOption.Normal); RemoveExpectation(expectation); ProxyMethodPair pair = new ProxyMethodPair(proxy, method); if (repeatableMethods.ContainsKey(pair) == false) repeatableMethods.Add(pair, new ExpectationsList()); ExpectationsList expectationsList = repeatableMethods[pair]; ExpectationNotOnList(expectationsList, expectation, MockRepository.IsStub(proxy)); expectationsList.Add(expectation); }