Tests unitaires, Int2Color converter et test coverage
continuous-integration/drone/push Build encountered an error Details
continuous-integration/drone/pr Build encountered an error Details

pull/15/head
Yoan 2 years ago
parent 5ea4f7287a
commit 6c58c3218f

@ -30,7 +30,7 @@ steps:
sonar_token: sonar_token:
from_secret: SECRET_SONAR_LOGIN from_secret: SECRET_SONAR_LOGIN
project_key: Ohara project_key: Ohara
coverage_exclusions: "Tests/**" coverage_exclusions: "Tests/**","Ohara/**"
commands: commands:
- cd Sources/ - cd Sources/
- dotnet restore Ohara.sln - dotnet restore Ohara.sln

@ -181,15 +181,15 @@ namespace Model.Managers
} }
/// \brief Récupère la liste des objets Ohara ayant le parametre EstFavori égal a true. /// \brief Récupère la liste des objets Ohara ayant le parametre EstFavori égal a true.
/// \return La liste des objets Ohara ayant le parametre EstFavori égal a true. /// \return La liste des objets Ohara ayant le parametre EstFavori égal a true.
public List<ObjetOhara> GetFavoris() public HashSet<ObjetOhara> GetFavoris()
{ {
List<ObjetOhara> listeFavoris = new List<ObjetOhara>(); HashSet<ObjetOhara> listeFavoris = new HashSet<ObjetOhara>();
listeFavoris.AddRange(Bateaux); listeFavoris.UnionWith(Bateaux);
listeFavoris.AddRange(Equipages); listeFavoris.UnionWith(Equipages);
listeFavoris.AddRange(Bestiaire); listeFavoris.UnionWith(Bestiaire);
listeFavoris.AddRange(Fruits); listeFavoris.UnionWith(Fruits);
listeFavoris.AddRange(Iles); listeFavoris.UnionWith(Iles);
listeFavoris.AddRange(Personnages); listeFavoris.UnionWith(Personnages);
foreach(ObjetOhara obj in listeFavoris.ToList()) foreach(ObjetOhara obj in listeFavoris.ToList())
{ {
if (obj.EstFavori == false) if (obj.EstFavori == false)

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ohara.Converters
{
public class Int2ColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is not int) return Colors.Red;
switch (value)
{
case < 0:
return Colors.Orange;
case >0:
return Colors.Green;
default:
return Colors.White;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

@ -2,9 +2,13 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Ohara.ModalBateau" x:Class="Ohara.ModalBateau"
xmlns:conv="clr-namespace:Ohara.Converters"
Title="ModalBateau" Title="ModalBateau"
BackgroundColor="#e2edf1" BackgroundColor="#e2edf1"
Shell.PresentationMode="ModalAnimated"> Shell.PresentationMode="ModalAnimated">
<ContentPage.Resources>
<conv:Int2ColorConverter x:Key="int2ColorConverter"/>
</ContentPage.Resources>
<ScrollView> <ScrollView>
<FlexLayout AlignItems="End" Wrap="Wrap" Direction="Row" JustifyContent="Center" HorizontalOptions="Center" VerticalOptions="Center" > <FlexLayout AlignItems="End" Wrap="Wrap" Direction="Row" JustifyContent="Center" HorizontalOptions="Center" VerticalOptions="Center" >
<VerticalStackLayout Spacing="4" Margin="2"> <VerticalStackLayout Spacing="4" Margin="2">
@ -24,13 +28,13 @@
</Grid> </Grid>
<Frame Style="{StaticResource frameModif}"> <Frame Style="{StaticResource frameModif}">
<HorizontalStackLayout HorizontalOptions="Center"> <HorizontalStackLayout HorizontalOptions="Center">
<Label Text="Premier Chapitre :" FontAttributes="Bold"/> <Label Text="Premier Chapitre :" FontAttributes="Bold" TextColor="{Binding PremierChap, Converter={StaticResource int2ColorConverter}}"/>
<Entry Text="{Binding PremierChap}" /> <Entry Text="{Binding PremierChap}" />
</HorizontalStackLayout> </HorizontalStackLayout>
</Frame> </Frame>
<Frame Style="{StaticResource frameModif}"> <Frame Style="{StaticResource frameModif}">
<HorizontalStackLayout HorizontalOptions="Center"> <HorizontalStackLayout HorizontalOptions="Center">
<Label Text="Premier Episode :" FontAttributes="Bold"/> <Label Text="Premier Episode :" FontAttributes="Bold" TextColor="{Binding PremierEp, Converter={StaticResource int2ColorConverter}}"/>
<Entry Text="{Binding PremierEp}" /> <Entry Text="{Binding PremierEp}" />
</HorizontalStackLayout > </HorizontalStackLayout >
</Frame> </Frame>

@ -1,3 +1,4 @@
using Model.Classes; using Model.Classes;
using Model.Managers; using Model.Managers;
@ -27,12 +28,23 @@ public partial class ModalBateau : ContentPage
{ {
if (manager.SelectedItem != null) if (manager.SelectedItem != null)
{ {
if (nouveauBateau.PremierChap < 0 || nouveauBateau.PremierEp < 0)
{
await DisplayAlert("Erreur", "Les paramètres PremierChap et PremierEp doivent être superieur à 0.", "OK");
return;
}
manager.ModifierBateau(nouveauBateau, ancienNom); manager.ModifierBateau(nouveauBateau, ancienNom);
nouveauBateau = manager.SelectedItem as Bateau; nouveauBateau = manager.SelectedItem as Bateau;
} }
else else
{ {
if (nouveauBateau.PremierChap<0 || nouveauBateau.PremierEp < 0)
{
await DisplayAlert("Erreur", "Les paramètres PremierChap et PremierEp doivent être superieur à 0.", "OK");
return;
}
manager.AjouterBateau(nouveauBateau); manager.AjouterBateau(nouveauBateau);
} }
await Navigation.PopModalAsync(); await Navigation.PopModalAsync();

@ -2,9 +2,13 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Ohara.ModalEquipage" x:Class="Ohara.ModalEquipage"
xmlns:conv="clr-namespace:Ohara.Converters"
Title="ModalEquipage" Title="ModalEquipage"
BackgroundColor="#e2edf1" BackgroundColor="#e2edf1"
Shell.PresentationMode="ModalAnimated"> Shell.PresentationMode="ModalAnimated">
<ContentPage.Resources>
<conv:Int2ColorConverter x:Key="int2ColorConverter"/>
</ContentPage.Resources>
<ScrollView> <ScrollView>
<FlexLayout AlignItems="End" Wrap="Wrap" Direction="Row" JustifyContent="Center" HorizontalOptions="Center" VerticalOptions="Center" > <FlexLayout AlignItems="End" Wrap="Wrap" Direction="Row" JustifyContent="Center" HorizontalOptions="Center" VerticalOptions="Center" >
<VerticalStackLayout Spacing="4" Margin="2"> <VerticalStackLayout Spacing="4" Margin="2">
@ -36,13 +40,13 @@
</Frame> </Frame>
<Frame Style="{StaticResource frameModif}"> <Frame Style="{StaticResource frameModif}">
<HorizontalStackLayout HorizontalOptions="Center"> <HorizontalStackLayout HorizontalOptions="Center">
<Label Text="Premier Chapitre :" FontAttributes="Bold"/> <Label Text="Premier Chapitre :" FontAttributes="Bold" TextColor="{Binding PremierChap, Converter={StaticResource int2ColorConverter}}"/>
<Entry Text="{Binding PremierChap}" /> <Entry Text="{Binding PremierChap}" />
</HorizontalStackLayout> </HorizontalStackLayout>
</Frame> </Frame>
<Frame Style="{StaticResource frameModif}"> <Frame Style="{StaticResource frameModif}">
<HorizontalStackLayout HorizontalOptions="Center"> <HorizontalStackLayout HorizontalOptions="Center">
<Label Text="Premier Episode :" FontAttributes="Bold"/> <Label Text="Premier Episode :" FontAttributes="Bold" TextColor="{Binding PremierEp, Converter={StaticResource int2ColorConverter}}"/>
<Entry Text="{Binding PremierEp}" /> <Entry Text="{Binding PremierEp}" />
</HorizontalStackLayout > </HorizontalStackLayout >
</Frame> </Frame>

@ -30,11 +30,21 @@ public partial class ModalEquipage : ContentPage
{ {
if (manager.SelectedItem != null) if (manager.SelectedItem != null)
{ {
if (nouvelEquipage.PremierChap < 0 || nouvelEquipage.PremierEp < 0)
{
await DisplayAlert("Erreur", "Les paramètres PremierChap et PremierEp doivent être superieur à 0.", "OK");
return;
}
manager.ModifierEquipage(nouvelEquipage, ancienNom); manager.ModifierEquipage(nouvelEquipage, ancienNom);
nouvelEquipage = manager.SelectedItem as Equipage; nouvelEquipage = manager.SelectedItem as Equipage;
} }
else else
{ {
if (nouvelEquipage.PremierChap < 0 || nouvelEquipage.PremierEp < 0)
{
await DisplayAlert("Erreur", "Les paramètres PremierChap et PremierEp doivent être superieur à 0.", "OK");
return;
}
manager.AjouterEquip(nouvelEquipage); manager.AjouterEquip(nouvelEquipage);
} }

@ -2,9 +2,13 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Ohara.ModalIle" x:Class="Ohara.ModalIle"
xmlns:conv="clr-namespace:Ohara.Converters"
Title="ModalIle" Title="ModalIle"
BackgroundColor="#e2edf1" BackgroundColor="#e2edf1"
Shell.PresentationMode="ModalAnimated"> Shell.PresentationMode="ModalAnimated">
<ContentPage.Resources>
<conv:Int2ColorConverter x:Key="int2ColorConverter"/>
</ContentPage.Resources>
<ScrollView> <ScrollView>
<FlexLayout AlignItems="End" Wrap="Wrap" Direction="Row" JustifyContent="Center" HorizontalOptions="Center" VerticalOptions="Center" > <FlexLayout AlignItems="End" Wrap="Wrap" Direction="Row" JustifyContent="Center" HorizontalOptions="Center" VerticalOptions="Center" >
<VerticalStackLayout Spacing="4" Margin="2"> <VerticalStackLayout Spacing="4" Margin="2">
@ -36,13 +40,13 @@
</Frame> </Frame>
<Frame Style="{StaticResource frameModif}"> <Frame Style="{StaticResource frameModif}">
<HorizontalStackLayout HorizontalOptions="Center"> <HorizontalStackLayout HorizontalOptions="Center">
<Label Text="Premier Chapitre :" FontAttributes="Bold"/> <Label Text="Premier Chapitre :" FontAttributes="Bold" TextColor="{Binding PremierChap, Converter={StaticResource int2ColorConverter}}"/>
<Entry Text="{Binding PremierChap}" /> <Entry Text="{Binding PremierChap}" />
</HorizontalStackLayout> </HorizontalStackLayout>
</Frame> </Frame>
<Frame Style="{StaticResource frameModif}"> <Frame Style="{StaticResource frameModif}">
<HorizontalStackLayout HorizontalOptions="Center"> <HorizontalStackLayout HorizontalOptions="Center">
<Label Text="Premier Episode :" FontAttributes="Bold"/> <Label Text="Premier Episode :" FontAttributes="Bold" TextColor="{Binding PremierEp, Converter={StaticResource int2ColorConverter}}"/>
<Entry Text="{Binding PremierEp}" /> <Entry Text="{Binding PremierEp}" />
</HorizontalStackLayout > </HorizontalStackLayout >
</Frame> </Frame>

@ -29,11 +29,21 @@ public partial class ModalIle : ContentPage
{ {
if (manager.SelectedItem != null) if (manager.SelectedItem != null)
{ {
if (nouvelIle.PremierChap < 0 || nouvelIle.PremierEp < 0)
{
await DisplayAlert("Erreur", "Les paramètres PremierChap et PremierEp doivent être superieur à 0.", "OK");
return;
}
manager.ModifierIle(nouvelIle,ancienNom); manager.ModifierIle(nouvelIle,ancienNom);
manager.SelectedItem=nouvelIle; manager.SelectedItem=nouvelIle;
} }
else else
{ {
if (nouvelIle.PremierChap < 0 || nouvelIle.PremierEp < 0)
{
await DisplayAlert("Erreur", "Les paramètres PremierChap et PremierEp doivent être superieur à 0.", "OK");
return;
}
manager.AjouterIle(nouvelIle); manager.AjouterIle(nouvelIle);
} }

@ -15,7 +15,7 @@ public partial class PageFavoris : ContentPage
void OnTextChanged(object sender, EventArgs e) void OnTextChanged(object sender, EventArgs e)
{ {
SearchBar searchBar = (SearchBar)sender; SearchBar searchBar = (SearchBar)sender;
BindableLayout.SetItemsSource(listeFav, manager.RechercheObjetOhara(searchBar.Text, manager.GetFavoris())); BindableLayout.SetItemsSource(listeFav, manager.RechercheObjetOhara(searchBar.Text, manager.GetFavoris().ToList()));
} }
searchBar.TextChanged += OnTextChanged; searchBar.TextChanged += OnTextChanged;

@ -4,6 +4,8 @@ using Model.Serializer;
using Model.Managers; using Model.Managers;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
// Tests fonctionnels : // Tests fonctionnels :
Manager manager = new Manager(new XML_Serializer()); Manager manager = new Manager(new XML_Serializer());
@ -105,7 +107,7 @@ foreach (Bateau b in manager.Bateaux)
// Recherche dansune liste de objet ohara pour afficher les objets ohara correspondant au mot clé "Sunny" // Recherche dansune liste de objet ohara pour afficher les objets ohara correspondant au mot clé "Sunny"
foreach (ObjetOhara o in manager.RechercheObjetOhara("Sunny", manager.GetFavoris())) foreach (ObjetOhara o in manager.RechercheObjetOhara("Sunny", manager.GetFavoris().ToList()))
{ {
Console.WriteLine(o.Nom); Console.WriteLine(o.Nom);
} }

@ -37,5 +37,25 @@ namespace TestProject1
Assert.False(resultat2); Assert.False(resultat2);
Assert.False(resultat3); Assert.False(resultat3);
} }
[Fact]
public void GetHashCode_BestiaireWithSameProperties_ReturnsSameHashCode()
{
Bestiaire obj1 = new Bestiaire("Humains", "??", "Les humains sont ...", "Ils possèdent les caractéristiques suivantes ...", "");
Bestiaire obj2 = new Bestiaire("Humains", "??", "Les humains sont ...", "Ils possèdent les caractéristiques suivantes ...", "");
var hashCode1 = obj1.GetHashCode();
var hashCode2 = obj2.GetHashCode();
Assert.True(hashCode1 == hashCode2);
}
[Fact]
public void ToString_ReturnsCorrectStringRepresentation()
{
Bestiaire obj1 = new Bestiaire("Humains", "??", "Les humains sont ...", "Ils possèdent les caractéristiques suivantes ...", "");
var result = obj1.ToString();
Assert.True("Bestiaire : Humains False ?? Les humains sont ... Ils possèdent les caractéristiques suivantes ... baseimage.png" == result);
}
} }
} }

@ -110,7 +110,7 @@ namespace TestProject1
var obj1 =manager.Fruits.First(); var obj1 =manager.Fruits.First();
var obj2 = manager.Equipages.First(); var obj2 = manager.Equipages.First();
manager.ModifierFavFDD(obj1, true); manager.ModifierFavFDD(obj1, true);
var result = manager.GetFavoris(); var result = manager.GetFavoris().ToList();
Assert.True(1==result.Count); Assert.True(1==result.Count);
Assert.Contains(obj1, result); Assert.Contains(obj1, result);

@ -14,12 +14,63 @@ namespace TestProject1
public class XMLSerializerTests public class XMLSerializerTests
{ {
public XML_Serializer serializer = new XML_Serializer(); public XML_Serializer serializer = new XML_Serializer();
private string TestFolderPath = Directory.GetCurrentDirectory();
[Fact] [Fact]
public void InitialiserFichiers_FileDoesNotExist_SetPersonnageCalled() public void InitialiserFichiers_FileDoesNotExist_SetPersonnageIfStubManagerReturnsNonNull()
{ {
// Arrange
var serializer = new XML_Serializer(TestFolderPath);
var stubManager = new StubManager();
var expectedPersonnages = stubManager.GetPersonnages();
var expectedBateaux = stubManager.GetBateaux();
var expectedFruits = stubManager.GetFruits();
var expectedBestiaires= stubManager.GetBestiaires();
var expectedEquipages=stubManager.GetEquipages();
var expectedIles = stubManager.GetIles();
// Act
serializer.InitialiserFichiers(stubManager);
// Assert
if (!File.Exists(Path.Combine(TestFolderPath, "./personnage.xml")))
{
if (expectedPersonnages != null)
{
Assert.True(expectedPersonnages.ToList()== serializer.GetPersonnages());
}
}
Assert.True(File.Exists(Path.Combine(serializer.Chemin, "./personnage.xml"))); if (!File.Exists(Path.Combine(TestFolderPath, "./bateau.xml")))
{
if (expectedBateaux != null)
{
Assert.True(expectedBateaux.ToList() == serializer.GetBateaux());
}
}
if (!File.Exists(Path.Combine(TestFolderPath, "./fruitdudemon.xml")))
{
if (expectedFruits != null)
{
Assert.True(expectedFruits.ToList() == serializer.GetFruits());
}
}
if (!File.Exists(Path.Combine(TestFolderPath, "./equipage.xml")))
{
if (expectedEquipages != null)
{
Assert.True(expectedEquipages.ToList() == serializer.GetEquipages());
}
}
if (!File.Exists(Path.Combine(TestFolderPath, "./ile.xml")))
{
if (expectedIles != null)
{
Assert.True(expectedIles.ToList() == serializer.GetIles());
}
}
} }
[Fact] [Fact]
public void SetPersonnage_SerializesAndWritesToFile() public void SetPersonnage_SerializesAndWritesToFile()

Loading…
Cancel
Save