2018-08-28 17:32:59 -04:00
|
|
|
|
using IW4MAdmin.Application;
|
|
|
|
|
using SharedLibraryCore;
|
2018-11-05 22:01:29 -05:00
|
|
|
|
using SharedLibraryCore.Database.Models;
|
2018-08-28 17:32:59 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Tests
|
|
|
|
|
{
|
|
|
|
|
[Collection("ManagerCollection")]
|
|
|
|
|
public class ManagerTests
|
|
|
|
|
{
|
|
|
|
|
readonly ApplicationManager Manager;
|
|
|
|
|
|
|
|
|
|
public ManagerTests(ManagerFixture fixture)
|
|
|
|
|
{
|
|
|
|
|
Manager = fixture.Manager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void AreCommandNamesUnique()
|
|
|
|
|
{
|
|
|
|
|
bool test = Manager.GetCommands().Count == Manager.GetCommands().Select(c => c.Name).Distinct().Count();
|
|
|
|
|
Assert.True(test, "command names are not unique");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void AreCommandAliasesUnique()
|
|
|
|
|
{
|
2019-06-24 12:01:34 -04:00
|
|
|
|
var mgr = Manager;
|
2018-08-28 17:32:59 -04:00
|
|
|
|
bool test = mgr.GetCommands().Count == mgr.GetCommands().Select(c => c.Alias).Distinct().Count();
|
|
|
|
|
|
2019-06-24 12:01:34 -04:00
|
|
|
|
foreach (var duplicate in mgr.GetCommands().GroupBy(_cmd => _cmd.Alias).Where(_grp => _grp.Count() > 1).Select(_grp => new { Command = _grp.First().Name, Alias = _grp.Key }))
|
2018-08-28 17:32:59 -04:00
|
|
|
|
{
|
2019-06-24 12:01:34 -04:00
|
|
|
|
Debug.WriteLine($"{duplicate.Command}: {duplicate.Alias}");
|
2018-08-28 17:32:59 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-24 12:01:34 -04:00
|
|
|
|
Assert.True(test, "command aliases are not unique");
|
2018-08-28 17:32:59 -04:00
|
|
|
|
}
|
2018-10-12 22:28:22 -04:00
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void PrintCommands()
|
|
|
|
|
{
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
sb.AppendLine("|Name |Alias|Description |Requires Target|Syntax |Required Level|");
|
|
|
|
|
sb.AppendLine("|--------------| -----| --------------------------------------------------------| -----------------| -------------| ----------------|");
|
|
|
|
|
|
|
|
|
|
foreach (var command in Manager.GetCommands().OrderByDescending(c => c.Permission).ThenBy(c => c.Name))
|
|
|
|
|
{
|
|
|
|
|
sb.AppendLine($"|{command.Name}|{command.Alias}|{command.Description}|{command.RequiresTarget}|{command.Syntax.Substring(8).EscapeMarkdown()}|{command.Permission}|");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.True(false, sb.ToString());
|
|
|
|
|
}
|
2018-08-28 17:32:59 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|