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:
from_secret: SECRET_SONAR_LOGIN
project_key: Ohara
coverage_exclusions: "Tests/**"
coverage_exclusions: "Tests/**","Ohara/**"
commands:
- cd Sources/
- 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.
/// \return La liste des objets Ohara ayant le parametre EstFavori égal a true.
public List<ObjetOhara> GetFavoris()
{
List<ObjetOhara> listeFavoris = new List<ObjetOhara>();
listeFavoris.AddRange(Bateaux);
listeFavoris.AddRange(Equipages);
listeFavoris.AddRange(Bestiaire);
listeFavoris.AddRange(Fruits);
listeFavoris.AddRange(Iles);
listeFavoris.AddRange(Personnages);
public HashSet<ObjetOhara> GetFavoris()
{
HashSet<ObjetOhara> listeFavoris = new HashSet<ObjetOhara>();
listeFavoris.UnionWith(Bateaux);
listeFavoris.UnionWith(Equipages);
listeFavoris.UnionWith(Bestiaire);
listeFavoris.UnionWith(Fruits);
listeFavoris.UnionWith(Iles);
listeFavoris.UnionWith(Personnages);
foreach(ObjetOhara obj in listeFavoris.ToList())
{
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"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Ohara.ModalBateau"
xmlns:conv="clr-namespace:Ohara.Converters"
Title="ModalBateau"
BackgroundColor="#e2edf1"
BackgroundColor="#e2edf1"
Shell.PresentationMode="ModalAnimated">
<ContentPage.Resources>
<conv:Int2ColorConverter x:Key="int2ColorConverter"/>
</ContentPage.Resources>
<ScrollView>
<FlexLayout AlignItems="End" Wrap="Wrap" Direction="Row" JustifyContent="Center" HorizontalOptions="Center" VerticalOptions="Center" >
<VerticalStackLayout Spacing="4" Margin="2">
@ -24,13 +28,13 @@
</Grid>
<Frame Style="{StaticResource frameModif}">
<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}" />
</HorizontalStackLayout>
</Frame>
<Frame Style="{StaticResource frameModif}">
<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}" />
</HorizontalStackLayout >
</Frame>

@ -1,3 +1,4 @@
using Model.Classes;
using Model.Managers;
@ -27,12 +28,23 @@ public partial class ModalBateau : ContentPage
{
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);
nouveauBateau = manager.SelectedItem as Bateau;
}
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);
}
await Navigation.PopModalAsync();

@ -2,9 +2,13 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Ohara.ModalEquipage"
xmlns:conv="clr-namespace:Ohara.Converters"
Title="ModalEquipage"
BackgroundColor="#e2edf1"
Shell.PresentationMode="ModalAnimated">
<ContentPage.Resources>
<conv:Int2ColorConverter x:Key="int2ColorConverter"/>
</ContentPage.Resources>
<ScrollView>
<FlexLayout AlignItems="End" Wrap="Wrap" Direction="Row" JustifyContent="Center" HorizontalOptions="Center" VerticalOptions="Center" >
<VerticalStackLayout Spacing="4" Margin="2">
@ -36,13 +40,13 @@
</Frame>
<Frame Style="{StaticResource frameModif}">
<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}" />
</HorizontalStackLayout>
</Frame>
<Frame Style="{StaticResource frameModif}">
<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}" />
</HorizontalStackLayout >
</Frame>

@ -30,11 +30,21 @@ public partial class ModalEquipage : ContentPage
{
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);
nouvelEquipage = manager.SelectedItem as Equipage;
}
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);
}

@ -2,9 +2,13 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Ohara.ModalIle"
xmlns:conv="clr-namespace:Ohara.Converters"
Title="ModalIle"
BackgroundColor="#e2edf1"
Shell.PresentationMode="ModalAnimated">
<ContentPage.Resources>
<conv:Int2ColorConverter x:Key="int2ColorConverter"/>
</ContentPage.Resources>
<ScrollView>
<FlexLayout AlignItems="End" Wrap="Wrap" Direction="Row" JustifyContent="Center" HorizontalOptions="Center" VerticalOptions="Center" >
<VerticalStackLayout Spacing="4" Margin="2">
@ -36,13 +40,13 @@
</Frame>
<Frame Style="{StaticResource frameModif}">
<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}" />
</HorizontalStackLayout>
</Frame>
<Frame Style="{StaticResource frameModif}">
<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}" />
</HorizontalStackLayout >
</Frame>

@ -29,11 +29,21 @@ public partial class ModalIle : ContentPage
{
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.SelectedItem=nouvelIle;
}
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);
}

@ -15,7 +15,7 @@ public partial class PageFavoris : ContentPage
void OnTextChanged(object sender, EventArgs e)
{
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;

@ -4,6 +4,8 @@ using Model.Serializer;
using Model.Managers;
using System.Collections.ObjectModel;
// Tests fonctionnels :
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"
foreach (ObjetOhara o in manager.RechercheObjetOhara("Sunny", manager.GetFavoris()))
foreach (ObjetOhara o in manager.RechercheObjetOhara("Sunny", manager.GetFavoris().ToList()))
{
Console.WriteLine(o.Nom);
}

@ -37,5 +37,25 @@ namespace TestProject1
Assert.False(resultat2);
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 obj2 = manager.Equipages.First();
manager.ModifierFavFDD(obj1, true);
var result = manager.GetFavoris();
var result = manager.GetFavoris().ToList();
Assert.True(1==result.Count);
Assert.Contains(obj1, result);

@ -14,12 +14,63 @@ namespace TestProject1
public class XMLSerializerTests
{
public XML_Serializer serializer = new XML_Serializer();
private string TestFolderPath = Directory.GetCurrentDirectory();
[Fact]
public void InitialiserFichiers_FileDoesNotExist_SetPersonnageCalled()
public void InitialiserFichiers_FileDoesNotExist_SetPersonnageIfStubManagerReturnsNonNull()
{
Assert.True(File.Exists(Path.Combine(serializer.Chemin, "./personnage.xml")));
// 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());
}
}
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]
public void SetPersonnage_SerializesAndWritesToFile()

Loading…
Cancel
Save