DockManager and NUnit

Docking/MDI for Windows Forms Forum

Posted 18 years ago by Jake Pearson - Software Developer, Alion Science and Technology
Avatar
Hi,
I am adding in some unit tests (using NUnit) that create the various editors of my application. To make the tests as close to reality as possible, I want to host each editor in a DocumentWindow in a DockManager. The problem is that when I activate the DocumentWindow an InvalidOperationException is thrown with the message "Drag drop registration failed". The same exception happens in the SyntaxEditor. I was able to avoid the exception with some code like this in my SyntaxEditor override:
        public static bool Testing = false;
        public override bool AllowDrop
        {
            get { return base.AllowDrop; }
            set
            {
                if (Testing)
                {
                    return;
                }
                base.AllowDrop = value;
            }
        }
Overriding, various parts of the DockManager doesn't really seem possible. Is there another work around that you know of or could you add in something like it to TabbedMdiWindow for the next release?

thanks,
Jake

Comments (4)

Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Jake,

Yeah that message is something that has always seemed to have plagued the .NET framework. I've seen it even happen on some of the native controls. If you google it, there is advice on using an STAThread attribute for your app. Is that something you can do?


Actipro Software Support

Posted 18 years ago by Jake Pearson - Software Developer, Alion Science and Technology
Avatar
I already have STAThread on my app, but I think NUnit creates an AppDomain that it runs the tests in. If I have to, I guess I can fiddle around with the source of NUnit but I would rather not if possible.
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I'm not really what we can do in this instance since it probably is a core .NET framework issue dealing with that attribute. When you google that message you get a ton of hits and from everything that I've read, it indicates to set that attribute on the application.

Were you able to check and see if NUnit does in fact set it or not?


Actipro Software Support

Posted 18 years ago by Greg Pattison - Software Engineer, Burke Porter Machinery
Avatar
I ran into the a problem that was close to yours. Not really sure what is going on, but the bulk of the information on the web indicates that the thread accessing the control must be executed with the ApartmentState set to STA. So I looked at the nunit 2.2.8 source code and found that they check for a configuration setting in the application program's .config file to see what the TestRunnerThread ApartmentState should be when run. It defaults to MTA if no configuration entry is found.

So, what I did, is added the configuration entry that nunit requires to my application's .config file.

See http://www.codeproject.com/dotnet/config.asp for information on how to add an app.config for you application.

Hope this helps.

Below is how my app.config file looked after I added the required entry.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="NUnit">
<section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>

<NUnit>
<TestRunner>
<add key="ApartmentState" value="STA" />
</TestRunner>
</NUnit>
</configuration>

[Modified at 10/17/2006 02:28 PM]
The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.