conflict resolves

pull/62/head
Ismail TAHA JANAN 2 years ago
commit ac4ebc71f0

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 307 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

@ -11,16 +11,28 @@
[![Technical Debt](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=dice-app&metric=sqale_index&token=bf024850973b7556eef0b981a1b838867848005c)](https://codefirst.iut.uca.fr/sonar/dashboard?id=dice-app)
[![Vulnerabilities](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=dice-app&metric=vulnerabilities&token=bf024850973b7556eef0b981a1b838867848005c)](https://codefirst.iut.uca.fr/sonar/dashboard?id=dice-app)
# dice_app: the die throwing app
## To use the app
TLDR: you can't really
Open the *DiceApp* solution and navigate to the *App* project. The *Program.cs* file has a `Main()` method that can be launched. It will soon be able to load a stub. Then you will be able to play a console prototype / perform functional tests. But it isn't ready yet.
## To contribute (workflow)
We are using the feature branch workflow ([details here](https://www.atlassian.com/git/tutorials/comparing-workflows/feature-branch-workflow), or see the summary below)
### 1 - Sync with the remote
Make sure you're working with the latest version of the project
```
git checkout main
git fetch origin
git reset --hard origin/main
```
### 2 - Create a new branch
Give your new branch a name referring to an issue (or maybe a group of similar issues)
```
git checkout -b new-feature
@ -30,16 +42,22 @@ Regularly, you might want to get all the new code from your main branch, to work
```
git pull --rebase origin main
```
### 3 - Code
:fire::technologist::bug::fire:............:white_check_mark:
### 4 - Save your changes to your new branch
For a refresher, see details about `add`, `commit`, `push`, etc. [here](https://www.atlassian.com/git/tutorials/saving-changes)
It should involve creating a corresponding feature branch on the remote repository
```
git push -u origin new-feature
```
### 5 - Create a Pull Request
On [the repository's main page](https://codefirst.iut.uca.fr/git/alexis.drai/dice_app), or on your new branch's main page, look for a `New Pull Request` button.
It should then allow you to `merge into: ...:main` and `pull from: ...:new-feature`

@ -1,5 +1,6 @@
using Data;
using Model;
using Model.Games;
using System.Diagnostics;
namespace App
{

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using Model.Games;
namespace Data
{

@ -1,4 +1,7 @@
using Model;
using Model.Dice;
using Model.Dice.Faces;
using Model.Games;
using Model.Players;
namespace Data
{
@ -11,8 +14,49 @@ namespace Data
public GameRunner LoadApp()
{
// this doesn't do much for now, because the class isn't coded
return new GameRunner();
string g1 = "game1", g2 = "game2", g3 = "game3";
Player player1 = new("Alice"), player2 = new("Bob"), player3 = new("Clyde");
FavGroupManager favGroupManager = new(new DieManager());
// create at least one fav group in there
// ...
Game game1 = new(name: g1, playerManager: new PlayerManager(), favGroup: favGroupManager.GetAll().First());
Game game2 = new(name: g2, playerManager: new PlayerManager(), favGroup: favGroupManager.GetAll().Last());
Game game3 = new(name: g3, playerManager: new PlayerManager(), favGroup: favGroupManager.GetAll().First());
List<Game> games = new() { game1, game2, game3 };
PlayerManager globalPlayerManager = new();
globalPlayerManager.Add(player1);
globalPlayerManager.Add(player2);
globalPlayerManager.Add(player3);
GameRunner gameRunner = new(globalPlayerManager, favGroupManager, games);
game1.AddPlayerToGame(player1);
game1.AddPlayerToGame(player2);
game2.AddPlayerToGame(player1);
game2.AddPlayerToGame(player2);
game2.AddPlayerToGame(player3);
game3.AddPlayerToGame(player1);
game3.AddPlayerToGame(player3);
foreach (Game game in games)
{
for (int i = 0; i < 10; i++)
{
Player currentPlayer = game.GetWhoPlaysNow();
game.PerformTurn(currentPlayer);
game.PrepareNextPlayer(currentPlayer);
}
}
return gameRunner;
}
public static List<Player> LoadPlayers()
@ -29,6 +73,7 @@ namespace Data
return list;
}
<<<<<<< HEAD
public static List<AbstractDie> LoadDices()
{
List<AbstractDie> list = new()
@ -44,6 +89,8 @@ namespace Data
return list;
}
=======
>>>>>>> main
public static List<NumberDieFace> LoadNumFaces()
{
List<NumberDieFace> list = new()

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using Model.Dice.Faces;
namespace Model.Dice
{
public class Die
{
private static readonly Random random = new Random();
private List<AbstractDieFace> faces;
public AbstractDieFace Throw()
{
// next(x, y) --> [x, y[
return faces[random.Next(0, faces.Count)];
// replace with better algo later
}
}
}

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace Model.Dice
{
public class DieManager
{
private readonly IEnumerable<Die> dice = new List<Die>();
}
}

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
namespace Model.Dice.Faces
{
public abstract class AbstractDieFace
{

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
namespace Model.Dice.Faces
{
public class ColorDieFace : AbstractDieFace
{
@ -38,7 +38,12 @@ namespace Model
{
// https://stackoverflow.com/questions/1139957/convert-integer-to-hexadecimal-and-back-again
// maybe prepend it with a "#"...
return Value.ToString("X");
return Value.ToString("X6").Insert(0, "#");
}
public override string ToString()
{
return GetPracticalValue().ToString();
}
}
}

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
namespace Model.Dice.Faces
{
public class ImageDieFace : AbstractDieFace
{
@ -29,7 +29,12 @@ namespace Model
public override object GetPracticalValue()
{
return String.Format("Assets/images/{0}", Value);
return string.Format("Assets/images/{0}", Value);
}
public override string ToString()
{
return GetPracticalValue().ToString();
}
}
}

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
namespace Model.Dice.Faces
{
public class NumberDieFace : AbstractDieFace
{
@ -18,5 +18,10 @@ namespace Model
{
return Value;
}
public override string ToString()
{
return GetPracticalValue().ToString();
}
}
}

@ -0,0 +1,13 @@
using Model.Players;
using System.Collections.Generic;
namespace Model.Dice
{
public class FavGroup
{
public IEnumerable<Die> Dice { get; private set; }
public string Name { get; private set; }
}
}

@ -0,0 +1,21 @@
using Model.Players;
using System.Collections.Generic;
using System.Linq;
namespace Model.Dice
{
public class FavGroupManager
{
private readonly List<FavGroup> favGroups = new();
private readonly DieManager dieManager;
public FavGroupManager(DieManager dieManager)
{
this.dieManager = dieManager;
}
public IEnumerable<FavGroup> GetAll() => favGroups.AsEnumerable();
}
}

@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
public class GameRunner
{
}
}

@ -0,0 +1,175 @@
using Model.Dice;
using Model.Dice.Faces;
using Model.Players;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
namespace Model.Games
{
public class Game
{
/// <summary>
/// the name of the game 😎
/// </summary>
public string Name
{
get
{
return name;
}
set // GameRunner will need to take care of forbidding
// (or allowing) having two Games with the same name etc.
{
if (string.IsNullOrWhiteSpace(value))
{
throw new ArgumentException("param should not be null or blank", nameof(value));
}
name = value;
}
}
private string name;
/// <summary>
/// whether this game is new or not
/// </summary>
public bool IsFirstTurn { get; private set; } = false;
/// <summary>
/// the turns that have been done so far
/// </summary>
private readonly List<Turn> turns;
/// </summary>
/// get a READ ONLY enumerable of all turns belonging to this game
/// </summary>
/// <returns>a readonly enumerable of all this game's turns</returns>
public IEnumerable<Turn> GetHistory() => turns.AsEnumerable();
/// <summary>
/// the game's player manager, doing CRUD on players and switching whose turn it is
/// </summary>
private readonly PlayerManager playerManager;
/// <summary>
/// the group of dice used for this game
/// </summary>
private readonly FavGroup favGroup;
/// <summary>
/// constructs a Game with its own history of Turns.
/// If <paramref name="turns"/> is null, starts a new history
/// </summary>
/// <param name="name">the name of the game 😎</param>
/// <param name="turns">the turns that have been done so far</param>
/// <param name="playerManager">the game's player manager, doing CRUD on players and switching whose turn it is</param>
/// <param name="favGroup">the group of dice used for this game</param>
public Game(string name, PlayerManager playerManager, FavGroup favGroup, IEnumerable<Turn> turns)
{
Name = name;
this.turns = turns.ToList() ?? new List<Turn>();
this.playerManager = playerManager;
this.favGroup = favGroup;
}
/// <summary>
/// constructs a Game with no history of turns.
/// </summary>
/// <param name="name">the name of the game 😎</param>
/// <param name="playerManager">the game's player manager, doing CRUD on players and switching whose turn it is</param>
/// <param name="favGroup">the group of dice used for this game</param>
public Game(string name, PlayerManager playerManager, FavGroup favGroup)
: this(name, playerManager, favGroup, null)
{ }
/// <summary>
/// performs a Turn, marks this Game as "started", and logs that Turn
/// </summary>
/// <param name="player">the player whose turn it is</param>
public void PerformTurn(Player player)
{
if (IsFirstTurn) { IsFirstTurn = false; } // only true one time (on the first turn...)
Turn turn = Turn.CreateWithDefaultTime(
new Player(player),
ThrowAll() //using a copy so that next line doesn't "change history"
);
turns.Add(turn);
}
/// <summary>
/// finds whose turn it is
/// </summary>
/// <returns>the Player whose turn it is</returns>
public Player GetWhoPlaysNow()
{
return playerManager.WhoPlaysNow(IsFirstTurn);
}
/// <summary>
/// throws all the Dice in FavGroup and returns a list of their Faces
/// </summary>
/// <returns>list of AbstractDieFaces after a throw</returns>
private List<AbstractDieFace> ThrowAll()
{
List<AbstractDieFace> faces = new();
foreach (Die die in favGroup.Dice)
{
faces.Add(die.Throw());
}
return faces;
}
/// <summary>
/// asks the PlayerManager to prepare the next Player
/// </summary>
/// <param name="currentPlayer">the Player whose turn it was</param>
public void PrepareNextPlayer(Player currentPlayer)
{
playerManager.PrepareNextPlayer(currentPlayer);
}
public Player AddPlayerToGame(Player player)
{
return playerManager.Add(player);
}
public IEnumerable<Player> GetPlayersFromGame()
{
return playerManager.GetAll();
}
public Player UpdatePlayerInGame(Player oldPlayer, Player newPlayer)
{
return playerManager.Update(oldPlayer, newPlayer);
}
public void RemovePlayerFromGame(Player player)
{
playerManager.Remove(player);
}
/// <summary>
/// represents a Game in string format
/// </summary>
/// <returns>a Game in string format</returns>
public override string ToString()
{
StringBuilder sb = new();
sb.AppendFormat("Game: {0}===========\n" +
"{1} are playing. {2} is next.\n" +
"Log:\n",
Name,
playerManager.GetAll().ToString(),
playerManager.WhoPlaysNow(IsFirstTurn));
foreach (Turn turn in this.turns)
{
sb.Append("\t" + turn.ToString());
}
return sb.ToString();
}
}
}

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model.Dice;
using Model.Players;
namespace Model.Games
{
public class GameRunner
{
private readonly PlayerManager globalPlayerManager;
private readonly FavGroupManager favGroupManager;
private readonly List<Game> games;
public GameRunner(PlayerManager globalPlayerManager, FavGroupManager favGroupManager, List<Game> games)
{
this.globalPlayerManager = globalPlayerManager;
this.favGroupManager = favGroupManager;
this.games = games ?? new();
}
public IEnumerable<Game> GetAll() => games.AsEnumerable();
/// <summary>
/// finds the game with that name and returns it
/// <br/>
/// that copy does not belong to this gamerunner's games, so it should not be modified
/// </summary>
/// <param name="name">a games's name</param>
/// <returns>game with said name, <em>or null</em> if no such game was found</returns>
public Game GetOneGameByName(string name)
{
if (!string.IsNullOrWhiteSpace(name))
{
Game result = games.FirstOrDefault(g => g.Name == name);
return result; // may return null
}
throw new ArgumentException("param should not be null or blank", nameof(name));
}
}
}

@ -1,6 +1,13 @@
using System;
namespace Model
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Model.Dice.Faces;
using Model.Players;
namespace Model.Games
{
/// <summary>
/// a Turn consists of a Player, a DateTime, and a IEnumerable of AbstractDieFace
@ -22,22 +29,22 @@ namespace Model
/// </summary>
public readonly Player player;
// ... faces
/// <summary>
/// the collection of Face that were rolled
/// </summary>
private readonly IEnumerable<AbstractDieFace> faces;
/// <summary>
/// this private constructor is to be used only by factories
/// </summary>
/// <param name="when">date and time of the turn</param>
/// <param name="player">player who played the turn</param>
// ... faces
private Turn(DateTime when, Player player/*, IEnumerable<AbstractDieFace> faces*/)
/// <param name="faces">faces that were rolled</param>
private Turn(DateTime when, Player player, IEnumerable<AbstractDieFace> faces)
{
this.when = when;
this.player = player;
// ... faces
this.faces = faces;
}
/// <summary>
@ -48,14 +55,16 @@ namespace Model
/// </summary>
/// <param name="when">date and time of the turn</param>
/// <param name="player">player who played the turn</param>
/// <param name="faces">faces that were rolled</param>
/// <returns>a new Turn object</returns>
// ... faces
public static Turn CreateWithSpecifiedTime(DateTime when, Player player/*, IEnumerable<AbstractDieFace> faces*/)
public static Turn CreateWithSpecifiedTime(DateTime when, Player player, IEnumerable<AbstractDieFace> faces)
{
// ... faces
if (player == null)
if (faces is null || !faces.Any())
{
throw new ArgumentException("param should not be null or empty", nameof(faces));
}
if (player is null)
{
throw new ArgumentNullException(nameof(player), "param should not be null");
}
@ -64,38 +73,43 @@ namespace Model
when = when.ToUniversalTime();
}
return new Turn(when, player/*, faces*/);
return new Turn(when, player, faces);
}
/// <summary>
/// creates a Turn with a default time, which is "now" in UTC.
/// </summary>
/// <param name="player">player who played the turn</param>
/// <param name="faces">faces that were rolled</param>
/// <returns>a new Turn object</returns>
// ... faces
public static Turn CreateWithDefaultTime(Player player/*, IEnumerable<AbstractDieFace> faces*/)
public static Turn CreateWithDefaultTime(Player player, IEnumerable<AbstractDieFace> faces)
{
return CreateWithSpecifiedTime(DateTime.UtcNow, player/*, faces*/);
return CreateWithSpecifiedTime(DateTime.UtcNow, player, faces);
}
// ... faces
/// <summary>
/// represents a turn in string format
/// </summary>
/// <returns>a turn in string format</returns>
public override string ToString()
{
return String.Format("{0} -- {1} rolled {2}",
ToStringIsoWithZ(),
this.player.ToString(),
"<face>, <face>, <face>...");
}
string[] datetime = when.ToString("s", System.Globalization.CultureInfo.InvariantCulture).Split("T");
string date = datetime[0];
string time = datetime[1];
private string ToStringIsoWithZ()
{
return this.when.ToString("s", System.Globalization.CultureInfo.InvariantCulture) + "Z";
StringBuilder sb = new();
sb.AppendFormat("{0} {1} -- {2} rolled:",
date,
time,
player.ToString());
foreach (AbstractDieFace face in faces)
{
sb.Append(" " + face.ToString());
}
return sb.ToString();
}
}
}

@ -1,6 +1,6 @@
using System;
namespace Model
namespace Model.Players
{
/// <summary>
/// A player for the purpose of a game of dice, consists of a name
@ -15,7 +15,7 @@ namespace Model
public string Name { get; private set; }
public Player(string name)
{
if (!String.IsNullOrWhiteSpace(name))
if (!string.IsNullOrWhiteSpace(name))
{
Name = name.Trim();
}
@ -40,7 +40,7 @@ namespace Model
return Name.ToUpper() == other.Name.ToUpper(); // equality is case insensitive
}
public override bool Equals(Object obj)
public override bool Equals(object obj)
{
if (obj is not Player)
{

@ -2,16 +2,21 @@
using System.Collections.Generic;
using System.Linq;
namespace Model
namespace Model.Players
{
public class PlayerManager : IManager<Player>
{
/// <summary>
/// a hashset of the players that this manager is in charge of
/// a collection of the players that this manager is in charge of
/// </summary>
private readonly List<Player> players;
/// <summary>
/// references the position in list of the current player, for a given game.
/// <br/>
/// each player is unique (set), and the hash is based on the player's values (name)
/// ASSUMING that each Game made its own instance of PlayerManager
/// </summary>
private readonly HashSet<Player> players;
public int NextIndex { get; private set; } = 0;
public PlayerManager()
{
@ -24,12 +29,16 @@ namespace Model
/// <returns>added player, or null if <paramref name="toAdd"/> was null</returns>
public Player Add(Player toAdd)
{
if (toAdd != null)
if (toAdd is null)
{
throw new ArgumentNullException(nameof(toAdd), "param should not be null");
}
if (players.Contains(toAdd))
{
players.Add(toAdd);
return toAdd;
throw new ArgumentException("this username is already taken", nameof(toAdd));
}
throw new ArgumentNullException(nameof(toAdd), "param should not be null");
players.Add(toAdd);
return toAdd;
}
/// <summary>
@ -52,7 +61,7 @@ namespace Model
/// <returns>player with said name, <em>or null</em> if no such player was found</returns>
public Player GetOneByName(string name)
{
if (!String.IsNullOrWhiteSpace(name))
if (!string.IsNullOrWhiteSpace(name))
{
Player wanted = new(name);
Player result = players.FirstOrDefault(p => p.Equals(wanted));
@ -68,6 +77,64 @@ namespace Model
/// <returns>a readonly enumerable of all this manager's players</returns>
public IEnumerable<Player> GetAll() => players.AsEnumerable();
/// <summary>
/// finds and returns the player whose turn it is
/// </summary>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public Player WhoPlaysNow(bool isFirstTurn)
{
if (players.Count == 0)
{
throw new MemberAccessException("you are exploring an empty collection\nthis should not have happened");
}
Player result;
if (isFirstTurn)
{
result = players[0];
}
else
{
result = players[NextIndex];
}
return result;
}
/// <summary>
/// this feels very dirty
/// </summary>
/// <param name="current"></param>
/// <exception cref="Exception"></exception>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="ArgumentException"></exception>
public void PrepareNextPlayer(Player current)
{
if (players.Count == 0)
{
throw new MemberAccessException("you are exploring an empty collection\nthis should not have happened");
}
if (current == null)
{
throw new ArgumentNullException(nameof(current), "param should not be null");
}
if (!players.Contains(current))
{
throw new ArgumentException("param could not be found in this collection\n did you forget to add it?", nameof(current));
}
if (players.Last() == current)
{
// if we've reached the last index, we need to loop back around
NextIndex = 0;
}
else
{
// else we can just move up one from current
NextIndex++;
}
}
/// <summary>
/// update a player from <paramref name="before"/> to <paramref name="after"/>
/// </summary>
@ -101,7 +168,7 @@ namespace Model
{
throw new ArgumentNullException(nameof(toRemove), "param should not be null");
}
// the built-in HashSet.Remove() method will use our redefined Equals(), using Name only
// the built-in Remove() method will use our redefined Equals(), using Name only
players.Remove(toRemove);
}
}

@ -8,8 +8,8 @@ namespace Tests.Model_UTs
[Fact]
public void TestConstructor()
{
AbstractDie die = new AbstractDie("Ben");
Assert.Equal("Ben", die.Name);
//AbstractDie die = new AbstractDie("Ben");
//Assert.Equal("Ben", die.Name);
}
}
}

@ -1,4 +1,4 @@
using Model;
using Model.Players;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

@ -1,4 +1,4 @@
using Model;
using Model.Players;
using System;
using Xunit;

@ -1,11 +1,35 @@
using Model;
using Model.Dice.Faces;
using Model.Games;
using Model.Players;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using Xunit;
namespace Tests.Model_UTs
{
public class TurnTest
{
private readonly List<AbstractDieFace> FACES;
private readonly int FACE_ONE = 1;
private readonly int FACE_TWO = 12;
private readonly int FACE_THREE = 54;
private readonly int FACE_FOUR = 16548;
public TurnTest()
{
FACES = new List<AbstractDieFace>
{
new NumberDieFace(FACE_ONE),
new NumberDieFace(FACE_TWO),
new ImageDieFace(FACE_THREE),
new ColorDieFace(FACE_FOUR)
};
}
[Fact]
public void TestCreateWithSpecifiedTimeNotUTCThenValid()
{
@ -15,7 +39,7 @@ namespace Tests.Model_UTs
Assert.NotEqual(DateTimeKind.Utc, dateTime.Kind);
// Act
Turn turn = Turn.CreateWithSpecifiedTime(dateTime, player);
Turn turn = Turn.CreateWithSpecifiedTime(dateTime, player, FACES);
// Assert
Assert.Equal(DateTimeKind.Utc, turn.when.Kind);
@ -31,7 +55,7 @@ namespace Tests.Model_UTs
Assert.Equal(DateTimeKind.Utc, dateTime.Kind);
// Act
Turn turn = Turn.CreateWithSpecifiedTime(dateTime, player);
Turn turn = Turn.CreateWithSpecifiedTime(dateTime, player, FACES);
// Assert
Assert.Equal(DateTimeKind.Utc, turn.when.Kind);
@ -45,38 +69,54 @@ namespace Tests.Model_UTs
DateTime dateTime = new(year: 2018, month: 06, day: 15, hour: 16, minute: 30, second: 0, kind: DateTimeKind.Utc);
// Act
void action() => Turn.CreateWithSpecifiedTime(dateTime, null);
void action() => Turn.CreateWithSpecifiedTime(dateTime, null, FACES);
// Assert
Assert.Throws<ArgumentNullException>(action);
}
[Fact]
public void TestCreateWithDefaultTimeThenValid()
public void TestCreateWithSpecifiedTimeNullFacesThenException()
{
// Arrange
Player player = new("Chloe");
DateTime dateTime = new(year: 2018, month: 06, day: 15, hour: 16, minute: 30, second: 0, kind: DateTimeKind.Utc);
Player player = new("Chucky");
// Act
Turn turn = Turn.CreateWithDefaultTime(player);
void action() => Turn.CreateWithSpecifiedTime(dateTime, player, null);
// Assert
Assert.Equal(DateTimeKind.Utc, turn.when.Kind);
Assert.Equal(DateTime.Now.ToUniversalTime().Date, turn.when.Date);
/*** N.B.: might fail between 11:59:59PM and 00:00:00AM ***/
Assert.Throws<ArgumentException>(action);
}
[Fact]
public void TestCreateWithDefaultTimeNullPlayerThenException()
public void TestCreateWithSpecifiedTimeEmptyFacesThenException()
{
// Arrange
Player player = new("Devon");
DateTime dateTime = new(year: 2018, month: 06, day: 15, hour: 16, minute: 30, second: 0, kind: DateTimeKind.Utc);
Player player = new("Chucky");
FACES.Clear();
// Act
static void action() => Turn.CreateWithDefaultTime(null);
void action() => Turn.CreateWithSpecifiedTime(dateTime, player, FACES);
// Assert
Assert.Throws<ArgumentNullException>(action);
Assert.Throws<ArgumentException>(action);
}
[Fact]
public void TestCreateWithDefaultTimeThenValid()
{
// Arrange
Player player = new("Chloe");
// Act
Turn turn = Turn.CreateWithDefaultTime(player, FACES);
// Assert
Assert.Equal(DateTimeKind.Utc, turn.when.Kind);
Assert.Equal(DateTime.Now.ToUniversalTime().Date, turn.when.Date);
/*** N.B.: might fail between 11:59:59PM and 00:00:00AM ***/
}
[Fact]
@ -86,11 +126,17 @@ namespace Tests.Model_UTs
DateTime dateTime = new(year: 2018, month: 06, day: 15, hour: 16, minute: 30, second: 0, kind: DateTimeKind.Utc);
string name = "Bobby";
Player player = new(name);
string expected = $"2018-06-15T16:30:00Z -- {name} rolled <face>, <face>, <face>...";
Turn turn = Turn.CreateWithSpecifiedTime(dateTime, player);
string expected = $"2018-06-15 16:30:00 -- {name} rolled: "
+ FACE_ONE + " "
+ FACE_TWO
+ " Assets/images/" + FACE_THREE + " "
+ FACE_FOUR.ToString("X6").Insert(0, "#");
Turn turn = Turn.CreateWithSpecifiedTime(dateTime, player, FACES);
// Act
string actual = turn.ToString();
Debug.WriteLine(actual);
// Assert
Assert.Equal(expected, actual);

Loading…
Cancel
Save