I have to write some tests using moq framework (https://code.google.com/p/moq/). I want to check if some value can be read correctly from a telerik textbox in some ASP.NET application. Therefore I want to mock the telerik text box and give this mock as a parameter to the SUT's method to check if it is read correctly.
Consider:
var telerikFake = new Mock<RadNumericTextBox>();
telerikFake.Setup(x => x.Text).Returns("23,456");
var result = telerikFake.Object; //The exception comes from inside the telerikFake.Object property implementation
Accessing the telerikFake.Object property gives a NullReferenceException with this stack trace:
at Castle.DynamicProxy.AttributeUtil.<GetNonInheritableAttributes>d__0.MoveNext()
at Castle.DynamicProxy.Contributors.ClassProxyInstanceContributor.Generate(ClassEmitter class, ProxyGenerationOptions options)
at Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateType(String name, Type[] interfaces, INamingScope namingScope)
at Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateCode(Type[] interfaces, ProxyGenerationOptions options)
at Castle.DynamicProxy.DefaultProxyBuilder.CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options)
at Castle.DynamicProxy.ProxyGenerator.CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options)
at Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors)
at Moq.Proxy.CastleProxyFactory.CreateProxy[T](ICallInterceptor interceptor, Type[] interfaces, Object[] arguments)
at Moq.Mock`1.<InitializeInstance>b__0()
at Moq.PexProtector.Invoke(Action action)
Do you have any hints under what circumstances the moq frameworks Mock.Object method leads to this error?
I found a ticket within the MoQ issue list: http://code.google.com/p/moq/issues/detail?id=326 . Are there any developers enabled to fix this issue soon? The ticket was created in 2011.
Regards, Michael