我必须使用moq框架(https://code.google.com/p/moq/)编写一些测试。我想检查是否可以从某些ASP.NET应用程序中的telerik文本框中正确读取某些值。因此,我想模拟telerik文本框并将此模拟作为参数提供给SUT的方法,以检查它是否被正确读取。
考虑:
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
访问telerikFake.Object属性会给出带有此堆栈跟踪的NullReferenceException:
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)
在moq框架Mock.Object方法导致此错误的情况下,您有任何提示吗?
我在MoQ问题列表中找到了一张票:http://code.google.com/p/moq/issues/detail?id=326。是否有任何开发人员能够尽快解决此问题?这张票是在2011年创建的。
此致 迈克尔