sgtHoloToaster/AutoMoqSlim

Cannot set instance to null

Opened this issue · 0 comments

An exception is thrown when trying to create an instance which has a dependency set to null:

var mocker = new AutoMoqer();
mocker.SetInstance<SomeDependency>(null);
mocker.Create<SomeClassWithSomeDependency>(); // here the exception is thrown

Exception details:

Message: 
    Castle.DynamicProxy.InvalidProxyConstructorArgumentsException : Can not instantiate proxy of class: ZTool.Data.DataContext.
    Could not find a parameterless constructor.
  Stack Trace: 
    ProxyGenerator.CreateClassProxyInstance(Type proxyType, List`1 proxyArguments, Type classToProxy, Object[] constructorArguments)
    ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors)
    CastleProxyFactory.CreateProxy(Type mockType, IInterceptor interceptor, Type[] interfaces, Object[] arguments) line 62
    Mock`1.InitializeInstance() line 311
    Mock`1.OnGetObject() line 325
    Mock.get_Object() line 179
    AutoMoqer.<GetParameters>b__9_0(ParameterInfo p)
    SelectArrayIterator`2.ToArray()
    Enumerable.ToArray[TSource](IEnumerable`1 source)
    AutoMoqer.GetParameters(ConstructorInfo constructor)
    AutoMoqer.Create(Type type)
    AutoMoqer.Create[T]()