diff --git a/Sources/Model/Dice/DieManager.cs b/Sources/Model/Dice/DieManager.cs index f6e8557..405288d 100644 --- a/Sources/Model/Dice/DieManager.cs +++ b/Sources/Model/Dice/DieManager.cs @@ -10,7 +10,6 @@ namespace Model.Dice public KeyValuePair> Add(KeyValuePair> toAdd) { - // on trim la clé d'abord if (string.IsNullOrWhiteSpace(toAdd.Key)) { throw new ArgumentNullException(nameof(toAdd), "param should not be null or empty"); @@ -60,21 +59,29 @@ namespace Model.Dice } } + /// + /// updates a (string, IEnumerable-of-Die) couple. only the name can be updated + /// + /// original couple + /// new couple + /// + /// + /// public KeyValuePair> Update(KeyValuePair> before, KeyValuePair> after) { // pas autorisé de changer les dés, juste le nom if (!before.Value.Equals(after.Value)) { - if (string.IsNullOrWhiteSpace(before.Key) || string.IsNullOrWhiteSpace(after.Key)) - { - throw new ArgumentNullException(nameof(before), "dice group name should not be null or empty"); - } - - diceGroups.Remove(before.Key); - diceGroups.Add(after.Key, after.Value); - return after; + throw new ArgumentException("the group of dice cannot be updated, only the name", nameof(before)); + } + if (string.IsNullOrWhiteSpace(before.Key) || string.IsNullOrWhiteSpace(after.Key)) + { + throw new ArgumentNullException(nameof(before), "dice group name should not be null or empty"); } - return before; + diceGroups.Remove(before.Key); + diceGroups.Add(after.Key, after.Value); + return after; + } } }