Mocking C # Timer Using Moq

I am trying to create a WPF MVVM View Model with a nested dependency System.Timing.Timer and want to test the view model using Moq.

I wrote a thin shell around the Timer class that has an ITimer interface, but I'm not sure if you really can check the timer tab in the class. Is there a good way to โ€œforceโ€ a fictitious past event? Does anyone else have the best technique?

+6
source share
1 answer

You should check your code in isolation . Otherwise, you donโ€™t know if your code leads as expected, or if there is a side effect in the external dependency. Thus, creating mockup wrappers for external resources (configuration files, timers, etc.) is the only way to separate your SUT from external code.

+3
source

All Articles