From 52d634af7b2c52dd4f77a6311a1ea0bf1de0c890 Mon Sep 17 00:00:00 2001 From: Inga Lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Mon, 28 Jul 2014 13:41:01 +0400 Subject: [PATCH] Dirty fix for appdomain base directory --- DotNetBuilder/NUnitTester.cs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/DotNetBuilder/NUnitTester.cs b/DotNetBuilder/NUnitTester.cs index 8af1579..9b966e3 100644 --- a/DotNetBuilder/NUnitTester.cs +++ b/DotNetBuilder/NUnitTester.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Reflection; using NUnit.Core; namespace MicroBuildServer.DotNetBuilder @@ -136,17 +138,20 @@ namespace MicroBuildServer.DotNetBuilder } } - [Serializable] - private class TestWorker + public interface ITestWorker { - public string TestLibraryPath { get; set; } + void DoTest(string testLibraryPath); + } - public void DoTest() + [Serializable] + public class TestWorker : MarshalByRefObject, ITestWorker + { + public void DoTest(string testLibraryPath) { Console.SetOut(new StubWriter()); var listener = new Listener(); CoreExtensions.Host.InitializeService(); - var package = new TestPackage(TestLibraryPath); + var package = new TestPackage(testLibraryPath); //package.AutoBinPath = true; //package.BasePath = Path.GetDirectoryName(TestLibraryPath); //package.ConfigurationFile = TestLibraryPath + ".config"; @@ -199,13 +204,12 @@ namespace MicroBuildServer.DotNetBuilder { AppDomainSetup setup = new AppDomainSetup(); setup.ConfigurationFile = request.TestLibraryPath + ".config"; + setup.ApplicationBase = Path.GetDirectoryName(request.TestLibraryPath); AppDomain tester = AppDomain.CreateDomain("tester", AppDomain.CurrentDomain.Evidence, setup); - var worker = new TestWorker(); - worker.TestLibraryPath = request.TestLibraryPath; + var worker = (ITestWorker) tester.CreateInstanceFromAndUnwrap(Assembly.GetExecutingAssembly().Location, typeof (TestWorker).FullName); - var del = new CrossAppDomainDelegate(worker.DoTest); - tester.DoCallBack(del); + worker.DoTest(request.TestLibraryPath); return (Response)(tester.GetData(DATA_TEST_RESULTS_KEY)); } }