Merge branch 'test_dice_group_manager' of https://codefirst.iut.uca.fr/git/alexis.drai/dice_app into test_dice_group_manager
continuous-integration/drone/push Build is failing Details

test_dice_group_manager
mzjeeawody 2 years ago
commit c6fd28541b

@ -23,6 +23,21 @@ namespace Model.Dice
}
diceGroups.Add(new(toAdd.Name.Trim(), toAdd.Dice));
return Task.FromResult(toAdd);
}
public Task<DiceGroup> AddCheckName(DiceGroup toAdd)
{
if (string.IsNullOrWhiteSpace(toAdd.Name))
{
throw new ArgumentNullException(nameof(toAdd), "param should not be null or empty");
}
if (diceGroups.Where(d => d.Name.Equals(toAdd.Name)).Any())
{
throw new ArgumentException("this dice group already exists", nameof(toAdd));
}
diceGroups.Add(new(toAdd.Name.Trim(), toAdd.Dice));
return Task.FromResult(toAdd);
}
public Task<ReadOnlyCollection<DiceGroup>> GetAll()

@ -77,13 +77,13 @@ namespace Tests.Data_UTs.Dice
{
DiceGroupManager dgm = new();
await dgm.Add(new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) }));
await dgm.AddCheckName(new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) }));
DiceGroup group1 = new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
async Task actionAsync() => await dgm.Add(group1);
async Task actionAsync() => await dgm.AddCheckName(group1);
// Assert
await Xunit.Assert.ThrowsAsync<Exception>(actionAsync);
await Xunit.Assert.ThrowsAsync<ArgumentException>(actionAsync);
}
@ -112,7 +112,7 @@ namespace Tests.Data_UTs.Dice
DiceGroup toAdd = new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
await dgm.Add(toAdd);
async Task action() => dgm.GetOneByName(name);
async Task action() => await dgm.GetOneByName(name);
// Assert
await Xunit.Assert.ThrowsAsync<ArgumentNullException>(action);

Loading…
Cancel
Save