-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
054389b
commit a3bf7dd
Showing
3 changed files
with
101 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using CubicBot.Telegram.Utils; | ||
using Telegram.Bot.Exceptions; | ||
using Xunit; | ||
|
||
namespace CubicBot.Telegram.Tests; | ||
|
||
public class ChatHelperTests | ||
{ | ||
[Fact] | ||
public void Get_Retry_Wait_Time_Normal() | ||
{ | ||
for (var i = 1; i <= 30; i++) | ||
{ | ||
Test_Get_Retry_Wait_Time(i); | ||
} | ||
} | ||
|
||
private static void Test_Get_Retry_Wait_Time(int seconds) | ||
{ | ||
var ex = new ApiRequestException($"Too Many Requests: retry after {seconds}", 429); | ||
|
||
var waitTimeSec = ChatHelper.GetRetryWaitTimeMs(ex) / 1000; | ||
|
||
Assert.InRange(waitTimeSec, seconds + 1, seconds + 5); | ||
} | ||
|
||
[Theory] | ||
[InlineData("💩")] | ||
[InlineData("Super super super super super super super long error message.")] | ||
public void Get_Retry_Wait_Time_Bad_Message(string message) | ||
{ | ||
var ex = new ApiRequestException(message, 429); | ||
|
||
var waitTimeMs = ChatHelper.GetRetryWaitTimeMs(ex); | ||
|
||
Assert.Equal(15 * 1000, waitTimeMs); | ||
} | ||
|
||
[Theory] | ||
[InlineData(null, "fakename", null, null)] | ||
[InlineData("lol", "fakename", null, null)] | ||
[InlineData("/", "fakename", null, null)] | ||
[InlineData("/ arg", "fakename", null, null)] | ||
[InlineData("/@", "fakename", null, null)] | ||
[InlineData("/@ arg", "fakename", null, null)] | ||
[InlineData("/@fakename", "fakename", null, null)] | ||
[InlineData("/@fakename arg", "fakename", null, null)] | ||
[InlineData("/@wrongname", "fakename", null, null)] | ||
[InlineData("/start", "fakename", "start", null)] | ||
[InlineData("/start ", "fakename", "start", null)] | ||
[InlineData("/start ", "fakename", "start", null)] | ||
[InlineData("/start arg", "fakename", "start", "arg")] | ||
[InlineData("/start arg ", "fakename", "start", "arg")] | ||
[InlineData("/start arg", "fakename", "start", "arg")] | ||
[InlineData("/start@ arg", "fakename", "start", "arg")] | ||
[InlineData("/start@wrongname arg", "fakename", null, null)] | ||
[InlineData("/start@fakename arg", "fakename", "start", "arg")] | ||
public void Parse_Message_Into_Command_And_Argument(string? message, string botUsername, string? expectedCommand, string? expectedArgument) | ||
{ | ||
var (command, argument) = ChatHelper.ParseMessageIntoCommandAndArgument(message, botUsername); | ||
|
||
Assert.Equal(expectedCommand, command); | ||
Assert.Equal(expectedArgument, argument); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\CubicBot.Telegram\CubicBot.Telegram.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters