| @@ -1,6 +1,6 @@ | |||||
| Microsoft Visual Studio Solution File, Format Version 12.00 | Microsoft Visual Studio Solution File, Format Version 12.00 | ||||
| # Visual Studio 15 | # Visual Studio 15 | ||||
| VisualStudioVersion = 15.0.26228.4 | |||||
| VisualStudioVersion = 15.0.26430.13 | |||||
| MinimumVisualStudioVersion = 10.0.40219.1 | MinimumVisualStudioVersion = 10.0.40219.1 | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Core", "src\Discord.Net.Core\Discord.Net.Core.csproj", "{91E9E7BD-75C9-4E98-84AA-2C271922E5C2}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Core", "src\Discord.Net.Core\Discord.Net.Core.csproj", "{91E9E7BD-75C9-4E98-84AA-2C271922E5C2}" | ||||
| EndProject | EndProject | ||||
| @@ -24,6 +24,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Tests", "test\D | |||||
| EndProject | EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Webhook", "src\Discord.Net.Webhook\Discord.Net.Webhook.csproj", "{9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Webhook", "src\Discord.Net.Webhook\Discord.Net.Webhook.csproj", "{9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30}" | ||||
| EndProject | EndProject | ||||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{01324441-C38B-4200-A675-0B7B32BA8CA8}" | |||||
| EndProject | |||||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord.Net.Commands.Tests", "test\Discord.Net.Commands.Tests\Discord.Net.Commands.Tests.csproj", "{CE02AD0A-B9D8-4C0A-B6F8-45A86D7DF3FF}" | |||||
| EndProject | |||||
| Global | Global | ||||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||
| Debug|Any CPU = Debug|Any CPU | Debug|Any CPU = Debug|Any CPU | ||||
| @@ -130,6 +134,18 @@ Global | |||||
| {9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30}.Release|x64.Build.0 = Release|Any CPU | {9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30}.Release|x64.Build.0 = Release|Any CPU | ||||
| {9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30}.Release|x86.ActiveCfg = Release|Any CPU | {9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30}.Release|x86.ActiveCfg = Release|Any CPU | ||||
| {9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30}.Release|x86.Build.0 = Release|Any CPU | {9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30}.Release|x86.Build.0 = Release|Any CPU | ||||
| {CE02AD0A-B9D8-4C0A-B6F8-45A86D7DF3FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||||
| {CE02AD0A-B9D8-4C0A-B6F8-45A86D7DF3FF}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||||
| {CE02AD0A-B9D8-4C0A-B6F8-45A86D7DF3FF}.Debug|x64.ActiveCfg = Debug|Any CPU | |||||
| {CE02AD0A-B9D8-4C0A-B6F8-45A86D7DF3FF}.Debug|x64.Build.0 = Debug|Any CPU | |||||
| {CE02AD0A-B9D8-4C0A-B6F8-45A86D7DF3FF}.Debug|x86.ActiveCfg = Debug|Any CPU | |||||
| {CE02AD0A-B9D8-4C0A-B6F8-45A86D7DF3FF}.Debug|x86.Build.0 = Debug|Any CPU | |||||
| {CE02AD0A-B9D8-4C0A-B6F8-45A86D7DF3FF}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||||
| {CE02AD0A-B9D8-4C0A-B6F8-45A86D7DF3FF}.Release|Any CPU.Build.0 = Release|Any CPU | |||||
| {CE02AD0A-B9D8-4C0A-B6F8-45A86D7DF3FF}.Release|x64.ActiveCfg = Release|Any CPU | |||||
| {CE02AD0A-B9D8-4C0A-B6F8-45A86D7DF3FF}.Release|x64.Build.0 = Release|Any CPU | |||||
| {CE02AD0A-B9D8-4C0A-B6F8-45A86D7DF3FF}.Release|x86.ActiveCfg = Release|Any CPU | |||||
| {CE02AD0A-B9D8-4C0A-B6F8-45A86D7DF3FF}.Release|x86.Build.0 = Release|Any CPU | |||||
| EndGlobalSection | EndGlobalSection | ||||
| GlobalSection(SolutionProperties) = preSolution | GlobalSection(SolutionProperties) = preSolution | ||||
| HideSolutionNode = FALSE | HideSolutionNode = FALSE | ||||
| @@ -140,6 +156,8 @@ Global | |||||
| {078DD7E6-943D-4D09-AFC2-D2BA58B76C9C} = {CC3D4B1C-9DE0-448B-8AE7-F3F1F3EC5C3A} | {078DD7E6-943D-4D09-AFC2-D2BA58B76C9C} = {CC3D4B1C-9DE0-448B-8AE7-F3F1F3EC5C3A} | ||||
| {688FD1D8-7F01-4539-B2E9-F473C5D699C7} = {288C363D-A636-4EAE-9AC1-4698B641B26E} | {688FD1D8-7F01-4539-B2E9-F473C5D699C7} = {288C363D-A636-4EAE-9AC1-4698B641B26E} | ||||
| {6BDEEC08-417B-459F-9CA3-FF8BAB18CAC7} = {B0657AAE-DCC5-4FBF-8E5D-1FB578CF3012} | {6BDEEC08-417B-459F-9CA3-FF8BAB18CAC7} = {B0657AAE-DCC5-4FBF-8E5D-1FB578CF3012} | ||||
| {C38E5BC1-11CB-4101-8A38-5B40A1BC6433} = {01324441-C38B-4200-A675-0B7B32BA8CA8} | |||||
| {9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30} = {CC3D4B1C-9DE0-448B-8AE7-F3F1F3EC5C3A} | {9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30} = {CC3D4B1C-9DE0-448B-8AE7-F3F1F3EC5C3A} | ||||
| {CE02AD0A-B9D8-4C0A-B6F8-45A86D7DF3FF} = {01324441-C38B-4200-A675-0B7B32BA8CA8} | |||||
| EndGlobalSection | EndGlobalSection | ||||
| EndGlobal | EndGlobal | ||||
| @@ -1,3 +1,4 @@ | |||||
| using System.Runtime.CompilerServices; | using System.Runtime.CompilerServices; | ||||
| [assembly: InternalsVisibleTo("Discord.Net.Tests")] | |||||
| [assembly: InternalsVisibleTo("Discord.Net.Tests")] | |||||
| [assembly: InternalsVisibleTo("Discord.Net.Commands.Tests")] | |||||
| @@ -0,0 +1,28 @@ | |||||
| using Discord.Commands; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| namespace Discord.Net.Commands.Tests | |||||
| { | |||||
| partial class CommandServiceConfigTests | |||||
| { | |||||
| public static IEnumerable<object[]> SeparatorNodeTestData => _separatorNodeTestData; | |||||
| private static readonly IEnumerable<object[]> _separatorNodeTestData = new List<CommandServiceConfig> | |||||
| { | |||||
| new CommandServiceConfig{ SeparatorChar = ' '}, | |||||
| new CommandServiceConfig{ SeparatorChar = '_'}, | |||||
| new CommandServiceConfig{ SeparatorChar = '.'}, | |||||
| new CommandServiceConfig{ SeparatorChar = '\u200b'}, | |||||
| new CommandServiceConfig{ SeparatorChar = '"'} | |||||
| }.Select(x => new object[] { x, x.SeparatorChar }); | |||||
| public static IEnumerable<object[]> CaseSensitivityTestData => _caseSensitivityTestData; | |||||
| private static readonly IEnumerable<object[]> _caseSensitivityTestData = new object[][] | |||||
| { | |||||
| new object[]{ true, false }, | |||||
| new object[]{ true, true }, | |||||
| new object[]{ false, true }, | |||||
| new object[]{ false, false } | |||||
| }; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,54 @@ | |||||
| using Discord.Commands; | |||||
| using Moq; | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Threading.Tasks; | |||||
| using Xunit; | |||||
| namespace Discord.Net.Commands.Tests | |||||
| { | |||||
| public partial class CommandServiceConfigTests | |||||
| { | |||||
| [Theory] | |||||
| [MemberData(nameof(SeparatorNodeTestData), MemberType = typeof(CommandServiceConfigTests))] | |||||
| public async Task CommandSeparators(CommandServiceConfig config, char separatorChar) | |||||
| { | |||||
| var service = new CommandService(config); | |||||
| await service.AddModuleAsync(typeof(DummyModule)).ConfigureAwait(false); | |||||
| var contextMock = new Mock<ICommandContext>(); | |||||
| var context = contextMock.Object; | |||||
| foreach (var _name in DummyModule.CommandNames) | |||||
| { | |||||
| var name = _name.Replace(' ', separatorChar); | |||||
| var result = service.Search(context, name); | |||||
| Assert.True(result.IsSuccess, result.ErrorReason); | |||||
| } | |||||
| } | |||||
| [Theory] | |||||
| [MemberData(nameof(CaseSensitivityTestData), MemberType = typeof(CommandServiceConfigTests))] | |||||
| public async Task CaseSensitivity(bool caseSensitive, bool upperCase) | |||||
| { | |||||
| var service = new CommandService(new CommandServiceConfig { CaseSensitiveCommands = caseSensitive }); | |||||
| await service.AddModuleAsync(typeof(DummyModule)).ConfigureAwait(false); | |||||
| var contextMock = new Mock<ICommandContext>(); | |||||
| var context = contextMock.Object; | |||||
| foreach (var _name in DummyModule.CommandNames) | |||||
| { | |||||
| var name = upperCase ? _name.ToUpper() : _name; | |||||
| var result = service.Search(context, name); | |||||
| if (caseSensitive && upperCase) | |||||
| Assert.False(result.IsSuccess, $"Searching for `{name}` returned successfully"); | |||||
| else | |||||
| Assert.True(result.IsSuccess, result.ErrorReason); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,45 @@ | |||||
| using Discord.Commands; | |||||
| using System; | |||||
| using System.Linq; | |||||
| using System.Threading.Tasks; | |||||
| using Xunit; | |||||
| namespace Discord.Net.Commands.Tests | |||||
| { | |||||
| class CommandServiceTests | |||||
| { | |||||
| [Fact] | |||||
| public async Task CommandsLoad() | |||||
| { | |||||
| var service = new CommandService(); | |||||
| var module = await service.AddModuleAsync(typeof(DummyModule)).ConfigureAwait(false); | |||||
| Assert.NotNull(module); | |||||
| var commandAliases = module.Commands.SelectMany(x => x.Aliases); | |||||
| foreach (var name in DummyModule.CommandNames) | |||||
| { | |||||
| Assert.True(commandAliases.Contains(name), $"The loaded module did not contain the command {name}"); | |||||
| } | |||||
| } | |||||
| [Fact] | |||||
| public async Task MultipleLoadsThrows() | |||||
| { | |||||
| var service = new CommandService(); | |||||
| var module = await service.AddModuleAsync(typeof(DummyModule)).ConfigureAwait(false); | |||||
| await Assert.ThrowsAsync<ArgumentException>(() => service.AddModuleAsync(typeof(DummyModule))) | |||||
| .ConfigureAwait(false); | |||||
| } | |||||
| [Fact] | |||||
| public async Task InvalidTypeThrows() | |||||
| { | |||||
| var service = new CommandService(); | |||||
| await Assert.ThrowsAsync<InvalidOperationException>(() => service.AddModuleAsync(typeof(CommandServiceTests))) | |||||
| .ConfigureAwait(false); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,24 @@ | |||||
| <Project Sdk="Microsoft.NET.Sdk"> | |||||
| <PropertyGroup> | |||||
| <TargetFramework>netcoreapp1.1</TargetFramework> | |||||
| <PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81</PackageTargetFallback> | |||||
| </PropertyGroup> | |||||
| <ItemGroup> | |||||
| <ProjectReference Include="../../src/Discord.Net.Commands/Discord.Net.Commands.csproj" /> | |||||
| <ProjectReference Include="../../src/Discord.Net.Core/Discord.Net.Core.csproj" /> | |||||
| </ItemGroup> | |||||
| <ItemGroup> | |||||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" /> | |||||
| <PackageReference Include="Moq" Version="4.7.25" /> | |||||
| <PackageReference Include="xunit" Version="2.2.0" /> | |||||
| <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" /> | |||||
| </ItemGroup> | |||||
| <ItemGroup> | |||||
| <Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" /> | |||||
| </ItemGroup> | |||||
| </Project> | |||||
| @@ -0,0 +1,38 @@ | |||||
| using Discord.Commands; | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| namespace Discord.Net.Commands.Tests | |||||
| { | |||||
| [Group("debug")] | |||||
| class DummyModule : ModuleBase | |||||
| { | |||||
| [Command("ping")] | |||||
| public Task TestCommandAsync(string param) | |||||
| { | |||||
| return Task.Delay(0); | |||||
| } | |||||
| [Command("pong")] | |||||
| public Task AnotherCommandAsync(int param) | |||||
| { | |||||
| return Task.Delay(0); | |||||
| } | |||||
| //NOTE: do not add this to CommandNames: it is intentional for this command to not be loaded! | |||||
| [Command("doesNotLoad")] | |||||
| private Task DoesNotLoadAsync() | |||||
| { | |||||
| return Task.Delay(0); | |||||
| } | |||||
| public static IEnumerable<string> CommandNames => _commandNames; | |||||
| private static readonly IEnumerable<string> _commandNames = new List<string> | |||||
| { | |||||
| "debug ping", | |||||
| "debug pong" | |||||
| }; | |||||
| } | |||||
| } | |||||