Beispiel #1
0
        public void Registry_ZeroByteRegistryJson_EmptyRegistryWithoutCrash()
        {
            // Arrange
            string        registryPath = TestData.DataDir("zero-byte-registry.json");
            DisposableKSP dispksp;

            CKAN.GameInstance ksp;

            // Act
            dispksp = new DisposableKSP(null, registryPath);
            ksp     = dispksp.KSP;

            // Assert
            CKAN.Registry reg = CKAN.RegistryManager.Instance(ksp).registry;
            Assert.IsNotNull(reg);
            // These lists should all be empty, copied from CKAN.Registry.Empty()
            Assert.IsFalse(reg.InstalledModules.Any());
            Assert.IsFalse(reg.InstalledDlls.Any());
            Assert.IsFalse(reg.HasAnyAvailable());
            // installed_files isn't exposed for testing
            // A default repo is set during load
            Assert.IsTrue(reg.Repositories.Any());

            dispksp.Dispose();
        }
Beispiel #2
0
 public void TearDown()
 {
     manager.Dispose();
     manager   = null;
     win32_reg = null;
     tidy.KSP.Dispose();
     tidy2.KSP.Dispose();
     tidy.Dispose();
     tidy2.Dispose();
 }
Beispiel #3
0
 public void Down()
 {
     _instance.Dispose();
     _manager.Dispose();
     _config.Dispose();
 }
Beispiel #4
0
 public void TearDown()
 {
     temp_ksp.Dispose();
 }
Beispiel #5
0
 public void TearDown()
 {
     manager.Dispose();
     tidy.Dispose();
 }
Beispiel #6
0
 public void TearDown()
 {
     ksp.Dispose();
 }
Beispiel #7
0
 public void TearDown()
 {
     tidy.Dispose();
 }
 public void TearDown()
 {
     manager.Dispose();
     ksp.Dispose();
 }
Beispiel #9
0
 public void TearDown()
 {
     Curl.CleanUp();
     manager.Dispose();
     ksp.Dispose();
 }
Beispiel #10
0
 public void Down()
 {
     _instance.Dispose();
 }
Beispiel #11
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();
        }