I want to unit test a class that reads the power information.
I have a private readonly variable which i assign a value from System.Windows.SystemInformation.PowerStatus and i can use reflection to change this no problem but…
System.Windows.PowerStatus does not have a public constructor and won’t let me inherit from it to derive a testPowerStatus class i can use with my tests.
I want to be able to override the getter for BatteryLifePercent and BatteryLifeRemaining property so i can test that the correct behavior happens when these are certain values.
Is there anyway i can do this? or is this impossible?
The “right” way to do this is to create an abstraction layer. You should create a IPowerInfoProvider interface, and then create a stub implementing the interface for tests, and another implementation providing real power info.
Your BL should only know about the IPowerInfoProvider interface.