Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the Compiler Error CS0122 - 'member' is inaccessible due to its protection level - while trying to access a class in a different project

I am trying to get to grips with NUnit - i have installed it and run it successfully within one project. I want to keep productioncode seperate from testcode, so i write tests in a different project. The Test Project Links to the original project. (IDE C# Express 2010)

My Testcode looks like this:

using NUnit.Framework;

namespace test.Import
{
    [TestFixture]
    class XMLOpenTest
    {
        [Test]
        public void openNotAPath(){
            try
            {
                production.Import.XMLHandler.open("Not A Path");
            }
            catch
            {
                Assert.Fail("File Open Fail");
            }
        }
    }
}

I know i could resolve this by making the production.Import.XMLHandler Class public, but i dont want to change my productioncode to allow this kind of testing.

How do i get around this? Can i make changes to my testcode? Are there other good ways to seperate test and production code in two projects? Are there ressources for dummys on the internet?

like image 494
Johannes Avatar asked Dec 29 '22 04:12

Johannes


1 Answers

This is usually solved using InternalsVisibleToAttribute. See this and this.

like image 139
Anton Gogolev Avatar answered Feb 06 '23 13:02

Anton Gogolev