chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
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
asked by ramnefors (3.9k points)

3 Answers

0 votes
Hello Mats,

First, which Typemock Isolator version do you use? You can check in Visual-Studio->Typemock->Options->About).

Second, can you please sent us (support@typemock.com) the Typemock Isolator logs?
In Visual-Studio, use Isolator options (Typemock->Options->Visual-Studio->Logs).

I'm sure that the logs will help us solve this issue.
answered by NofarC (4k points)
0 votes
Hi Nofar,

Version is 7.3.0.0.

I have mailed the log.

Thanks for your support /Mats
answered by ramnefors (3.9k points)
0 votes
Hi,

Thanks for the logs, we might have a direction but we need a little more information. Is is possible to create a small project that reproduces this issue? In addition, can you please add the stack trace of the exception?
answered by Elisha (12k points)
...