it:ad:mstest:howto:map_paths_to_content_files

IT:AD:MSTest:HowTo:Map Paths to Content Files

If you are relying on AppDomain.CurrentDomain.BaseDirectory to get the root directory, your test will break.

There are two fixes.

The fix is explained at http://www.ademiller.com/blogs/tech/2008/01/gotchas-mstest-appdomain-changes-in-vs-2008/.

Basically, you need to set your BaseDirectory in your MSTest TestClass constructor like this:

string currDir = Environment.CurrentDirectory.Substring(0, Environment.CurrentDirectory.IndexOf("TestResults"));
AppDomain.CurrentDomain.SetData("APPBASE", currDir);

which is:

     /// <summary>
        ///   An Example Test.
        /// </summary>
        [TestMethod]
        [DeploymentItem(@"Templates\NV\Parts\SubHeader.nv",@"Templates\NV\Parts")]
        [DeploymentItem(@"Templates\NV\body.nv", @"Templates\NV")]
        [DeploymentItem(@"Templates\NV\Header.nv", @"Templates\NV")]
        public void UnitTest_TransformDIrectlyUsingVendorService()
        {

            string path = environmentService.MapPath(@"Templates\NV\body.nv");

            Assert.IsTrue(System.IO.File.Exists(path));
        }

  • /home/skysigal/public_html/data/pages/it/ad/mstest/howto/map_paths_to_content_files.txt
  • Last modified: 2023/11/04 01:49
  • by 127.0.0.1