/// <summary>
        /// Gets the all expectations for proxy.
        /// </summary>
        /// <param name="proxy">Mocked object.</param>
        /// <returns>List of all relevant expectation</returns>
        protected override ExpectationsList DoGetAllExpectationsForProxy(object proxy)
        {
            Validate.IsNotNull(proxy, "proxy");

            ExpectationsList expectations = new ExpectationsList();

            foreach (object action in recordedActions)
            {
                ProxyMethodExpectationTriplet triplet = action as ProxyMethodExpectationTriplet;
                if (triplet != null)
                {
                    if (MockedObjectsEquality.Instance.Equals(triplet.Proxy, proxy))
                    {
                        expectations.Add(triplet.Expectation);
                    }
                }
                else                 //Action is another recorder
                {
                    IMethodRecorder  innerRecorder        = (IMethodRecorder)action;
                    ExpectationsList expectationsForProxy = innerRecorder.GetAllExpectationsForProxy(proxy);
                    expectations.AddRange(expectationsForProxy);
                }
            }
            return(expectations);
        }
        /// <summary>
        /// Gets the all expectations for a mocked object and method combination,
        /// regardless of the expected arguments / callbacks / contraints.
        /// </summary>
        /// <param name="proxy">Mocked object.</param>
        /// <param name="method">Method.</param>
        /// <returns>List of all relevant expectation</returns>
        public override ExpectationsList GetAllExpectationsForProxyAndMethod(object proxy, MethodInfo method)
        {
            Validate.IsNotNull(proxy, "proxy");
            Validate.IsNotNull(method, "method");

            ExpectationsList expectations = new ExpectationsList();

            foreach (object action in recordedActions)
            {
                ProxyMethodExpectationTriplet triplet = action as ProxyMethodExpectationTriplet;
                if (triplet != null)
                {
                    if (MockedObjectsEquality.Instance.Equals(triplet.Proxy, proxy) &&
                        MethodsEquals(method, triplet))
                    {
                        expectations.Add(triplet.Expectation);
                    }
                }
                else                 //Action is another recorder
                {
                    IMethodRecorder innerRecorder = (IMethodRecorder)action;
                    expectations.AddRange(innerRecorder.GetAllExpectationsForProxyAndMethod(proxy, method));
                }
            }
            return(expectations);
        }
Esempio n. 3
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);
        }
        /// <summary>
        /// Gets the all expectations for proxy.
        /// </summary>
        /// <param name="proxy">Mocked object.</param>
        /// <returns>List of all relevant expectation</returns>
        protected override ExpectationsList DoGetAllExpectationsForProxy(object proxy)
        {
            Validate.IsNotNull(proxy, "proxy");

            ExpectationsList expectations = new ExpectationsList();
            foreach (object action in recordedActions)
            {
                ProxyMethodExpectationTriplet triplet = action as ProxyMethodExpectationTriplet;
                if (triplet != null)
                {
                    if (MockedObjectsEquality.Instance.Equals( triplet.Proxy , proxy))
                    {
                        expectations.Add(triplet.Expectation);
                    }
                }
                else //Action is another recorder
                {
                    IMethodRecorder innerRecorder = (IMethodRecorder) action;
                    ExpectationsList expectationsForProxy = innerRecorder.GetAllExpectationsForProxy(proxy);
                    expectations.AddRange(expectationsForProxy);
                }
            }
            return expectations;
        }
        /// <summary>
        /// Gets the all expectations for a mocked object and method combination,
        /// regardless of the expected arguments / callbacks / contraints.
        /// </summary>
        /// <param name="proxy">Mocked object.</param>
        /// <param name="method">Method.</param>
        /// <returns>List of all relevant expectation</returns>
        public override ExpectationsList GetAllExpectationsForProxyAndMethod(object proxy, MethodInfo method)
        {
            Validate.IsNotNull(proxy, "proxy");
            Validate.IsNotNull(method, "method");

            ExpectationsList expectations = new ExpectationsList();
            foreach (object action in recordedActions)
            {
                ProxyMethodExpectationTriplet triplet = action as ProxyMethodExpectationTriplet;
                if (triplet != null)
                {
                    if (MockedObjectsEquality.Instance.Equals( triplet.Proxy , proxy ) &&
                        MethodsEquals(method, triplet))
                    {
                        expectations.Add(triplet.Expectation);
                    }
                }
                else //Action is another recorder
                {
                    IMethodRecorder innerRecorder = (IMethodRecorder) action;
                    expectations.AddRange(innerRecorder.GetAllExpectationsForProxyAndMethod(proxy, method));
                }
            }
            return expectations;
        }