Skip to content

Commit ddf9e95

Browse files
Code comments
1 parent 30943d3 commit ddf9e95

File tree

6 files changed

+98
-60
lines changed

6 files changed

+98
-60
lines changed

src/Nullinside.Api.TwitchBot.Tests/ChatRules/AChatRuleUnitTestBase.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55

66
namespace Nullinside.Api.TwitchBot.Tests.ChatRules;
77

8+
/// <summary>
9+
/// A generic set of sets that all chat rules should be put through.
10+
/// </summary>
11+
/// <typeparam name="T"></typeparam>
812
public abstract class AChatRuleUnitTestBase<T> : UnitTestBase where T : AChatRule, new()
913
{
1014
/// <summary>
11-
/// Tests that the message filter is capable of passing at all.
15+
/// Tests that the message filter is capable of passing at all.
1216
/// </summary>
1317
/// <param name="goodString">A friendly string with no issues.</param>
1418
[Test]
@@ -17,38 +21,38 @@ public async Task TestItDoesntAlwaysFail(string goodString)
1721
{
1822
var rule = new T();
1923
var botProxy = new Mock<ITwitchApiProxy>();
20-
24+
2125
// Process the message and assert that we pass the message.
2226
var chat = new TwitchChatMessage(true, goodString, "123", "456");
23-
var result = await rule.Handle("123", botProxy.Object, chat, this._db);
27+
var result = await rule.Handle("123", botProxy.Object, chat, _db);
2428
Assert.That(result, Is.True);
25-
29+
2630
// Process the message and assert that we pass the message.
2731
chat = new TwitchChatMessage(false, goodString, "123", "456");
28-
result = await rule.Handle("123", botProxy.Object, chat, this._db);
32+
result = await rule.Handle("123", botProxy.Object, chat, _db);
2933
Assert.That(result, Is.True);
3034
}
31-
35+
3236
/// <summary>
33-
/// Tests that the rules are only running when they should be.
37+
/// Tests that the rules are only running when they should be.
3438
/// </summary>
3539
[Test]
3640
public void TestShouldRun()
3741
{
3842
var rule = new T();
39-
43+
4044
// Rule is turned on and so is scanning.
4145
var shouldRun = rule.ShouldRun(new TwitchUserConfig { Enabled = true, BanKnownBots = true });
4246
Assert.That(shouldRun, Is.True);
43-
47+
4448
// Scanning is turned off
4549
shouldRun = rule.ShouldRun(new TwitchUserConfig { Enabled = false, BanKnownBots = true });
4650
Assert.That(shouldRun, Is.False);
47-
51+
4852
// Rule is turned off.
4953
shouldRun = rule.ShouldRun(new TwitchUserConfig { Enabled = true, BanKnownBots = false });
5054
Assert.That(shouldRun, Is.False);
51-
55+
5256
// Everything is off.
5357
shouldRun = rule.ShouldRun(new TwitchUserConfig { Enabled = false, BanKnownBots = false });
5458
Assert.That(shouldRun, Is.False);

src/Nullinside.Api.TwitchBot.Tests/ChatRules/BestCheapViewersTests.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
using Moq;
22
using Nullinside.Api.Common.Twitch;
3-
using Nullinside.Api.Model;
43
using Nullinside.Api.TwitchBot.ChatRules;
5-
using TwitchLib.Client.Models;
64

75
namespace Nullinside.Api.TwitchBot.Tests.ChatRules;
86

9-
public class BestCheapViewersTests : AChatRuleUnitTestBase<BestCheapViewers> {
7+
/// <summary>
8+
/// Tests the <see cref="BestCheapViewers" /> class.
9+
/// </summary>
10+
public class BestCheapViewersTests : AChatRuleUnitTestBase<BestCheapViewers>
11+
{
12+
/// <summary>
13+
/// Tests strings that have been typed in chats.
14+
/// </summary>
15+
/// <param name="badString">The string that should fail.</param>
1016
[Test]
1117
[TestCase("Best viewers on ***")]
1218
[TestCase("Best viewers on ***")]
@@ -28,9 +34,9 @@ public async Task TestKnownStrings(string badString)
2834
var rule = new BestCheapViewers();
2935
var botProxy = new Mock<ITwitchApiProxy>();
3036
var chat = new TwitchChatMessage(true, badString, "123", "456");
31-
37+
3238
// Process the message and assert that we fail the message.
33-
var result = await rule.Handle("123", botProxy.Object, chat, this._db);
39+
var result = await rule.Handle("123", botProxy.Object, chat, _db);
3440
Assert.That(result, Is.False);
3541
}
3642
}

src/Nullinside.Api.TwitchBot.Tests/ChatRules/DiscordTests.cs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,52 @@
44

55
namespace Nullinside.Api.TwitchBot.Tests.ChatRules;
66

7+
/// <summary>
8+
/// Tests the <see cref="Discord" /> class.
9+
/// </summary>
710
public class DiscordTests : AChatRuleUnitTestBase<Discord>
811
{
12+
/// <summary>
13+
/// Tests the strings typed in chats.
14+
/// </summary>
15+
/// <param name="badString">The string that should fail.</param>
916
[Test]
10-
[TestCase("Hello mate you stream pretty cool that's why I follow I would love to be a fan of yours if you don't mind kindly add me on Discord: 👉👉lacaster5")]
11-
[TestCase("Hello, I just recently found your channel and can already tell that your content is great, and I would love to stick with you long term. If you're open to it, I'd be willing to connect with you on Discord. My username is teecash1000")]
12-
[TestCase("Hey there 👋 You stream pretty cool that’s why I followed you. I will like to make you a friend and be a fan, if you don’t mind Kindly chat me on Discord, my Discord username is tuckzay")]
13-
[TestCase("Hi! Just wanted to say that I absolutely love your gameplay and content.l'd love to connect better with you on Discord if that's possible. Looking forward to more awesome streams from you! My username is 👉👉👉 edisonpires")]
14-
[TestCase("What's up Friend, great stream! I'm having a blast watching you stream. Let's move the conversation to Discord, where we can discuss more about streaming in more detail and get to know each other better. See you there! My discord username is 👉john_6029")]
17+
[TestCase(
18+
"Hello mate you stream pretty cool that's why I follow I would love to be a fan of yours if you don't mind kindly add me on Discord: 👉👉lacaster5")]
19+
[TestCase(
20+
"Hello, I just recently found your channel and can already tell that your content is great, and I would love to stick with you long term. If you're open to it, I'd be willing to connect with you on Discord. My username is teecash1000")]
21+
[TestCase(
22+
"Hey there 👋 You stream pretty cool that’s why I followed you. I will like to make you a friend and be a fan, if you don’t mind Kindly chat me on Discord, my Discord username is tuckzay")]
23+
[TestCase(
24+
"Hi! Just wanted to say that I absolutely love your gameplay and content.l'd love to connect better with you on Discord if that's possible. Looking forward to more awesome streams from you! My username is 👉👉👉 edisonpires")]
25+
[TestCase(
26+
"What's up Friend, great stream! I'm having a blast watching you stream. Let's move the conversation to Discord, where we can discuss more about streaming in more detail and get to know each other better. See you there! My discord username is 👉john_6029")]
1527
public async Task TestKnownStrings(string badString)
1628
{
1729
var rule = new Discord();
1830
var botProxy = new Mock<ITwitchApiProxy>();
1931
var chat = new TwitchChatMessage(true, badString, "123", "456");
20-
32+
2133
// Process the message and assert that we fail the message.
22-
var result = await rule.Handle("123", botProxy.Object, chat, this._db);
34+
var result = await rule.Handle("123", botProxy.Object, chat, _db);
2335
Assert.That(result, Is.False);
2436
}
25-
37+
38+
/// <summary>
39+
/// Ensure that the rule doesn't fail just because it contains the word discord.
40+
/// </summary>
41+
/// <param name="message">The message.</param>
2642
[Test]
2743
[TestCase("I've heard of the application discord before and it sounds great")]
2844
[TestCase("I was talking on my discord the other day")]
29-
public async Task EnsureNoFalsePositives(string badString)
45+
public async Task EnsureNoFalsePositives(string message)
3046
{
3147
var rule = new Discord();
3248
var botProxy = new Mock<ITwitchApiProxy>();
33-
var chat = new TwitchChatMessage(true, badString, "123", "456");
34-
49+
var chat = new TwitchChatMessage(true, message, "123", "456");
50+
3551
// Process the message and assert that we do not fail the message.
36-
var result = await rule.Handle("123", botProxy.Object, chat, this._db);
52+
var result = await rule.Handle("123", botProxy.Object, chat, _db);
3753
Assert.That(result, Is.True);
3854
}
3955
}

src/Nullinside.Api.TwitchBot.Tests/ChatRules/StreamViewersTests.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,28 @@
44

55
namespace Nullinside.Api.TwitchBot.Tests.ChatRules;
66

7+
/// <summary>
8+
/// Tests the <see cref="StreamViewers" /> class.
9+
/// </summary>
710
public class StreamViewersTests : AChatRuleUnitTestBase<StreamViewers>
811
{
12+
/// <summary>
13+
/// Tests the strings typed in chats.
14+
/// </summary>
15+
/// <param name="badString">The string that should fail.</param>
916
[Test]
10-
[TestCase("@jellynyeko dо уоu alrеady triеd strеamviewers оrg? Real viewеrs, fire works! Тhеy arе now giving оut а frее рackagе for streamers оО")]
11-
[TestCase("@kygaming98 dо уоu аlready tried streаmviewers оrg? Real viewers, firе works! Thеy arе now giving оut а freе package fоr streamers oО")]
17+
[TestCase(
18+
"@jellynyeko dо уоu alrеady triеd strеamviewers оrg? Real viewеrs, fire works! Тhеy arе now giving оut а frее рackagе for streamers оО")]
19+
[TestCase(
20+
"@kygaming98 dо уоu аlready tried streаmviewers оrg? Real viewers, firе works! Thеy arе now giving оut а freе package fоr streamers oО")]
1221
public async Task TestKnownStrings(string badString)
1322
{
1423
var rule = new StreamViewers();
1524
var botProxy = new Mock<ITwitchApiProxy>();
1625
var chat = new TwitchChatMessage(true, badString, "123", "456");
17-
26+
1827
// Process the message and assert that we fail the message.
19-
var result = await rule.Handle("123", botProxy.Object, chat, this._db);
28+
var result = await rule.Handle("123", botProxy.Object, chat, _db);
2029
Assert.That(result, Is.False);
2130
}
2231
}

src/Nullinside.Api.TwitchBot.Tests/Nullinside.Api.TwitchBot.Tests.csproj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@
1111

1212
<ItemGroup>
1313
<PackageReference Include="coverlet.collector" Version="6.0.2">
14-
<PrivateAssets>all</PrivateAssets>
15-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
<PrivateAssets>all</PrivateAssets>
15+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
</PackageReference>
17-
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.8" />
18-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
19-
<PackageReference Include="Moq" Version="4.20.72" />
20-
<PackageReference Include="NUnit" Version="4.2.2" />
17+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.8"/>
18+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
19+
<PackageReference Include="Moq" Version="4.20.72"/>
20+
<PackageReference Include="NUnit" Version="4.2.2"/>
2121
<PackageReference Include="NUnit.Analyzers" Version="4.3.0">
22-
<PrivateAssets>all</PrivateAssets>
23-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22+
<PrivateAssets>all</PrivateAssets>
23+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2424
</PackageReference>
25-
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
25+
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0"/>
2626
</ItemGroup>
2727

2828
<ItemGroup>
2929
<Using Include="NUnit.Framework"/>
3030
</ItemGroup>
3131

3232
<ItemGroup>
33-
<ProjectReference Include="..\Nullinside.Api.TwitchBot\Nullinside.Api.TwitchBot.csproj" />
33+
<ProjectReference Include="..\Nullinside.Api.TwitchBot\Nullinside.Api.TwitchBot.csproj"/>
3434
</ItemGroup>
3535

3636
</Project>

src/Nullinside.Api.TwitchBot.Tests/UnitTestBase.cs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,31 @@
55
namespace Nullinside.Api.TwitchBot.Tests;
66

77
/// <summary>
8-
/// A base class for all unit tests.
8+
/// A base class for all unit tests.
99
/// </summary>
10-
public abstract class UnitTestBase {
10+
public abstract class UnitTestBase
11+
{
1112
/// <summary>
12-
/// A fake database.
13+
/// A fake database.
1314
/// </summary>
1415
protected INullinsideContext _db;
1516

16-
[SetUp]
17-
public virtual void Setup() {
18-
// Create an in-memory database to fake the SQL queries. Note that we generate a random GUID for the name
19-
// here. If you use the same name more than once you'll get collisions between tests.
20-
DbContextOptions<NullinsideContext> contextOptions = new DbContextOptionsBuilder<NullinsideContext>()
21-
.UseInMemoryDatabase(Guid.NewGuid().ToString())
22-
.ConfigureWarnings(b => b.Ignore(InMemoryEventId.TransactionIgnoredWarning))
23-
.Options;
24-
_db = new NullinsideContext(contextOptions);
25-
}
17+
[SetUp]
18+
public virtual void Setup()
19+
{
20+
// Create an in-memory database to fake the SQL queries. Note that we generate a random GUID for the name
21+
// here. If you use the same name more than once you'll get collisions between tests.
22+
var contextOptions = new DbContextOptionsBuilder<NullinsideContext>()
23+
.UseInMemoryDatabase(Guid.NewGuid().ToString())
24+
.ConfigureWarnings(b => b.Ignore(InMemoryEventId.TransactionIgnoredWarning))
25+
.Options;
26+
_db = new NullinsideContext(contextOptions);
27+
}
2628

27-
[TearDown]
28-
public virtual async Task TearDown() {
29-
// Dispose since it has one.
30-
await _db.DisposeAsync();
31-
}
29+
[TearDown]
30+
public virtual async Task TearDown()
31+
{
32+
// Dispose since it has one.
33+
await _db.DisposeAsync();
34+
}
3235
}

0 commit comments

Comments
 (0)