Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InternalsVisibleTo not working for MSTest

I have looked into google and stack over flow and read all the posts regarding how to get InternalsVisibleTo to work.

But its not working for me.

Please do not down vote this question because I have tried my best to look and implement the answers on the forums..

My code is as follows:

* Inside TestInternal project *

namespace TestInteral
{
    [TestClass]
    public class MyProviderTest
    {
        [TestMethod]
        public void TestBar()
        {
            bool retval = false;

            retval = new MyProviderClass().Bar();

            Assert.AreEqual(true,retval);
        }

    }
}

* Inside Provider Project *

[assembly: InternalsVisibleTo("TestInternal")]
namespace Provider
{

    public class MyProviderClass
    {
        internal bool Bar()
        {
            return true;

        }

        private void UseBar()
        {
            bool retval = Bar();

        }
    }
}

I am getting the following error in my test class.

Error 1 'Provider.MyProviderClass' does not contain a definition for 'Bar' and no extension method 'Bar' accepting a first argument of type 'Provider.MyProviderClass' could be found (are you missing a using directive or an assembly reference?)

Please let me know how I could use the InternalsVisibleTo correctly so I could correctly test the Internal method in the MyProviderClass.

Thanks

like image 286
dotnet-practitioner Avatar asked May 14 '12 17:05

dotnet-practitioner


People also ask

How do I find my public key for InternalsVisibleTo?

In the "Solution explorer" click on your project assembly name, and then head to "Tools > Get PublicKey".

What is InternalsVisibleTo in C#?

From the documentation, the assembly-level InternalsVisibleTo attribute: Specifies that all nonpublic types in an assembly are visible to another assembly. This attribute was introduced in C# 2.0, and allows you to specify other assemblies that can see all types and members marked “internal”.


1 Answers

Assuming you have just copied and pasted your EXACT code into the question, this is a simple typo. I noticed your namespace on the test assembly is TestInteral with no 'N'. And your InternalsVisibleTo declaration has the last 'N':

[assembly: InternalsVisibleTo("TestInternal")]

That's probably all it is.

like image 183
Steve Danner Avatar answered Sep 30 '22 03:09

Steve Danner