♻️ Rename DieManager to DiceGroupManager #126

Merged
alexis.drai merged 1 commits from rename-diemanager into main 3 years ago

@ -28,7 +28,7 @@ namespace App
{ {
Console.WriteLine(ex.Message); Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace); Console.WriteLine(ex.StackTrace);
masterOfCeremonies = new(new PlayerManager(), new DieManager(), null); masterOfCeremonies = new(new PlayerManager(), new DiceGroupManager(), null);
} }
try try
@ -90,7 +90,7 @@ namespace App
case "n": case "n":
if (!masterOfCeremonies.DieGroupManager.GetAll().Any()) if (!masterOfCeremonies.DiceGroupManager.GetAll().Any())
{ {
Console.WriteLine("make at least one dice group first, then try again"); Console.WriteLine("make at least one dice group first, then try again");
break; break;
@ -151,7 +151,7 @@ namespace App
newGroupDice.Add(die); newGroupDice.Add(die);
} }
} }
masterOfCeremonies.DieGroupManager.Add(new KeyValuePair<string, IEnumerable<Die>>(newGroupName, newGroupDice)); masterOfCeremonies.DiceGroupManager.Add(new KeyValuePair<string, IEnumerable<Die>>(newGroupName, newGroupDice));
break; break;
case "p": case "p":
@ -257,7 +257,7 @@ namespace App
private static void ShowDice(MasterOfCeremonies masterOfCeremonies) private static void ShowDice(MasterOfCeremonies masterOfCeremonies)
{ {
foreach ((string name, IEnumerable<Die> dice) in masterOfCeremonies.DieGroupManager.GetAll()) foreach ((string name, IEnumerable<Die> dice) in masterOfCeremonies.DiceGroupManager.GetAll())
{ {
Console.WriteLine($"{name} -- {dice}"); Console.WriteLine($"{name} -- {dice}");
} }
@ -345,7 +345,7 @@ namespace App
menuChoiceDice = Console.ReadLine(); menuChoiceDice = Console.ReadLine();
if (!menuChoiceDice.Equals("ok")) if (!menuChoiceDice.Equals("ok"))
{ {
IEnumerable<Die> chosenDice = masterOfCeremonies.DieGroupManager.GetOneByName(menuChoiceDice).Value; IEnumerable<Die> chosenDice = masterOfCeremonies.DiceGroupManager.GetOneByName(menuChoiceDice).Value;
foreach (Die die in chosenDice) foreach (Die die in chosenDice)
{ {
result.Add(die); result.Add(die);

@ -10,7 +10,7 @@ namespace Data
{ {
public MasterOfCeremonies LoadApp() public MasterOfCeremonies LoadApp()
{ {
MasterOfCeremonies gr = new(new PlayerManager(), new DieManager(), new GameManager()); MasterOfCeremonies gr = new(new PlayerManager(), new DiceGroupManager(), new GameManager());
Player player1 = new("Alice(Old Stub)"), player2 = new("Bob(Old Stub)"), player3 = new("Clyde(Old Stub)"); Player player1 = new("Alice(Old Stub)"), player2 = new("Bob(Old Stub)"), player3 = new("Clyde(Old Stub)");
@ -63,8 +63,8 @@ namespace Data
dndDice.Add(new NumberDie(d20Faces)); dndDice.Add(new NumberDie(d20Faces));
gr.DieGroupManager.Add(new KeyValuePair<string, IEnumerable<Die>>(dndName, dndDice.AsEnumerable())); gr.DiceGroupManager.Add(new KeyValuePair<string, IEnumerable<Die>>(dndName, dndDice.AsEnumerable()));
gr.DieGroupManager.Add(new KeyValuePair<string, IEnumerable<Die>>(monopolyName, monopolyDice.AsEnumerable())); gr.DiceGroupManager.Add(new KeyValuePair<string, IEnumerable<Die>>(monopolyName, monopolyDice.AsEnumerable()));
string game1 = "Forgotten Realms", game2 = "4e", game3 = "The Coopers"; string game1 = "Forgotten Realms", game2 = "4e", game3 = "The Coopers";

@ -1,87 +1,87 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace Model.Dice namespace Model.Dice
{ {
public class DieManager : IManager<KeyValuePair<string, IEnumerable<Die>>> public class DiceGroupManager : IManager<KeyValuePair<string, IEnumerable<Die>>>
{ {
private readonly Dictionary<string, IEnumerable<Die>> diceGroups = new(); private readonly Dictionary<string, IEnumerable<Die>> diceGroups = new();
public KeyValuePair<string, IEnumerable<Die>> Add(KeyValuePair<string, IEnumerable<Die>> toAdd) public KeyValuePair<string, IEnumerable<Die>> Add(KeyValuePair<string, IEnumerable<Die>> toAdd)
{ {
if (string.IsNullOrWhiteSpace(toAdd.Key)) if (string.IsNullOrWhiteSpace(toAdd.Key))
{ {
throw new ArgumentNullException(nameof(toAdd), "param should not be null or empty"); throw new ArgumentNullException(nameof(toAdd), "param should not be null or empty");
} }
if (diceGroups.Contains(toAdd)) if (diceGroups.Contains(toAdd))
{ {
throw new ArgumentException("this username is already taken", nameof(toAdd)); throw new ArgumentException("this username is already taken", nameof(toAdd));
} }
diceGroups.Add(toAdd.Key.Trim(), toAdd.Value); diceGroups.Add(toAdd.Key.Trim(), toAdd.Value);
return toAdd; return toAdd;
} }
public IEnumerable<KeyValuePair<string, IEnumerable<Die>>> GetAll() public IEnumerable<KeyValuePair<string, IEnumerable<Die>>> GetAll()
{ {
return diceGroups.AsEnumerable(); return diceGroups.AsEnumerable();
} }
public KeyValuePair<string, IEnumerable<Die>> GetOneByID(Guid ID) public KeyValuePair<string, IEnumerable<Die>> GetOneByID(Guid ID)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public KeyValuePair<string, IEnumerable<Die>> GetOneByName(string name) public KeyValuePair<string, IEnumerable<Die>> GetOneByName(string name)
{ {
// les groupes de dés nommés : // les groupes de dés nommés :
// ils sont case-sensistive, mais "mon jeu" == "mon jeu " == " mon jeu" // ils sont case-sensistive, mais "mon jeu" == "mon jeu " == " mon jeu"
if (string.IsNullOrWhiteSpace(name)) if (string.IsNullOrWhiteSpace(name))
{ {
throw new ArgumentNullException(nameof(name), "param should not be null or empty"); throw new ArgumentNullException(nameof(name), "param should not be null or empty");
} }
else else
{ {
return new KeyValuePair<string, IEnumerable<Die>>(name, diceGroups[name]); return new KeyValuePair<string, IEnumerable<Die>>(name, diceGroups[name]);
} }
} }
public void Remove(KeyValuePair<string, IEnumerable<Die>> toRemove) public void Remove(KeyValuePair<string, IEnumerable<Die>> toRemove)
{ {
if (toRemove.Key is null) if (toRemove.Key is null)
{ {
throw new ArgumentNullException(nameof(toRemove), "param should not be null"); throw new ArgumentNullException(nameof(toRemove), "param should not be null");
} }
else else
{ {
diceGroups.Remove(toRemove.Key); diceGroups.Remove(toRemove.Key);
} }
} }
/// <summary> /// <summary>
/// updates a (string, IEnumerable-of-Die) couple. only the name can be updated /// updates a (string, IEnumerable-of-Die) couple. only the name can be updated
/// </summary> /// </summary>
/// <param name="before">original couple</param> /// <param name="before">original couple</param>
/// <param name="after">new couple</param> /// <param name="after">new couple</param>
/// <returns></returns> /// <returns></returns>
/// <exception cref="ArgumentException"></exception> /// <exception cref="ArgumentException"></exception>
/// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentNullException"></exception>
public KeyValuePair<string, IEnumerable<Die>> Update(KeyValuePair<string, IEnumerable<Die>> before, KeyValuePair<string, IEnumerable<Die>> after) public KeyValuePair<string, IEnumerable<Die>> Update(KeyValuePair<string, IEnumerable<Die>> before, KeyValuePair<string, IEnumerable<Die>> after)
{ {
// pas autorisé de changer les dés, juste le nom // pas autorisé de changer les dés, juste le nom
if (!before.Value.Equals(after.Value)) if (!before.Value.Equals(after.Value))
{ {
throw new ArgumentException("the group of dice cannot be updated, only the name", nameof(before)); throw new ArgumentException("the group of dice cannot be updated, only the name", nameof(before));
} }
if (string.IsNullOrWhiteSpace(before.Key) || string.IsNullOrWhiteSpace(after.Key)) if (string.IsNullOrWhiteSpace(before.Key) || string.IsNullOrWhiteSpace(after.Key))
{ {
throw new ArgumentNullException(nameof(before), "dice group name should not be null or empty"); throw new ArgumentNullException(nameof(before), "dice group name should not be null or empty");
} }
diceGroups.Remove(before.Key); diceGroups.Remove(before.Key);
diceGroups.Add(after.Key, after.Value); diceGroups.Add(after.Key, after.Value);
return after; return after;
} }
} }
} }

@ -7,13 +7,13 @@ namespace Model.Games
public class MasterOfCeremonies public class MasterOfCeremonies
{ {
public IManager<Player> GlobalPlayerManager { get; private set; } public IManager<Player> GlobalPlayerManager { get; private set; }
public IManager<KeyValuePair<string, IEnumerable<Die>>> DieGroupManager { get; private set; } public IManager<KeyValuePair<string, IEnumerable<Die>>> DiceGroupManager { get; private set; }
public IManager<Game> GameManager { get; private set; } public IManager<Game> GameManager { get; private set; }
public MasterOfCeremonies(IManager<Player> globalPlayerManager, IManager<KeyValuePair<string, IEnumerable<Die>>> globalDieManager, IManager<Game> gameManager) public MasterOfCeremonies(IManager<Player> globalPlayerManager, IManager<KeyValuePair<string, IEnumerable<Die>>> globalDiceGroupManager, IManager<Game> gameManager)
{ {
GlobalPlayerManager = globalPlayerManager; GlobalPlayerManager = globalPlayerManager;
DieGroupManager = globalDieManager; DiceGroupManager = globalDiceGroupManager;
GameManager = gameManager; GameManager = gameManager;
} }

@ -20,8 +20,8 @@ namespace Tests.Model_UTs.Games
private readonly IEnumerable<Die> DICE_1, DICE_2; private readonly IEnumerable<Die> DICE_1, DICE_2;
public GameTest() public GameTest()
{ {
DICE_1 = stubMasterOfCeremonies.DieGroupManager.GetAll().First().Value; DICE_1 = stubMasterOfCeremonies.DiceGroupManager.GetAll().First().Value;
DICE_2 = stubMasterOfCeremonies.DieGroupManager.GetAll().Last().Value; DICE_2 = stubMasterOfCeremonies.DiceGroupManager.GetAll().Last().Value;
} }

Loading…
Cancel
Save