protocal degalite

test_dice_group_manager
mzjeeawody 2 years ago
parent 5432a07e9e
commit 7581220fb7

@ -68,7 +68,16 @@ namespace Model.Dice
/// <exception cref="ArgumentNullException"></exception>
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))
{
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
{
public abstract class Die
public abstract class Die:IEquatable<Die>
{
public ReadOnlyCollection<Face> Faces => new(faces);
@ -23,6 +23,21 @@ namespace Model.Dice
{
int faceIndex = rnd.Next(0, Faces.Count);
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; }
@ -13,6 +17,15 @@
{
Value = value;
StringValue = value.ToString();
}
}
public bool Equals(DiceGroup other)
{
return StringValue == other.Name;
}
}
}

@ -1,22 +1,22 @@
using Data;
using Data.EF;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Model.Dice;
using Model.Dice.Faces;
using Model.Games;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace Tests.Data_UTs.Dice
{
public class DiceGroupManagerTest
using Data;
using Data.EF;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Model.Dice;
using Model.Dice.Faces;
using Model.Games;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace Tests.Data_UTs.Dice
{
public class DiceGroupManagerTest
{
private static readonly Task<MasterOfCeremonies> stubGameRunner = new Stub().LoadApp();
[Fact]
@ -43,18 +43,18 @@ namespace Tests.Data_UTs.Dice
public async Task TestAddWhenDiceGroupThenDoAddAndReturnDiceGroup()
{
// Arrange
DiceGroupManager dgm = new();
DiceGroup group1 = new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
DiceGroupManager dgm = new();
DiceGroup group1 = new("Monopoly", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
DiceGroup group2 = new("Scrabble", new List<NumberDie> { new NumberDie(new NumberFace(5), new NumberFace(7)), new NumberDie(new NumberFace(5), new NumberFace(7)) });
//...storing the results of DiceGroupManager.Add() in variables
Collection<DiceGroup> expected = new() {group1,group2 };
Collection<DiceGroup> actual = new()
{
await dgm.Add(group1),
await dgm.Add(group2)
};
// Assert
Collection<DiceGroup> expected = new() {group1,group2 };
Collection<DiceGroup> actual = new()
{
await dgm.Add(group1),
await dgm.Add(group2)
};
// Assert
Xunit.Assert.Equal(expected, actual);
Xunit.Assert.Equal(expected, actual);
}
@ -68,8 +68,8 @@ namespace Tests.Data_UTs.Dice
async Task actionAsync() => await dgm.Add(expected);// Add() returns the added element if succesful
// Assert
Xunit.Assert.Null(expected);
await Xunit.Assert.ThrowsAsync<ArgumentNullException>(actionAsync);
Xunit.Assert.Null(expected);
await Xunit.Assert.ThrowsAsync<ArgumentNullException>(actionAsync);
Xunit.Assert.DoesNotContain(expected, await dgm.GetAll());
}
[Fact]
@ -148,7 +148,8 @@ namespace Tests.Data_UTs.Dice
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()
{
// Arrange
@ -237,5 +238,5 @@ namespace Tests.Data_UTs.Dice
}
}
}
}

Loading…
Cancel
Save