Modifs Monstre.cs, MonsterBase.cs et User.cs car TESTS
continuous-integration/drone/push Build is failing Details

pull/32/head
ImNicolasTheDev 2 years ago
parent 8409c0ec71
commit 7171d42db5

@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Console", "Console\Console.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Modèle", "Modèle\Modèle.csproj", "{D11EF161-2695-4FCF-8A91-C2E736AF791E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{46069EC9-FB44-4C94-9214-CEE664598EA7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -29,6 +31,10 @@ Global
{D11EF161-2695-4FCF-8A91-C2E736AF791E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D11EF161-2695-4FCF-8A91-C2E736AF791E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D11EF161-2695-4FCF-8A91-C2E736AF791E}.Release|Any CPU.Build.0 = Release|Any CPU
{46069EC9-FB44-4C94-9214-CEE664598EA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{46069EC9-FB44-4C94-9214-CEE664598EA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46069EC9-FB44-4C94-9214-CEE664598EA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46069EC9-FB44-4C94-9214-CEE664598EA7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -12,7 +12,6 @@ namespace Modèle
/// </summary>
public class MonsterBase : IRechercheMonstre
{
private List<Monstre> monsters = null!;
public List<Monstre> ListMonsters
{
get
@ -24,6 +23,7 @@ namespace Modèle
monsters = value;
}
}
private List<Monstre> monsters = null!;
public MonsterBase()
{

@ -9,7 +9,7 @@ public class Monstre
public string Name { get; set; }
public string Description { get; set; } = string.Empty;
private List<string> characteristic = null!;
public List<string> CharacteristicsList
{
get {
@ -19,24 +19,19 @@ public class Monstre
characteristic = value;
}
}
private List<string> characteristic = null!;
private List<string> appearance = null!;
public List<string> AppearanceList
{
get
{
return appearance;
}
get => appearance;
set
{
appearance = value;
}
}
private List<string> appearance = null!;
public string IntroduceTest()
{
return $"Je suis un {Name} (id : {Id}). Description : {Description}";
}
public Monstre(int id, string name, string desc, List<string> characList, List<string> appearList)
{
Id = id;
@ -44,5 +39,9 @@ public class Monstre
Description = desc;
CharacteristicsList = characList;
AppearanceList = appearList;
if (string.IsNullOrWhiteSpace(Name) && string.IsNullOrWhiteSpace(Description))
{
throw new ArgumentException("Un monstre doit avoir un nom et une description!");
}
}
}

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace Modèle
{
@ -14,10 +15,22 @@ namespace Modèle
public class User
{
public string Pseudo { get; private set; }
private string Nom { get; set; }
private string Prenom { get; set; }
public string Nom { get; private set; }
public string Prenom { get; private set; }
private string Mdp { get; set; }
private List<Monstre> monstresDejaVu { get; set; }
public List<Monstre>? monstresDejaVu { get; private set; }
public User(string pseudo, string nom, string prenom, string mdp)
{
Pseudo = pseudo;
Nom = nom;
Prenom = prenom;
Mdp = mdp;
if (string.IsNullOrWhiteSpace(pseudo) || string.IsNullOrWhiteSpace(nom) || string.IsNullOrWhiteSpace(prenom) || string.IsNullOrWhiteSpace(mdp))
{
throw new ArgumentException("Un User doit avoir un pseudo, un nom, un prénom et un mot de passe au minimum!");
}
}
public User(string pseudo, string nom, string prenom, string mdp, List<Monstre> monstresVus)
{
@ -26,6 +39,10 @@ namespace Modèle
Prenom = prenom;
Mdp = mdp;
monstresDejaVu = monstresVus;
if (string.IsNullOrWhiteSpace(pseudo) || string.IsNullOrWhiteSpace(nom) || string.IsNullOrWhiteSpace(prenom) || string.IsNullOrWhiteSpace(mdp))
{
throw new ArgumentException("Un User doit avoir un pseudo, un nom, un prénom et un mot de passe au minimum!");
}
}
public bool verifyPssw(string pssw)

@ -0,0 +1,25 @@
using Modèle;
namespace Tests
{
public class Monstres_UT
{
[Fact]
public void TestFullConstructor()
{
Monstre a = new Monstre(0, "Name", "This is my description", new List<string> { "Carac 1", "Carac 2", "Carac 3" }, new List<string> { "App 1", "App 2", "App 3" });
Assert.NotNull(a);
Assert.Equal("Name", a.Name);
Assert.Equal("This is my description", a.Description);
Assert.Equal(new List<string> { "Carac 1", "Carac 2", "Carac 3" }, a.CharacteristicsList);
Assert.Equal(new List<string> { "App 1", "App 2", "App 3" }, a.AppearanceList);
}
[Fact]
public void TestVoidConstructor()
{
Assert.Throws<ArgumentException>(() => new Monstre(0, "", "", new List<string> { "" }, new List<string> { "" }));
}
}
}

@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<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">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Modèle\Modèle.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,97 @@
using Modèle;
namespace Tests
{
public class User_UT
{
[Theory]
[MemberData(nameof(DataWithoutList))]
public void TestConstructorWithoutList(string pseudo, string nom, string prenom, string mdp)
{
Assert.Throws<ArgumentException>(() => new User(pseudo, nom, prenom, mdp));
/*User u = new User(pseudo, nom, prenom, mdp);
Assert.Equal(pseudo, u.Pseudo);
Assert.Equal(nom, u.Nom);
Assert.Equal(prenom, u.Prenom);
Assert.True(u.verifyPssw(mdp));*/
}
public static IEnumerable<object[]> DataWithoutList =>
new List<object[]>
{
//Test de toutes les possibilités
new object[] { "", "", "", "" },
new object[] { "Pseudo", "", "", "" },
new object[] { "", "Nom", "", "" },
new object[] { "Pseudo", "Nom", "", "" },
new object[] { "", "", "Prenom", "" },
new object[] { "Pseudo", "", "Prenom", "" },
new object[] { "", "Nom", "Prenom", "" },
new object[] { "Prenom", "Nom", "Prenom", "" },
new object[] { "", "", "", "Mdp" },
new object[] { "Pseudo", "", "", "Mdp" },
new object[] { "", "Nom", "", "Mdp" },
new object[] { "Pseudo", "Nom", "", "Mdp" },
new object[] { "", "", "Prenom", "Mdp" },
new object[] { "Pseudo", "", "Prenom", "Mdp" },
new object[] { "", "Nom", "Prenom", "Mdp" },
new object[] { "Pseudo", "Nom", "Prenom", "Mdp" },
//Puis quelques tests avec des ints au lieu de strings
new object[] { 0, "Nom", "Prenom", "Mdp" },
new object[] { "Pseudo", 0, "Prenom", "Mdp" },
new object[] { "Pseudo", "Nom", 0, "Mdp" },
new object[] { "Pseudo", "Nom", "Prenom", 0 },
new object[] { 1, 12, 123, 1234}
};
[Theory]
[MemberData(nameof(DataWithList))]
public void TestConstructorWithList(string pseudo, string nom, string prenom, string mdp, List<Monstre> monstresVus)
{
if (Assert.Throws<ArgumentException>(() => new User(pseudo, nom, prenom, mdp, monstresVus)) == null ) {
return;
}
User u = new User(pseudo, nom, prenom, mdp, monstresVus);
Assert.Equal(pseudo, u.Pseudo);
Assert.Equal(nom, u.Nom);
Assert.Equal(prenom, u.Prenom);
Assert.True(u.verifyPssw(mdp));
Assert.Equal(monstresVus, u.monstresDejaVu);
}
public static IEnumerable<object[]> DataWithList =>
new List<object[]>
{
new object[] { "Pseudo", "Nom", "Prenom", "Mdp", new List<Monstre> { new Monstre(1, "Poule",
"Je suis un animal présent un peu partout, sauf dans le desert car il fait beaucoup trop chaud. Mais j'aime beaucoup la jungle !",
new List<string> { "Quand une poule est tuée, il y a 3.12% de chance que la poule laisse tomber un oeuf " },
new List<string> { "Apparence1", "App2", "App3" } ),
new Monstre(2, "Mouton",
"Je suis présent un peu partout, sauf dnas le desert.",
new List<string> { "Avec une cisaille il est possible de raser la laine d'un mouton, il se retrouvera sans laine.", "Pour faire repousser la laine d'un mouton, il faut qu'il ait de l'herbe sous ses pattes pour qu'il puisse manger. Une fois mangé, la laine du mouton repousse instantanément !" },
new List<string> { "Apparence1", "App2", "App3" } )} },
new object[] { "", "", "", "", new List<Monstre> { new Monstre(1, "Poule",
"Je suis un animal présent un peu partout, sauf dans le desert car il fait beaucoup trop chaud. Mais j'aime beaucoup la jungle !",
new List<string> { "Quand une poule est tuée, il y a 3.12% de chance que la poule laisse tomber un oeuf " },
new List<string> { "Apparence1", "App2", "App3" } ),
new Monstre(2, "Mouton",
"Je suis présent un peu partout, sauf dnas le desert.",
new List<string> { "Avec une cisaille il est possible de raser la laine d'un mouton, il se retrouvera sans laine.", "Pour faire repousser la laine d'un mouton, il faut qu'il ait de l'herbe sous ses pattes pour qu'il puisse manger. Une fois mangé, la laine du mouton repousse instantanément !" },
new List<string> { "Apparence1", "App2", "App3" } )} },
new object[] { "", "", "", "", new List<Monstre>() },
new object[] { "Pseudo", "", "", "", new List<Monstre>() },
new object[] { "Pseudo", "Nom", "", "", new List<Monstre>() },
new object[] { "Pseudo", "Nom", "Prenom", "", new List<Monstre>() },
new object[] { "Pseudo", "Nom", "Prenom", "Mdp", new List<Monstre>() },
new object[] { 0, "Nom", "Prenom", "Mdp", new List<Monstre>() },
new object[] { "Pseudo", 0, "Prenom", "Mdp", new List<Monstre>() },
new object[] { "Pseudo", "Nom", 0, "Mdp", new List<Monstre>() },
new object[] { "Pseudo", "Nom", "Prenom", 0, new List<Monstre>() },
new object[] { 1, 12, 123, 1234, 12345 }
};
}
}

@ -0,0 +1 @@
global using Xunit;
Loading…
Cancel
Save