TShock/TShockLauncher.Tests/GroupTests.cs
Luke 8ce81136b4 Update GroupTests.cs
Sets the 1.4.4.2 static variable that Terraria.Main has a dependency on
2022-09-30 15:38:13 +10:00

51 lines
1.2 KiB
C#

using NUnit.Framework;
using Terraria;
using Terraria.Localization;
using TShockAPI;
using TShockAPI.DB;
namespace TShockLauncher.Tests;
public class GroupTests
{
[SetUp]
public static void SetupTShock()
{
Program.SavePath = ""; // 1.4.4.2
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);
}
}