Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Any docs for NCrunch's AppDomain setup? (Ref running tests in Medium Trust from BoxBinary.com)
alexnorcliffe
#1 Posted : Monday, October 24, 2011 9:44:29 AM(UTC)
Rank: Member

Groups: Registered
Joined: 9/2/2011(UTC)
Posts: 23

Thanks: 1 times
Was thanked: 5 time(s) in 5 post(s)
I recently implemented a method for running tests in a Medium Trust context (part three here (- BROKEN LINK -))

It's working great for us in R#, NUnit and TeamCity's runners.

This involves setting up a new AppDomain loading the PermissionSet from the web_mediumtrust.config, and invoking the test method in the other AppDomain. It's not feature-complete (I don't attempt compatibility yet with passing in parameterised tests) but for parameterless tests it works great.

I'm having a prob with NCrunch though, in that I'm unsure how to determine the assembly resolving policy of NCrunch and my partial-trust AppDomain cannot resolve referenced assemblies because the AppDomain.CurrentDomain.BaseDirectory of the NCrunch runner's domain only contains the dll of the actual test project (as would be expected).

I can turn on "copy all referenced assemblies to workspace" in the NCrunch settings, but this has all the usual downsides, and it would be far better instead to know what NCrunch is doing already to resolve referenced assemblies so I can detect and take advantage of the same logic. Providing, of course, that logic works in partial trust :)

I'll be blogging about NCrunch in the near future, and would be the icing on the cake to reference back to my Medium Trust posts and say this works there too.

BTW, if you want to collaborate on getting NCrunch to support running tests in Medium Trust, please do let me know.
Remco
#2 Posted : Monday, October 24, 2011 9:08:40 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Cross appdomain/process tests do generally tend to suffer from the fact that NCrunch artificially wires together its test domains from files that can exist in separate locations.

There is some documentation in the wiki that briefly describes how you can set up your own appdomain by using references to assemblies already loaded into the NCrunch test appdomain. You can rely on NCrunch to have loaded all required references into your appdomain before any tests are run.

In terms of running tests with medium trust, this isn't really an area that's been well tested with NCrunch (to my knowledge), though in theory sandboxing your own application domain would allow you to do this. An unfortunate side-effect is that you won't have any code coverage from NCrunch for code that is executing inside your own application domain or process, as it doesn't have control over how this domain is managed.

I admit that I haven't come across any situations before where people had a need to do something like this, so I'm guessing it's to test some kind of application specific functionality that needs to make use of .NET security features. Is the scope for this kind of test very large for you?
alexnorcliffe
#3 Posted : Monday, October 24, 2011 9:16:41 PM(UTC)
Rank: Member

Groups: Registered
Joined: 9/2/2011(UTC)
Posts: 23

Thanks: 1 times
Was thanked: 5 time(s) in 5 post(s)
Going off the feedback I've got for the post series so far, it's not an area that's well exercised full stop really. I devised the solution to avoid us having extension methods / library usages creep into our codebase that unwittingly don't support Medium Trust (e.g., the Clone() method I use as an example in the post series was taken from perhaps the most simple yet major stumbling block in getting Fluent NHibernate to work in Medium Trust when using SubclassMaps)

Our Framework needs testable support for Medium Trust (at least, the default configuration of it) for users using our Framework on shared hosting, so that it's not a case of us writing & running integration tests of the UI simply to assert compatibility otherwise we'd have to have massive code coverage in our integration tests which is just not feasible with our current resource levels (OSS, free & MIT)

I'll take a look at grabbing the assembly references from the existing NCrunch AppDomain, although sadly I think that's not going to be practical due to the restrictions in the secondary domain - but I'll let you know how I get on.

Cheers
Alex
Remco
#4 Posted : Tuesday, October 25, 2011 8:16:38 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Thanks, I'd like to hear how you get on with this. I've made a note to have a deeper look into making this possible with NCrunch, though it's hard to make any commitments on whether I'll be able to do so at this point in time :)

Cheers,

Remco
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.042 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download