title: Unit Testing Sitecore LicenseManager
body: <p>I'm trying to unit test with the Sitecore api.
  I got a unit test project (MSTest) in my solution in Visual Studio. I copied the configSections, connectionStrings, appSettings, sitecore, log4net elements from my web.config to my app.config.</p>
  
  <p>The test I'm trying to run is:</p>
  
  <pre><code>Sitecore.Context.Database = Factory.GetDatabase("master");
  Item a = Sitecore.Context.Database.GetItem("/sitecore/content/Home");
  Assert.IsFalse(a.HasChildren);
  </code></pre>
  
  <p>I defined my datafolder in the app.config file and the connectionstrings to my core, master and web databases are also set in the app.config.</p>
  
  <p>The exception that is thrown is:</p>
  
  <pre><code>System.TypeInitializationException: The type initializer for 'Sitecore.SecurityModel.License.LicenseManager' threw an exception. ---&gt; System.IO.FileNotFoundException: Could not load file or assembly 'file:///c:\inetpub\bin\Sitecore.Nexus.dll' or one of its dependencies. The system cannot find the file specified.=== Pre-bind state information ===
  LOG: User = NT AUTHORITY\SYSTEM
  LOG: Where-ref bind. Location = c:\inetpub\bin\Sitecore.Nexus.dll
  LOG: Appbase = file:///C:/BuildAgent/temp/buildTmp/SYSTEM_E1259 2012-07-16 14_42_19/Out
  LOG: Initial PrivatePath = NULL
  Calling assembly : (Unknown).
  ===
  LOG: This bind starts in LoadFrom load context.
  WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
  LOG: Using application configuration file: C:\BuildAgent\temp\buildTmp\SYSTEM_E1259 2012-07-16 14_42_19\Out\foo.bar.Framework.Tests.Core.DLL.config
  LOG: Using host configuration file: 
  LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
  LOG: Attempting download of new URL file:///c:/inetpub/bin/Sitecore.Nexus.dll.
  </code></pre>
  
  <p>The strange thing is, when i run it with "Run Test in Current Context" I don't get an exception. When I run it in TeamCity or with "Run All Tests in Solution" I get the exception. Obviously the file isn't located in c:/inetpub/bin/Sitecore.Nexus.dll</p>
  
  <p>Can anyone tell me what I did wrong?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>When I added an HttpSimulator the error disappeared.
  Another error occurred:</p>
  
  <pre><code>Test method foo.Bar.Framework.Tests.Core.UnitTest1.TestMethod1 threw exception: 
  System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---&gt; System.TypeInitializationException: The type initializer for 'Sitecore.Services.Heartbeat' threw an exception. ---&gt; System.InvalidOperationException: Could not read Sitecore configuration.
  </code></pre>
  
  <p>The setting which is being read is "HeartbeatInterval" and this setting IS in my app.config. When I add Settings.GetSetting("HeartbeatInterval") to my quick watch it returns the right value.
  It is like the sitecore.kernel cannot access the app.config?!</p>