Exemplo n.º 1
0
        /// <summary>
        /// Run all apply settings in a random fashion.
        /// </summary>
        /// <param name="universe"></param>
        /// <param name="m"></param>
        /// <param name="worldName"></param>
        /// <param name="seed"></param>
        /// <returns></returns>
        public static TestUniverse ApplyRandomly(this TestUniverse universe, IActivityMonitor m, string worldName, int seed)
        {
            EnsureWorldOpened(universe, worldName);
            var commandRegister = universe.UserHost.CommandRegister;
            var commands        = commandRegister.GetCommands("*applysettings*");

            Action[] actions = commands.Select(s => new Action(() => { s.Execute(m, s.CreatePayload()); }))
                               .Append(() => { CommitAll(universe, m, "Applied some settings.", worldName); })
                               .Append(() => { universe = universe.RestartCKli(); }).ToArray();

            bool[] ranAction = new bool[actions.Length];
            m.Info($"Running random actions with seed '{seed}'");
            var rand = new Random(seed);

            for (int i = 0; i < actions.Length * 2; i++) //TODO: we can add better checks.
            {
                int choosed = rand.Next(0, actions.Length);
                ranAction[choosed] = true;
                actions[choosed]();
            }

            IOrderedEnumerable <Action> shuffled = actions.Where((p, i) => !ranAction[i]).OrderBy(k => rand.Next());

            foreach (var action in shuffled)
            {
                action();
            }
            return(universe);
        }
Exemplo n.º 2
0
        public static TestUniverse RestartCKli(this TestUniverse universe)
        {
            string         tempName = "temp";
            NormalizedPath tempZip  = ImageManager.CacheUniverseFolder.AppendPart(tempName + ".zip");

            File.Delete(tempZip);
            universe.SnapshotState(tempName).Should().Be(tempZip);
            return(ImageManager.InstantiateImage(TestHelper.Monitor, tempZip));
        }
Exemplo n.º 3
0
        public static TestUniverse AllBuild(this TestUniverse universe, IActivityMonitor m, string worldName)
        {
            EnsureWorldOpened(universe, m, worldName);
            var w = universe.UserHost.WorldSelector.CurrentWorld;

            w.Should().NotBeNull();
            w.AllBuild(m, true).Should().BeTrue();
            return(universe);
        }
Exemplo n.º 4
0
        public static TestUniverse CommitAll(this TestUniverse universe, IActivityMonitor m, string commitMessage, string worldName)
        {
            EnsureWorldOpened(universe, worldName);
            var currentWorld = universe.UserHost.WorldSelector.CurrentWorld;

            foreach (var gitFolder in currentWorld.SolutionDrivers.GetDriverOnCurrentBranch().Select(s => s.GitRepository))
            {
                gitFolder.Commit(m, commitMessage);
            }
            return(universe);
        }
Exemplo n.º 5
0
        public static TestUniverse ApplyAll(this TestUniverse universe, IActivityMonitor m, string worldName)
        {
            EnsureWorldOpened(universe, m, worldName);
            var commandRegister = universe.UserHost.CommandRegister;

            foreach (var command in commandRegister.GetCommands("*applysettings*"))
            {
                command.Execute(m, command.CreatePayload());
            }
            return(universe);
        }
Exemplo n.º 6
0
        public static TestUniverse SeedInitialSetup(this TestUniverse universe, IActivityMonitor m)
        {
            universe.UserHost.WorldStore.EnsureStackRepository(m, universe.StackBareGitPath, isPublic: true);

            TestUniverse.PlaceHolderSwapEverything(
                m: m,
                tempPath: universe.UniversePath,
                oldString: TestUniverse.PlaceHolderString,
                newString: universe.UniversePath
                );
            EnsureWorldOpened(universe, "CKTest-Build");
            return(universe);
        }
Exemplo n.º 7
0
 public static NormalizedPath minimal_solution_setup(Action <TestUniverse> action, bool useless)
 {
     using (TestUniverse universe = ImageManager.InstantiateImage(
                m: TestHelper.Monitor,
                imagePath: ImageManager.SeedUniverseFolder.AppendPart("minimal_project.zip"))
            )
     {
         universe.SeedInitialSetup(TestHelper.Monitor);
         var snapshotPath = universe.SnapshotState(nameof(minimal_solution_setup));
         action?.Invoke(universe);
         return(snapshotPath);
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Instantiate a <see cref="TestUniverse"/> from the given path.
        /// </summary>
        /// <param name="m"></param>
        /// <param name="imagePath"></param>
        /// <returns></returns>
        public static TestUniverse InstantiateImage(IActivityMonitor m, NormalizedPath imagePath)
        {
            if (!File.Exists(imagePath))
            {
                throw new FileNotFoundException(nameof(imagePath));
            }
            NormalizedPath tempPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            m.Info($"Creating temp directory {tempPath} and dezipping '{imagePath}' into.");
            Directory.CreateDirectory(tempPath);
            ZipFile.ExtractToDirectory(imagePath, tempPath);
            return(TestUniverse.Create(m, tempPath));
        }
Exemplo n.º 9
0
        public static TestUniverse EnsureWorldOpened(this TestUniverse universe, IActivityMonitor m, string worldName)
        {
            var currentWorldName = universe.UserHost.WorldSelector.CurrentWorld?.WorldName?.FullName;

            if (currentWorldName != worldName)
            {
                if (currentWorldName != null)
                {
                    universe.UserHost.WorldSelector.Close(m);
                }
                universe.UserHost.WorldSelector.Open(m, worldName).Should().BeTrue();
            }
            return(universe);
        }
Exemplo n.º 10
0
        public static World EnsureWorldOpened(this TestUniverse universe, string worldName)
        {
            var currentWorldName = universe.UserHost.WorldSelector.CurrentWorld?.WorldName?.FullName;

            if (currentWorldName != worldName)
            {
                if (currentWorldName != null)
                {
                    universe.UserHost.WorldSelector.CloseWorld(TestHelper.Monitor);
                }
                universe.UserHost.WorldStore.SetWorldMapping(TestHelper.Monitor, worldName, universe.DevDirectory);
                universe.UserHost.WorldSelector.OpenWorld(TestHelper.Monitor, worldName).Should().BeTrue();
            }
            return(universe.UserHost.WorldSelector.CurrentWorld);
        }
Exemplo n.º 11
0
 static NormalizedPath ImageBuilderHelper(
     Action <TestUniverse> action,
     bool refreshCache,
     Func <Action <TestUniverse>, bool, NormalizedPath> parentBuilder,
     Action <TestUniverse> buildAction,
     [CallerMemberName] string callerMemberName = null)
 {
     using (TestUniverse universe = ImageManager.InstantiateImage(TestHelper.Monitor, parentBuilder, refreshCache))
     {
         buildAction(universe);
         var snapshotPath = universe.SnapshotState(callerMemberName);
         action?.Invoke(universe);
         return(snapshotPath);
     }
 }
Exemplo n.º 12
0
        public static TestUniverse RunCommands(this TestUniverse universe, IActivityMonitor m, string worldName, string commandFilter, params object[] args)
        {
            EnsureWorldOpened(universe, worldName);
            var commandRegister = universe.UserHost.CommandRegister;

            foreach (var command in commandRegister.GetCommands(commandFilter))
            {
                var payload = (SimplePayload)command.CreatePayload();
                for (int i = 0; i < args.Length; i++)
                {
                    payload.Fields[i].SetValue(args[i]);
                }
                command.Execute(m, payload);
            }
            return(universe);
        }
Exemplo n.º 13
0
        public static TestUniverse CommitAll(this TestUniverse universe, IActivityMonitor m, string worldName)
        {
            EnsureWorldOpened(universe, worldName);
            var commandRegister = universe.UserHost.CommandRegister;

            foreach (var command in commandRegister.GetCommands("*commit"))
            {
                var payload = command.CreatePayload();
                if (!(payload is SimplePayload simple))
                {
                    m.Error("Unsupported payload type: " + payload.GetType());
                    throw new NotSupportedException();
                }
                simple.Fields[0].SetValue("Tests automated commit. If you see this commit online, blame Kuinox.");
                simple.Fields[1].SetValue(0);
                command.Execute(m, payload);
            }
            return(universe);
        }
Exemplo n.º 14
0
 public static TestUniverse SeedInitialSetup(this TestUniverse universe, IActivityMonitor m)
 {
     universe.UserHost.WorldStore.EnsureStackDefinition(
         m: m,
         stackName: "CKTest-Build",
         url: universe.StackBareGitPath,
         isPublic: true,
         mappedPath: universe.UserLocalDirectory
         );
     TestUniverse.PlaceHolderSwapEverything(
         m: m,
         tempPath: universe.UniversePath,
         oldString: TestUniverse.PlaceHolderString,
         newString: universe.UniversePath
         );
     universe.UserHost.WorldStore.PullAll(m).Should().BeFalse();  //The repo was previously cloned, pulling should do nothing.
     EnsureWorldOpened(universe, m, "CKTest-Build");
     return(universe);
 }
Exemplo n.º 15
0
        /// <summary>
        /// Create a <see cref="TestUniverse"/> in a given folder.
        /// </summary>
        /// <param name="path"> The path where the <see cref="TestUniverse"/> will be. The Directory will be deleted when disposed.</param>
        /// <returns></returns>
        public static TestUniverse Create(IActivityMonitor m, NormalizedPath path)
        {
            m.Info($"Creating TestUniverse from {path}.");
            NormalizedPath ckliPath = path.AppendPart(_ckliMapping);

            if (Directory.Exists(ckliPath))
            {
                ReplaceInDirectoriesPaths(
                    ckliPath: ckliPath,
                    oldString: GitWorldStore.CleanPathDirName(PlaceHolderString),
                    newString: GitWorldStore.CleanPathDirName(path)
                    );
            }
            PlaceHolderSwapEverything(m, path, PlaceHolderString, path);
            var userHost = new UserHost(new FakeApplicationLifetime(), ckliPath);
            var output   = new TestUniverse(m, path, userHost);

            userHost.Initialize(m);
            userHost.WorldStore.DeleteStackDefinition(m, "CK");
            userHost.WorldStore.DeleteStackDefinition(m, "CK-Build");
            return(output);
        }
Exemplo n.º 16
0
 public static TestUniverse ApplyAll(this TestUniverse universe, IActivityMonitor m, string worldName)
 => RunCommands(universe, m, worldName, "*applysettings*");