Skip to content

Commit

Permalink
Convert to Coverlet .NET for coverage report
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Sedláček committed Sep 15, 2018
1 parent abd33ef commit 5d08d02
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 72 deletions.
8 changes: 4 additions & 4 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ build_script:
- dotnet build -c Release
test_script:
- ps: >-
nuget install xunit.runner.console -OutputDirectory packages -Version 2.3.1
dotnet test
&('dotnet') ('test', './CommunityBot.NUnit.Tests/Justine.NUnit.Tests.csproj', '/p:CollectCoverage=true', '/p:"Include=[CommunityBot]*"', '/p:"Exclude=[NUnit3.TestAdapter]*"', '/p:CoverletOutputFormat=opencover')
nuget install OpenCover -OutputDirectory packages -Version 4.6.519
dotnet tool install coveralls.net --version 1.0.0 --tool-path tools
.\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -register:user -target:"C:\Program Files\dotnet\dotnet.exe" "-targetargs:"".\packages\xunit.runner.console.2.3.1\tools\netcoreapp2.0\xunit.console.dll"" ""CommunityBot.Tests\bin\Release\netcoreapp2.0\CommunityBot.Tests.dll"" -noshadow -appveyor" -filter:"+[CommunityBot*]* -[CommunityBot*]*Tests.* -[CommunityBot*]*AutoGeneratedProgram" -oldStyle -output:opencoverCoverage.xml
$coveralls = ".\tools\csmacnz.coveralls.exe"
if (Get-Variable 'COVERALLS_REPO_TOKEN' -Scope Global -ErrorAction 'Ignore') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,59 @@
using CommunityBot.Configuration;
using Discord;
using Moq;
using Xunit;
using NUnit.Framework;

namespace CommunityBot.Tests
{
public class ApplicationSettingsTests
{
[Fact]
[Test]
public void HeadlessArgumentTest()
{
var settings = new ApplicationSettings(new []{ "-hl" });
Assert.True(settings.Headless);
}

[Fact]
[Test]
public void VerboseArgumentTest()
{
var settings = new ApplicationSettings(new []{ "-vb" });
Assert.True(settings.Verbose);
}

[Fact]
[Test]
public void CacheSizeArgumentTest()
{
const int expected = 999;
var settings = new ApplicationSettings(new []{ $"-cs={expected}" });
Assert.Equal(expected, settings.CacheSize);
Assert.AreEqual(expected, settings.CacheSize);
}

[Fact]
[Test]
public void LogDestinationArgument_FileTest()
{
var settings = new ApplicationSettings(new []{ "-log=f" });
Assert.True(settings.LogIntoFile);
Assert.False(settings.LogIntoConsole);
}

[Fact]
[Test]
public void LogDestinationArgument_ConsoleTest()
{
var settings = new ApplicationSettings(new []{ "-log=c" });
Assert.True(settings.LogIntoConsole);
Assert.False(settings.LogIntoFile);
}

[Fact]
[Test]
public void LogDestinationArgument_ConsoleDefaultTest()
{
var settings = new ApplicationSettings(new []{ "" });
Assert.True(settings.LogIntoConsole);
Assert.False(settings.LogIntoFile);
}

[Fact]
[Test]
public void LogDestinationArgument_BothTest()
{
var settings = new ApplicationSettings(new []{ "-log=cf" });
Expand Down
16 changes: 16 additions & 0 deletions CommunityBot.NUnit.Tests/CommunityBot.NUnit.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="nunit" Version="3.10.1"/>
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2"/>
<PackageReference Include="coverlet.msbuild" Version="*"/>
<PackageReference Include="Moq" Version="*"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CommunityBot\CommunityBot.csproj"/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using CommunityBot.Features.RoleAssignment;
using Xunit;
using NUnit.Framework;

namespace CommunityBot.Tests.FeatureTests
{
Expand Down Expand Up @@ -47,7 +47,7 @@ private static RoleByPhraseSettings GetFilledSettings()
};
}

[Fact]
[Test]
public void Rbp_RemoveRelationTest()
{
const int expectedRelCount = 3;
Expand All @@ -56,10 +56,10 @@ public void Rbp_RemoveRelationTest()
rbps.RemoveRelation(0, 0);
var actual = rbps.Relations.Count;

Assert.Equal(expectedRelCount, actual);
Assert.AreEqual(expectedRelCount, actual);
}

[Fact]
[Test]
public void Rbp_RemoveRelationTest_ArgEx()
{
var rbps = GetFilledSettings();
Expand All @@ -72,14 +72,14 @@ public void Rbp_RemoveRelationTest_ArgEx()
Assert.Throws<ArgumentException>(() => rbps.RemoveRelation(invalidIndex, invalidIndex));
}

[Fact]
[Test]
public void Rbp_RemoveRelationTest_RelNotFoundEx()
{
var rbps = GetFilledSettings();
Assert.Throws<RelationNotFoundException>(() => rbps.RemoveRelation(1,1));
}

[Fact]
[Test]
public void Rbp_AddRelationTest()
{
const int expectedRelCount = 5;
Expand All @@ -88,10 +88,10 @@ public void Rbp_AddRelationTest()
rbps.CreateRelation(0, 2);
var acutal = rbps.Relations.Count;

Assert.Equal(expectedRelCount, acutal);
Assert.AreEqual(expectedRelCount, acutal);
}

[Fact]
[Test]
public void Rbp_AddRelationTest_ArgEx()
{
var rbps = GetFilledSettings();
Expand All @@ -104,14 +104,14 @@ public void Rbp_AddRelationTest_ArgEx()
Assert.Throws<ArgumentException>(() => rbps.CreateRelation(invalidIndex, invalidIndex));
}

[Fact]
[Test]
public void Rbp_AddRelationTest_RelExists()
{
var rbps = GetFilledSettings();
Assert.Throws<RelationAlreadyExistsException>(() => rbps.CreateRelation(1, 0));
}

[Fact]
[Test]
public void Rbp_AddPhraseTest()
{
const int expected = 3;
Expand All @@ -120,24 +120,24 @@ public void Rbp_AddPhraseTest()
rbps.AddPhrase("CC");
var actual = rbps.Phrases.Count;

Assert.Equal(expected, actual);
Assert.AreEqual(expected, actual);
}

[Fact]
[Test]
public void Rbp_AddPhraseTest_InvalidPhraseEx()
{
var rbps = GetFilledSettings();
Assert.Throws<InvalidPhraseException>(() => rbps.AddPhrase(string.Empty));
}

[Fact]
[Test]
public void Rbp_AddPhraseTest_InvalidPhraseEx_TooLong()
{
var rbps = GetFilledSettings();
Assert.Throws<InvalidPhraseException>(() => rbps.AddPhrase(new string('A', Constants.MaxMessageLength)));
}

[Fact]
[Test]
public void Rbp_RemovePhraseTest()
{
const int expected = 1;
Expand All @@ -146,10 +146,10 @@ public void Rbp_RemovePhraseTest()
rbps.RemovePhraseByIndex(1);
var actual = rbps.Phrases.Count;

Assert.Equal(expected, actual);
Assert.AreEqual(expected, actual);
}

[Fact]
[Test]
public void Rbp_AddRoleTest()
{
const int expected = 4;
Expand All @@ -158,17 +158,17 @@ public void Rbp_AddRoleTest()
rbps.AddRole(123);
var actual = rbps.RolesIds.Count;

Assert.Equal(expected, actual);
Assert.AreEqual(expected, actual);
}

[Fact]
[Test]
public void Rbp_AddRoleTest_AlreadyAddedEx()
{
var rbps = GetFilledSettings();
Assert.Throws<RoleIdAlreadyAddedException>(() => rbps.AddRole(111));
}

[Fact]
[Test]
public void Rbp_RemoveRoleTest()
{
const int expected = 2;
Expand All @@ -177,7 +177,7 @@ public void Rbp_RemoveRoleTest()
rbps.RemoveRoleIdByIndex(0);
var actual = rbps.RolesIds.Count;

Assert.Equal(expected, actual);
Assert.AreEqual(expected, actual);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
using Castle.Core.Resource;
using Discord;
using Moq;
using Xunit;
using NUnit.Framework;

namespace CommunityBot.Tests
{
public class GlobalTests
{
[Fact]
[Test]
public void ReplacePlaceholderString_NoNicknameTest()
{
const string expected = "Username";
var guildUser = CreateMockGuildUser(null, expected);
TestReplacePlaceholderString("<username>", expected, guildUser);
}

[Fact]
[Test]
public void ReplacePlaceholderString_ValidUsernameTest()
{
const string expected = "Nickname";
var guildUser = CreateMockGuildUser(expected, "Username");
TestReplacePlaceholderString("<username>", expected, guildUser);
}

[Fact]
[Test]
public void ReplacePlaceholderString_GuildNameTest()
{
const string expected = "TestGuildName";
var guildUser = CreateMockGuildUser("Jon", "jj36", expected);
TestReplacePlaceholderString("<guildname>", expected, guildUser);
}

[Fact]
[Test]
public void ReplacePlaceholderString_UserMentionTest()
{
const string expected = "@JonDoe";
var guildUser = CreateMockGuildUser("Jon", "jj36", userMention: "@JonDoe");
TestReplacePlaceholderString("<usermention>", expected, guildUser);
}

[Fact]
[Test]
public void ReplacePlaceholderString_Multiple()
{
const string expected = "Hello, Peter! Welcome to MyCoolGuild!";
var guildUser = CreateMockGuildUser("Peter", "spelos", "MyCoolGuild");
TestReplacePlaceholderString("Hello, <username>! Welcome to <guildname>!", expected, guildUser);
}

[Fact]
[Test]
public void ReplacePlaceholderString_MultipleNoNickname()
{
const string expected = "Hello, spelos! Welcome to MyCoolGuild!";
Expand All @@ -58,7 +58,7 @@ public void ReplacePlaceholderString_MultipleNoNickname()
private static void TestReplacePlaceholderString(string input, string expected, IMock<IGuildUser> user)
{
var actual = input.ReplacePlacehoderStrings(user.Object);
Assert.Equal(expected, actual);
Assert.AreEqual(expected, actual);
}

private static Mock<IGuildUser> CreateMockGuildUser(string nickname, string username, string guildName = "MyGuild", string userMention = "@User")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using Xunit;
using NUnit.Framework;

namespace CommunityBot.Tests
{
public static class ImmutableConstantsTests
{
[Fact]
[Test]
public static void ConstantArrayIsImmutableTest()
{
Assert.Throws<NotSupportedException>(() => Constants.DidYouKnows.Add("Hello, World!"));
Expand Down
24 changes: 0 additions & 24 deletions CommunityBot.Tests/CommunityBot.Tests.csproj

This file was deleted.

10 changes: 5 additions & 5 deletions CommunityBot.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VisualStudioVersion = 15.0.27130.2036
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityBot", "CommunityBot\CommunityBot.csproj", "{82B51A90-044B-4F54-91A0-AA9AF8D7EEAE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityBot.Tests", "CommunityBot.Tests\CommunityBot.Tests.csproj", "{5C95BE8F-63F6-4289-B91C-42DFE61E784C}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityBot.NUnit.Tests", "CommunityBot.NUnit.Tests\CommunityBot.NUnit.Tests.csproj", "{CE128E01-DC44-4D2C-B011-FAE0DD2157C9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -17,10 +17,10 @@ Global
{82B51A90-044B-4F54-91A0-AA9AF8D7EEAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{82B51A90-044B-4F54-91A0-AA9AF8D7EEAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{82B51A90-044B-4F54-91A0-AA9AF8D7EEAE}.Release|Any CPU.Build.0 = Release|Any CPU
{5C95BE8F-63F6-4289-B91C-42DFE61E784C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5C95BE8F-63F6-4289-B91C-42DFE61E784C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5C95BE8F-63F6-4289-B91C-42DFE61E784C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5C95BE8F-63F6-4289-B91C-42DFE61E784C}.Release|Any CPU.Build.0 = Release|Any CPU
{CE128E01-DC44-4D2C-B011-FAE0DD2157C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CE128E01-DC44-4D2C-B011-FAE0DD2157C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE128E01-DC44-4D2C-B011-FAE0DD2157C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE128E01-DC44-4D2C-B011-FAE0DD2157C9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 5d08d02

Please sign in to comment.