/// <summary> /// Resets the state of the factory. /// </summary> /// <remarks> /// Use this method after expected exceptions. /// </remarks> public void ClearExpectations() { _currentMockObjectFactory = new CastleMockObjectFactory(); //ReflectiveMockObjectFactory(); // _expectations = new UnorderedExpectationList(null); _thrownUnexpectedInvocationException = null; FirstIncompleteExpectationException = null; }
public object Create(Type primaryType, MockFactory mockFactory, IMockObjectFactory mockObjectFactory) { if (_name == null) { _name = primaryType.DefaultNameFor(); } DiscoverInterfaces(primaryType); var compositeType = new CompositeType(primaryType, _types.ToArray()); if (compositeType.PrimaryType.IsInterface) { if (_constructorArgs.Length > 0) { throw new InvalidOperationException("Cannot specify constructor arguments when mocking an interface"); } } return(mockObjectFactory.CreateMock( mockFactory, compositeType, _name, _mockStyle ?? MockStyle.Default, _constructorArgs)); }
/// <summary> /// Changes the current MockObjectFactory to a user defined one. /// </summary> /// <param name="factory">The new factory</param> public void ChangeDefaultMockObjectFactory(IMockObjectFactory factory) { if (factory == null) { throw new ArgumentNullException("factory"); } _currentMockObjectFactory = factory; }
/// <summary> /// Allows the default <see cref="IMockObjectFactory"/> to be replaced with a different implementation. /// </summary> /// <param name="factoryType">The System.Type of the <see cref="IMockObjectFactory"/> implementation to use. /// This is expected to implement <see cref="IMockObjectFactory"/> and have a default constructor.</param> public void ChangeDefaultMockObjectFactory(Type factoryType) { if (!typeof(IMockObjectFactory).IsAssignableFrom(factoryType)) { throw new ArgumentException("Supplied factory type does not implement IMockObjectFactory", "factoryType"); } if (factoryType.GetConstructor(Type.EmptyTypes) == null) { throw new ArgumentException("Supplied factory type does not have a default constructor.", "factoryType"); } _currentMockObjectFactory = (IMockObjectFactory)Activator.CreateInstance(factoryType); }