Skip to content
This repository has been archived by the owner on Feb 3, 2024. It is now read-only.

Commit

Permalink
add WIP tests for KSP-CKAN#1866
Browse files Browse the repository at this point in the history
  • Loading branch information
ayan4m1 committed Aug 29, 2016
1 parent bdcacdc commit 7836c1f
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 2 deletions.
3 changes: 1 addition & 2 deletions GUI/MainModList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,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
119 changes: 119 additions & 0 deletions Tests/GUI/GH1866.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
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
/// </summary>
[TestFixture]
public class GH1866
{
private CkanModule _anyVersionModule;
private DisposableKSP _instance;
private KSPManager _manager;
private Registry _registry;
private MainModList _modList;
private MainModListGUI _listGui;

/*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)
);
// throws Exception*/
[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 async 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);
}
}
}

0 comments on commit 7836c1f

Please sign in to comment.