public void KSPCompatibility_OutOfOrderGameVersions_TrueMaxVersion() { using (var tidy = new DisposableKSP()) { // Arrange CkanModule mainVersion = CkanModule.FromJson(@"{ ""identifier"": ""OutOfOrderMod"", ""version"": ""1.2.0"", ""ksp_version"": ""0.90"", ""download"": ""http://www.ksp-ckan.space"" }"); CkanModule prevVersion = CkanModule.FromJson(@"{ ""identifier"": ""OutOfOrderMod"", ""version"": ""1.1.0"", ""ksp_version"": ""1.4.2"", ""download"": ""http://www.ksp-ckan.space"" }"); Registry registry = Registry.Empty(); registry.AddAvailable(mainVersion); registry.AddAvailable(prevVersion); // Act GUIMod m = new GUIMod(mainVersion, registry, tidy.KSP.VersionCriteria(), false); // Assert Assert.AreEqual("1.4.2", m.KSPCompatibility); } }
public void Up() { _instance = new DisposableKSP(); _registryManager = RegistryManager.Instance(_instance.KSP); _registry = Registry.Empty(); _config = new FakeConfiguration(_instance.KSP, _instance.KSP.Name); _manager = new GameInstanceManager( new NullUser(), _config ); // 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 _manager.Cache.Store(TestData.DogeCoinFlag_101_module(), TestData.DogeCoinFlagZip()); _registry.RegisterModule(_anyVersionModule, new string[] { }, _instance.KSP, false); _registry.AddAvailable(_anyVersionModule); HashSet <string> possibleConfigOnlyDirs = null; ModuleInstaller.GetInstance(_instance.KSP, _manager.Cache, _manager.User).InstallList( new List <CkanModule> { { _anyVersionModule } }, new RelationshipResolverOptions(), _registryManager, ref possibleConfigOnlyDirs, new NetAsyncModulesDownloader(_manager.User, _manager.Cache) ); // this module is not for "any" version, to provide another to sort against _registry.AddAvailable(TestData.kOS_014_module()); // test object _modList = new ModList(null); _listGui = new DataGridView(); // 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()); _listGui.Columns.Add(new DataGridViewCheckBoxColumn()); _listGui.Columns.Add(new DataGridViewCheckBoxColumn()); for (int i = 0; i < 10; i++) { _listGui.Columns.Add(i.ToString(), "Column" + i); } }
public void Constructor_WithMissingDependants_Throws() { var list = new List <string>(); var dependant = generator.GeneratorRandomModule(); var depender = generator.GeneratorRandomModule(depends: new List <RelationshipDescriptor> { new RelationshipDescriptor { name = dependant.identifier } }); list.Add(depender.identifier); registry.AddAvailable(depender); Assert.Throws <ModuleNotFoundKraken>(() => new RelationshipResolver( list, options, registry)); }
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(); }