diff --git a/GUI/MainModList.cs b/GUI/MainModList.cs index 8814fabc28..0a88b14aca 100644 --- a/GUI/MainModList.cs +++ b/GUI/MainModList.cs @@ -56,7 +56,9 @@ private IEnumerable Sort(IEnumerable rows, /// private string DefaultSorter(DataGridViewRow row) { - return row.Cells[this.configuration.SortByColumnIndex].Value.ToString(); + // changed so that it never returns null + var cellVal = row.Cells[configuration.SortByColumnIndex].Value as string; + return string.IsNullOrWhiteSpace(cellVal) ? string.Empty : cellVal; } /// @@ -135,12 +137,11 @@ private void _UpdateFilters() } } - private void UpdateModsList(Boolean repo_updated = false) + public void UpdateModsList(Boolean repo_updated = false) { Util.Invoke(this, () => _UpdateModsList(repo_updated)); } - private void _UpdateModsList(bool repo_updated) { log.Debug("Updating the mod list"); diff --git a/Tests/GUI/GH1866.cs b/Tests/GUI/GH1866.cs new file mode 100644 index 0000000000..d36afe121e --- /dev/null +++ b/Tests/GUI/GH1866.cs @@ -0,0 +1,124 @@ +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Windows.Forms; +using CKAN; +using NUnit.Framework; +using Tests.Core; +using Tests.Data; +using ModuleInstaller = CKAN.ModuleInstaller; + +namespace Tests.GUI +{ + /// + /// This test attempts to reproduce the state of GitHub issue #1866 + /// which involves sorting the GUI table by Max KSP Version and then performing a repo operation. + /// + [Explicit] + [TestFixture] + public class GH1866 + { + private CkanModule _anyVersionModule; + private DisposableKSP _instance; + private KSPManager _manager; + private Registry _registry; + private MainModList _modList; + private MainModListGUI _listGui; + + + /* + * 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 + ModuleInstaller.GetInstance(_instance.KSP, main.currentUser).InstallList( + changeList, + new RelationshipResolverOptions(), + new NetAsyncModulesDownloader(main.currentUser) + );*/ + + [TestFixtureSetUp] + 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 { { _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(delegate { }, delegate { return null; }); + _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); + } + } + + [TestFixtureTearDown] + public void Down() + { + _instance.Dispose(); + } + + [Test] + public void Sanity() + { + Assert.IsNotNull(_instance.KSP); + Assert.IsNotNull(_manager); + Assert.IsNotNull(_modList); + } + + [Test] + public void TestSimple() + { + var modules = _registry.available_modules + .Select((mod) => new GUIMod(mod.Value.Latest(), _registry, _instance.KSP.Version())) + .ToList(); + + // varargs method signature means we must call .ToArray() + _listGui.Rows.AddRange(_modList.ConstructModList(modules).ToArray()); + Assert.AreEqual(3, _listGui.Rows.Count); + + // sort by version, this is the fuse-lighting + _listGui.Sort(_listGui.Columns[6], ListSortDirection.Descending); + + var anyVersionModule = modules.First((mod) => mod.Identifier.Contains("Doge")); + var anyVersionRow = _listGui.Rows + .Cast() + .First((mod) => mod.Tag.Equals(anyVersionModule)); + anyVersionModule.SetInstallChecked(anyVersionRow, true); + Assert.IsTrue(anyVersionModule.IsInstallChecked); + } + } +} diff --git a/Tests/NetKAN/JenkinsTests.cs b/Tests/NetKAN/JenkinsTests.cs deleted file mode 100644 index 04012c231f..0000000000 --- a/Tests/NetKAN/JenkinsTests.cs +++ /dev/null @@ -1,13 +0,0 @@ -using NUnit.Framework; - -namespace Tests.NetKAN -{ - [TestFixture] - public class JenkinsAPITests - { - [Test] - public void Inflate() - { - } - } -} \ No newline at end of file diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 4861aaad7b..2f92acea33 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -142,13 +142,13 @@ + -