PageRenderTime 40ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/NUnit/mocks/MockCall.cs

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