Compare commits

..

20 Commits
EF ... master

Author SHA1 Message Date
Maxence LANONE 8619817ac5 Reajout de dbdatamanager
continuous-integration/drone/push Build is failing Details
2 years ago
Maxence LANONE cfd98c2412 🤡 je sais pas ce que je commit
continuous-integration/drone/push Build is failing Details
2 years ago
Maxence LANONE 7e7cb63859 Mise à jour de 'README.md'
continuous-integration/drone/push Build is passing Details
2 years ago
Maxence LANONE f6e2b37a62 🐛 fix test player
continuous-integration/drone/push Build is passing Details
2 years ago
Maxence LANONE 8e64c82e1f 🐛 fix test player
continuous-integration/drone/push Build is failing Details
2 years ago
Maxence LANONE 2ce035db0b Merge remote-tracking branch 'refs/remotes/origin/master'
continuous-integration/drone/push Build is failing Details
2 years ago
Maxence LANONE 4927665890 add test for player class
2 years ago
Maxence LANONE 1637cee73b Mise à jour de '.drone.yml'
continuous-integration/drone/push Build is passing Details
2 years ago
Maxence LANONE c7cc318b36 add test for games (not very clean but passed)
continuous-integration/drone/push Build is passing Details
2 years ago
Maxence LANONE 8f8536ab1d 🔨 add jsonconverter for dictionary, requetes for games OK
continuous-integration/drone/push Build is failing Details
2 years ago
Maxence LANONE 7b5206b161 Mise à jour de '.drone.yml'
continuous-integration/drone/push Build is failing Details
2 years ago
Maxence LANONE f992120ad8 🐛 reglage build
continuous-integration/drone/push Build is failing Details
2 years ago
Maxence LANONE 8933ae3150 🐛 reglage api players OK
continuous-integration/drone/push Build is failing Details
2 years ago
Maxence LANONE 7e9768025c 🐛 fix build
continuous-integration/drone/push Build is passing Details
2 years ago
Théo DUPIN e7ba152332 Merge branch 'master' of https://codefirst.iut.uca.fr/git/Trek_Prod/Trek12_API
continuous-integration/drone/push Build is failing Details
2 years ago
Maxence LANONE ec282eae0b Mise à jour de '.drone.yml'
continuous-integration/drone/push Build is passing Details
2 years ago
Marc CHEVALDONNE 6abd8d4d95 Mise à jour de '.drone.yml'
continuous-integration/drone/push Build is passing Details
2 years ago
Aurelien PINTRAND fe9affed75 Merge branch 'master' of https://codefirst.iut.uca.fr/git/Trek_Prod/Trek12_API
continuous-integration/drone/push Build is passing Details
2 years ago
Aurelien PINTRAND 7e20d4ff16 🔨🔨 ajout de masse méthode converters et DTO + changements Model ( principalement leurs constructeurs )
2 years ago
Maxence LANONE faa3d625f1 Mise à jour de '.drone.yml'
continuous-integration/drone/push Build is passing Details
2 years ago

@ -45,7 +45,7 @@ steps:
# accessible en ligne de commande par $${PLUGIN_SONAR_TOKEN}
sonar_token:
from_secret: SECRET_SONAR_LOGIN
depends on: [tests]
depends_on: [tests]
# docker image build
- name: docker-build
@ -54,7 +54,7 @@ steps:
dockerfile: Sources/Trek12_API/Dockerfile
context: Sources/
registry: hub.codefirst.iut.uca.fr
repo: hub.codefirst.iut.uca.fr/Trek_Prod/Trek12_API
repo: hub.codefirst.iut.uca.fr/maxence.lanone/trek12_api
username:
from_secret: SECRET_REGISTRY_USERNAME
password:
@ -64,11 +64,11 @@ steps:
- name: deploy-container
image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest
environment:
IMAGENAME: hub.codefirst.iut.uca.fr/Trek_Prod/Trek12_API:latest
IMAGENAME: hub.codefirst.iut.uca.fr/maxence.lanone/trek12_api:latest
CONTAINERNAME: trek12api
COMMAND: create
OVERWRITE: true
ADMINS: maxencelanone, aurelienpintrand, theodupin, zakariyasaoula
ADMINS: maxencelanone,aurelienpintrand,theodupin,zakariyasaoula
depends_on: [ docker-build ]
volumes:

@ -1,15 +1,9 @@
[![Build Status](https://codefirst.iut.uca.fr/api/badges/Trek_Prod/Trek12_API/status.svg)](https://codefirst.iut.uca.fr/Trek_Prod/Trek12_API)
[![Quality Gate Status](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=Trek12_API&metric=alert_status)](https://codefirst.iut.uca.fr/sonar/dashboard?id=Trek12_API)
[![Bugs](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=Trek12_API&metric=bugs)](https://codefirst.iut.uca.fr/sonar/dashboard?id=Trek12_API)
[![Code Smells](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=Trek12_API&metric=code_smells)](https://codefirst.iut.uca.fr/sonar/dashboard?id=Trek12_API)
[![Coverage](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=Trek12_API&metric=coverage)](https://codefirst.iut.uca.fr/sonar/dashboard?id=Trek12_API)
[![Duplicated Lines (%)](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=Trek12_API&metric=duplicated_lines_density)](https://codefirst.iut.uca.fr/sonar/dashboard?id=Trek12_API)
[![Lines of Code](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=Trek12_API&metric=ncloc)](https://codefirst.iut.uca.fr/sonar/dashboard?id=Trek12_API)
[![Maintainability Rating](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=Trek12_API&metric=sqale_rating)](https://codefirst.iut.uca.fr/sonar/dashboard?id=Trek12_API)
[![Reliability Rating](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=Trek12_API&metric=reliability_rating)](https://codefirst.iut.uca.fr/sonar/dashboard?id=Trek12_API)
[![Security Rating](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=Trek12_API&metric=security_rating)](https://codefirst.iut.uca.fr/sonar/dashboard?id=Trek12_API)
[![Technical Debt](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=Trek12_API&metric=sqale_index)](https://codefirst.iut.uca.fr/sonar/dashboard?id=Trek12_API)
[![Vulnerabilities](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=Trek12_API&metric=vulnerabilities)](https://codefirst.iut.uca.fr/sonar/dashboard?id=Trek12_API)
[![Quality Gate Status](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=Trek12_API&metric=alert_status&token=92713f88adaca17889743593e014bf147c0e764d)](https://codefirst.iut.uca.fr/sonar/dashboard?id=Trek12_API)
[![Duplicated Lines (%)](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=Trek12_API&metric=duplicated_lines_density&token=92713f88adaca17889743593e014bf147c0e764d)](https://codefirst.iut.uca.fr/sonar/dashboard?id=Trek12_API)
[![Coverage](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=Trek12_API&metric=coverage&token=92713f88adaca17889743593e014bf147c0e764d)](https://codefirst.iut.uca.fr/sonar/dashboard?id=Trek12_API)
[![Maintainability Rating](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=Trek12_API&metric=sqale_rating&token=92713f88adaca17889743593e014bf147c0e764d)](https://codefirst.iut.uca.fr/sonar/dashboard?id=Trek12_API)
[![Security Hotspots](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=Trek12_API&metric=security_hotspots&token=92713f88adaca17889743593e014bf147c0e764d)](https://codefirst.iut.uca.fr/sonar/dashboard?id=Trek12_API)
# Trek12_API

@ -0,0 +1,20 @@
using Model;
namespace DbDataManager;
public class DbDataManager : IDataManager
{
public IPlayersManager PlayersMgr => throw new NotImplementedException();
public IGamesManager GamesMgr => throw new NotImplementedException();
public IGamesModeManager GamesModeMgr => throw new NotImplementedException();
public ICasesManager CasesMgr => throw new NotImplementedException();
public IGrillesManager GrillesMgr => throw new NotImplementedException();
public IStatsManager StatsMgr => throw new NotImplementedException();
public ITurnsManager TurnsMgr => throw new NotImplementedException();
}

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
</Project>

@ -26,7 +26,7 @@ namespace Model
public Case()
{
Valeur = 0;
}
public Case(int valeur)

@ -13,19 +13,19 @@ namespace Model
public TimeSpan Duration { get; set; }
public DateOnly Date { get; set; }
public DateTime Date { get; set; }
public ReadOnlyCollection<Player> Players { get; private set; }
private List<Player> players = new();
private List<Player> players;
public ReadOnlyCollection<Turn> Turns { get; private set; }
private List<Turn> turns = new();
private List<Turn> turns;
public ReadOnlyDictionary<Player, Grille> Grilles { get; private set; }
private readonly Dictionary<Player, Grille> grilles = new Dictionary<Player, Grille>();
private Dictionary<Player, Grille> grilles;
public ReadOnlyDictionary<Player, int> Scores { get; private set; }
private readonly Dictionary<Player, int> scores = new Dictionary<Player, int>();
private Dictionary<Player, int> scores;
public GameMode GameMode { get; set; }
@ -42,18 +42,52 @@ namespace Model
// Id = id;
//}
public Game(DateOnly date, Player ?owner, GameMode gameMode, int id = 0)
public Game(Player ?owner, GameMode gameMode, int id = 0)
{
Date = date;
Date = DateTime.Now;
// Creation list de player + ajout d'une player owner dans la liste
players = new();
Players = new ReadOnlyCollection<Player>(players);
Grilles = new ReadOnlyDictionary<Player, Grille>(grilles);
Scores = new ReadOnlyDictionary<Player, int>(scores);
players.Add(owner);
turns = new();
Turns = new ReadOnlyCollection<Turn>(turns);
Grilles = new ReadOnlyDictionary<Player, Grille>(new Dictionary<Player, Grille>());
grilles ??= new Dictionary<Player, Grille>();
grilles.Add(owner, new Grille());
Scores = new ReadOnlyDictionary<Player, int>(new Dictionary<Player, int>());
scores ??= new Dictionary<Player, int>();
scores.Add(owner, 0);
players.Add(owner);
GameMode = gameMode;
Id = id;
}
public Game(int id, ReadOnlyCollection<Player> players, GameMode gameMode)
{
Id = id;
GameMode = gameMode;
}
public Game(int id, TimeSpan duration, DateTime date, List<Player> players, List<Turn> turns, Dictionary<Player, Grille> grilles, Dictionary<Player, int> scores, GameMode gameMode)
{
Id = id;
Duration = duration;
Date = date;
this.players = players;
Players = new ReadOnlyCollection<Player>(this.players);
this.turns = turns;
Turns = new ReadOnlyCollection<Turn>(this.turns);
this.grilles = grilles;
Grilles = new ReadOnlyDictionary<Player, Grille>(this.grilles);
this.scores = scores;
Scores = new ReadOnlyDictionary<Player, int>(this.scores);
GameMode = gameMode;
}
public bool AddPlayerToGame(Player player)

@ -24,10 +24,11 @@ namespace Model
}
private string name = "";
public GameMode(string name, int id =0)
public GameMode(int id= 0,string name = "Classique")
{
this.Id = id;
Name = name;
this.Name = name;
}
}
}

@ -16,7 +16,7 @@ namespace Model
public int MaxZone { get; set; }
public ReadOnlyCollection<Case> Cases { get; private set; }
private List<Case> cases = new();
private List<Case> cases { get; set; }
//public Grille(List<Case> cases)
@ -26,13 +26,15 @@ namespace Model
public Grille(List<Case> cases)
{
this.cases = new();
Cases = new ReadOnlyCollection<Case>(cases);
cases.AddRange(Enumerable.Repeat(new Case(), 19));
}
public Grille()
{
this.cases = new();
Cases = new ReadOnlyCollection<Case>(this.cases);
}
public bool AddValueToCase(int value, int index)

@ -1,11 +0,0 @@
using System;
namespace Model
{
public class Participate
{
public Participate()
{
}
}
}

@ -1,5 +1,5 @@
namespace Model;
public class Player : IEquatable<Player>
public class Player : IEquatable<Player>
{
public int Id { get; set; }
@ -26,6 +26,13 @@
Stats = new Stats();
}
public Player(string pseudo, int id)
{
Pseudo = pseudo;
Id = id;
Stats = new Stats();
}
public Player(string pseudo, Stats stats, int id=0)
{
Pseudo = pseudo;

@ -38,8 +38,9 @@ namespace Model
}
private int diceValue2;
public Turn(int diceValue1, int diceValue2)
public Turn(int Id, int diceValue1, int diceValue2)
{
this.Id = Id;
DiceValue1 = diceValue1;
DiceValue2 = diceValue2;
}

@ -13,12 +13,10 @@ namespace Stub
{
private List<Game> games = new()
{
new Game(new DateOnly(2023,06,03), new Player("test1"),new GameMode("gamemode test1")),
new Game(new DateOnly(2023,06,03), new Player("test2"),new GameMode("gamemode test2")),
new Game(new DateOnly(2023,06,03), new Player("test3"),new GameMode("gamemode test3")),
new Game(new DateOnly(2023,06,03), new Player("test4"),new GameMode("gamemode test4")),
new Game(new DateOnly(2023,06,03), new Player("test5"),new GameMode("gamemode test5")),
new Game(new Player("Aurélien",0),new GameMode(),1),
new Game(new Player("Maxence",1),new GameMode(),2),
new Game(new Player("Théo",2),new GameMode(),3),
new Game(new Player("Zakariya",3),new GameMode(),4),
};
public class GamesManager : IGamesManager

@ -12,10 +12,10 @@ namespace Stub
{
private List<Player> players = new()
{
new Player("Aurelien"),
new Player("Theo"),
new Player("Maxence"),
new Player("Zakariya"),
new Player("Aurelien", 0),
new Player("Theo",1),
new Player("Maxence",2),
new Player("Zakariya",3),
};
public class PlayersManager : IPlayersManager

@ -21,11 +21,11 @@
<None Remove="projet.Score.db" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.2">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.4" />
</ItemGroup>
</Project>

@ -9,16 +9,16 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

@ -15,9 +15,8 @@ namespace ModelTest
public void Test_AddNewPlayer()
{
Player player = new Player("Jax");
GameMode gameMode = new GameMode("Classique");
DateOnly dateTime = new DateOnly(2023, 01, 01);
Game game = new Game(dateTime, player, gameMode, 1);
GameMode gameMode = new GameMode();
Game game = new Game(player, gameMode, 1);
}
}
}

@ -0,0 +1,41 @@
using System;
using Model;
namespace Test_Model
{
public class TestGame
{
public static IEnumerable<object[]> GameData_init()
{
yield return new object[]
{
true,
new Player[]
{
new Player("Player 1",2)
},
new Game(new Player("Player1",2),new GameMode(1,"Classique")),
new Player("Player1",2)
};
}
[Theory]
[MemberData(nameof(GameData_init))]
public void AddPlayerToGame_Should_Return_Correct_Result(bool expectedResult,
IEnumerable<Player> expectedPlayers,
Game game,
Player playerToBeAdded)
{
// Act
bool result = game.AddPlayerToGame(playerToBeAdded);
Console.WriteLine(result);
// Assert
Assert.Equal(expectedResult, result);
Assert.Equal(expectedPlayers.Count(), game.Players.Count());
Assert.All(expectedPlayers, p => game.Players.Contains(p));
}
}
}

@ -0,0 +1,152 @@
using Model;
namespace Test_Model;
public class TestPlayer
{
//public static IEnumerable<object[]> PlayerData =>
// new List<object[]>
// {
// new object[] { new Player("Alice", new Stats { NbWin = 2, NbPlayed = 5, MaxChain = 3, MaxZone = 10, MaxPoints = 200 }), true },
// new object[] { new Player("Bob", new Stats { NbWin = 1, NbPlayed = 2, MaxChain = 2, MaxZone = 5, MaxPoints = 100 }), true },
// new object[] { new Player("Alice", new Stats { NbWin = 1, NbPlayed = 3, MaxChain = 4, MaxZone = 12, MaxPoints = 150 }), true },
// new object[] { new Player(null), false },
// new object[] { new Player("Charlie"), false }
// };
//[Theory]
//[MemberData(nameof(PlayerData))]
//public void TestEquals(Player p1, bool expected)
//{
// var p2 = new Player(p1.Pseudo, p1.Stats, p1.Id);
// Assert.Equal(expected, p1.Equals(p2));
//}
[Theory]
[InlineData("Alice", 2, 5, 3, 10, 200)]
[InlineData("Bob", 1, 2, 2, 5, 100)]
[InlineData("Charlie", 0, 0, 0, 0, 0)]
public void TestConstructorWithStats(string pseudo, int nbWin, int nbPlayed, int maxChain, int maxZone, int maxPoints)
{
var stats = new Stats { NbWin = nbWin, NbPlayed = nbPlayed, MaxChain = maxChain, MaxZone = maxZone, MaxPoints = maxPoints };
var player = new Player(pseudo, stats);
Assert.Equal(pseudo, player.Pseudo);
Assert.Equal(0, player.Id);
Assert.Equal(nbWin, player.Stats.NbWin);
Assert.Equal(nbPlayed, player.Stats.NbPlayed);
Assert.Equal(maxChain, player.Stats.MaxChain);
Assert.Equal(maxZone, player.Stats.MaxZone);
Assert.Equal(maxPoints, player.Stats.MaxPoints);
}
[Fact]
public void TestAddWin()
{
var player = new Player("Alice");
player.AddWin();
player.AddWin();
player.AddWin();
Assert.Equal(3, player.Stats.NbWin);
}
[Fact]
public void TestAddPlayed()
{
var player = new Player("Alice");
player.AddPlayed();
player.AddPlayed();
Assert.Equal(2, player.Stats.NbPlayed);
}
[Theory]
[InlineData("John")]
[InlineData("Jane")]
[InlineData("Jake")]
public void AddWin_ShouldIncrementNbWinByOne(string pseudo)
{
// Arrange
var player = new Player(pseudo);
var initialNbWin = player.Stats.NbWin;
// Act
player.AddWin();
// Assert
Assert.Equal(initialNbWin + 1, player.Stats.NbWin);
}
[Theory]
[InlineData("John")]
[InlineData("Jane")]
[InlineData("Jake")]
public void AddPlayed_ShouldIncrementNbPlayedByOne(string pseudo)
{
// Arrange
var player = new Player(pseudo);
var initialNbPlayed = player.Stats.NbPlayed;
// Act
player.AddPlayed();
// Assert
Assert.Equal(initialNbPlayed + 1, player.Stats.NbPlayed);
}
[Theory]
[InlineData("John", 10)]
[InlineData("Jane", 5)]
[InlineData("Jake", 7)]
public void AddMaxChain_ShouldSetMaxChain(string pseudo, int maxChain)
{
// Arrange
var player = new Player(pseudo);
var initialMaxChain = player.Stats.MaxChain;
// Act
player.AddMaxChain(maxChain);
// Assert
Assert.Equal(maxChain, player.Stats.MaxChain);
Assert.NotEqual(initialMaxChain, player.Stats.MaxChain);
}
[Theory]
[InlineData("John", 5)]
[InlineData("Jane", 8)]
[InlineData("Jake", 12)]
public void AddMaxZone_ShouldSetMaxZone(string pseudo, int maxZone)
{
// Arrange
var player = new Player(pseudo);
var initialMaxZone = player.Stats.MaxZone;
// Act
player.AddMaxZone(maxZone);
// Assert
Assert.Equal(maxZone, player.Stats.MaxZone);
Assert.NotEqual(initialMaxZone, player.Stats.MaxZone);
}
[Theory]
[InlineData("John", 100)]
[InlineData("Jane", 50)]
[InlineData("Jake", 75)]
public void AddMaxPoints_ShouldSetMaxPoints(string pseudo, int maxPoints)
{
// Arrange
var player = new Player(pseudo);
var initialMaxPoints = player.Stats.MaxPoints;
// Act
player.AddMaxPoints(maxPoints);
// Assert
Assert.Equal(maxPoints, player.Stats.MaxPoints);
Assert.NotEqual(initialMaxPoints, player.Stats.MaxPoints);
}
}

@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Model\Model.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1 @@
global using Xunit;

@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Stub\Stub\Stub.csproj" />
<ProjectReference Include="..\..\Model\Model.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,117 @@
using System.Numerics;
using Model;
using Stub;
namespace Test_Stub;
public class Test_Stub_Games
{
public static IEnumerable<object[]> GetGameAndPlayerIds()
{
yield return new object[] { 1, 0 };
yield return new object[] { 2, 1 };
yield return new object[] { 3, 2 };
yield return new object[] { 4, 3 };
}
public static IEnumerable<object[]> GetInvalidGameAndPlayerIds()
{
yield return new object[] { -1, 0 };
yield return new object[] { 1, -1 };
yield return new object[] { 5, 0 };
yield return new object[] { 1, 4 };
}
//[Theory]
//[MemberData(nameof(GetGameAndPlayerIds))]
//public async Task AddScoreToPlayer_ValidIds_ReturnsTrue(int gameId, int playerId)
//{
// // Arrange
// var stubData = new StubData();
// var manager = new StubData.GamesManager(stubData);
// // Act
// var result = await manager.AddScoreToPlayer(gameId, playerId, 10);
// // Assert
// Assert.True(result);
//}
[Theory]
[MemberData(nameof(GetInvalidGameAndPlayerIds))]
public async Task AddScoreToPlayer_InvalidIds_ReturnsFalse(int gameId, int playerId)
{
// Arrange
var stubData = new StubData();
var manager = new StubData.GamesManager(stubData);
// Act
var result = await manager.AddScoreToPlayer(gameId, playerId, 10);
// Assert
Assert.False(result);
}
//[Fact]
//public async Task AddPlayer_ValidPlayer_ReturnsTrue()
//{
// // Arrange
// var stubData = new StubData();
// var manager = new StubData.GamesManager(stubData);
// var player = new Player("John", 4);
// // Act
// var result = await manager.AddPlayer(player);
// // Assert
// Assert.True(result);
//}
//[Fact]
//public async Task AddPlayer_InvalidGame_ReturnsFalse()
//{
// // Arrange
// var stubData = new StubData();
// var manager = new StubData.GamesManager(stubData);
// var player = new Player("John", 4);
// // Act
// var result = await manager.AddPlayer(player);
// // Assert
// Assert.True(result);
//}
[Fact]
public async Task GetItems_ReturnsCorrectCount()
{
// Arrange
var stubData = new StubData();
var manager = new StubData.GamesManager(stubData);
// Act
var items = await manager.GetItems(0, 3, null);
// Assert
Assert.Equal(3, items.Count());
}
[Theory]
[InlineData(1)]
[InlineData(2)]
[InlineData(3)]
[InlineData(4)]
public async Task GetItemsById_ReturnsCorrectItem(int id)
{
// Arrange
var stubData = new StubData();
var manager = new StubData.GamesManager(stubData);
// Act
var items = await manager.GetItemsById(id);
// Assert
Assert.Single(items);
Assert.Equal(id, items.First()?.Id);
}
}

@ -0,0 +1 @@
global using Xunit;

@ -21,6 +21,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stub", "Stub\Stub\Stub.cspr
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "Shared\Shared.csproj", "{8B6EC777-57F8-4509-9163-4312A40FE63C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_Stub", "Tests\Test_Stub\Test_Stub.csproj", "{5A1D87FF-E82F-43FF-AC5C-59659B91D5B8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_Model", "Tests\Test_Model\Test_Model.csproj", "{593766AA-8E2A-4B3D-A299-8E45F5C19C18}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -55,6 +59,14 @@ Global
{8B6EC777-57F8-4509-9163-4312A40FE63C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8B6EC777-57F8-4509-9163-4312A40FE63C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8B6EC777-57F8-4509-9163-4312A40FE63C}.Release|Any CPU.Build.0 = Release|Any CPU
{5A1D87FF-E82F-43FF-AC5C-59659B91D5B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5A1D87FF-E82F-43FF-AC5C-59659B91D5B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5A1D87FF-E82F-43FF-AC5C-59659B91D5B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5A1D87FF-E82F-43FF-AC5C-59659B91D5B8}.Release|Any CPU.Build.0 = Release|Any CPU
{593766AA-8E2A-4B3D-A299-8E45F5C19C18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{593766AA-8E2A-4B3D-A299-8E45F5C19C18}.Debug|Any CPU.Build.0 = Debug|Any CPU
{593766AA-8E2A-4B3D-A299-8E45F5C19C18}.Release|Any CPU.ActiveCfg = Release|Any CPU
{593766AA-8E2A-4B3D-A299-8E45F5C19C18}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -63,6 +75,8 @@ Global
{75B303CC-F36E-46FA-BE23-05EEA35D9B28} = {C75DF644-C41F-4A08-8B69-C8554204AC72}
{6EC6383D-10E8-44E1-8EDD-EF4DF460A9B1} = {C75DF644-C41F-4A08-8B69-C8554204AC72}
{5E45E953-4FCC-42B6-9F22-15108D002D78} = {B1585816-FCBB-484F-A1AA-C7AEB501C39B}
{5A1D87FF-E82F-43FF-AC5C-59659B91D5B8} = {C75DF644-C41F-4A08-8B69-C8554204AC72}
{593766AA-8E2A-4B3D-A299-8E45F5C19C18} = {C75DF644-C41F-4A08-8B69-C8554204AC72}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4D47853B-D1A3-49A5-84BA-CD2DC65FD105}

@ -11,7 +11,7 @@ namespace Trek12_API.Controllers
public class GameController: ControllerBase
{
private readonly ILogger<GameController> _logger;
private StubData.GamesManager gamesManager { get; set; } = new StubData.GamesManager(new StubData());
private GamesManager gamesManager { get; set; } = new StubData.GamesManager(new StubData());
public GameController(ILogger<GameController> logger)
@ -65,7 +65,7 @@ namespace Trek12_API.Controllers
return Ok("Partie bien supprimée");
}
/* [HttpPut(Name = "UpdateGameById")]
/*[HttpPut(Name = "UpdateGameById")]
public async Task<IActionResult> Update(int id, GameDTO newGame)
{
await gamesManager.UpdateItem(gamesManager.GetItemsById(id).Result.FirstOrDefault(), newGame.toModel());

@ -54,7 +54,7 @@ namespace Trek12_API.Controllers
return Ok(player?.toDTOs());
}
[HttpPost]
[HttpPost(Name= "AddPlayer")]
public async Task<IActionResult> Post(PlayerDTO player)
{
Player playerToCreate = player.toModel();

@ -0,0 +1,48 @@
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Model;
using System.Runtime.CompilerServices;
using Trek12_API.DTO;
namespace Trek12_API.Converter
{
public static class CaseConverter
{
public static CaseDTO toDTO(this Case caseToConvert)
{
CaseDTO dto = new CaseDTO();
dto.Id = caseToConvert.Id;
dto.Value = caseToConvert.Valeur;
return dto;
}
public static List<CaseDTO> toDTOs(this List<Case> listParam)
{
List<CaseDTO> list = new List<CaseDTO>();
foreach(var caseToConvert in listParam)
{
list.Add(caseToConvert.toDTO());
}
return list;
}
public static List<Case> toModels(this List<CaseDTO> listParam)
{
List<Case> list = new List<Case>();
foreach (var caseToConvert in listParam)
{
list.Add(caseToConvert.toModel());
}
return list;
}
public static Case toModel(this CaseDTO caseToConvert)
{
Case model = new Case();
model.Id = caseToConvert.Id;
model.Valeur = caseToConvert.Value;
return model;
}
}
}

@ -1,5 +1,4 @@
using Model;
using System.Collections.Generic;
using Trek12_API.DTO;
namespace Trek12_API.Converter
@ -38,38 +37,36 @@ namespace Trek12_API.Converter
return gameDTO;
}
/*public static Game toModel(this GameDTO gameDTO)
public static Game toModel(this GameDTO gameDTO)
{
{
var game = new Game();
game.Duration = gameDTO.Duration;
game.Date = gameDTO.Date;
game.Turns = new List<Turn>();
foreach (var turn in game.Turns)
var turnsList = new List<Turn>();
foreach (var turn in gameDTO.Turns)
{
gameDTO.Turns.Add(turn.toDTO());
turnsList.Add(turn.toModel());
}
gameDTO.Grilles = new Dictionary<PlayerDTO, GrilleDTO>();
foreach (var grille in game.Grilles)
var playersList = new List<Player>();
foreach (var player in gameDTO.Players)
{
gameDTO.Grilles.Add(grille.Key.toDTO(), grille.Value.toDTO());
playersList.Add(player.toModel());
}
gameDTO.Scores = new Dictionary<PlayerDTO, int>();
foreach (var score in game.Scores)
var grillesDict = new Dictionary<Player, Grille>();
foreach (var (key, value) in gameDTO.Grilles)
{
gameDTO.Scores.Add(score.Key.toDTO(), score.Value);
grillesDict.Add(key.toModel(), value.toModel());
}
gameDTO.Players = new List<PlayerDTO>();
foreach (var player in game.Players)
var scoresDict = new Dictionary<Player, int>();
foreach (var (key, value) in gameDTO.Scores)
{
gameDTO.Players.Add(player.toDTO());
scoresDict.Add(key.toModel(), value);
}
gameDTO.GameMode = new GamemodeDTO()
{
Id = game.GameMode.Id,
Name = game.GameMode.Name
};
return gameDTO;
}*/
var game = new Game(gameDTO.Id, gameDTO.Duration, gameDTO.Date, playersList, turnsList, grillesDict, scoresDict, gameDTO.GameMode.toModel());
return game;
}
}
}
}

@ -13,5 +13,14 @@ namespace Trek12_API.Converter
Name = gameMode.Name,
};
}
public static GameMode toModel( this GamemodeDTO gamemode)
{
return new GameMode()
{
Id = gamemode.Id,
Name = gamemode.Name
};
}
}
}

@ -1,4 +1,5 @@
using Model;
using System.Runtime.CompilerServices;
using Trek12_API.DTO;
namespace Trek12_API.Converter
@ -13,8 +14,31 @@ namespace Trek12_API.Converter
NbChaines = grille.NbChaine,
NbZones = grille.NbZone,
MaxChaines = grille.MaxChaine,
MaxZones = grille.MaxZone
MaxZones = grille.MaxZone,
};
}
public static Grille toModel(this GrilleDTO grilleDTO)
{
return new Grille(grilleDTO.Cases.toModels())
{
Id = grilleDTO.Id,
NbChaine = grilleDTO.NbChaines,
NbZone = grilleDTO.NbZones,
MaxChaine = grilleDTO.MaxChaines,
MaxZone = grilleDTO.MaxZones
};
}
public static IEnumerable<Grille> toModels(this IEnumerable<GrilleDTO> grilles)
{
var grilleModels = new List<Grille>();
foreach( var grille in grilles)
{
grilleModels.Add(grille.toModel());
}
return grilleModels;
}
}
}

@ -1,4 +1,5 @@
using Model;
using System.Text.Json.Serialization;
using Model;
using Trek12_API.DTO;
namespace Trek12_API.Converter

@ -14,5 +14,20 @@ namespace Trek12_API.Converter
diceValue2 = turn.DiceValue2,
};
}
public static Turn toModel(this TurnDTO turnDTO)
{
return new Turn(turnDTO.Id, turnDTO.diceValue1, turnDTO.diceValue2);
}
public static IEnumerable<Turn> toModels(this IEnumerable<TurnDTO> turns)
{
var turnsList = new List<Turn>();
foreach(var turn in turns)
{
turnsList.Add(turn.toModel());
}
return turnsList;
}
}
}

@ -0,0 +1,8 @@
namespace Trek12_API.DTO
{
public class CaseDTO
{
public int Id { get; set; }
public int Value { get; set; }
}
}

@ -7,7 +7,7 @@ namespace Trek12_API.DTO
{
public int Id { get; set; }
public TimeSpan Duration { get; set; }
public DateOnly Date { get; set; }
public DateTime Date { get; set; }
public List<TurnDTO> Turns { get; set; }
public Dictionary<PlayerDTO, GrilleDTO> Grilles { get; set; }
public Dictionary<PlayerDTO, int> Scores { get; set; }

@ -1,4 +1,6 @@
namespace Trek12_API.DTO
using Model;
namespace Trek12_API.DTO
{
public class GrilleDTO
{
@ -7,5 +9,7 @@
public int NbZones { get; set; }
public int MaxChaines { get; set; }
public int MaxZones { get; set; }
public List<CaseDTO> Cases { get; set; }
}
}

@ -0,0 +1,23 @@
using System;
using System.Collections.ObjectModel;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Trek12_API.JsonConverter
{
public class ReadOnlyDictionnaryConverter<TKey,TValue>: JsonConverter<ReadOnlyDictionary<TKey,TValue>>
{
public override ReadOnlyDictionary<TKey, TValue>? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
Dictionary<TKey, TValue> dictionary = JsonSerializer.Deserialize<Dictionary<TKey, TValue>>(ref reader, options);
return new ReadOnlyDictionary<TKey, TValue>(dictionary);
}
public override void Write(Utf8JsonWriter writer, ReadOnlyDictionary<TKey, TValue> value, JsonSerializerOptions options)
{
JsonSerializer.Serialize(writer, value.ToDictionary(kv => kv.Key, kv => kv.Value),options);
}
}
}

@ -1,12 +1,20 @@
var builder = WebApplication.CreateBuilder(args);
using Model;
using Trek12_API.JsonConverter;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddControllers().AddJsonOptions(options =>
{
options.JsonSerializerOptions.Converters.Add(new ReadOnlyDictionnaryConverter<Player, Grille>());
options.JsonSerializerOptions.Converters.Add(new ReadOnlyDictionnaryConverter<int, Player>());
});
var app = builder.Build();
// Configure the HTTP request pipeline.

@ -16,4 +16,10 @@
<ProjectReference Include="..\Stub\Stub\Stub.csproj" />
</ItemGroup>
<ItemGroup>
<None Remove="JsonConverter\" />
</ItemGroup>
<ItemGroup>
<Folder Include="JsonConverter\" />
</ItemGroup>
</Project>

Loading…
Cancel
Save