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

Rename GH1866 test, fix invalid char test, fix equality assertion order #3509

Merged
merged 1 commit into from
Jan 19, 2022
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
5 changes: 4 additions & 1 deletion Tests/Core/Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ public void ZipValid_ContainsFilenameWithBadChars_NoException()
// only check the reason if found invalid
if (!valid)
{
Assert.AreEqual(reason, "Illegal characters in path.");
Assert.AreEqual(
@"Error in step EntryHeader for GameData/FlagPack/Flags/Weyland-Yutani from ""Alien"".png: Exception during test - 'Name is invalid'",
reason
);
}

// Switch back to the original locale
Expand Down
4 changes: 2 additions & 2 deletions Tests/Core/Types/CkanModuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public void CompatibleWith()
public void StandardName()
{
CkanModule module = CkanModule.FromJson(TestData.kOS_014());
Assert.AreEqual(module.StandardName(), "kOS-0.14.zip");
Assert.AreEqual("kOS-0.14.zip", module.StandardName());

CkanModule module2 = CkanModule.FromJson(TestData.kOS_014_with_invalid_version_characters());
Assert.AreEqual(module2.StandardName(), "kOS-0-14-0.zip");
Assert.AreEqual("kOS-0-14-0.zip", module2.StandardName());
}

[Test]
Expand Down
161 changes: 0 additions & 161 deletions Tests/GUI/GH1866.cs

This file was deleted.

136 changes: 131 additions & 5 deletions Tests/GUI/Model/ModList.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using System;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using CKAN;
using CKAN.Versioning;
using System.ComponentModel;
using System.Windows.Forms;
using NUnit.Framework;
using Tests.Core.Configuration;
using Tests.Data;
using ModuleInstaller = CKAN.ModuleInstaller;

using CKAN;
using CKAN.Versioning;

namespace Tests.GUI
{
Expand Down Expand Up @@ -63,7 +65,7 @@ public void CountModsByFilter_EmptyModList_ReturnsZero(GUIModFilter filter)
}

[Test]
[Category("Display")]
[NUnit.Framework.Category("Display")]
public void ConstructModList_NumberOfRows_IsEqualToNumberOfMods()
{
using (var tidy = new DisposableKSP())
Expand Down Expand Up @@ -95,5 +97,129 @@ public void ConstructModList_NumberOfRows_IsEqualToNumberOfMods()
}
}

/// <summary>
/// Sort the GUI table by Max KSP Version
/// and then perform a repo operation.
/// Attempts to reproduce:
/// https://github.com/KSP-CKAN/CKAN/issues/1803
/// https://github.com/KSP-CKAN/CKAN/issues/1875
/// https://github.com/KSP-CKAN/CKAN/pull/1866
/// https://github.com/KSP-CKAN/CKAN/pull/1882
/// </summary>
[Test]
[NUnit.Framework.Category("Display")]
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();
}

}
}
6 changes: 3 additions & 3 deletions Tests/NetKAN/Transformers/AvcKrefTransformerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public void Transform_SimpleVersionFile_PropertiesSet(string remoteUrl, string v

// Assert
var json = m.Json();
Assert.AreEqual((string)json["version"], version);
Assert.AreEqual((string)json["ksp_version"], GameVersion);
Assert.AreEqual((string)json["download"], download);
Assert.AreEqual(version, (string)json["version"]);
Assert.AreEqual(GameVersion, (string)json["ksp_version"]);
Assert.AreEqual(download, (string)json["download"]);
}

private Metadata TryKref(IHttpService http, string kref)
Expand Down