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