Add Simple Unit Tests
This commit is contained in:
parent
41f8b1bc0b
commit
11df9d7955
6 changed files with 117 additions and 1 deletions
|
@ -10,12 +10,18 @@ before_script:
|
|||
build:
|
||||
stage: build
|
||||
image: microsoft/dotnet:2.0.3-sdk-stretch
|
||||
variables:
|
||||
NUGET_PACKAGES: "${CI_PROJECT_DIR}/.nugetcache"
|
||||
cache:
|
||||
paths:
|
||||
- .nugetcache
|
||||
artifacts:
|
||||
expire_in: 1h
|
||||
paths:
|
||||
- Geekbot.net/Binaries/
|
||||
script:
|
||||
- dotnet restore
|
||||
- dotnet test Tests
|
||||
- dotnet publish --configuration Release -o Binaries ./
|
||||
|
||||
deploy:
|
||||
|
|
|
@ -5,6 +5,8 @@ VisualStudioVersion = 12.0.0.0
|
|||
MinimumVisualStudioVersion = 10.0.0.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Geekbot.net", "Geekbot.net/Geekbot.net.csproj", "{FDCB3D92-E7B5-47BB-A9B5-CFAEFA57CDB4}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{4CAF5F02-EFFE-4FDA-BD44-EEADDBA9600E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -15,6 +17,10 @@ Global
|
|||
{FDCB3D92-E7B5-47BB-A9B5-CFAEFA57CDB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FDCB3D92-E7B5-47BB-A9B5-CFAEFA57CDB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FDCB3D92-E7B5-47BB-A9B5-CFAEFA57CDB4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4CAF5F02-EFFE-4FDA-BD44-EEADDBA9600E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4CAF5F02-EFFE-4FDA-BD44-EEADDBA9600E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4CAF5F02-EFFE-4FDA-BD44-EEADDBA9600E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4CAF5F02-EFFE-4FDA-BD44-EEADDBA9600E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<Authors>Pizza and Coffee Studios</Authors>
|
||||
<Description>A Discord bot</Description>
|
||||
<RepositoryUrl>https://github.com/pizzaandcoffee/Geekbot.net</RepositoryUrl>
|
||||
<NoWarn>NU1701</NoWarn>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Discord.Net">
|
||||
|
|
|
@ -11,7 +11,19 @@ namespace Geekbot.net.Lib
|
|||
{
|
||||
return "🔟";
|
||||
}
|
||||
var emojiMap = new string[] {"0⃣", "1⃣", "2⃣", "3⃣", "4⃣", "5⃣", "6⃣", "7⃣", "8⃣", "9⃣"};
|
||||
var emojiMap = new string[]
|
||||
{
|
||||
":zero:",
|
||||
":one:",
|
||||
":two:",
|
||||
":three:",
|
||||
":four:",
|
||||
":five:",
|
||||
":six:",
|
||||
":seven:",
|
||||
":eight:",
|
||||
":nine:",
|
||||
};
|
||||
var numbers = number.ToString().ToCharArray();
|
||||
var returnString = new StringBuilder();
|
||||
foreach (var n in numbers)
|
||||
|
|
75
Tests/Lib/EmojiConverter.test.cs
Normal file
75
Tests/Lib/EmojiConverter.test.cs
Normal file
|
@ -0,0 +1,75 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Geekbot.net.Lib;
|
||||
using Xunit;
|
||||
|
||||
namespace Tests.Lib
|
||||
{
|
||||
public class EmojiConverter_test
|
||||
{
|
||||
public static IEnumerable<object[]> NumberToEmojiTestData
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new object[]
|
||||
{
|
||||
2,
|
||||
":two:"
|
||||
};
|
||||
|
||||
yield return new object[]
|
||||
{
|
||||
10,
|
||||
"🔟"
|
||||
};
|
||||
|
||||
yield return new object[]
|
||||
{
|
||||
15,
|
||||
":one::five:"
|
||||
};
|
||||
|
||||
yield return new object[]
|
||||
{
|
||||
null,
|
||||
":zero:"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Theory, MemberData(nameof(NumberToEmojiTestData))]
|
||||
public async Task NumberToEmoji(int number, string expectedResult)
|
||||
{
|
||||
var emojiConverter = new EmojiConverter();
|
||||
var result = emojiConverter.numberToEmoji(number);
|
||||
Assert.Equal(result, expectedResult);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> textToEmojiTestData
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new object[]
|
||||
{
|
||||
"test",
|
||||
":regional_indicator_t::regional_indicator_e::regional_indicator_s::regional_indicator_t:"
|
||||
};
|
||||
yield return new object[]
|
||||
{
|
||||
"Best3+?",
|
||||
":b::regional_indicator_e::regional_indicator_s::regional_indicator_t::three::heavy_plus_sign::question:"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Theory, MemberData(nameof(textToEmojiTestData))]
|
||||
public async Task TextToEmoji(string text, string expectedResult)
|
||||
{
|
||||
var emojiConverter = new EmojiConverter();
|
||||
var result = emojiConverter.textToEmoji(text);
|
||||
Assert.Equal(result, expectedResult);
|
||||
}
|
||||
}
|
||||
}
|
16
Tests/Tests.csproj
Normal file
16
Tests/Tests.csproj
Normal file
|
@ -0,0 +1,16 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<NoWarn>NU1701</NoWarn>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
|
||||
<PackageReference Include="xunit" Version="2.3.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
|
||||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Geekbot.net\Geekbot.net.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Reference in a new issue