Ejemplo n.º 1
0
        public static void Run(TestMethodInformation testMethodInformation, bool unloadAppDomain)
        {
            var appDomainSetup = new AppDomainSetup();

            appDomainSetup.ApplicationBase   = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
            appDomainSetup.ConfigurationFile = testMethodInformation.ConfigurationFile;

            AppDomain appDomain = AppDomain.CreateDomain(ISOLATED_APP_DOMAIN_NAME, null, appDomainSetup, GetPermissionSet());

            appDomain.Load(testMethodInformation.AssemblyName);

            var instance = (InAppDomainRunner)appDomain.CreateInstanceAndUnwrap(
                typeof(InAppDomainRunner).Assembly.FullName,
                typeof(InAppDomainRunner).FullName);


            try
            {
                instance.Execute(testMethodInformation);
            }
            finally
            {
                if (unloadAppDomain)
                {
                    AppDomain.Unload(appDomain);
                }
            }
        }
Ejemplo n.º 2
0
        public static void Run(TestMethodInformation testMethodInformation)
        {
            var startInfo = new ProcessStartInfo();

            startInfo.FileName  = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
            startInfo.Arguments = string.Format(@" ""{0}"" ""{1}"" ""{2}"" ""{3}"" ",
                                                testMethodInformation.AttachDebugger,
                                                testMethodInformation.AssemblyName,
                                                testMethodInformation.TypeAssemblyQualifiedName,
                                                testMethodInformation.TestMethodName);

            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError  = true;
            startInfo.CreateNoWindow         = true;
            startInfo.ErrorDialog            = false;
            startInfo.UseShellExecute        = false;

            var process = new Process();

            process.StartInfo           = startInfo;
            process.OutputDataReceived += (sender, eventArgs) => Console.WriteLine(eventArgs.Data);
            process.ErrorDataReceived  += (sender, eventArgs) => Console.Error.WriteLine(eventArgs.Data);

            try
            {
                process.Start();
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
                process.WaitForExit();
            }
            finally
            {
                if (!process.HasExited)
                {
                    process.Kill();
                    throw new NotExitingProcessException();
                }
            }

            if (process.ExitCode != 0)
            {
                throw new TestRunInSubProcessFailedException("Test failed. See output for more information about the exception");
            }

            // everything ok
            Assert.Pass();
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            IsolationDispatcher.IsRootAppDomainOfIsolatedProcess = true;

            bool attachDebugger = bool.Parse(args[0]);
            string testAssemblyFullName = args[1];
            string typeAssemblyQualifiedName = args[2];
            string testMethodName = args[3];

            var testMethodInformation = new TestMethodInformation(testAssemblyFullName, typeAssemblyQualifiedName, testMethodName, attachDebugger);

            if (testMethodInformation.AttachDebugger)
                Debugger.Launch();

            // remark: no need to close the appdomain, as we close the process
            AppDomainRunner.Run(testMethodInformation, false);
        }
Ejemplo n.º 4
0
        public static void Run(TestMethodInformation testMethodInformation)
        {
            var startInfo = new ProcessStartInfo();
            startInfo.FileName = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
            startInfo.Arguments = string.Format(@" ""{0}"" ""{1}"" ""{2}"" ""{3}"" ",
                                            testMethodInformation.AttachDebugger,
                                            testMethodInformation.AssemblyName,
                                            testMethodInformation.TypeAssemblyQualifiedName,
                                            testMethodInformation.TestMethodName);

            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError = true;
            startInfo.CreateNoWindow = true;
            startInfo.ErrorDialog = false;
            startInfo.UseShellExecute = false;

            var process = new Process();
            process.StartInfo = startInfo;
            process.OutputDataReceived += (sender, eventArgs) => Console.WriteLine(eventArgs.Data);
            process.ErrorDataReceived += (sender, eventArgs) => Console.Error.WriteLine(eventArgs.Data);

            try
            {
                process.Start();
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
                process.WaitForExit();
            }
            finally
            {
                if (!process.HasExited)
                {
                    process.Kill();
                    throw new NotExitingProcessException();
                }
            }

            if (process.ExitCode != 0)
                throw new TestRunInSubProcessFailedException("Test failed. See output for more information about the exception");

            // everything ok
            Assert.Pass();
        }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            IsolationDispatcher.IsRootAppDomainOfIsolatedProcess = true;

            bool   attachDebugger            = bool.Parse(args[0]);
            string testAssemblyFullName      = args[1];
            string typeAssemblyQualifiedName = args[2];
            string testMethodName            = args[3];

            var testMethodInformation = new TestMethodInformation(testAssemblyFullName, typeAssemblyQualifiedName, testMethodName, attachDebugger);

            if (testMethodInformation.AttachDebugger)
            {
                Debugger.Launch();
            }

            // remark: no need to close the appdomain, as we close the process
            AppDomainRunner.Run(testMethodInformation, false);
        }
        public static void IsolateTestRun(Isolations isolation, TestMethodInformation testMethodInformation)
        {
            if (IsInIsolatedAppDomain)
                return;

            switch (isolation)
            {
                case Isolations.AppDomain:
                    AppDomainRunner.Run(testMethodInformation, true);
                    break;
                case Isolations.Process:
                    ProcessRunner.Run(testMethodInformation);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
            }
            Assert.Pass();
        }
        public void Execute(TestMethodInformation testMethodInformation)
        {
            IsolationDispatcher.IsInIsolatedAppDomain = true;

            // todo: re-use Nunit material instead of doing this ourself

            //Assembly assembly = Assembly.Load(testMethodInformation.AssemblyName);
            //List<Type> types = assembly.GetTypes().ToList();

            Type typeUnderTest = Type.GetType(testMethodInformation.TypeAssemblyQualifiedName);

            if (typeUnderTest == null)
            {
                throw new TypeLoadException(testMethodInformation.TypeAssemblyQualifiedName);
            }

            object instance = Activator.CreateInstance(typeUnderTest);

            typeUnderTest.GetMethods()
            .Where(m => m.GetCustomAttributes(typeof(SetUpFixtureAttribute), false).Length > 0)
            .ToList()
            .ForEach(m => m.Invoke(instance, null));

            typeUnderTest.GetMethods()
            .Where(m => m.GetCustomAttributes(typeof(TestFixtureTearDownAttribute), false).Length > 0)
            .ToList()
            .ForEach(m => m.Invoke(instance, null));

            typeUnderTest.GetMethods()
            .Where(m => m.GetCustomAttributes(typeof(SetUpAttribute), false).Length > 0)
            .ToList()
            .ForEach(m => m.Invoke(instance, null));

            typeUnderTest.GetMethods()
            .Where(m => m.GetCustomAttributes(typeof(TearDownAttribute), false).Length > 0)
            .ToList()
            .ForEach(m => m.Invoke(instance, null));

            typeUnderTest.GetMethod(testMethodInformation.TestMethodName)
            .Invoke(instance, null);
        }
Ejemplo n.º 8
0
        public static void IsolateTestRun(Isolations isolation, TestMethodInformation testMethodInformation)
        {
            if (IsInIsolatedAppDomain)
            {
                return;
            }

            switch (isolation)
            {
            case Isolations.AppDomain:
                AppDomainRunner.Run(testMethodInformation, true);
                break;

            case Isolations.Process:
                ProcessRunner.Run(testMethodInformation);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            Assert.Pass();
        }
Ejemplo n.º 9
0
        public void Execute(TestMethodInformation testMethodInformation)
        {
            IsolationDispatcher.IsInIsolatedAppDomain = true;

            // todo: re-use Nunit material instead of doing this ourself

            //Assembly assembly = Assembly.Load(testMethodInformation.AssemblyName);
            //List<Type> types = assembly.GetTypes().ToList();

            Type typeUnderTest = Type.GetType(testMethodInformation.TypeAssemblyQualifiedName);

            if (typeUnderTest == null)
                throw new TypeLoadException(testMethodInformation.TypeAssemblyQualifiedName);

            object instance = Activator.CreateInstance(typeUnderTest);

            typeUnderTest.GetMethods()
                .Where(m => m.GetCustomAttributes(typeof(SetUpFixtureAttribute), false).Length > 0)
                .ToList()
                .ForEach(m => m.Invoke(instance, null));

            typeUnderTest.GetMethods()
                .Where(m => m.GetCustomAttributes(typeof(TestFixtureTearDownAttribute), false).Length > 0)
                .ToList()
                .ForEach(m => m.Invoke(instance, null));

            typeUnderTest.GetMethods()
                .Where(m => m.GetCustomAttributes(typeof(SetUpAttribute), false).Length > 0)
                .ToList()
                .ForEach(m => m.Invoke(instance, null));

            typeUnderTest.GetMethods()
                .Where(m => m.GetCustomAttributes(typeof(TearDownAttribute), false).Length > 0)
                .ToList()
                .ForEach(m => m.Invoke(instance, null));

            typeUnderTest.GetMethod(testMethodInformation.TestMethodName)
                .Invoke(instance, null);
        }
Ejemplo n.º 10
0
        public static void Run(TestMethodInformation testMethodInformation, bool unloadAppDomain)
        {
            var appDomainSetup = new AppDomainSetup();
            appDomainSetup.ApplicationBase = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
            appDomainSetup.ConfigurationFile = testMethodInformation.ConfigurationFile;

            AppDomain appDomain = AppDomain.CreateDomain(ISOLATED_APP_DOMAIN_NAME, null, appDomainSetup, GetPermissionSet());
            appDomain.Load(testMethodInformation.AssemblyName);

            var instance = (InAppDomainRunner)appDomain.CreateInstanceAndUnwrap(
              typeof(InAppDomainRunner).Assembly.FullName,
              typeof(InAppDomainRunner).FullName);

            try
            {
                instance.Execute(testMethodInformation);
            }
            finally
            {
                if (unloadAppDomain)
                    AppDomain.Unload(appDomain);
            }
        }