Browse Source

add some tests for the new DiscordWebhookClient constructor

pull/1260/head
Chris Johnston 6 years ago
parent
commit
1ca76df8db
2 changed files with 63 additions and 0 deletions
  1. +1
    -0
      test/Discord.Net.Tests/Discord.Net.Tests.csproj
  2. +62
    -0
      test/Discord.Net.Tests/Tests.DiscordWebhookClient.cs

+ 1
- 0
test/Discord.Net.Tests/Discord.Net.Tests.csproj View File

@@ -19,6 +19,7 @@
<ProjectReference Include="../../src/Discord.Net.Core/Discord.Net.Core.csproj" /> <ProjectReference Include="../../src/Discord.Net.Core/Discord.Net.Core.csproj" />
<ProjectReference Include="../../src/Discord.Net.Rest/Discord.Net.Rest.csproj" /> <ProjectReference Include="../../src/Discord.Net.Rest/Discord.Net.Rest.csproj" />
<ProjectReference Include="../../src/Discord.Net.Analyzers/Discord.Net.Analyzers.csproj" /> <ProjectReference Include="../../src/Discord.Net.Analyzers/Discord.Net.Analyzers.csproj" />
<ProjectReference Include="..\..\src\Discord.Net.Webhook\Discord.Net.Webhook.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Akavache" Version="6.0.31" /> <PackageReference Include="Akavache" Version="6.0.31" />


+ 62
- 0
test/Discord.Net.Tests/Tests.DiscordWebhookClient.cs View File

@@ -0,0 +1,62 @@
using Discord.Webhook;
using System;
using System.Collections.Generic;
using System.Text;
using Xunit;

namespace Discord
{
/// <summary>
/// Tests that the <see cref=""/>
/// </summary>
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<ArgumentNullException>(() =>
{
_ = 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<ArgumentException>(() =>
{
_ = new DiscordWebhookClient(webhookurl);
});
}
}
}

Loading…
Cancel
Save