🙈 UT_NumberDice

pull/3/head
Najlae LAMBARAA 3 years ago
parent bb311054b2
commit 844e6a637a

@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model", "Model\Model.csproj
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{836BDD1E-455B-4F88-8E96-41477F8013E6}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{836BDD1E-455B-4F88-8E96-41477F8013E6}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testeur", "Testeur\Testeur.csproj", "{FA65498D-FD52-41F7-A87E-CED9A2AD2CFF}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -21,6 +23,10 @@ Global
{836BDD1E-455B-4F88-8E96-41477F8013E6}.Debug|Any CPU.Build.0 = Debug|Any CPU {836BDD1E-455B-4F88-8E96-41477F8013E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{836BDD1E-455B-4F88-8E96-41477F8013E6}.Release|Any CPU.ActiveCfg = Release|Any CPU {836BDD1E-455B-4F88-8E96-41477F8013E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{836BDD1E-455B-4F88-8E96-41477F8013E6}.Release|Any CPU.Build.0 = Release|Any CPU {836BDD1E-455B-4F88-8E96-41477F8013E6}.Release|Any CPU.Build.0 = Release|Any CPU
{FA65498D-FD52-41F7-A87E-CED9A2AD2CFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA65498D-FD52-41F7-A87E-CED9A2AD2CFF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA65498D-FD52-41F7-A87E-CED9A2AD2CFF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA65498D-FD52-41F7-A87E-CED9A2AD2CFF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

@ -1,21 +1,27 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Model namespace Model
{ {
class Game public class Game
{ {
private string name; private string name;
private List<Die> listDice = new List<Die>(); //encapsulation des collections voir les videos partie 2
public ReadOnlyCollection <Die> ListDice { get; set; }
public Game(string name) public Game(string name)
{ {
this.name = name; Name = name;
} }
public readonly Collection<Die> ListDice { get; set; }
private List<Die> listDice = new List<Die>(); //encapsulation des collections voir les videos partie 2
public string Name public string Name
{ {
get get
@ -34,9 +40,14 @@ namespace Model
} }
} }
public void AddDice(Die die) public bool AddDice(Die die)
{ {
if (listDice.Contains(die))
{
return false;
}
listDice.Add(die); listDice.Add(die);
return true;
} }

@ -13,6 +13,7 @@ namespace Model
private static Random random=new Random(); private static Random random=new Random();
public NumberDie(string name,int min,int max) : base(name) public NumberDie(string name,int min,int max) : base(name)
{ {
Name = name;
Min = min; Min = min;
Max = max; Max = max;
} }

@ -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.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
namespace Testeur
{
public class UT_NumberDice
{
[Theory]
[InlineData(true, "De1", "De1" ,1,6,1,6)]
[InlineData(false, "", "", 1, 7, 1, 6)]
public void TestConstructor(bool isValid,string expectedName, string name ,int expectedMin,int expectedMax,int min,int max)
{
if (!isValid)
{
Assert.Throws<ArgumentException>(() => new NumberDie(name,min, max));
return;
}
NumberDie d = new NumberDie(name,min,max);
Assert.Equal(expectedMin, d.Min);
Assert.Equal (expectedMax, d.Max);
Assert.Equal( expectedName,d.Name);
}
}
}

@ -0,0 +1,15 @@
using Model;
namespace Testeur
{
public class UnitTest1
{
[Fact]
public void TestConstructeurGame()
{
Game G = new Game("Monopoly");
Assert.NotNull(G);
Assert.Equal("Monopoly",G.Name);
}
}
}

@ -6,6 +6,7 @@
public void testConstructor() public void testConstructor()
{ {
} }
} }
} }
Loading…
Cancel
Save