I have a class
like this: Notice it does not have a default constructor
either and inherits from some other class
public class IdentifierManager : IdentifierManagerBase
{
public IdentifierManager(ILogger<IdentifierManager> logger, IMemoryCache cache)
{
this.logger = logger;
this.cache = cache;
cacheSemaphore = new SemaphoreSlim(1, 1);
}
protected override string DoSomething()
{
return "This is the method I want to test...";
}
}
So I want to write a unit test
for that DoSomething()
method.
And here is the class
it inherits from:
public abstract class IdentifierManagerBase : IIdentifierManager
{
// bunch of other public methods
protected abstract string DoSomething();
}
So how do I test that protected DoSomething()
method?
I saw this answer Unit testing C# protected methods and this blog post https://codingjourneyman.com/2015/07/27/unit-tests-and-protected-methods/
and tried to do something like this: but having trouble with constructors
public class IdentifierManager_Exposed: IdentifierManager
{
public string DoSomething()
{
return base.DoSomething();
}
}
and then in the test if my test class is inheriting
from the IdentifierManager_Exposed
one
but like I said I can't figure out how to deal with the constructor parameters.