Fix sqlite null parameters + unit test
This commit is contained in:
parent
13e82110ee
commit
5a98add6de
2 changed files with 51 additions and 1 deletions
|
|
@ -45,7 +45,7 @@ namespace TShockAPI.DB
|
|||
{
|
||||
com.CommandText = query;
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
com.AddParameter("@" + i, args[i]);
|
||||
com.AddParameter("@" + i, args[i] ?? DBNull.Value);
|
||||
return com.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
50
TShockLauncher.Tests/GroupTests.cs
Normal file
50
TShockLauncher.Tests/GroupTests.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using NUnit.Framework;
|
||||
using Terraria;
|
||||
using Terraria.Localization;
|
||||
using TShockAPI;
|
||||
using TShockAPI.DB;
|
||||
|
||||
namespace TShockLauncher.Tests;
|
||||
|
||||
public class GroupTests
|
||||
{
|
||||
[SetUp]
|
||||
public static void SetupTShock()
|
||||
{
|
||||
LanguageManager.Instance.SetLanguage(GameCulture.DefaultCulture);
|
||||
Lang.InitializeLegacyLocalization();
|
||||
|
||||
//Setup();
|
||||
var ts = new TShock(null); // prepares configs etc
|
||||
ts.Initialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This tests to ensure the group commands work.
|
||||
/// </summary>
|
||||
/// <remarks>Due to the switch to Microsoft.Data.Sqlite, nulls have to be replaced with DBNull for the query to complete</remarks>
|
||||
[TestCase]
|
||||
public void TestPermissions()
|
||||
{
|
||||
var groups = TShock.Groups = new GroupManager(TShock.DB);
|
||||
|
||||
if (!groups.GroupExists("test"))
|
||||
groups.AddGroup("test", null, "test", Group.defaultChatColor);
|
||||
|
||||
groups.AddPermissions("test", new() { "abc" });
|
||||
|
||||
var hasperm = groups.GetGroupByName("test").Permissions.Contains("abc");
|
||||
Assert.IsTrue(hasperm);
|
||||
|
||||
groups.DeletePermissions("test", new() { "abc" });
|
||||
|
||||
hasperm = groups.GetGroupByName("test").Permissions.Contains("abc");
|
||||
Assert.IsFalse(hasperm);
|
||||
|
||||
groups.DeleteGroup("test");
|
||||
|
||||
var g = groups.GetGroupByName("test");
|
||||
Assert.IsNull(g);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue