Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3788218
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:57:51+00:00 2026-05-19T11:57:51+00:00

I like to be able to run MSTest in partial trust. This would allow

  • 0

I like to be able to run MSTest in partial trust. This would allow me to configure what the code, that my unit tests call, can and can’t do.

The problem I’m trying to solve is to let my automated (unit) tests fail when things like the file system, database, system clock and other external resources are used. By running in partial trust I can configure what type of actions the AppDomain may and may not do. This allows me to detect places in the code that do not correctly abstract away the used resources.

If there are other ways of achieving this, please let me know.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T11:57:51+00:00Added an answer on May 19, 2026 at 11:57 am

    Unfortunately, MSTest does not have a built-in mechanism for this, and changes to CAS policy application in .NET 4.0 have severely restricted the supported approaches for this.

    The simplest approach to this would be to restrict the CAS permission grant on the AppDomain created by MSTest to run the tests in a particular test assembly. However, current versions of MSTest do not allow interception and/or customization of AppDomain creation. We can’t work around this by adding code to an AssemblyInitialize method since AppDomain policy changes made after code starts running in the AppDomain have no effect.

    This basically leaves us with a single supported mechanism for applying CAS permission restrictions for testing: applying a PermissionSet.PermitOnly from within a test method or code that invokes the test method. e.g.:

    [TestMethod]
    public void SomeTest()
    {
        SomeStaticTestUtilityClass.TargetPermissionSet.PermitOnly();
    
        // Run the rest of your test code here.
    }
    

    It may be possible to do this via custom test attributes using the approach described at http://blogs.msdn.com/b/vstsqualitytools/archive/2009/09/04/extending-the-visual-studio-unit-test-type-part-1.aspx. However, I haven’t tested this, and I’m not sure if the test method invocation mechanism would allow applying the PermitOnly in a manner that would result in it’s being present on the call stack for the tested code.

    If you have a lot of these to author and use of a custom ITestMethodInvoker either doesn’t work or is otherwise unsuitable, another option would be to use a post-compiler like PostSharp to insert the PermitOnly calls.

    If none of this suits, and you’re not married to MSTest, you might also want to consider changing your test framework to one that is more easily extensible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to be able to know, in run-time in my code, how
Basically I would like to tell MSTest to execute a bit of code before
I would like to be able to add a message to a unit test,
I'd like to be able to run a script that parsed through the twitter
I would like to be able to run ruby and perl scripts from build.xml
I would like to be able to run an on demand backup of a
I would like to be able to have a user be able run through
I would like to be able to run a function from the directory where
I'm creating a library that includes both Clojure and Java code, and would like
I'd like to be able to run an already parameterized query from within the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.