我正在尝试为单元测试创建一个模拟 HttpContextBase。
var fakePrinciple = new GenericPrincipal(
new GenericIdentity(userId),
rolesList.ToArray());
var mockHttpContext = new Mock<HttpContextBase>();
mockHttpContext.Setup(t => t.User).Returns(fakePrinciple);
HttpContextBase mockedContext = mockHttpContext.Object;
单元测试在最后一条语句中失败
抛出异常:System.ArgumentException:无法获取 StrongNameKeyPair 的公钥..
System.Reflection.StrongNameKeyPair.nGetPublicKey(布尔导出,字节 [] 数组,字符串容器) System.Reflection.StrongNameKeyPair.get_PublicKey() System.AppDomain.InternalDefineDynamicAssembly(AssemblyName 名称,AssemblyBuilderAccess 访问,字符串目录,证据证据,PermissionSet requiredPermissions,PermissionSet optionalPermissions, PermissionSet deniedPermissions, StackCrawlMark& stackMark, IEnumerable`1 unsafeAssemblyAttributes) System.AppDomain.DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access) Castle.DynamicProxy.ModuleScope.CreateModule(Boolean signStrongName) Castle.DynamicProxy.ModuleScope.ObtainDynamicModuleWithStrongName() Castle.DynamicProxy.ModuleScope .ObtainDynamicModule(Boolean isStrongNamed) Castle.DynamicProxy.Generators.Emitters.ClassEmitter。CreateTypeBuilder(ModuleScope 模块范围,字符串名称,类型(等等等等)
我用谷歌搜索,这里的建议似乎不起作用(更改 RSA 文件夹安全设置等)http://groups.google.com.br/group/castle-project-users/browse_thread/thread/85685cf32a795158
我认为这是正确的吗,因为HttpContextBase
它System.Web.Abstraction
是已签名程序集的一部分。Moq 实际上会尝试对动态程序集进行签名,但会失败?