public void GetTests() { TestDbProvider.AlterAndVerify( alter: _ => { }, verify: db => { foreach (ulong id in MockData.Ids) { IReadOnlyList <ulong> all = this.Service.GetIds(id); Assert.That(all, Is.Empty); } } ); TestDbProvider.SetupAlterAndVerify( setup: db => this.AddMockData(db), alter: _ => { }, verify: db => { IReadOnlyList <ulong> gid0 = this.Service.GetIds(MockData.Ids[0]); Assert.That(gid0, Is.EquivalentTo(new[] { MockData.Ids[0], MockData.Ids[1] })); IReadOnlyList <ulong> gid1 = this.Service.GetIds(MockData.Ids[1]); Assert.That(gid1, Is.EquivalentTo(new[] { MockData.Ids[2] })); foreach (ulong id in MockData.Ids.Skip(2)) { IReadOnlyList <ulong> gidx = this.Service.GetIds(id); Assert.That(gidx, Is.Empty); } } ); }
public async Task GuildHasTextReactionTests() { TestDbProvider.SetupAlterAndVerify( setup: db => this.AddMockReactions(db), alter: db => this.Service.LoadData(), verify: db => { Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[0], "abc"), Is.True); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[0], "test"), Is.True); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[0], "trigger me"), Is.True); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[0], "y u DO dis"), Is.True); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[0], "pls"), Is.True); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[1], "y u do dis"), Is.True); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[1], "rIck"), Is.True); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[1], "astLey"), Is.True); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[3], "test"), Is.True); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[3], "test(ing)?"), Is.True); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[0], "asstley"), Is.False); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[0], "abcd"), Is.False); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[0], "ABCCC"), Is.False); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[1], "RICKY"), Is.False); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[2], "Ha"), Is.False); } ); TestDbProvider.AlterAndVerify( alter: db => this.Service.LoadData(), verify: db => { Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[0], "abc"), Is.False); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[0], "test"), Is.False); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[0], "trigger me"), Is.False); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[0], "y u DO dis"), Is.False); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[0], "pls"), Is.False); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[1], "y u do dis"), Is.False); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[1], "rIck"), Is.False); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[1], "astLey"), Is.False); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[0], "asstley"), Is.False); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[0], "abcd"), Is.False); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[0], "ABCCC"), Is.False); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[1], "RICK"), Is.False); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[2], "Ha"), Is.False); } ); await TestDbProvider.AlterAndVerifyAsync( alter : db => this.Service.AddTextReactionAsync(MockData.Ids[0], "test", "response", false), verify : db => { Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[0], "test"), Is.True); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[0], "teSt"), Is.True); Assert.That(this.Service.GuildHasTextReaction(MockData.Ids[0], "test"), Is.True); return(Task.CompletedTask); } ); }
public void GetGuildTextReactionsTests() { Assert.That(this.Service.GetGuildTextReactions(MockData.Ids[0]), Is.Empty); TestDbProvider.AlterAndVerify( alter: db => this.Service.LoadData(), verify: db => { for (int i = 0; i < MockData.Ids.Count; i++) { AssertGuildReactionCount(i, 0); } } ); TestDbProvider.SetupAlterAndVerify( setup: db => this.AddMockReactions(db), alter: db => { this.UpdateTextReactionCount(db); this.Service.LoadData(); }, verify: db => { for (int i = 0; i < MockData.Ids.Count; i++) { AssertGuildReactionCount(i, this.trCount[i]); } IReadOnlyCollection <TextReaction> trs = this.Service.GetGuildTextReactions(MockData.Ids[1]); Assert.That(trs.Single(tr => tr.Response == "response12" && tr.Triggers.Single() == "y u do dis"), Is.Not.Null); Assert.That(trs.Single(tr => tr.Response == "response23" && tr.Triggers.Single() == "rick"), Is.Not.Null); Assert.That(trs.Single(tr => tr.Response == "response34" && tr.Triggers.Single() == "astley"), Is.Not.Null); } ); void AssertGuildReactionCount(int id, int count) { IReadOnlyCollection <TextReaction> trs = this.Service.GetGuildTextReactions(MockData.Ids[id]); Assert.That(trs, Has.Exactly(count).Items); Assert.That(trs.Select(tr => tr.Id), Is.Unique); foreach (IEnumerable <string> triggers in trs.Select(tr => tr.Triggers)) { Assert.That(triggers, Is.Not.Empty); } } }
public void GetGuildEmojiReactionsTests() { Assert.That(this.Service.GetGuildEmojiReactions(MockData.Ids[0]), Is.Empty); TestDbProvider.AlterAndVerify( alter: db => this.Service.LoadData(), verify: db => { for (int i = 0; i < MockData.Ids.Count; i++) { AssertGuildReactionCount(i, 0); } } ); TestDbProvider.SetupAlterAndVerify( setup: db => this.AddMockReactions(db), alter: db => { this.UpdateEmojiReactionCount(db); this.Service.LoadData(); }, verify: db => { for (int i = 0; i < MockData.Ids.Count; i++) { AssertGuildReactionCount(i, this.erCount[i]); } IReadOnlyCollection <EmojiReaction> ers = this.Service.GetGuildEmojiReactions(MockData.Ids[1]); Assert.That(ers.Single(er => er.Response == Emojis.Cake.GetDiscordName() && er.Triggers.Single() == "abc"), Is.Not.Null); Assert.That(ers.Single(er => er.Response == Emojis.ArrowUp.GetDiscordName() && er.Triggers.Single() == "abc"), Is.Not.Null); Assert.That(ers.Single(er => er.Response == Emojis.ArrowDown.GetDiscordName() && er.Triggers.Single() == "abc"), Is.Not.Null); } ); void AssertGuildReactionCount(int id, int count) { IReadOnlyCollection <EmojiReaction> ers = this.Service.GetGuildEmojiReactions(MockData.Ids[id]); Assert.That(ers, Has.Exactly(count).Items); Assert.That(ers.Select(er => er.Id), Is.Unique); foreach (IEnumerable <string> triggers in ers.Select(er => er.Triggers)) { Assert.That(triggers, Is.Not.Empty); } } }
public void GetTests() { TestDbProvider.AlterAndVerify( alter: _ => { }, verify: db => { IReadOnlyList <ulong> all = this.Service.GetIds(); Assert.That(all, Is.Empty); } ); TestDbProvider.SetupAlterAndVerify( setup: db => this.AddMockData(db), alter: _ => { }, verify: db => { IReadOnlyList <ulong> all = this.Service.GetIds(); Assert.That(all, Is.EqualTo(new[] { MockData.Ids[0], MockData.Ids[1] })); } ); }
public void GetGuildFiltersTests() { foreach (ulong id in MockData.Ids) { Assert.That(this.Service.GetGuildFilters(id), Is.Empty); } TestDbProvider.AlterAndVerify( alter: db => this.Service.LoadData(), verify: db => { for (int i = 0; i < MockData.Ids.Count; i++) { this.AssertGuildFilterCount(db, i, 0); } } ); TestDbProvider.SetupAlterAndVerify( setup: db => this.AddMockFilters(db), alter: db => this.Service.LoadData(), verify: db => { this.AssertGuildFilterCount(db, 0, 5); this.AssertGuildFilterCount(db, 1, 3); this.AssertGuildFilterCount(db, 2, 3); this.AssertGuildFilterCount(db, 3, 0); this.AssertSingleAndTest(db, 0, regex: "fish", match: true, "fish", "this is just a fish", "my name is mr.Fishy, and I swim."); this.AssertSingleAndTest(db, 0, regex: "fish", match: false, "fi sh", "f1sh"); this.AssertSingleAndTest(db, 0, regex: "dog(e|gy)?", match: true, "doge", "what a cute doggy you have", "your DoGs bite?"); this.AssertSingleAndTest(db, 0, regex: "dog(e|gy)?", match: false, "does your D0Gge bite?"); this.AssertSingleAndTest(db, 1, regex: "cat", match: true, "cat", "a CaT abc", "play with my Cat.", "cat-dog"); this.AssertSingleAndTest(db, 1, regex: "cat", match: false, "do you have any c@ts"); this.AssertSingleAndTest(db, 2, regex: "no-way", match: true, "no-way", "there can be No-way!", "oh no-way-!"); this.AssertSingleAndTest(db, 2, regex: "no-way", match: false, "nope-way", "no way"); this.AssertSingleAndTest(db, 2, regex: @"dot\.com", match: true, "*****@*****.**", "dot.dot.coms", "dot.com.com", "dot-me-dot.com"); this.AssertSingleAndTest(db, 2, regex: @"dot\.com", match: false, "dot-com"); } ); }
public void IsGuildRegisteredTests() { foreach (ulong id in MockData.Ids) { Assert.That(this.Service.IsGuildRegistered(id), Is.False); } Assert.That(this.Service.IsGuildRegistered(1), Is.False); Assert.That(this.Service.IsGuildRegistered(MockData.Ids[0] + 1), Is.False); Assert.That(this.Service.IsGuildRegistered(MockData.Ids[0] - 1), Is.False); TestDbProvider.AlterAndVerify( alter: db => this.Service.LoadData(), verify: db => { foreach (ulong id in MockData.Ids) { Assert.That(this.Service.IsGuildRegistered(id), Is.True); } Assert.That(this.Service.IsGuildRegistered(1), Is.False); Assert.That(this.Service.IsGuildRegistered(MockData.Ids[0] + 1), Is.False); Assert.That(this.Service.IsGuildRegistered(MockData.Ids[0] - 1), Is.False); } ); }