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.

Tests.DiscordWebhookClient.cs 2.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using Discord.Webhook;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using Xunit;
  6. namespace Discord
  7. {
  8. /// <summary>
  9. /// Tests that the <see cref=""/>
  10. /// </summary>
  11. public class DiscordWebhookClientTests
  12. {
  13. [Theory]
  14. [InlineData("https://discordapp.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK")]
  15. // ptb, canary, etc will have slightly different urls
  16. [InlineData("https://ptb.discordapp.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK")]
  17. [InlineData("https://canary.discordapp.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK")]
  18. // don't care about https
  19. [InlineData("http://canary.discordapp.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK")]
  20. // this is the minimum that the regex cares about
  21. [InlineData("discordapp.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK")]
  22. public void TestWebhook_Valid(string webhookurl)
  23. {
  24. try
  25. {
  26. _ = new DiscordWebhookClient(webhookurl);
  27. }
  28. catch (InvalidOperationException)
  29. {
  30. // ignore, thrown because webhook urls are invalid
  31. }
  32. // pass if no exception thrown
  33. Assert.True(true);
  34. }
  35. [Theory]
  36. [InlineData("")]
  37. [InlineData(" ")]
  38. [InlineData(null)]
  39. public void TestWebhook_Null(string webhookurl)
  40. {
  41. Assert.Throws<ArgumentNullException>(() =>
  42. {
  43. _ = new DiscordWebhookClient(webhookurl);
  44. });
  45. }
  46. [Theory]
  47. [InlineData("123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK")]
  48. // trailing slash
  49. [InlineData("https://discordapp.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK/")]
  50. public void TestWebhook_Invalid(string webhookurl)
  51. {
  52. Assert.Throws<ArgumentException>(() =>
  53. {
  54. _ = new DiscordWebhookClient(webhookurl);
  55. });
  56. }
  57. }
  58. }