Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GUI exceptions when installing/uninstalling after sorting by KSP max version #1882

Merged
merged 6 commits into from
Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions GUI/MainModList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ private IEnumerable<DataGridViewRow> Sort<T>(IEnumerable<DataGridViewRow> rows,
/// </summary>
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;
}

/// <summary>
Expand Down Expand Up @@ -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");
Expand Down
124 changes: 124 additions & 0 deletions Tests/GUI/GH1866.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// 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.
/// </summary>
[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<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(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<DataGridViewRow>()
.First((mod) => mod.Tag.Equals(anyVersionModule));
anyVersionModule.SetInstallChecked(anyVersionRow, true);
Assert.IsTrue(anyVersionModule.IsInstallChecked);
}
}
}
13 changes: 0 additions & 13 deletions Tests/NetKAN/JenkinsTests.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@
<Compile Include="Data\TestData.cs" />
<Compile Include="Data\ZipLib.cs" />
<Compile Include="GUI\Configuration.cs" />
<Compile Include="GUI\GH1866.cs" />
<Compile Include="GUI\GUIMod.cs" />
<Compile Include="GUI\MainModList.cs" />
<Compile Include="GUI\NavigationHistoryTests.cs" />
<Compile Include="NetKAN\AVC.cs" />
<Compile Include="NetKAN\Extensions\JObjectExtensionsTests.cs" />
<Compile Include="NetKAN\Extensions\VersionExtensionsTests.cs" />
<Compile Include="NetKAN\JenkinsTests.cs" />
<Compile Include="NetKAN\SDMod.cs" />
<Compile Include="NetKAN\MainClass.cs" />
<Compile Include="NetKAN\NetkanOverride.cs" />
Expand Down