C# Unit Testing: How do I set a Lazy<T>.ValueCreated to false?

Posted by michael paul on Stack Overflow See other posts from Stack Overflow or by michael paul
Published on 2011-01-11T23:24:42Z Indexed on 2011/01/11 23:53 UTC
Read the original article Hit count: 138

Filed under:
|
|
|

Basically, I have a unit test that gets a singleton instance of a class. Some of my tests required me to mock this singleton, so when I do Foo.Instance I get a different type of instance.

The problem is that my checks are passing individually, but failing overall because one test is interfering with another.

I tried to do a TestCleanup where I set: Foo_Accessor._instance = null; but that didn't work. What I really need is Foo_Accessor._instance.IsValueCreated = false; (_instance is a Lazy).

Any way to unset the Lazy object that I didn't think of?

© Stack Overflow or respective owner

Related posts about c#

Related posts about unit-testing