Beispiel #1
0
        public void UninstallModNotFound()
        {
            using (var tidy = new DisposableKSP())
            {
                var config = new FakeConfiguration(tidy.KSP, tidy.KSP.Name);

                GameInstanceManager manager = new GameInstanceManager(
                    new NullUser(),
                    config
                    )
                {
                    CurrentInstance = tidy.KSP
                };

                Assert.Throws <ModNotInstalledKraken>(delegate
                {
                    HashSet <string> possibleConfigOnlyDirs = null;
                    // This should throw, as our tidy KSP has no mods installed.
                    new CKAN.ModuleInstaller(manager.CurrentInstance, manager.Cache, nullUser).UninstallList(new List <string> {
                        "Foo"
                    }, ref possibleConfigOnlyDirs, CKAN.RegistryManager.Instance(manager.CurrentInstance));
                });

                manager.CurrentInstance = null; // I weep even more.
                manager.Dispose();
                config.Dispose();
            }
        }
Beispiel #2
0
        public void ConstructModList_NumberOfRows_IsEqualToNumberOfMods()
        {
            using (var tidy = new DisposableKSP())
            {
                var config = new FakeConfiguration(tidy.KSP, tidy.KSP.Name);

                GameInstanceManager manager = new GameInstanceManager(
                    new NullUser(),
                    config
                    )
                {
                    CurrentInstance = tidy.KSP
                };
                var registry = Registry.Empty();
                registry.AddAvailable(TestData.FireSpitterModule());
                registry.AddAvailable(TestData.kOS_014_module());
                var main_mod_list = new ModList(null);
                var mod_list      = main_mod_list.ConstructModList(
                    new List <GUIMod>
                {
                    new GUIMod(TestData.FireSpitterModule(), registry, manager.CurrentInstance.VersionCriteria()),
                    new GUIMod(TestData.kOS_014_module(), registry, manager.CurrentInstance.VersionCriteria())
                },
                    manager.CurrentInstance.Name
                    );
                Assert.That(mod_list, Has.Count.EqualTo(2));

                manager.Dispose();
                config.Dispose();
            }
        }
Beispiel #3
0
        public void IsVisible_WithAllAndNoNameFilter_ReturnsTrueForCompatible()
        {
            using (var tidy = new DisposableKSP())
            {
                var config = new FakeConfiguration(tidy.KSP, tidy.KSP.Name);

                GameInstanceManager manager = new GameInstanceManager(
                    new NullUser(),
                    config
                    )
                {
                    CurrentInstance = tidy.KSP
                };

                var ckan_mod = TestData.FireSpitterModule();
                var registry = Registry.Empty();
                registry.AddAvailable(ckan_mod);
                var item = new ModList(delegate { });
                Assert.That(item.IsVisible(
                                new GUIMod(ckan_mod, registry, manager.CurrentInstance.VersionCriteria()),
                                manager.CurrentInstance.Name
                                ));

                manager.Dispose();
                config.Dispose();
            }
        }
Beispiel #4
0
        public void UninstallEmptyDirs()
        {
            string emptyFolderName = "DogeCoinFlag";

            // Create a new disposable KSP instance to run the test on.
            using (var ksp = new DisposableKSP())
            {
                var config = new FakeConfiguration(ksp.KSP, ksp.KSP.Name);

                GameInstanceManager manager = new GameInstanceManager(
                    new NullUser(),
                    config
                ) {
                    CurrentInstance = ksp.KSP
                };

                string directoryPath = Path.Combine(ksp.KSP.game.PrimaryModDirectory(ksp.KSP), emptyFolderName);

                // Install the base test mod.

                var registry = CKAN.RegistryManager.Instance(ksp.KSP).registry;
                manager.Cache.Store(TestData.DogeCoinFlag_101_module(), TestData.DogeCoinFlagZip());
                registry.AddAvailable(TestData.DogeCoinFlag_101_module());

                List<string> modules = new List<string> { TestData.DogeCoinFlag_101_module().identifier };

                HashSet<string> possibleConfigOnlyDirs = null;
                CKAN.ModuleInstaller.GetInstance(manager.CurrentInstance, manager.Cache, nullUser).InstallList(modules, new RelationshipResolverOptions(), CKAN.RegistryManager.Instance(manager.CurrentInstance), ref possibleConfigOnlyDirs);

                modules.Clear();

                // Install the plugin test mod.
                manager.Cache.Store(TestData.DogeCoinPlugin_module(), TestData.DogeCoinPluginZip());
                registry.AddAvailable(TestData.DogeCoinPlugin_module());

                modules.Add(TestData.DogeCoinPlugin_module().identifier);

                CKAN.ModuleInstaller.GetInstance(manager.CurrentInstance, manager.Cache, nullUser).InstallList(modules, new RelationshipResolverOptions(), CKAN.RegistryManager.Instance(manager.CurrentInstance), ref possibleConfigOnlyDirs);

                modules.Clear();

                // Check that the directory is installed.
                Assert.IsTrue(Directory.Exists(directoryPath));

                // Uninstall both mods.

                modules.Add(TestData.DogeCoinFlag_101_module().identifier);
                modules.Add(TestData.DogeCoinPlugin_module().identifier);

                CKAN.ModuleInstaller.GetInstance(manager.CurrentInstance, manager.Cache, nullUser).UninstallList(modules, ref possibleConfigOnlyDirs, CKAN.RegistryManager.Instance(manager.CurrentInstance));

                // Check that the directory has been deleted.
                Assert.IsFalse(Directory.Exists(directoryPath));

                manager.Dispose();
                config.Dispose();
            }
        }
Beispiel #5
0
 public void GetPreferredInstance_WithEmptyAutoStartAndMultipleInstances_ReturnsNull()
 {
     using (var tidy2 = new DisposableKSP())
     {
         cfg.Instances.Add(new Tuple <string, string, string>("tidy2", tidy2.KSP.GameDir(), "KSP"));
         // Make a new manager with the updated config
         var multiMgr = new GameInstanceManager(new NullUser(), cfg);
         multiMgr.ClearAutoStart();
         Assert.That(multiMgr.GetPreferredInstance(), Is.Null);
         multiMgr.Dispose();
     }
 }
Beispiel #6
0
        public void CanInstallMod()
        {
            string mod_file_name = "DogeCoinFlag/Flags/dogecoin.png";

            // Create a new disposable KSP instance to run the test on.
            using (DisposableKSP ksp = new DisposableKSP())
            {
                var config = new FakeConfiguration(ksp.KSP, ksp.KSP.Name);

                GameInstanceManager manager = new GameInstanceManager(
                    new NullUser(),
                    config
                    )
                {
                    CurrentInstance = ksp.KSP
                };

                // Make sure the mod is not installed.
                string mod_file_path = Path.Combine(ksp.KSP.game.PrimaryModDirectory(ksp.KSP), mod_file_name);

                Assert.IsFalse(File.Exists(mod_file_path));

                // Copy the zip file to the cache directory.
                Assert.IsFalse(manager.Cache.IsCachedZip(TestData.DogeCoinFlag_101_module()));

                string cache_path = manager.Cache.Store(TestData.DogeCoinFlag_101_module(), TestData.DogeCoinFlagZip());

                Assert.IsTrue(manager.Cache.IsCachedZip(TestData.DogeCoinFlag_101_module()));
                Assert.IsTrue(File.Exists(cache_path));

                // Mark it as available in the registry.
                var registry = CKAN.RegistryManager.Instance(ksp.KSP).registry;
                Assert.AreEqual(0, registry.CompatibleModules(ksp.KSP.VersionCriteria()).Count());

                registry.AddAvailable(TestData.DogeCoinFlag_101_module());

                Assert.AreEqual(1, registry.CompatibleModules(ksp.KSP.VersionCriteria()).Count());

                // Attempt to install it.
                List <string> modules = new List <string> {
                    TestData.DogeCoinFlag_101_module().identifier
                };

                HashSet <string> possibleConfigOnlyDirs = null;
                new CKAN.ModuleInstaller(ksp.KSP, manager.Cache, nullUser).InstallList(modules, new RelationshipResolverOptions(), CKAN.RegistryManager.Instance(manager.CurrentInstance), ref possibleConfigOnlyDirs);

                // Check that the module is installed.
                Assert.IsTrue(File.Exists(mod_file_path));

                manager.Dispose();
                config.Dispose();
            }
        }
Beispiel #7
0
        public void ModuleManagerInstancesAreDecoupled()
        {
            string mod_file_name = "DogeCoinFlag/Flags/dogecoin.png";

            // Create a new disposable KSP instance to run the test on.
            Assert.DoesNotThrow(delegate
            {
                for (int i = 0; i < 5; i++)
                {
                    using (DisposableKSP ksp = new DisposableKSP())
                    {
                        var config = new FakeConfiguration(ksp.KSP, ksp.KSP.Name);

                        GameInstanceManager manager = new GameInstanceManager(
                            new NullUser(),
                            config
                            )
                        {
                            CurrentInstance = ksp.KSP
                        };

                        // Copy the zip file to the cache directory.
                        manager.Cache.Store(TestData.DogeCoinFlag_101_module(), TestData.DogeCoinFlagZip());

                        // Mark it as available in the registry.
                        var registry = CKAN.RegistryManager.Instance(ksp.KSP).registry;
                        registry.AddAvailable(TestData.DogeCoinFlag_101_module());

                        // Attempt to install it.
                        List <string> modules = new List <string> {
                            TestData.DogeCoinFlag_101_module().identifier
                        };

                        HashSet <string> possibleConfigOnlyDirs = null;
                        new CKAN.ModuleInstaller(ksp.KSP, manager.Cache, nullUser).InstallList(modules, new RelationshipResolverOptions(), CKAN.RegistryManager.Instance(manager.CurrentInstance), ref possibleConfigOnlyDirs);

                        // Check that the module is installed.
                        string mod_file_path = Path.Combine(ksp.KSP.game.PrimaryModDirectory(ksp.KSP), mod_file_name);

                        Assert.IsTrue(File.Exists(mod_file_path));

                        manager.Dispose();
                        config.Dispose();
                    }
                }
            });
        }
Beispiel #8
0
        public void CanUninstallMod()
        {
            string mod_file_name = "DogeCoinFlag/Flags/dogecoin.png";

            // Create a new disposable KSP instance to run the test on.
            using (var ksp = new DisposableKSP())
            {
                var config = new FakeConfiguration(ksp.KSP, ksp.KSP.Name);

                GameInstanceManager manager = new GameInstanceManager(
                    new NullUser(),
                    config
                    )
                {
                    CurrentInstance = ksp.KSP
                };

                string mod_file_path = Path.Combine(ksp.KSP.game.PrimaryModDirectory(ksp.KSP), mod_file_name);

                // Install the test mod.
                var registry = CKAN.RegistryManager.Instance(ksp.KSP).registry;
                manager.Cache.Store(TestData.DogeCoinFlag_101_module(), TestData.DogeCoinFlagZip());
                registry.AddAvailable(TestData.DogeCoinFlag_101_module());

                List <string> modules = new List <string> {
                    TestData.DogeCoinFlag_101_module().identifier
                };

                HashSet <string> possibleConfigOnlyDirs = null;
                new CKAN.ModuleInstaller(manager.CurrentInstance, manager.Cache, nullUser).InstallList(modules, new RelationshipResolverOptions(), CKAN.RegistryManager.Instance(manager.CurrentInstance), ref possibleConfigOnlyDirs);

                // Check that the module is installed.
                Assert.IsTrue(File.Exists(mod_file_path));

                // Attempt to uninstall it.
                new CKAN.ModuleInstaller(manager.CurrentInstance, manager.Cache, nullUser).UninstallList(modules, ref possibleConfigOnlyDirs, CKAN.RegistryManager.Instance(manager.CurrentInstance));

                // Check that the module is not installed.
                Assert.IsFalse(File.Exists(mod_file_path));

                manager.Dispose();
                config.Dispose();
            }
        }
Beispiel #9
0
        public void InstallList_IdentifierEqualsVersionSyntax_InstallsModule()
        {
            using (DisposableKSP ksp = new DisposableKSP())
            {
                // Arrange
                var config = new FakeConfiguration(ksp.KSP, ksp.KSP.Name);

                GameInstanceManager manager = new GameInstanceManager(
                    new NullUser(),
                    config
                    )
                {
                    CurrentInstance = ksp.KSP
                };
                var registry = CKAN.RegistryManager.Instance(ksp.KSP).registry;
                var inst     = new CKAN.ModuleInstaller(ksp.KSP, manager.Cache, nullUser);

                const string mod_file_name = "DogeCoinFlag/Flags/dogecoin.png";
                string       mod_file_path = Path.Combine(ksp.KSP.game.PrimaryModDirectory(ksp.KSP), mod_file_name);
                CkanModule   mod           = TestData.DogeCoinFlag_101_module();
                registry.AddAvailable(mod);
                manager.Cache.Store(mod, TestData.DogeCoinFlagZip());
                List <string> modules = new List <string>()
                {
                    $"{mod.identifier}={mod.version}"
                };

                // Act
                HashSet <string> possibleConfigOnlyDirs = null;
                inst.InstallList(modules, new RelationshipResolverOptions(), CKAN.RegistryManager.Instance(manager.CurrentInstance), ref possibleConfigOnlyDirs);

                // Assert
                Assert.IsTrue(File.Exists(mod_file_path));

                manager.Dispose();
                config.Dispose();
            }
        }
Beispiel #10
0
        public void NewGuiModsAreNotSelectedForUpgrade()
        {
            using (var tidy = new DisposableKSP())
            {
                var config = new FakeConfiguration(tidy.KSP, tidy.KSP.Name);

                GameInstanceManager manager = new GameInstanceManager(
                    new NullUser(),
                    config
                    )
                {
                    CurrentInstance = tidy.KSP
                };
                var registry = Registry.Empty();
                var ckan_mod = TestData.kOS_014_module();
                registry.AddAvailable(ckan_mod);
                var mod = new GUIMod(ckan_mod, registry, manager.CurrentInstance.VersionCriteria());
                Assert.False(mod.IsUpgradeChecked);

                manager.Dispose();
                config.Dispose();
            }
        }
Beispiel #11
0
 public void Down()
 {
     _instance.Dispose();
     _manager.Dispose();
     _config.Dispose();
 }
Beispiel #12
0
 public void TearDown()
 {
     manager.Dispose();
     tidy.Dispose();
     cfg.Dispose();
 }
Beispiel #13
0
        public void InstallAndSortByCompat_WithAnyCompat_NoCrash()
        {
            /*
             * // An exception would be thrown at the bottom of this.
             * var main = new Main(null, new GUIUser(), false);
             * main.Manager = _manager;
             * // First sort by name
             * main.configuration.SortByColumnIndex = 2;
             * // Now sort by version
             * main.configuration.SortByColumnIndex = 6;
             * main.MarkModForInstall("kOS");
             *
             * // Make sure we have one requested change
             * var changeList = main.mainModList.ComputeUserChangeSet()
             *  .Select((change) => change.Mod.ToCkanModule()).ToList();
             *
             * // Do the install
             * new ModuleInstaller(_instance.KSP, main.currentUser).InstallList(
             *  changeList,
             *  new RelationshipResolverOptions(),
             *  new NetAsyncModulesDownloader(main.currentUser)
             * );
             */

            // Arrange

            DisposableKSP       instance        = new DisposableKSP();
            RegistryManager     registryManager = RegistryManager.Instance(instance.KSP);
            Registry            registry        = Registry.Empty();
            FakeConfiguration   config          = new FakeConfiguration(instance.KSP, instance.KSP.Name);
            GameInstanceManager manager         = new GameInstanceManager(new NullUser(), config);
            // A module with a ksp_version of "any" to repro our issue
            CkanModule   anyVersionModule = TestData.DogeCoinFlag_101_module();
            ModList      modList          = new ModList(null);
            DataGridView listGui          = new DataGridView();

            CKAN.ModuleInstaller      installer  = new CKAN.ModuleInstaller(instance.KSP, manager.Cache, manager.User);
            NetAsyncModulesDownloader downloader = new NetAsyncModulesDownloader(manager.User, manager.Cache);

            // Act

            // Install module and set it as pre-installed
            manager.Cache.Store(TestData.DogeCoinFlag_101_module(), TestData.DogeCoinFlagZip());
            registry.RegisterModule(anyVersionModule, new string[] { }, instance.KSP, false);
            registry.AddAvailable(anyVersionModule);

            HashSet <string> possibleConfigOnlyDirs = null;

            installer.InstallList(
                new List <CkanModule> {
                anyVersionModule
            },
                new RelationshipResolverOptions(),
                registryManager,
                ref possibleConfigOnlyDirs,
                downloader
                );

            // This module is not for "any" version,
            // to provide another to sort against
            registry.AddAvailable(TestData.kOS_014_module());

            // TODO: Refactor the column header code to allow mocking of the GUI without creating columns
            const int numCheckboxCols = 4;
            const int numTextCols     = 10;

            listGui.Columns.AddRange(
                Enumerable.Range(1, numCheckboxCols)
                .Select(i => (DataGridViewColumn) new DataGridViewCheckBoxColumn())
                .Concat(Enumerable.Range(1, numTextCols)
                        .Select(i => new DataGridViewTextBoxColumn()))
                .ToArray());

            // Assert (and Act a bit more)

            Assert.IsNotNull(instance.KSP);
            Assert.IsNotNull(manager);
            Assert.IsNotNull(modList);

            var modules = registry.available_modules
                          .Select(mod => new GUIMod(mod.Value.Latest(), registry, instance.KSP.VersionCriteria()))
                          .ToList();

            listGui.Rows.AddRange(modList.ConstructModList(modules, null).ToArray());
            // The header row adds one to the count
            Assert.AreEqual(modules.Count + 1, listGui.Rows.Count);

            // Sort by game compatibility, this is the fuse-lighting
            listGui.Sort(listGui.Columns[8], ListSortDirection.Descending);

            // Mark the mod for install, after completion we will get an exception
            var otherModule = modules.First(mod => mod.Identifier.Contains("kOS"));

            otherModule.IsInstallChecked = true;

            Assert.IsTrue(otherModule.IsInstallChecked);
            Assert.IsFalse(otherModule.IsInstalled);

            Assert.DoesNotThrow(() =>
            {
                // Install the "other" module
                installer.InstallList(
                    modList.ComputeUserChangeSet(null).Select(change => change.Mod).ToList(),
                    new RelationshipResolverOptions(),
                    registryManager,
                    ref possibleConfigOnlyDirs,
                    downloader
                    );

                // Now we need to sort
                // Make sure refreshing the GUI state does not throw a NullReferenceException
                listGui.Refresh();
            });

            instance.Dispose();
            manager.Dispose();
            config.Dispose();
        }