0

I have an internal class with multiple methods inside it, I want to write Nunit for each method, how can I call the method? Note: this method has interface.

Sample Code:

internal class Sample : ISsample
{
    public string getValueabc(int a, int b)
    {
        String h="Value:"+a+"and another:"+b;
        return h;
    }
}
Dmitry
  • 13,797
  • 6
  • 32
  • 48
ravi
  • 188
  • 1
  • 14
  • Typically you don't test internal or private nested classes. Another alternative to using `InternalsVisibleToAttribute` is to put the unit test inside the project itself, and surround it with something like `#if TEST` so that the testing code doesn't get compiled to release. – Ron Beyer Sep 29 '15 at 20:56
  • It's all Services and each service has to be tested individually using Nunit, created a test project and started writing the Nunit's. It will be good if someone can help me with it – ravi Sep 29 '15 at 21:16

1 Answers1

0

You can return this class from other publicly available method like this:

public class MySampleFactory
{
    public ISample CreateSample()
    {
        return new Sample();
    }
}

//Inside a Unit Test
ISample sample = mySampleFactory.CreateSample();
sample.getValueAbc();
Vova
  • 1,356
  • 1
  • 12
  • 26