Hi,
Is there a way to mock a private static constructor?
I got an static class with a private static constructor and I don't want to execute it because it configures himself from a configuration within the app.config.
I just want to mock one of is method but the constructor is always call causing the test to throw an exception.
Here an example thats illustrate my problem:
I got a static class like this
I want to be able to test Text property without executing the static constructor.
Is there a way to do this?
Thanks
Is there a way to mock a private static constructor?
I got an static class with a private static constructor and I don't want to execute it because it configures himself from a configuration within the app.config.
I just want to mock one of is method but the constructor is always call causing the test to throw an exception.
Here an example thats illustrate my problem:
I got a static class like this
public
static
class
StaticClassWithPrivateStaticConstructor
{
private
static
string
_text =
"Text"
;
static
StaticClassWithPrivateStaticConstructor()
{
throw
new
Exception();
}
public
static
string
Text
{
get
{
return
_text; }
}
}
I want to be able to test Text property without executing the static constructor.
[TestMethod]
public
void
MockStaticConstructor()
{
Mock.SetupStatic(
typeof
(StaticClassWithPrivateStaticConstructor));
Assert.AreEqual(
"Text"
, StaticClassWithPrivateStaticConstructor.Text);
}
Is there a way to do this?
Thanks