C# Unit Testing: How do I set a Lazy<T>.ValueCreated to false?
- by michael paul
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?