I have a WPF UserControl that wraps the WebBrowser control to provide a "BindableSource" property. When BindableSource is updated, my wrapper control adds a LoadCompleted event handler and sets the Source property of the WebBrowser. When the LoadCompleted handler is fired, my control invokes script on my page to update the contents based on data in my ViewModel.
I am trying to write a unit test for my UserControl that does the following:
- Mocks my ViewModel to return the data that needs to be sent to the page (we are using Moq)
- Since I can't mock the WebBrowser, I am trying to load a page with the script functions that I need. The idea is that when the script is invoked on my "fake" page, it will simply assign the data passed to elements on the page, which can be examined by the unit test via the WebBrowser.Document property
My problem is that the LoadCompleted event is never fired. I've read elsewhere that the LoadCompleted event is not fired unless the WebBrowser is actually visible. My experience confirms this. If I wait long enough (and add code that processes the pending events), the readyState of the document eventually gets set to "interactive" but it is never completely loaded.
How can I make the WebBrowser completely load the page in a unit test?
Thanks