public void When_given_configuration_file_it_should_place_it_the_configuration_space()
 {
     var directory = new PathTranslator(format("/StorageLocation"), format("/home/ack/src/MySolution/SomeSolution.sln"), _directoryExists, _createDirectory)
         .Translate(format("/home/ack/src/MySolution/AutoTest.config"));
     Assert.That(
         directory,
         Is.EqualTo(format("/StorageLocation/Configuration/MySolution_cdd8fcbb3e82fce3dc5b40e585a4949d/AutoTest.config")));
 }
 public void When_given_mm_dll_file_it_should_place_it_the_cache_space()
 {
     var directory = new PathTranslator(format("/StorageLocation"), format("/home/ack/src/MySolution/SomeSolution.sln"), _directoryExists, _createDirectory)
         .Translate(format("/home/ack/src/MySolution/Project/bin/autotest.net/project.mm.dll"));
     Assert.That(
         directory,
         Is.EqualTo(format("/home/ack/src/MySolution/Project/bin/autotest.net/project.mm.dll")));
 }
 public void When_given_a_file_on_solution_root_it_should_place_it_on_storage_solution_root()
 {
     var directory = new PathTranslator(format("/StorageLocation"), format("/home/ack/src/MySolution/SomeSolution.sln"), _directoryExists, _createDirectory)
         .Translate(format("/home/ack/src/MySolution/SomeFileOnRoot.txt"));
     Assert.That(
         directory,
         Is.EqualTo(format("/StorageLocation/MySolution_cdd8fcbb3e82fce3dc5b40e585a4949d/SomeFileOnRoot.txt")));
 }
 public void When_given_a_token_ending_with_directory_separator_it_will_parse_as_usual()
 {
     var directory = new PathTranslator(format("/StorageLocation"), format("/home/ack/src/MySolution/"), _directoryExists, _createDirectory)
         .Translate(format("/home/ack/src/MySolution/Project/Project.csproj"));
     Assert.That(
         directory,
         Is.EqualTo(format("/StorageLocation/MySolution_cdd8fcbb3e82fce3dc5b40e585a4949d/Project_f1d7213851ba028add97b0669af210b6/Project.csproj")));
 }
        public void When_given_configuration_file_it_should_place_it_the_configuration_space()
        {
            var directory = new PathTranslator(format("/StorageLocation"), format("/home/ack/src/MySolution/SomeSolution.sln"), _directoryExists, _createDirectory)
                .Translate(format("/home/ack/src/MySolution/AutoTest.config"));
			var resultHash = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX ? "089916fa47d570a46efee1a1c04d77bc" : "cdd8fcbb3e82fce3dc5b40e585a4949d";
            Assert.That(
                directory,
                Is.EqualTo(format("/StorageLocation/Configuration/MySolution_" + resultHash + "/AutoTest.config")));
        }
        public void When_given_a_file_on_solution_root_it_should_place_it_on_storage_solution_root()
        {
            var directory = new PathTranslator(format("/StorageLocation"), format("/home/ack/src/MySolution/SomeSolution.sln"), _directoryExists, _createDirectory)
                .Translate(format("/home/ack/src/MySolution/SomeFileOnRoot.txt"));
			
			var resultHash = OS.IsPosix ? "089916fa47d570a46efee1a1c04d77bc" : "cdd8fcbb3e82fce3dc5b40e585a4949d";
            Assert.That(
                directory,
                Is.EqualTo(format("/StorageLocation/MySolution_" + resultHash + "/SomeFileOnRoot.txt")));
        }
        public void When_given_a_token_ending_with_directory_separator_it_will_parse_as_usual()
        {
            var directory = new PathTranslator(format("/StorageLocation"), format("/home/ack/src/MySolution/"), _directoryExists, _createDirectory)
                .Translate(format("/home/ack/src/MySolution/Project/Project.csproj"));
			var resultHash = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX ? "089916fa47d570a46efee1a1c04d77bc" : "cdd8fcbb3e82fce3dc5b40e585a4949d";
			var fileHash = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX ? "8ea3519034d6d6a404a6e174b03615e1" : "f1d7213851ba028add97b0669af210b6";
            Assert.That(
                directory,
                Is.EqualTo(format("/StorageLocation/MySolution_" + resultHash + "/Project_" + fileHash + "/Project.csproj")));
        }
 public void When_having_a_solution_file_watch_token_it_will_translate_to_the_same_path_as_directory()
 {
     var directory = new PathTranslator(format("/StorageLocation"), format("/home/ack/src/MySolution"), _directoryExists, _createDirectory)
         .Translate(format("/home/ack/src/MySolution/Project/Project.csproj"));
     var file = new PathTranslator(format("/StorageLocation"), format("/home/ack/src/MySolution"), _directoryExists, _createDirectory)
         .Translate(format("/home/ack/src/MySolution/Project/Project.csproj"));
     Assert.That(
         directory,
         Is.EqualTo(format("/StorageLocation/MySolution_cdd8fcbb3e82fce3dc5b40e585a4949d/Project_f1d7213851ba028add97b0669af210b6/Project.csproj")));
     Assert.That(
         file,
         Is.EqualTo(format("/StorageLocation/MySolution_cdd8fcbb3e82fce3dc5b40e585a4949d/Project_f1d7213851ba028add97b0669af210b6/Project.csproj")));
     Assert.That(file, Is.EqualTo(directory));
 }
 public string GetConfiguration(string watchToken)
 {
     if (watchToken == null)
         return null;
     var localFile = Path.Combine(getWatchPath(watchToken), "AutoTest.config");
     var file = new PathTranslator(watchToken).Translate(localFile);
     if (file == null)
         file = "";
     if (File.Exists(file))
         return file;
     if (File.Exists(localFile))
         return localFile;
     return file;
 }
        public void When_having_a_solution_file_watch_token_it_will_translate_to_the_same_path_as_directory()
        {
            var directory = new PathTranslator(format("/StorageLocation"), format("/home/ack/src/MySolution"), _directoryExists, _createDirectory)
                .Translate(format("/home/ack/src/MySolution/Project/Project.csproj"));
            var file = new PathTranslator(format("/StorageLocation"), format("/home/ack/src/MySolution"), _directoryExists, _createDirectory)
                .Translate(format("/home/ack/src/MySolution/Project/Project.csproj"));
			var resultHash = OS.IsPosix ? "089916fa47d570a46efee1a1c04d77bc" : "cdd8fcbb3e82fce3dc5b40e585a4949d";
			var fileHash = OS.IsPosix ? "8ea3519034d6d6a404a6e174b03615e1" : "f1d7213851ba028add97b0669af210b6";
            Assert.That(
                directory,
                Is.EqualTo(format("/StorageLocation/MySolution_" + resultHash + "/Project_" + fileHash + "/Project.csproj")));
            Assert.That(
                file,
                Is.EqualTo(format("/StorageLocation/MySolution_" + resultHash + "/Project_" + fileHash + "/Project.csproj")));
            Assert.That(file, Is.EqualTo(directory));
        }
        public void SetUp()
        {
			_launcer = MockRepository.GenerateMock<IApplicatonLauncher>();
            _messageBus = MockRepository.GenerateMock<IMessageBus>();
            _validator = MockRepository.GenerateMock<IWatchValidator>();
			_configuration = MockRepository.GenerateMock<IConfiguration>();
            _pathLocator = MockRepository.GenerateMock<IWatchPathLocator>();
            _cahce = MockRepository.GenerateMock<ICache>();
            _slnConsumer = MockRepository.GenerateMock<ISolutionChangeConsumer>();
            _rebuildMarker = MockRepository.GenerateMock<IMarkProjectsForRebuild>();
            _configuration.Stub(x => x.IgnoreFile).Return("");
			_validator.Stub(v => v.GetIgnorePatterns()).Return("");
			_configuration.Stub(c => c.FileChangeBatchDelay).Return(50);
            _configuration.Stub(c => c.WatchAllFiles).Return(true);
            _configuration.Stub(c => c.WatchToken).Return(_watchDirectory);
            _watcher = new DirectoryWatcher(_messageBus, _validator, _configuration, MockRepository.GenerateMock<IHandleDelayedConfiguration>(), _pathLocator, _launcer, _cahce, _rebuildMarker, _slnConsumer);
            _file = Path.GetFullPath("watcher_test.txt");
            _directory = Path.GetFullPath("mytestfolder");
			_watchDirectory = Path.GetDirectoryName(_file);
            _pathLocator.Stub(x => x.Locate(_watchDirectory)).Return(_watchDirectory);
			_localConfig = new PathTranslator(_watchDirectory).Translate(Path.Combine(_watchDirectory, "AutoTest.config"));
			File.WriteAllText(_localConfig, "<configuration></configuration>");
            _watcher.Watch(_watchDirectory);
        }
Example #12
0
 public bool IsSolutionInitialized()
 {
     if (Environment.OSVersion.Platform != PlatformID.MacOSX && Environment.OSVersion.Platform != PlatformID.Unix && _configuration.AllSettings("mm-ProfilerSetup") != "DONTRUN")
     {
         var minimizer = getMinimizer();
         if (!File.Exists(minimizer.GetDBName()))
             return false;
         var dbInfo = new FileInfo(minimizer.GetDBName());
         if (dbInfo.Length == 0 && DateTime.Now.Subtract(dbInfo.CreationTime).TotalMinutes <= 2)
             return false;
     }
     var hasValidMMFile = false;
     var cache = BootStrapper.Services.Locate<ICache>();
     var projects = cache.GetAll<Project>();
     foreach (var project in projects)
     {
         Logger.WriteDebug("Preparing existence check for project: " + project.Key);
         var assembly = project.GetAssembly(_configuration.CustomOutputPath);
         if (assembly == "")
         {
             Logger.WriteDebug("Could not build assembly path");
             continue;
         }
         var extension = Path.GetExtension(assembly);
         try
         {
             var mm = Path.Combine(Path.GetDirectoryName(assembly), Path.GetFileNameWithoutExtension(assembly) + ".mm" + extension);
             mm = new PathTranslator(_configuration.WatchToken).Translate(mm);
             Logger.WriteDebug("Checking for the existence of " + mm);
             if (File.Exists(mm))
             {
                 hasValidMMFile = true;
                 continue;
             }
             if (!File.Exists(assembly))
             {
                 if (project.Value != null)
                     project.Value.RebuildOnNextRun();
                 continue;
             }
             File.Copy(assembly, mm);
             if (project.Value != null)
                 project.Value.RebuildOnNextRun();
         }
         catch (Exception ex)
         {
             Logger.WriteError("Failed to check for " + assembly);
             Logger.WriteError(ex.ToString());
         }
     }
     return hasValidMMFile;
 }
 public void When_given_mm_cache_bin_file_it_should_place_it_the_cache_space()
 {
     var directory = new PathTranslator(format("/StorageLocation"), format("/home/ack/src/MySolution/SomeSolution.sln"), _directoryExists, _createDirectory)
         .Translate(format("/home/ack/src/MySolution/Project/bin/autotest.net/projectmm_cache.bin"));
     Assert.That(
         directory,
         Is.EqualTo(format("/StorageLocation/Cache/MySolution_cdd8fcbb3e82fce3dc5b40e585a4949d/projectmm_cache_c39a9a2c31917ec0f174c8bde0fdb00a/projectmm_cache.bin")));
 }
 public void When_translating_from_a_storage_url_that_has_not_been_translated_to_it_will_return_null()
 {
     var translator = new PathTranslator(format("/StorageLocation/"), format("/home/ack/src/MySolution"), _directoryExists, _createDirectory);
     Assert.That(translator.TranslateFrom(format("/home/ack/src/MySolution/Project/ProjectNonExistent.csproj")), Is.Null);
 }
 public void When_translating_from_a_storage_url_that_has_been_translated_to_it_will_return_original_url()
 {
     var toTranslate = format("/home/ack/src/MySolution/Project/Project.csproj");
     var translator = new PathTranslator(format("/StorageLocation/"), format("/home/ack/src/MySolution"), _directoryExists, _createDirectory);
     var directory = translator.Translate(toTranslate);
     Assert.That(translator.TranslateFrom(directory), Is.EqualTo(toTranslate));
 }
 public void When_given_null_as_path_to_translate_it_will_respond_with_null()
 {
     var directory = new PathTranslator(format("/StorageLocation/"), format("/home/ack/src/MySolution"), _directoryExists, _createDirectory)
         .Translate(null);
     Assert.That(
         directory,
         Is.Null);
 }
 public void When_given_null_as_watch_token_it_will_respond_with_null()
 {
     var directory = new PathTranslator(format("/StorageLocation/"), null, _directoryExists, _createDirectory)
         .Translate(format("/home/some/other/location/Project/Project.csproj"));
     Assert.That(
         directory,
         Is.Null);
 }
        public void When_given_a_project_outside_the_solution_tree_it_will_use_an_alternative_storage_under_the_solution_location()
        {
            var directory = new PathTranslator(format("/StorageLocation/"), format("/home/ack/src/MySolution/ASolution.sln"), _directoryExists, _createDirectory)
                .Translate(format("/home/some/other/location/Project/Project.csproj"));
			
			var resultHash = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX ? "089916fa47d570a46efee1a1c04d77bc" : "cdd8fcbb3e82fce3dc5b40e585a4949d";
			var fileHash = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX ? "4fba365c1b1e9fb388685dd707a8dd5a" : "c1657f5a6230c5e986018dd389088a6e";
            Assert.That(
                directory,
                Is.EqualTo(format("/StorageLocation/MySolution_" + resultHash + "/Project_" + fileHash + "/Project.csproj")));
        }
        public void When_returning_a_storage_apth_it_will_make_sure_that_all_directories_exists()
        {
            var directory = new PathTranslator(format("/StorageLocation/"), format("/home/ack/src/MySolution"), _directoryExists, _createDirectory)
                .Translate(format("/home/ack/src/MySolution/Project/Project.csproj"));

			var resultHash = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX ? "089916fa47d570a46efee1a1c04d77bc" : "cdd8fcbb3e82fce3dc5b40e585a4949d";
			var fileHash = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX ? "8ea3519034d6d6a404a6e174b03615e1" : "f1d7213851ba028add97b0669af210b6";
			
            Assert.That(_createdDirectories, Contains.Item(format("/StorageLocation")));
            Assert.That(_createdDirectories, Contains.Item(format("/StorageLocation/MySolution_" + resultHash)));
            Assert.That(_createdDirectories, Contains.Item(format("/StorageLocation/MySolution_" + resultHash + "/Project_" + fileHash)));
        }
        public PreProcessedTesRuns PreProcess(PreProcessedTesRuns preProcessed)
        {
            // Clean up profiler logs before we start
            var logFiles = getProfilerOutput();
            cleanUpFiles(logFiles);

            var runMinimized = !(_isFullRun || minimizerIsDisabled() || _minimizerPaused);
            Logger.WriteDebug("Run minimized is " + runMinimized.ToString());
            if (runMinimized)
                _bus.Publish(new RunInformationMessage(InformationType.PreProcessing, "", "", typeof(MinimizingPreProcessor)));
            var finalDetails = new List<RunInfo>();
            var details = preProcessed.RunInfos;
            if (!minimizerGraphsAndRiskIsOff())
            {
                try
                {
                    var assemblies = GetAssemblies();
                    //var hash = details.ToDictionary(current => current.Assembly);
                    if (!runMinimized || _runCount % 10 == 0)
                        _minimizer.LoadOldCachedFiles(assemblies);
                    _runCount++;
                    var tests = _minimizer.GetTestsFor(assemblies);
                    Logger.WriteDebug("minimizer returns " + tests.Count + " tests");

                    if (runMinimized)
                    {
                        var profiled = GetProfiledEntries();
                        Logger.WriteDebug("profiler returns " + profiled.Count() + " tests");
                        var all = Combine(tests, profiled);

                        //TODO THIS IS A HACK TO ENRICH PROFILED TESTS, REFACTOR ME
                        foreach (var t in all)
                        {
                            var original = t.TestAssembly
                                .Replace(".mm.dll", ".dll")
                                .Replace(".mm.exe", ".exe");
                            var testAssembly = original;
                            testAssembly = new PathTranslator(_configuration.WatchToken).TranslateFrom(testAssembly);
                            if (testAssembly == null)
                                testAssembly = original;
                            Logger.WriteDebug("Translated TestAssembly is: " + testAssembly + " original is: " + t.TestAssembly);
                            var current = details.FirstOrDefault(x => x.Assembly.Equals(testAssembly));
                            if (current == null)
                            {
                                current = finalDetails.FirstOrDefault(x => x.Assembly.Equals(testAssembly));
                                if (current == null)
                                    current = GetRunInfoFromAssembly(testAssembly);
                                if (current == null)
                                    throw new Exception("unable to match assembly for test. - assembly is " + testAssembly);
                                if (!finalDetails.Exists(x => x.Assembly.Equals(testAssembly)))
                                    finalDetails.Add(current);
                            }

                            foreach (var s in t.TestRunners)
                            {
                                var runner = ConvertStringToTestRunnerEnum(s);
                                var test = getTestSignature(t, runner);
                                Logger.WriteDetails(string.Format("Adding test {0} to runner {1} on run info {2}", test,
                                                                  runner, current.Assembly));
                                current.AddTestsToRun(runner, test);
                            }
                        }

                        if (runMinimized)
                            addCurrentBrokenTests(details);

                        foreach (var detail in details)
                        {
                            detail.ShouldOnlyRunSpcifiedTestsFor(TestRunner.Any);
                        }
                        Logger.WritePreprocessor(string.Format("Found {0} affected tests", tests.Count));
                        _bus.Publish(new AssembliesMinimizedMessage());
                        finalDetails.AddRange(details);
                    }

                }
                catch (Exception ex)
                {
                    Logger.WriteError(ex.ToString());
                    var newDetails = new List<RunInfo>();
                    foreach (var detail in details)
                    {
                        var newDetail = new RunInfo(detail.Project);
                        newDetail.SetAssembly(detail.Assembly);
                        if (detail.ShouldBeBuilt)
                            newDetail.ShouldBuild();
                        newDetails.Add(newDetail);
                    }
                }

                Logger.WriteDebug("Running 2nd generation garbage collection");
                GC.Collect(2);
                Logger.WriteDebug("Waiting for finalizers");
                GC.WaitForPendingFinalizers();
                Logger.WriteDebug("GC done");
            }

            Logger.WriteDebug("Getting profiler wrapper");
            _profilerWrapper = getProfilerWrapper();
            if (!runMinimized)
            {
                var wrapper = _profilerWrapper;
                _profilerWrapper = null;
                Logger.WriteDebug("Returning original runinfos");
                return new PreProcessedTesRuns(wrapper, preProcessed.RunInfos); // return original runInfos
            }
            finalDetails.ForEach(x => _runsToProfile.Add(x.CloneToTestRunInfo()));
            Logger.WriteDebug("Returning modified details");
            return new PreProcessedTesRuns(_profilerWrapper, finalDetails.ToArray());
        }
 public void When_given_a_project_outside_the_solution_tree_it_will_use_an_alternative_storage_under_the_solution_location()
 {
     var directory = new PathTranslator(format("/StorageLocation/"), format("/home/ack/src/MySolution/ASolution.sln"), _directoryExists, _createDirectory)
         .Translate(format("/home/some/other/location/Project/Project.csproj"));
     Assert.That(
         directory,
         Is.EqualTo(format("/StorageLocation/MySolution_cdd8fcbb3e82fce3dc5b40e585a4949d/Project_c1657f5a6230c5e986018dd389088a6e/Project.csproj")));
 }
        public void When_given_mm_cache_bin_file_it_should_place_it_the_cache_space()
        {
            var directory = new PathTranslator(format("/StorageLocation"), format("/home/ack/src/MySolution/SomeSolution.sln"), _directoryExists, _createDirectory)
                .Translate(format("/home/ack/src/MySolution/Project/bin/autotest.net/projectmm_cache.bin"));
			var resultHash = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX ? "089916fa47d570a46efee1a1c04d77bc" : "cdd8fcbb3e82fce3dc5b40e585a4949d";
			var fileHash = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX ? "3cc7aa37453f484476369d12180e2a0a" : "c39a9a2c31917ec0f174c8bde0fdb00a";
            Assert.That(
                directory,
                Is.EqualTo(format("/StorageLocation/Cache/MySolution_" + resultHash + "/projectmm_cache_" + fileHash + "/projectmm_cache.bin")));
        }
        public void When_returning_a_storage_apth_it_will_make_sure_that_all_directories_exists()
        {
            var directory = new PathTranslator(format("/StorageLocation/"), format("/home/ack/src/MySolution"), _directoryExists, _createDirectory)
                .Translate(format("/home/ack/src/MySolution/Project/Project.csproj"));

            Assert.That(_createdDirectories, Contains.Item(format("/StorageLocation")));
            Assert.That(_createdDirectories, Contains.Item(format("/StorageLocation/MySolution_cdd8fcbb3e82fce3dc5b40e585a4949d")));
            Assert.That(_createdDirectories, Contains.Item(format("/StorageLocation/MySolution_cdd8fcbb3e82fce3dc5b40e585a4949d/Project_f1d7213851ba028add97b0669af210b6")));
        }