Compare commits

...

2 Commits

Author SHA1 Message Date
mzjeeawody c6fd28541b 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
2 years ago
mzjeeawody 7581220fb7 protocal degalite
2 years ago

@ -83,7 +83,16 @@ namespace Model.Dice
/// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentNullException"></exception>
public Task<DiceGroup> Update(DiceGroup before, DiceGroup after) public Task<DiceGroup> Update(DiceGroup before, DiceGroup after)
{ {
// pas autorisé de changer les dés, juste le nom
var results= after.Dice.Where(dice => before.Dice.Contains(after.Dice[0]));
/* foreach(Die die in before.Dice)
{
if (after.Dice.Contains((die)))
{
throw new ArgumentException("the group of dice cannot be updated, only the name", nameof(before));
}
}*/
// pas autorisé de changer les dés, juste le nom
if (!before.Dice.SequenceEqual(after.Dice)) if (!before.Dice.SequenceEqual(after.Dice))
{ {
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));

@ -6,7 +6,7 @@ using System.Linq;
namespace Model.Dice namespace Model.Dice
{ {
public abstract class Die public abstract class Die:IEquatable<Die>
{ {
public ReadOnlyCollection<Face> Faces => new(faces); public ReadOnlyCollection<Face> Faces => new(faces);
@ -23,6 +23,21 @@ namespace Model.Dice
{ {
int faceIndex = rnd.Next(0, Faces.Count); int faceIndex = rnd.Next(0, Faces.Count);
return Faces.ElementAt(faceIndex); return Faces.ElementAt(faceIndex);
} }
public bool Equals(Die other)
{
return Faces == other.Faces && Faces.SequenceEqual(other.Faces);
}
public override bool Equals(object obj)
{
if (obj is null) return false; // is null
if (ReferenceEquals(obj, this)) return true; // is me
if (!obj.GetType().Equals(GetType())) return false; // is different type
return Equals(obj as Die); // is not me, is not null, is same type : send up
}
} }
} }

@ -1,11 +1,15 @@
namespace Model.Dice.Faces using System;
namespace Model.Dice.Faces
{ {
public abstract class Face public abstract class Face
{ {
public string StringValue { get; protected set; } public string StringValue { get; protected set; }
} }
public abstract class Face<T> : Face public abstract class Face<T> : Face, IEquatable<Face<T>>
{ {
public T Value { get; protected set; } public T Value { get; protected set; }
@ -13,6 +17,15 @@
{ {
Value = value; Value = value;
StringValue = value.ToString(); StringValue = value.ToString();
} }
public bool Equals(DiceGroup other)
{
return StringValue == other.Name;
}
} }
} }

@ -148,7 +148,8 @@ namespace Tests.Data_UTs.Dice
Xunit.Assert.DoesNotContain(toAdd2, await dgm.GetAll()); Xunit.Assert.DoesNotContain(toAdd2, await dgm.GetAll());
} }
[Fact]//To check sequence equal does not work properly //To check sequence equal does not work properly
[Fact]
public async Task TestUpdateWorksIfValid() public async Task TestUpdateWorksIfValid()
{ {
// Arrange // Arrange

Loading…
Cancel
Save