diff --git a/TPP.Persistence.MongoDB/Repos/ResponseCommandRepo.cs b/TPP.Persistence.MongoDB/Repos/ResponseCommandRepo.cs index 94fa406d..4e13d897 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; @@ -36,9 +37,10 @@ public async Task> GetCommands() => public async Task UpsertCommand(string command, string response) { - ResponseCommand newCommand = new(command, response); + var commandLower = command.ToLower(); + ResponseCommand newCommand = new(commandLower, response); ResponseCommand? oldCommand = await Collection.FindOneAndReplaceAsync( - Builders.Filter.Eq(c => c.Command, command), + Builders.Filter.Eq(c => c.Command, commandLower), newCommand, new FindOneAndReplaceOptions { @@ -53,7 +55,8 @@ public async Task UpsertCommand(string command, string response public async Task RemoveCommand(string command) { - DeleteResult deleteOneAsync = await Collection.DeleteOneAsync(c => c.Command == command); + var commandLower = command.ToLower(); + DeleteResult deleteOneAsync = await Collection.DeleteOneAsync(c => c.Command == command || c.Command == commandLower); 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 })); } }