/// ------------------------------------------------------------------------------------
        /// <summary>
        /// Override the Call method so that we can find the return value for the passed-in
        /// parameters.
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns>The return value set up for the passed-in parameters; otherwise
        /// <c>null</c></returns>
        /// ------------------------------------------------------------------------------------
        public override object Call(params object[] parameters)
        {
            // loop over all the set up method calls
            for (int i = 0; i < expectations.Count; i++)
            {
                MockCall mockCall = expectations[i];
                if (parameters.Length != mockCall.ExpectedArgs.Length)
                {
                    continue;
                }

                // Now compare all the parameters
                bool fFoundAllParams = true;
                for (int j = 0; j < parameters.Length; j++)
                {
                    IConstraint constraint = mockCall.ExpectedArgs[j];
                    fFoundAllParams = (fFoundAllParams && constraint.Eval(parameters[j]));
                }

                if (fFoundAllParams)
                {
                    return(mockCall.Call(signature.methodName, parameters));
                }
            }
            return(null);
        }
Example #2
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Adds a fixed return value for the passed in args.
 /// </summary>
 /// <param name="methodName">Name of the method/property</param>
 /// <param name="returnVal">Return value</param>
 /// <param name="args">Input parameters</param>
 /// ------------------------------------------------------------------------------------
 public virtual void SetupResultForParams(string methodName, object returnVal,
                                          params object[] args)
 {
     AddMethodWithoutExpecations(
         new MethodSignature(Name, methodName, MockCall.GetArgTypes(args)),
         typeof(CallMethodWithParams), returnVal, null, args);
 }
Example #3
0
        public virtual object Call(params object[] parameters)
        {
            MockCall mockCall = expectations[timesCalled];

            timesCalled++;
            return(mockCall.Call(signature.methodName, parameters));
        }
Example #4
0
 public virtual void ExpectAndReturn(int nCount, string methodName, object result, params object[] args)
 {
     for (int i = 0; i < nCount; i++)
     {
         addExpectation(methodName,
                        new MockCall(new MethodSignature(Name, methodName, MockCall.GetArgTypes(args)), result, null, args));
     }
 }
Example #5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Override the Call method so that we can wrap around if called to often
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        public override object Call(params object[] parameters)
        {
            MockCall mockCall = expectations[timesCalled];

            timesCalled++;
            if (timesCalled >= expectations.Count)
            {
                timesCalled = 0;
            }
            return(mockCall.Call(signature.methodName, parameters));
        }
Example #6
0
        [Test] public void ArgTypes()
        {
            MockCall call = new MockCall(
                new MethodSignature("mymock", "call", new Type[] { typeof(int), typeof(string), typeof(bool[]) }),
                null, null,
                new object[] { 1, "string", new bool[] { true, false } });

            Assertion.AssertEquals("Parameter one", typeof(int).FullName, call.ArgTypes[0]);
            Assertion.AssertEquals("Parameter two", typeof(string).FullName, call.ArgTypes[1]);
            Assertion.AssertEquals("Parameter three", typeof(bool[]).FullName, call.ArgTypes[2]);
        }
Example #7
0
        protected void addExpectation(string methodName, MockCall call)
        {
            MethodSignature signature = new MethodSignature(Name, methodName, call.ArgTypes);
            IMethod         method    = getMethod(signature);

            if (method == null)
            {
                method = new Method(signature);
                methods[methodName] = method;
            }
            method.SetExpectation(call);
        }
Example #8
0
 public virtual void SetExpectation(MockCall aCall)
 {
     expectations.Add(aCall);
 }
Example #9
0
 public void Add(MockCall aCall)
 {
     sequence.Add(aCall);
 }
 public virtual void SetExpectation(MockCall call)
 {
     this.call = call;
 }
Example #11
0
 public virtual void ExpectAndThrow(string methodName, Exception e, params object[] args)
 {
     addExpectation(methodName,
                    new MockCall(new MethodSignature(Name, methodName, MockCall.GetArgTypes(args)), null, e, args));
 }
Example #12
0
 public virtual void SetExpectation(MockCall expectation)
 {
     this.expectation = expectation;
 }
Example #13
0
			public void Add(MockCall aCall)
			{
				sequence.Add(aCall);
			}
Example #14
0
		public virtual void SetExpectation(MockCall aCall)
		{
			expectations.Add(aCall);
		}
		public virtual void SetExpectation(MockCall call)
		{
			this.call = call;
		}
Example #16
0
		[Test] public void ArgTypes()
		{
			MockCall call = new MockCall(
				new MethodSignature("mymock", "call", new Type[] {typeof(int), typeof(string), typeof(bool[]) }),
				null, null,
				new object[] {1, "string",	new bool[] {true, false}});
			Assertion.AssertEquals("Parameter one", typeof(int).FullName, call.ArgTypes[0]);
			Assertion.AssertEquals("Parameter two", typeof(string).FullName, call.ArgTypes[1]);
			Assertion.AssertEquals("Parameter three", typeof(bool[]).FullName, call.ArgTypes[2]);
		}
Example #17
0
		public virtual void SetExpectation(MockCall expectation)
		{
			this.expectation = expectation;
		}
Example #18
0
		protected void addExpectation(string methodName, MockCall call)
		{
			MethodSignature signature = new MethodSignature(Name, methodName, call.ArgTypes);
			IMethod method = getMethod(signature);
			if (method == null)
			{
				method = new Method(signature);
				methods[methodName] = method;
			}
			method.SetExpectation(call);
		}