You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommandServiceTests.cs 1.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using Discord.Commands;
  2. using System;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Xunit;
  6. namespace Discord.Net.Commands.Tests
  7. {
  8. class CommandServiceTests
  9. {
  10. [Fact]
  11. public async Task CommandsLoad()
  12. {
  13. var service = new CommandService();
  14. var module = await service.AddModuleAsync(typeof(DummyModule)).ConfigureAwait(false);
  15. Assert.NotNull(module);
  16. var commandAliases = module.Commands.SelectMany(x => x.Aliases);
  17. foreach (var name in DummyModule.CommandNames)
  18. {
  19. Assert.True(commandAliases.Contains(name), $"The loaded module did not contain the command {name}");
  20. }
  21. }
  22. [Fact]
  23. public async Task MultipleLoadsThrows()
  24. {
  25. var service = new CommandService();
  26. var module = await service.AddModuleAsync(typeof(DummyModule)).ConfigureAwait(false);
  27. await Assert.ThrowsAsync<ArgumentException>(() => service.AddModuleAsync(typeof(DummyModule)))
  28. .ConfigureAwait(false);
  29. }
  30. [Fact]
  31. public async Task InvalidTypeThrows()
  32. {
  33. var service = new CommandService();
  34. await Assert.ThrowsAsync<InvalidOperationException>(() => service.AddModuleAsync(typeof(CommandServiceTests)))
  35. .ConfigureAwait(false);
  36. }
  37. }
  38. }