2009-12-09 Jb Evain <jbevain@novell.com>
[mcs.git] / nunit24 / NUnitMocks / mocks / MockCall.cs
blob2d5ef7fd52aefba971992dd9cd417d929e973a53
1 // ****************************************************************
2 // Copyright 2007, Charlie Poole
3 // This is free software licensed under the NUnit license. You may
4 // obtain a copy of the license at http://nunit.org/?p=license&r=2.4
5 // ****************************************************************
7 using System;
8 using NUnit.Framework;
9 using NUnit.Framework.Constraints;
11 namespace NUnit.Mocks
13 /// <summary>
14 /// Summary description for ExpectedCall.
15 /// </summary>
16 public class MockCall : ICall
18 private MethodSignature signature;
19 private object returnVal;
20 private Exception exception;
21 private object[] expectedArgs;
23 // public static object[] Any = new object[0];
25 public MockCall( MethodSignature signature, object returnVal, Exception exception, params object[] args )
27 this.signature = signature;
28 this.returnVal = returnVal;
29 this.exception = exception;
30 this.expectedArgs = args;
33 public object Call( object[] actualArgs )
35 if ( expectedArgs != null )
37 Assert.AreEqual( expectedArgs.Length, actualArgs.Length, "Invalid argument count in call to {0}", this.signature.methodName );
39 for( int i = 0; i < expectedArgs.Length; i++ )
41 if ( expectedArgs[i] is Constraint )
42 Assert.That( actualArgs[i], (Constraint)expectedArgs[i] );
43 else
44 Assert.AreEqual( expectedArgs[i], actualArgs[i] );
48 if ( exception != null )
49 throw exception;
51 return returnVal;