Skip to content

Commit

Permalink
Handle duplicate keys in connection string
Browse files Browse the repository at this point in the history
  • Loading branch information
shaan1337 committed Jul 6, 2020
1 parent 3f72371 commit f4ffa9c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,11 @@ private static Dictionary<string, string> ParseKeyValuePairs(string s) {
var optionsTokens = s.Split(Ampersand);
foreach (var optionToken in optionsTokens) {
var (key, val) = ParseKeyValuePair(optionToken);
options[key] = val;
try {
options.Add(key, val);
} catch (ArgumentException) {
throw new DuplicateKeyException(key);
}
}
return options;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace EventStore.Client {
public class DuplicateKeyException : ConnectionStringParseException {
public DuplicateKeyException(string key)
: base($"Duplicate key: '{key}'") { }
}
}
11 changes: 11 additions & 0 deletions test/EventStore.Client.Tests/ConnectionStringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ public void connection_string_with_invalid_key_value_pair_should_throw() {
});
}

[Fact]
public void connection_string_with_duplicate_key_should_throw() {
Assert.Throws<DuplicateKeyException>(() => {
EventStoreClientSettings.Create("esdb://user:pass@127.0.0.1/?maxDiscoverAttempts=1234&MaxDiscoverAttempts=10");
});

Assert.Throws<DuplicateKeyException>(() => {
EventStoreClientSettings.Create("esdb://user:pass@127.0.0.1/?gossipTimeout=10&gossipTimeout=30");
});
}

[Fact]
public void connection_string_with_invalid_settings_should_throw() {
Assert.Throws<InvalidSettingException>(() => {
Expand Down

0 comments on commit f4ffa9c

Please sign in to comment.