Testing .NET code in a partial trust environment

I want to test the behavior of a certain part of .NET code in a partial trust environment. What is the fastest way to configure this? Feel free to assume that I (and other readers) are complete CAS noobs.

@Nick: Thanks for the answer. Alas, this tool is not explicitly used for unmanaged code. I did not say β€œmanaged” in my question and should not have assumed that people would derive it from the β€œ.NET” tag.

+5
source share
5 answers

This is a great question, especially in terms of TDD and code verification in different trust scenarios.

I think I would come close to this, it would be something like:

  • AppDomain TDD-, AppDomain.CreateDomain(), PermissionSet. PermissionSet , .

  • , ,

  • / .. ,

- . .

+3

, , :

"...", , .

+3

Microsoft Application Verifier.

AppVerifier :

  • API:     ( API TerminateThread., API- Thread Local Storage (TLS). O (, VirtualAlloc, MapViewOfFile).
  • .
  • .
  • .
  • .
  • .
  • , , .
  • , .
  • .
+1

.NET Framework Configuration Tool. .NET SDK, ... http://msdn.microsoft.com/en-us/library/2bc0cxhc.aspx

Runtime 3 : Enterprise, Machine User. , . , .NET- , , , Internet. , ( ), .

, .

, , , . , _All _ Code_. , New...

, PartialTrustGroup, "" .

, . PartialTrust , URL, . , URL- ... ://C:////partialtrust/*

* - , . "" .

. . , Java-. "" "".

"". "" , , "".

.NET, URL-, , . SecurityExceptions, , .

, . , .

+1

I just posted an article on my blog called Partial Trust Testing from xUnit.net . It describes the infrastructure based on xUnit.net that we use in the Entity Framework team to implement code under average trust.

Here is an example of its use.

public class SomeTests : MarshalByRefObject
{
    [PartialTrustFact]
    public void Partial_trust_test1()
    {
        // Runs in medium trust
    }
}

// Or...

[PartialTrustFixture]
public class MoreTests : MarshalByRefObject
{
    [Fact]
    public void Another_partial_trust_test()
    {
        // Runs in medium trust
    }
}
+1
source

All Articles