Hi,
I am trying to extend my unit tests with robustness tests of some key windows forms.
So far one form worked OK, on the second one I get the following exception.
System.InvalidOperationException: DragDrop registration did not succeed. ---> System.Threading.ThreadStateException: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it.
The unit test code, somewhat simplified is:
[TestMethod]
public void RandomLeftClickTest()
{
// Model in the MVC pattern
Assessment assessment = Assessment.GenerateTestContent();
DsAssessment dsAssessment = new DsAssessment(assessment);
// Fake items normally supplied by the main form
UltraToolbarsManager toolbar = Isolate.Fake.Instance<UltraToolbarsManager>();
UltraSpellChecker spellChecker = Isolate.Fake.Instance<UltraSpellChecker>();
Boilerplate boilerplate = Isolate.Fake.Instance<Boilerplate>();
// Create the viewer and controller in the MVC pattern
dsAssessment.StartEditSession(toolbar, spellChecker, boilerplate);
// Get the viewer (editor form) and show it
SpiceEditor viewer = (SpiceEditor) dsAssessment.Viewer;
viewer.Show();
viewer.Refresh();
// TODO: add actual test here
}
How do I handle thread states of unit tests when run?
If I step through the UT in debug mode, no exceptions are raised.
/Mats