test Dgm
continuous-integration/drone/push Build is failing Details

test_dice_group_manager
mohammad_zafir.jeeawody 2 years ago
parent 0f1f253746
commit df65ada43e

@ -69,8 +69,8 @@ namespace Model.Dice
/// <exception cref="ArgumentNullException"></exception>
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
if (!before.Value.Equals(after.Value))
if (!before.Value.ToList().Equals(after.Value.ToList()))
{
throw new ArgumentException("the group of dice cannot be updated, only the name", nameof(before));
}

@ -142,6 +142,60 @@ namespace Tests.Data_UTs.Dice
Xunit.Assert.Throws<ArgumentNullException>(action);
}
[Fact]
public void TestRemoveWorksIfExists()
{
// Arrange
DiceGroupManager dgm = new();
KeyValuePair<string, IEnumerable<Die>> toAdd = new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
dgm.Add(toAdd);
dgm.Remove(toAdd);
Xunit.Assert.DoesNotContain(toAdd, dgm.GetAll());
}
[Fact]
public void TestRemoveFailsSilentlyIfGivenNonExistent()
{
DiceGroupManager dgm = new();
KeyValuePair<string, IEnumerable<Die>> toAdd = new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
dgm.Add(toAdd);
KeyValuePair<string, IEnumerable<Die>> toAdd2 = new("Scrabble", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
// Act
dgm.Remove(toAdd2);
// Assert
Xunit.Assert.DoesNotContain(toAdd2, dgm.GetAll());
}
[Fact]
public void TestUpdateWorksIfValid()
{
// Arrange
DiceGroupManager dgm = new();
KeyValuePair<string, IEnumerable<Die>> toAdd = new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
dgm.Add(toAdd);
KeyValuePair<string, IEnumerable<Die>> toAdd2 = new("Scrabble", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
dgm.Update(toAdd, toAdd2);
Xunit.Assert.DoesNotContain(toAdd, dgm.GetAll());
Xunit.Assert.Contains(toAdd2, dgm.GetAll());
Xunit.Assert.True(dgm.GetAll().Count() == 1);
}
}

Loading…
Cancel
Save