public void SetUp() { invokable = new MockInvokable(); adapter = new ProxyInvokableAdapter(typeof (ProxiedInterface), invokable); transparentProxy = (ProxiedInterface) adapter.GetTransparentProxy(); }
/// <summary> /// Creates a mock of the specified type(s). /// </summary> /// <param name="mockery">The mockery used to create this mock instance.</param> /// <param name="typesToMock">The type(s) to include in the mock.</param> /// <param name="name">The name to use for the mock instance.</param> /// <param name="constructorArgs">Constructor arguments for the class to be mocked. Only valid if mocking a class type.</param> /// <returns> /// A mock instance of the specified type(s). /// </returns> public object CreateMock(Mockery mockery, CompositeType typesToMock, string name, object[] constructorArgs) { Type mockedType = typesToMock.PrimaryType; if (mockedType.IsClass) { throw new NotSupportedException(GetType().Name + " does not support mocking of classes."); } if (typesToMock.AdditionalInterfaceTypes.Length > 0) { throw new NotSupportedException(GetType().Name + " does not support mocking of multiple interfaces."); } Type facadeType = facadeFactory.GetType(typeof (IMockObject), mockedType); var mockObject = Activator.CreateInstance( GetMockedType( Id(new[] {mockedType, typeof (IMockObject)}), mockedType), new object[] {mockery, mockedType, name}) as MockObject; var adapter = new ProxyInvokableAdapter( facadeType, new ProxiedObjectIdentity(mockObject, new Invoker(typeof (IMockObject), mockObject, mockObject))); return adapter.GetTransparentProxy(); }