PageRenderTime 29ms CodeModel.GetById 5ms RepoModel.GetById 0ms app.codeStats 0ms

/src/NUnit/mocks/DynamicMock.cs

#
C# | 47 lines | 28 code | 9 blank | 10 comment | 2 complexity | 3fbaebe55cfbad8f8fc776bd10d6e3f7 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. namespace NUnit.Mocks
  8. {
  9. /// <summary>
  10. /// Summary description for DynamicMock.
  11. /// </summary>
  12. public class DynamicMock : Mock
  13. {
  14. private Type type;
  15. private object mockInstance;
  16. public object MockInstance
  17. {
  18. get
  19. {
  20. if ( mockInstance == null )
  21. {
  22. MockInterfaceHandler handler = new MockInterfaceHandler( type, this );
  23. mockInstance = handler.GetTransparentProxy();
  24. }
  25. return mockInstance;
  26. }
  27. }
  28. #region Constructors
  29. public DynamicMock( Type type ) : this( "Mock" + type.Name, type ) { }
  30. public DynamicMock( string name, Type type ) : base( name )
  31. {
  32. // if ( !type.IsInterface )
  33. // throw new VerifyException( "DynamicMock constructor requires an interface type" );
  34. this.type = type;
  35. }
  36. #endregion
  37. }
  38. }