From 1ca76df8dbaca85b5564276b358e216adf05a217 Mon Sep 17 00:00:00 2001 From: Chris Johnston Date: Fri, 8 Feb 2019 12:41:49 -0800 Subject: [PATCH] add some tests for the new DiscordWebhookClient constructor --- .../Discord.Net.Tests.csproj | 1 + .../Tests.DiscordWebhookClient.cs | 62 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 test/Discord.Net.Tests/Tests.DiscordWebhookClient.cs diff --git a/test/Discord.Net.Tests/Discord.Net.Tests.csproj b/test/Discord.Net.Tests/Discord.Net.Tests.csproj index 46e37655e..d29a728b0 100644 --- a/test/Discord.Net.Tests/Discord.Net.Tests.csproj +++ b/test/Discord.Net.Tests/Discord.Net.Tests.csproj @@ -19,6 +19,7 @@ + diff --git a/test/Discord.Net.Tests/Tests.DiscordWebhookClient.cs b/test/Discord.Net.Tests/Tests.DiscordWebhookClient.cs new file mode 100644 index 000000000..b7b049592 --- /dev/null +++ b/test/Discord.Net.Tests/Tests.DiscordWebhookClient.cs @@ -0,0 +1,62 @@ +using Discord.Webhook; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; + +namespace Discord +{ + /// + /// Tests that the + /// + public class DiscordWebhookClientTests + { + [Theory] + [InlineData("https://discordapp.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK")] + // ptb, canary, etc will have slightly different urls + [InlineData("https://ptb.discordapp.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK")] + [InlineData("https://canary.discordapp.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK")] + // don't care about https + [InlineData("http://canary.discordapp.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK")] + // this is the minimum that the regex cares about + [InlineData("p.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK")] + public void TestWebhook_Valid(string webhookurl) + { + try + { + _ = new DiscordWebhookClient(webhookurl); + } + catch (InvalidOperationException) + { + // ignore, thrown because webhook urls are invalid + } + + // pass if no exception thrown + Assert.True(true); + } + + [Theory] + [InlineData("")] + [InlineData(" ")] + [InlineData(null)] + public void TestWebhook_Null(string webhookurl) + { + Assert.Throws(() => + { + _ = new DiscordWebhookClient(webhookurl); + }); + } + + [Theory] + [InlineData("123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK")] + // trailing slash + [InlineData("https://discordapp.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK/")] + public void TestWebhook_Invalid(string webhookurl) + { + Assert.Throws(() => + { + _ = new DiscordWebhookClient(webhookurl); + }); + } + } +}