Skip to content

Commit

Permalink
Removed the case checking on upsert. Everything is forced to lowercas…
Browse files Browse the repository at this point in the history
…e anyway.
  • Loading branch information
m4-used-rollout committed Dec 14, 2023
1 parent 69c5917 commit 88313ae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions TPP.Persistence.MongoDB/Repos/ResponseCommandRepo.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -39,7 +40,7 @@ public async Task<ResponseCommand> UpsertCommand(string command, string response
var commandLower = command.ToLower();
ResponseCommand newCommand = new(commandLower, response);
ResponseCommand? oldCommand = await Collection.FindOneAndReplaceAsync(
Builders<ResponseCommand>.Filter.Eq(c => c.Command.ToLower(), commandLower),
Builders<ResponseCommand>.Filter.Eq(c => c.Command, commandLower),
newCommand,
new FindOneAndReplaceOptions<ResponseCommand>
{
Expand All @@ -54,8 +55,7 @@ public async Task<ResponseCommand> UpsertCommand(string command, string response

public async Task<bool> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
}
Expand All @@ -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 }));
}
}
Expand Down

0 comments on commit 88313ae

Please sign in to comment.