简体   繁体   English

内部属性不由NSubstitute处理

[英]Internal properties are not handled by NSubstitute

Suppose, that I've got a following class: 假设我有以下课程:

public abstract class Test
{
    internal abstract int Prop 
    {
        get;
    }
}

Now, I try to make a mock using NSubstitute: 现在,我尝试使用NSubstitute进行模拟:

var mock = Substitute.For<Test>();

But that fails: 但那失败了:

Method 'get_Prop' in type 'Castle.Proxies.TestProxy' from assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=a621a9e7e5c32e69' does not have an implementation. 程序集'DynamicProxyGenAssembly2,Version = 0.0.0.0,Culture = neutral,PublicKeyToken = a621a9e7e5c32e69'中类型'Castle.Proxies.TestProxy'中的方法'get_Prop'没有实现。

I thought of adding NSubstitute to [InternalsVisibleTo] , but unfortunately my tested assembly is signed, NSubstitute is not and Internals cannot be VisibleTo unsigned class. 我想到将NSubstitute添加到[InternalsVisibleTo] ,但不幸的是我测试的程序集已经签名, NSubstitute不是,而Internals不能是VisibleTo unsigned类。

How can I solve this problem? 我怎么解决这个问题?

I've found the solution. 我找到了解决方案。 One has to add the following line to the Assembly.cs file of the assembly, he wants to test ( not the test assembly): 必须将以下行添加到要测试的程序集的Assembly.cs文件中( 而不是测试程序集):

[assembly:InternalsVisibleTo("DynamicProxyGenAssembly2,PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NSubstitute:模拟属性 - NSubstitute: Mocking properties 如何配置NSubstitute NOT调用内部虚拟方法 - How to configure NSubstitute NOT call internal virtual method Nsubstitute 根据对象属性返回不同 - Nsubstitute return different based on the object properties 如何伪造NSubstitute中的对象并忽略其方法的内部实现? - How to fake an object in NSubstitute and ignore its method's internal implementation? 如何使用NSubstitute获取被调用的参数? (或至少断言其属性) - How to get the called parameters with NSubstitute? (or at least assert against their properties) 属性之间的内部关系 - internal relationship between properties 在RazorEngine中使用内部属性 - Using Internal Properties in RazorEngine 忽略 ShouldBeEquivalentTo 中的内部属性 - Ignore internal properties in ShouldBeEquivalentTo 如何为具有内部构造函数的 model 创建测试替身? 使用 c#、xunit 和 nsubstitute - How to create a test double for model that has internal constructor? using c#, xunit and nsubstitute 方法上的多个NSubstitute调用配置访问引用类型参数上的不同属性(以避免NullReferenceException) - Multiple NSubstitute call configurations on method accessing different properties on a reference type parameter (to avoid NullReferenceException)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM