简体   繁体   English

对于内部方法,测试用例方法无法访问

[英]for internal method test case method is not accessible

I am writing unit test case for my internal method. 我正在为我的内部方法编写单元测试用例。 I have made necessary changes in AssemblyInfo.cs of my mail class project [assembly: InternalsVisibleTo("myunitest_assemblyname")] 我在我的邮件类项目的AssemblyInfo.cs中进行了必要的更改[assembly:InternalsVisibleTo(“myunitest_assemblyname”)]

now i can access my internal method in unit test case method. 现在我可以在单元测试用例方法中访问我的内部方法。 but when i compile the code it is giving an error as below 但是当我编译代码时,它给出了如下错误

Error 1 'main class project name' does not contain a definition for 'Process' and no extension method 'Process' accepting a first argument of type 'main class project name' could be found (are you missing a using directive or an assembly reference?) 错误1'主类项目名'不包含'Process'的定义,并且没有扩展方法'Process'接受类型'main class project name'的第一个参数可以找到(你是否缺少using指令或程序集引用?)

my main class has strong name. 我的主要班级有很强的名字。

it would be great if some one point where i am missing. 如果我错过了一点,那就太好了。

main class structure 主类结构

namespace Renewals
{
    public class StateProcessor
    {
        internal virtual void PutEmailInQueue(DataTable dataTable)
        {    
        }
    }
}

//test class structure //测试类结构

namespace Renewals.Tests.Unit
{
    [TestClass]
    public class StateProcessorTest
    {

        [TestMethod]
        public void PutEmailInQueueTest()
        {
            DateTime processingDate = Convert.ToDateTime("27-feb-2013"); ;

            StateProcessor stateProcess = new StateProcessor(processingDate);
            stateProcess.PutEmailInQueue(new DataTable());
        }
    }
}

PutEmailInQueue - this method giving me problem. PutEmailInQueue - 这个方法给我带来了问题。

you wrote that your class use strong name. 你写道你的班级使用强名称。

I think you have to modify your InternalsVisibleTo() statement with the public key. 我认为你必须使用公钥修改你的InternalsVisibleTo()语句。

eg: [assembly: InternalsVisibleTo("friend_signed_B, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e3aedce99b7e10823920206f8e46cd5558b4ec7345bd1a5b201ffe71660625dcb8f9a08687d881c8f65a0dcf042f81475d2e88f3e3e273c8311ee40f952db306c02fbfc5d8bc6ee1e924e6ec8fe8c01932e0648a0d3e5695134af3bb7fab370d3012d083fa6b83179dd3d031053f72fc1f7da8459140b0af5afc4d2804deccb6")] 例如:[组件:InternalsVisibleTo( “friend_signed_B,公钥= 0024000004800000940000000602000000240000525341310004000001000100e3aedce99b7e10823920206f8e46cd5558b4ec7345bd1a5b201ffe71660625dcb8f9a08687d881c8f65a0dcf042f81475d2e88f3e3e273c8311ee40f952db306c02fbfc5d8bc6ee1e924e6ec8fe8c01932e0648a0d3e5695134af3bb7fab370d3012d083fa6b83179dd3d031053f72fc1f7da8459140b0af5afc4d2804deccb6”)]

for more informations see: http://msdn.microsoft.com/en-us/library/bb385180.aspx 有关更多信息,请参阅: http//msdn.microsoft.com/en-us/library/bb385180.aspx

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM