Ejemplo n.º 1
0
        public void Setup()
        {
            // Make a fake KSP install
            temp_ksp = new DisposableKSP(null, test_registry);

            // Easy short-cut
            registry = CKAN.RegistryManager.Instance(temp_ksp.KSP).registry;
        }
Ejemplo n.º 2
0
        public void Setup()
        {
            // Make a fake KSP install
            temp_ksp = new DisposableKSP(null, test_registry);

            // Easy short-cut
            registry = temp_ksp.KSP.Registry;
        }
Ejemplo n.º 3
0
 public void Setup()
 {
     ksp = new DisposableKSP();
     registry = CKAN.RegistryManager.Instance(ksp.KSP).registry;
     registry.ClearAvailable();
     registry.ClearDlls();
     registry.Installed().Clear();
 }
Ejemplo n.º 4
0
        public void Setup()
        {
            ksp = new DisposableKSP();
            registry = ksp.KSP.Registry;

            registry.ClearAvailable();
            registry.ClearDlls();
            registry.Installed().Clear();
        }
Ejemplo n.º 5
0
        public void Setup()
        {
            ksp = new DisposableKSP();

            registry = ksp.KSP.Registry;
            registry.ClearAvailable();
            registry.ClearDlls();
            registry.Installed().Clear();

            Repo.UpdateRegistry(TestData.TestKANZip(), registry, ksp.KSP, new NullUser());
        }
Ejemplo n.º 6
0
 public void NewGuiModsAreNotSelectedForUpgrade()
 {
     using (var tidy = new DisposableKSP())
     {
         KSPManager manager = new KSPManager(new NullUser(), new FakeWin32Registry(tidy.KSP)){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.Version());
         Assert.False(mod.IsUpgradeChecked);
     }
 }
Ejemplo n.º 7
0
        public void IsVisible_WithAllAndNoNameFilter_ReturnsTrueForCompatible()
        {
            using (var tidy = new DisposableKSP())
            {
                KSPManager manager = new KSPManager(new NullUser(), new FakeWin32Registry(tidy.KSP)) { CurrentInstance = tidy.KSP };

                var ckan_mod = TestData.FireSpitterModule();
                var registry = Registry.Empty();
                registry.AddAvailable(ckan_mod);
                var item = new MainModList(delegate { }, null);
                Assert.That(item.IsVisible(new GUIMod(ckan_mod, registry, manager.CurrentInstance.Version())));
            }
        }
Ejemplo n.º 8
0
        public void HasUpdateReturnsTrueWhenUpdateAvailible()
        {
            using (var tidy = new DisposableKSP())
            {
                var generatror = new RandomModuleGenerator(new Random(0451));
                var old_version = generatror.GeneratorRandomModule(version: new Version("0.24"), ksp_version: tidy.KSP.Version());
                var new_version = generatror.GeneratorRandomModule(version: new Version("0.25"), ksp_version: tidy.KSP.Version(),
                    identifier:old_version.identifier);
                var registry = Registry.Empty();
                registry.RegisterModule(old_version, Enumerable.Empty<string>(), null);
                registry.AddAvailable(new_version);

                var mod = new GUIMod(old_version, registry, tidy.KSP.Version());
                Assert.True(mod.HasUpdate);
            }
        }
Ejemplo n.º 9
0
        public void AutodetectedCanSatisfyRelationships()
        {
            using (var ksp = new DisposableKSP ())
            {
                registry.RegisterDll(ksp.KSP, Path.Combine(ksp.KSP.GameData(), "ModuleManager.dll"));

                var depends = new List<CKAN.RelationshipDescriptor>();
                depends.Add(new CKAN.RelationshipDescriptor { name = "ModuleManager" });

                CkanModule mod = generator.GeneratorRandomModule(depends: depends);

                new RelationshipResolver(
                    new CKAN.CkanModule[] { mod },
                    RelationshipResolver.DefaultOpts(),
                    registry,
                    KspVersion.Parse("1.0.0")
                );
            }
        }
Ejemplo n.º 10
0
        public void Setup()
        {
            // Make sure curl is all set up.
            Curl.Init();

            // Give us a registry to play with.
            ksp = new DisposableKSP();
            registry = ksp.KSP.Registry;

            registry.ClearAvailable();
            registry.ClearDlls();
            registry.Installed().Clear();

            // Make sure we have a registry we can use.
            CKAN.Repo.UpdateRegistry(TestData.TestKANZip(), registry, ksp.KSP, new NullUser());

            // Ready our downloader.
            async = new CKAN.NetAsyncModulesDownloader(new NullUser());

            // General shortcuts
            cache = ksp.KSP.Cache;
        }
Ejemplo n.º 11
0
        public async Task ComputeChangeSetFromModList_WithConflictingMods_ThrowsInconsistentKraken()
        {
            using (var tidy = new DisposableKSP())
            {
                KSPManager manager = new KSPManager(new NullUser(), new FakeWin32Registry(tidy.KSP)) { CurrentInstance = tidy.KSP };

                var registry = Registry.Empty();
                var module = TestData.FireSpitterModule();
                module.conflicts = new List<RelationshipDescriptor> { new RelationshipDescriptor { name = "kOS" } };
                registry.AddAvailable(TestData.FireSpitterModule());
                registry.AddAvailable(TestData.kOS_014_module());
                registry.RegisterModule(module, Enumerable.Empty<string>(), tidy.KSP);

                var main_mod_list = new MainModList(null, null);
                var mod = new GUIMod(TestData.FireSpitterModule(), registry, manager.CurrentInstance.Version());
                var mod2 = new GUIMod(TestData.kOS_014_module(), registry, manager.CurrentInstance.Version());
                mod.IsInstallChecked = true;
                mod2.IsInstallChecked = true;

                var compute_change_set_from_mod_list = main_mod_list.ComputeChangeSetFromModList(registry, main_mod_list.ComputeUserChangeSet(), null, tidy.KSP.Version());
                await UtilStatic.Throws<InconsistentKraken>(async ()=> { await compute_change_set_from_mod_list; });
            }
        }
Ejemplo n.º 12
0
        public async Task ComputeChangeSetFromModList_WithConflictingMods_ThrowsInconsistentKraken()
        {
            using (var tidy = new DisposableKSP())
            {
                var registry = Registry.Empty();
                var module = TestData.FireSpitterModule();
                module.conflicts = new List<RelationshipDescriptor> { new RelationshipDescriptor { name = "kOS" } };
                registry.AddAvailable(module);
                registry.AddAvailable(TestData.kOS_014_module());
                registry.RegisterModule(module, Enumerable.Empty<string>(), tidy.KSP);

                var mainList = new MainModList(null, null, new GUIUser());
                var mod = new GUIMod(module, registry, tidy.KSP.VersionCriteria());
                var mod2 = new GUIMod(TestData.kOS_014_module(), registry, tidy.KSP.VersionCriteria());
                var mods = new List<GUIMod>() { mod, mod2 };
                mainList.ConstructModList(mods, true);
                mainList.Modules = new ReadOnlyCollection<GUIMod>(mods);
                mod2.IsInstallChecked = true;
                var computeTask = mainList.ComputeChangeSetFromModList(registry, mainList.ComputeUserChangeSet(), null,
                    tidy.KSP.VersionCriteria());

                await UtilStatic.Throws<InconsistentKraken>(() => computeTask);
            }
        }
Ejemplo n.º 13
0
 public void AddInstance_ManagarHasInstance()
 {
     using (var tidy2 = new DisposableKSP())
     {
         const string newInstance = "tidy2";
         Assert.That(manager.HasInstance(newInstance), Is.False);
         manager.AddInstance(newInstance, tidy2.KSP);
         Assert.That(manager.HasInstance(newInstance),Is.True);
     }
 }
Ejemplo n.º 14
0
 public void SetUp()
 {
     tidy = new DisposableKSP();
     win32_reg = GetTestWin32Reg(nameInReg);
     manager = new KSPManager(new NullUser(), win32_reg);
 }
Ejemplo n.º 15
0
        public void GetPreferredInstance_WithEmptyAutoStartAndMultipleInstances_ReturnsNull()
        {
            using (var tidy2 = new DisposableKSP())
            {
                win32_reg.Instances.Add(new Tuple<string, string>("tidy2",tidy2.KSP.GameDir()));
                manager.LoadInstancesFromRegistry();
                manager.ClearAutoStart();
                Assert.That(manager.GetPreferredInstance(), Is.Null);
            }

        }
Ejemplo n.º 16
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())
            {
                KSPManager manager = new KSPManager(new NullUser(), new FakeWin32Registry(ksp.KSP)){CurrentInstance = ksp.KSP};

                Assert.IsTrue(Directory.Exists(ksp.KSP.DownloadCacheDir()));

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

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

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

                CKAN.ModuleInstaller.GetInstance(manager.CurrentInstance, NullUser.User).InstallList(modules, new RelationshipResolverOptions());

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

                // Attempt to uninstall it.
                CKAN.ModuleInstaller.GetInstance(manager.CurrentInstance, NullUser.User).UninstallList(modules);

                // Check that the module is not installed.
                Assert.IsFalse(File.Exists(mod_file_path));
            }
        }
Ejemplo n.º 17
0
        public void FindInstallableFilesWithBonusPath(string path)
        {
            dogemod.install[0].install_to = path;
            using (var tidy = new DisposableKSP())
            {
                IEnumerable<InstallableFile> contents = CKAN.ModuleInstaller.FindInstallableFiles(
                                                            dogemod, dogezip, tidy.KSP
                                                        );

                string file = contents
                    .Select(x => x.destination).FirstOrDefault(
                        x => Regex.IsMatch(x, "GameData/SuchTest/DogeCoinFlag/Flags/dogecoin\\.png$"));

                Assert.IsNotNull(file);
            }
        }
Ejemplo n.º 18
0
        public void UninstallModNotFound()
        {
            using (var tidy = new DisposableKSP())
            {
                KSPManager manager = new KSPManager(new NullUser(), new FakeWin32Registry(tidy.KSP)){CurrentInstance = tidy.KSP};

                Assert.Throws<ModNotInstalledKraken>(delegate
                {
                    // This should throw, as our tidy KSP has no mods installed.
                    CKAN.ModuleInstaller.GetInstance(manager.CurrentInstance, NullUser.User).UninstallList("Foo");
                });

                manager.CurrentInstance = null; // I weep even more.
            }
        }
Ejemplo n.º 19
0
        public void AllowInstallsToScenarios()
        {
            // Bogus zip with example to install.
            var zip = ZipFile.Create(new MemoryStream());
            zip.BeginUpdate();
            zip.AddDirectory("saves");
            zip.AddDirectory("saves/scenarios");
            zip.Add(new ZipEntry("/saves/scenarios/AwesomeRace.sfs") { Size = 0, CompressedSize = 0 });
            zip.CommitUpdate();

            var mod = CkanModule.FromJson(@"
                {
                    ""spec_version"": ""v1.14"",
                    ""identifier"": ""AwesomeMod"",
                    ""version"": ""1.0.0"",
                    ""download"": ""https://awesomemod.example/AwesomeMod.zip"",
                    ""install"": [
                        {
                            ""file"": ""saves/scenarios/AwesomeRace.sfs"",
                            ""install_to"": ""Scenarios""
                        }
                    ]
                }")
                ;

            List<InstallableFile> results;
            using (var ksp = new DisposableKSP())
            {
                results = CKAN.ModuleInstaller.FindInstallableFiles(mod.install.First(), zip, ksp.KSP);

                Assert.AreEqual(
                    CKAN.KSPPathUtils.NormalizePath(
                        Path.Combine(ksp.KSP.GameDir(), "saves/scenarios/AwesomeRace.sfs")
                    ),
                    results.First().destination
                );
            }
        }
Ejemplo n.º 20
0
        public void AllowsInstallsToShipsDirectories(string directory)
        {
            // Arrange
            var zip = ZipFile.Create(new MemoryStream());
            zip.BeginUpdate();
            zip.AddDirectory("ExampleShips");
            zip.Add(new ZipEntry("/ExampleShips/AwesomeShip.craft") { Size = 0, CompressedSize = 0 });
            zip.CommitUpdate();

            var mod = CkanModule.FromJson(string.Format(@"
            {{
                ""spec_version"": 1,
                ""identifier"": ""AwesomeMod"",
                ""version"": ""1.0.0"",
                ""download"": ""https://awesomemod.example/AwesomeMod.zip"",
                ""install"": [
                    {{
                        ""file"": ""ExampleShips/AwesomeShip.craft"",
                        ""install_to"": ""{0}""
                    }}
                ]
            }}
            ", directory));

            // Act
            List<InstallableFile> results;
            using (var ksp = new DisposableKSP())
            {
                results = CKAN.ModuleInstaller.FindInstallableFiles(mod.install.First(), zip, ksp.KSP);
            }

            // Assert
            Assert.That(
                results.Count(i => i.destination.EndsWith(string.Format("/{0}/AwesomeShip.craft", directory))) == 1,
                Is.True
            );
        }
Ejemplo n.º 21
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())
                    {
                        // Copy the zip file to the cache directory.
                        ksp.KSP.Cache.Store(TestData.DogeCoinFlag_101_module().download, 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};
                        
                        CKAN.ModuleInstaller.GetInstance(ksp.KSP, NullUser.User).InstallList(modules, new RelationshipResolverOptions());
                        
                        // Check that the module is installed.
                        string mod_file_path = Path.Combine(ksp.KSP.GameData(), mod_file_name);
                        
                        Assert.IsTrue(File.Exists(mod_file_path));
                    }
                }
            });
        }
Ejemplo n.º 22
0
        public void UninstallEmptyDirs()
        {
            string emptyFolderName = "DogeCoinFlag";

            // Create a new disposable KSP instance to run the test on.
            using (var ksp = new DisposableKSP())
            {
                KSPManager manager = new KSPManager(new NullUser(), new FakeWin32Registry(ksp.KSP)){CurrentInstance = ksp.KSP};

                Assert.IsTrue(Directory.Exists(ksp.KSP.DownloadCacheDir()));

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

                // Install the base test mod.

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

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

                CKAN.ModuleInstaller.GetInstance(manager.CurrentInstance, NullUser.User).InstallList(modules, new RelationshipResolverOptions());

                modules.Clear();

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

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

                CKAN.ModuleInstaller.GetInstance(manager.CurrentInstance, NullUser.User).InstallList(modules, new RelationshipResolverOptions());

                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, NullUser.User).UninstallList(modules);

                // Check that the directory has been deleted.
                Assert.IsFalse(Directory.Exists(directoryPath));
            }
        }
Ejemplo n.º 23
0
 public void ConstructModList_NumberOfRows_IsEqualToNumberOfMods()
 {
     using (var tidy = new DisposableKSP())
     {
         KSPManager manager = new KSPManager(new NullUser(), new FakeWin32Registry(tidy.KSP)) { CurrentInstance = tidy.KSP };
         var registry = Registry.Empty();
         registry.AddAvailable(TestData.FireSpitterModule());
         registry.AddAvailable(TestData.kOS_014_module());
         var main_mod_list = new MainModList(null, null);
         var mod_list = main_mod_list.ConstructModList(new List<GUIMod>
         {
             new GUIMod(TestData.FireSpitterModule(), registry, manager.CurrentInstance.Version()),
             new GUIMod(TestData.kOS_014_module(), registry, manager.CurrentInstance.Version())
         });
         Assert.That(mod_list, Has.Count.EqualTo(2));
     }
 }
Ejemplo n.º 24
0
        public void Up()
        {
            _instance = new DisposableKSP();
            _registry = Registry.Empty();
            _manager = new KSPManager(new NullUser(), new FakeWin32Registry(_instance.KSP));

            // this module contains a ksp_version of "any" which repros our issue
            _anyVersionModule = TestData.DogeCoinFlag_101_module();

            // install it and set it as pre-installed
            _instance.KSP.Cache.Store(TestData.DogeCoinFlag_101_module().download, TestData.DogeCoinFlagZip());
            _registry.RegisterModule(_anyVersionModule, new string[] { }, _instance.KSP);
            _registry.AddAvailable(_anyVersionModule);

            ModuleInstaller.GetInstance(_instance.KSP, _manager.User).InstallList(
                new List<CkanModule> { { _anyVersionModule } },
                new RelationshipResolverOptions(),
                new NetAsyncModulesDownloader(_manager.User)
            );

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

            // test object
            _modList = new MainModList(null, null, _manager.User);
            _listGui = new MainModListGUI();

            // todo: refactor the column header code to allow mocking of the GUI without creating columns
            _listGui.Columns.Add(new DataGridViewCheckBoxColumn());
            _listGui.Columns.Add(new DataGridViewCheckBoxColumn());
            for (int i = 0; i < 10; i++)
            {
                _listGui.Columns.Add(i.ToString(), "Column" + i);
            }
        }
Ejemplo n.º 25
0
        public async Task TooManyProvidesCallsHandlers()
        {
            using (var tidy = new DisposableKSP())
            {
                var registry = Registry.Empty();
                var generator = new RandomModuleGenerator(new Random(0451));
                var provide_ident = "provide";
                var ksp_version = tidy.KSP.Version();
                var mod = generator.GeneratorRandomModule(depends: new List<RelationshipDescriptor>
                {
                    new RelationshipDescriptor {name = provide_ident}
                },ksp_version:ksp_version);
                var moda = generator.GeneratorRandomModule(provides: new List<string> { provide_ident }
                , ksp_version: ksp_version);
                var modb = generator.GeneratorRandomModule(provides: new List<string> { provide_ident }
                , ksp_version: ksp_version);
                var choice_of_provide = modb;
                registry.AddAvailable(mod);
                registry.AddAvailable(moda);
                registry.AddAvailable(modb);
                var installer = ModuleInstaller.GetInstance(tidy.KSP, null);
                var main_mod_list = new MainModList(null, async kraken => await Task.FromResult(choice_of_provide));
                var a = new HashSet<ModChange>
                {
                    new ModChange(new GUIMod(mod,registry,ksp_version), GUIModChangeType.Install, null)
                };

                var mod_list = await main_mod_list.ComputeChangeSetFromModList(registry, a, installer, ksp_version);
                CollectionAssert.AreEquivalent(
                    new[] {
                        new ModChange(new GUIMod(mod,registry,ksp_version), GUIModChangeType.Install, null),
                        new ModChange(new GUIMod(modb,registry,ksp_version),GUIModChangeType.Install, null)
                    }, mod_list);

            }
        }
Ejemplo n.º 26
0
        public void ModuleManagerInstall()
        {
            using (var tidy = new DisposableKSP())
            {
                List<InstallableFile> contents = CKAN.ModuleInstaller.FindInstallableFiles(mm_mod, mm_zip, tidy.KSP);

                string file = contents
                    .Select(x => x.destination).FirstOrDefault(
                    x => Regex.IsMatch(x, @"ModuleManager\.2\.5\.1\.dll$"));

                Assert.IsNotNull(file, "ModuleManager install");
            }
        }
Ejemplo n.º 27
0
        public void FindInstallableFilesWithKSP(CkanModule mod)
        {
            using (var tidy = new DisposableKSP())
            {
                List<InstallableFile> contents = CKAN.ModuleInstaller.FindInstallableFiles(mod, dogezip, tidy.KSP);

                // See if we can find an expected destination path in the right place.
                string file = contents
                    .Select(x => x.destination).FirstOrDefault(
                        x => Regex.IsMatch(x, "GameData/DogeCoinFlag/Flags/dogecoin\\.png$"));

                Assert.IsNotNull(file);
            }
        }
Ejemplo n.º 28
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())
            {
                // Make sure the mod is not installed.
                string mod_file_path = Path.Combine(ksp.KSP.GameData(), mod_file_name);

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

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

                string cache_path = ksp.KSP.Cache.Store(TestData.DogeCoinFlag_101_module().download, TestData.DogeCoinFlagZip());

                Assert.IsTrue(ksp.KSP.Cache.IsCachedZip(TestData.DogeCoinFlag_101_module().download));
                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.Available(ksp.KSP.VersionCriteria()).Count());

                registry.AddAvailable(TestData.DogeCoinFlag_101_module());

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

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

                CKAN.ModuleInstaller.GetInstance(ksp.KSP, NullUser.User).InstallList(modules, new RelationshipResolverOptions());

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