/// <summary>
        /// This check the methods that were setup using the SetupResult.For()
        /// or LastCall.Repeat.Any() and that bypass the whole expectation model.
        /// </summary>
        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);
        }
 public void CtorValueReturnedInProperties()
 {
     object mockProxy = new object(); // mock for the mocked, he he
     ProxyMethodPair pair = new ProxyMethodPair(mockProxy, endsWith);
     Assert.AreSame(mockProxy, pair.Proxy);
     Assert.AreSame(endsWith, pair.Method);
 }
 public void NotEqualIfNotSameMethod()
 {
     ProxyInstance mockProxy = new ProxyInstance(null);
     ProxyMethodPair pair1 = new ProxyMethodPair(mockProxy, endsWith);
     ProxyMethodPair pair2 = new ProxyMethodPair(mockProxy, startsWith);
     Assert.AreNotEqual(pair1, pair2);
     Assert.AreNotEqual(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.AreEqual(pair1, pair2);
     Assert.AreEqual(pair2, pair1); //make sure that it works both ways
 }
        /// <summary>
        /// Determines whatever obj equals to this instance.
        /// ProxyMethodPairs are equal when they point to the same /instance/ of
        /// an object, and to the same method.
        /// </summary>
        /// <param name="obj">Obj.</param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            ProxyMethodPair other = obj as ProxyMethodPair;

            if (other == null)
            {
                return(false);
            }
            return(MockedObjectsEquality.Instance.Compare(other.proxy, proxy) == 0 &&
                   other.method == method);
        }
 /// <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);
         }
     }
 }
        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>
        /// Set the expectation so it can repeat any number of times.
        /// </summary>
        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);
        }
Example #9
0
 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;
 }
Example #10
0
 /// <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);
     }
 }
Example #11
0
 /// <summary>
 /// This check the methods that were setup using the SetupResult.For()
 /// or LastCall.Repeat.Any() and that bypass the whole expectation model.
 /// </summary>
 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;
 }
Example #12
0
 /// <summary>
 /// Set the expectation so it can repeat any number of times.
 /// </summary>
 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);
 }
 public void NotEqualToNull()
 {
     ProxyInstance mockProxy = new ProxyInstance(null);
     ProxyMethodPair pair1 = new ProxyMethodPair(mockProxy, endsWith);
     Assert.IsFalse(pair1.Equals(null));
 }
 public void NotEqualIfNotSameMethodAndNotSameProxy()
 {
     ProxyInstance mockProxy1 = new ProxyInstance(null);
     ProxyInstance mockProxy2 = new ProxyInstance(null);
     ProxyMethodPair pair1 = new ProxyMethodPair(mockProxy1, this.endsWith);
     ProxyMethodPair pair2 = new ProxyMethodPair(mockProxy2, this.startsWith);
     Assert.NotEqual(pair1, pair2);
     Assert.NotEqual(pair2, pair1); //make sure that it works both ways
 }