/src/NUnit/mocks/MockCall.cs
C# | 54 lines | 37 code | 8 blank | 9 comment | 6 complexity | cbb26b1c671af276a2aa0df17da42498 MD5 | raw file
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 5// **************************************************************** 6 7using System; 8using NUnit.Framework; 9using NUnit.Framework.Constraints; 10 11namespace NUnit.Mocks 12{ 13 /// <summary> 14 /// Summary description for ExpectedCall. 15 /// </summary> 16 public class MockCall : ICall 17 { 18 private MethodSignature signature; 19 private object returnVal; 20 private Exception exception; 21 private object[] expectedArgs; 22 23// public static object[] Any = new object[0]; 24 25 public MockCall( MethodSignature signature, object returnVal, Exception exception, params object[] args ) 26 { 27 this.signature = signature; 28 this.returnVal = returnVal; 29 this.exception = exception; 30 this.expectedArgs = args; 31 } 32 33 public object Call( object[] actualArgs ) 34 { 35 if ( expectedArgs != null ) 36 { 37 Assert.AreEqual( expectedArgs.Length, actualArgs.Length, "Invalid argument count in call to {0}", this.signature.methodName ); 38 39 for( int i = 0; i < expectedArgs.Length; i++ ) 40 { 41 if ( expectedArgs[i] is IResolveConstraint ) 42 Assert.That( actualArgs[i], (IResolveConstraint)expectedArgs[i] ); 43 else 44 Assert.AreEqual( expectedArgs[i], actualArgs[i] ); 45 } 46 } 47 48 if ( exception != null ) 49 throw exception; 50 51 return returnVal; 52 } 53 } 54}