Note that there are some explanatory texts on larger screens.

plurals
  1. PORunning NUnit integration tests with different credentials
    primarykey
    data
    text
    <p>I am running integration tests with C#, NUnit, and SQL Server 2008 r2 dev edition database. Setting up my fixture includes creating a new database and loading test data, so I need dbo privileges for that.</p> <p>However, I want to run the tests themselves with less privileges. I have another AD account I can authenticate with, and I do can run some T-SQL using impersonation as described here: <a href="http://support.microsoft.com/?scid=306158" rel="nofollow">http://support.microsoft.com/?scid=306158</a>, as follows:</p> <pre><code>public static bool ExecuteFileAs(string fileName, string connectionString, string user, string domain, string password) { using(new Impersonator(user, domain, password)) { using(var connection = new SqlConnection(connectionString)) { connection.Open(); return SqlFileExecuter.RunSql(connection, fileName); } } } </code></pre> <p>When I hit the breakpoint inside this code snippet, and start the Profiler, I see another connection open with the username I submitted to it, so impersonation really works. Unfortunately, I cannot run all the tests impersonating at the end of fixture set up, and ending it at fixture tear down. At the end of set up I execute the following:</p> <pre><code> impersonator = new Impersonator("username", "DOMAIN", "pwd"); </code></pre> <p>As soon as the first unit test begins, I am getting this error listing one of the dlls used in this test: <code>System.IO.FileLoadException: Could not load file or assembly '...' or one of its dependencies. Access is denied.</code> I have granted that other account full access to the directory with all my binaries, which did not help.</p> <p>Any suggestions are welcome.</p> <p>Edit: my workstation is still running XP.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload