From 88313ae1454da1bdd269c9bc9317486f4d55c0ec Mon Sep 17 00:00:00 2001 From: m4-used-rollout Date: Thu, 14 Dec 2023 07:20:42 +0000 Subject: [PATCH] Removed the case checking on upsert. Everything is forced to lowercase anyway. --- TPP.Persistence.MongoDB/Repos/ResponseCommandRepo.cs | 6 +++--- .../Repos/ResponseCommandRepoTest.cs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/TPP.Persistence.MongoDB/Repos/ResponseCommandRepo.cs b/TPP.Persistence.MongoDB/Repos/ResponseCommandRepo.cs index 3edbd1ab..714a1314 100644 --- a/TPP.Persistence.MongoDB/Repos/ResponseCommandRepo.cs +++ b/TPP.Persistence.MongoDB/Repos/ResponseCommandRepo.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Immutable; using System.Threading.Tasks; +using System.Xml.Linq; using MongoDB.Bson.Serialization; using MongoDB.Driver; using TPP.Model; @@ -39,7 +40,7 @@ public async Task UpsertCommand(string command, string response var commandLower = command.ToLower(); ResponseCommand newCommand = new(commandLower, response); ResponseCommand? oldCommand = await Collection.FindOneAndReplaceAsync( - Builders.Filter.Eq(c => c.Command.ToLower(), commandLower), + Builders.Filter.Eq(c => c.Command, commandLower), newCommand, new FindOneAndReplaceOptions { @@ -54,8 +55,7 @@ public async Task UpsertCommand(string command, string response public async Task RemoveCommand(string command) { - var commandLower = command.ToLower(); - DeleteResult deleteOneAsync = await Collection.DeleteOneAsync(c => c.Command.ToLower() == commandLower); + DeleteResult deleteOneAsync = await Collection.DeleteOneAsync(c => c.Command.Equals(command, StringComparison.InvariantCultureIgnoreCase)); CommandRemoved?.Invoke(this, command); return deleteOneAsync.DeletedCount > 0; } diff --git a/tests/TPP.Persistence.MongoDB.Tests/Repos/ResponseCommandRepoTest.cs b/tests/TPP.Persistence.MongoDB.Tests/Repos/ResponseCommandRepoTest.cs index 6856e624..7f96783f 100644 --- a/tests/TPP.Persistence.MongoDB.Tests/Repos/ResponseCommandRepoTest.cs +++ b/tests/TPP.Persistence.MongoDB.Tests/Repos/ResponseCommandRepoTest.cs @@ -13,11 +13,11 @@ public async Task persists_and_deletes_successfully() ResponseCommandRepo repo = new(CreateTemporaryDatabase()); Assert.That(await repo.GetCommands(), Is.Empty); - ResponseCommand command1 = await repo.UpsertCommand("command1", "response 1"); + ResponseCommand command1 = await repo.UpsertCommand("Command1", "response 1"); ResponseCommand command2 = await repo.UpsertCommand("command2", "response 2"); Assert.That(await repo.GetCommands(), Is.EquivalentTo(new[] { command1, command2 })); - Assert.That(await repo.RemoveCommand("command1"), Is.True); + Assert.That(await repo.RemoveCommand("COMMAND1"), Is.True); Assert.That(await repo.RemoveCommand("command1"), Is.False); // already deleted Assert.That(await repo.GetCommands(), Is.EquivalentTo(new[] { command2 })); } @@ -30,7 +30,7 @@ public async Task updates_existing() ResponseCommand command1 = await repo.UpsertCommand("command", "response 1"); Assert.That(await repo.GetCommands(), Is.EquivalentTo(new[] { command1 })); - ResponseCommand command2 = await repo.UpsertCommand("command", "response 2"); + ResponseCommand command2 = await repo.UpsertCommand("COMMAND", "response 2"); Assert.That(await repo.GetCommands(), Is.EquivalentTo(new[] { command2 })); } }