diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..c6dcbe4 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,42 @@ +kind: pipeline +type: docker +name: CI_Linaris_pipeline + +trigger: + event: + - push + +steps: + - name: build + image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dotnet7-maui:latest + commands: + - cd Sources/ + - dotnet restore Linaris.sln + - dotnet build Linaris.sln -c Release --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 + - dotnet publish Linaris/Linaris.csproj -c Release --no-restore -o $CI_PROJECT_DIR/build/release -f:net7.0-android /p:AndroidSdkDirectory=/usr/lib/android-sdk + - name: tests + image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dotnet7-maui:latest + commands: + - cd Sources/ + - dotnet restore Linaris.sln + - dotnet test Linaris.sln --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 + depends_on: [build] + - name: code-inspection + image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dronesonarplugin-dotnet7-maui + secrets: [ SECRET_SONAR_LOGIN ] + environment: + sonar_host: https://codefirst.iut.uca.fr/sonar/ + sonar_token: + from_secret: SECRET_SONAR_LOGIN + project_key: Linaris_LEMAIRE_LABORIE + coverage_exclusions: "Tests/**" + commands: + - cd Sources/ + - dotnet restore Linaris.sln + - dotnet sonarscanner begin /k:$${project_key} /d:sonar.host.url=$${sonar_host} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions=$${coverage_exclusions} /d:sonar.login=$${sonar_token} + - dotnet build Linaris.sln -c Release --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 + - dotnet test Linaris.sln --logger trx --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage" + - reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport" + - dotnet publish Linaris/Linaris.csproj -c Release --no-restore -o $CI_PROJECT_DIR/build/release -f:net7.0-android /p:AndroidSdkDirectory=/usr/lib/android-sdk + - dotnet sonarscanner end /d:sonar.login=$${sonar_token} + depends_on: [tests] diff --git a/Sources/Linaris.sln b/Sources/Linaris.sln index 6f91fb4..e01685e 100644 --- a/Sources/Linaris.sln +++ b/Sources/Linaris.sln @@ -5,9 +5,11 @@ VisualStudioVersion = 17.0.31611.283 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Linaris", "Linaris\Linaris.csproj", "{9E6281F7-95F6-472C-B268-894CE377C8A9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Console", "Console\Console.csproj", "{BB50C1E3-5A9A-40AF-8CD7-55B41064290B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Console", "Console\Console.csproj", "{BB50C1E3-5A9A-40AF-8CD7-55B41064290B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{AA1DB94B-8273-437F-A07A-BB1F5F0D278D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model", "Model\Model.csproj", "{AA1DB94B-8273-437F-A07A-BB1F5F0D278D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUnitaires", "TestUnitaires\TestUnitaires.csproj", "{8B0671CF-1302-4244-8837-916E632007E2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -29,6 +31,10 @@ Global {AA1DB94B-8273-437F-A07A-BB1F5F0D278D}.Debug|Any CPU.Build.0 = Debug|Any CPU {AA1DB94B-8273-437F-A07A-BB1F5F0D278D}.Release|Any CPU.ActiveCfg = Release|Any CPU {AA1DB94B-8273-437F-A07A-BB1F5F0D278D}.Release|Any CPU.Build.0 = Release|Any CPU + {8B0671CF-1302-4244-8837-916E632007E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8B0671CF-1302-4244-8837-916E632007E2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8B0671CF-1302-4244-8837-916E632007E2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8B0671CF-1302-4244-8837-916E632007E2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Sources/Linaris/AlbumPage.xaml.cs b/Sources/Linaris/AlbumPage.xaml.cs index 821b100..adde9b9 100644 --- a/Sources/Linaris/AlbumPage.xaml.cs +++ b/Sources/Linaris/AlbumPage.xaml.cs @@ -6,13 +6,4 @@ public partial class AlbumPage : ContentPage { InitializeComponent(); } - - /* async void Button_Clicked(object sender, EventArgs e) - { - var random = new Random(); - var color = String.Format("#{0:X6}", random.Next(0x1000000)); - bouton.BackgroundColor = Color.FromArgb(color); - await bouton.RelRotateTo(360, 1000); - bouton.Rotation = 0; - }*/ } \ No newline at end of file diff --git a/Sources/Linaris/FooterPage.xaml.cs b/Sources/Linaris/FooterPage.xaml.cs index fcc1e8e..8176381 100644 --- a/Sources/Linaris/FooterPage.xaml.cs +++ b/Sources/Linaris/FooterPage.xaml.cs @@ -9,7 +9,7 @@ public partial class FooterPage : ContentView System.Timers.Timer timer; bool changementManuel = true; bool closing = false; - string morceauEnCours; + // string morceauEnCours; public FooterPage() { @@ -19,7 +19,7 @@ public partial class FooterPage : ContentView // (s,a) = convention, s = sender, a = arguments, si appli fermée, on free tout outputDevice.PlaybackStopped += PlaybackStoppedHandler; - /*morceauEnCours = "peaches.mp3"; + /*morceauEnCours = "Resources/Musics/peaches.mp3"; audioFile = new AudioFileReader(morceauEnCours); outputDevice.Init(audioFile);*/ } diff --git a/Sources/Linaris/Linaris.csproj b/Sources/Linaris/Linaris.csproj index b1d6590..2202648 100644 --- a/Sources/Linaris/Linaris.csproj +++ b/Sources/Linaris/Linaris.csproj @@ -1,8 +1,10 @@  - net7.0-android;net7.0-ios;net7.0-maccatalyst - $(TargetFrameworks);net7.0-windows10.0.19041.0 + net7.0-android + $(TargetFrameworks);net7.0-windows10.0.19041.0 + $(TargetFrameworks);net7.0-ios + $(TargetFrameworks);net7.0-maccatalyst Exe diff --git a/Sources/Linaris/MainPage.xaml.cs b/Sources/Linaris/MainPage.xaml.cs index 9e8598f..d6caaeb 100644 --- a/Sources/Linaris/MainPage.xaml.cs +++ b/Sources/Linaris/MainPage.xaml.cs @@ -2,23 +2,19 @@ public partial class MainPage : ContentPage { - // int count = 0; public MainPage() { InitializeComponent(); - } - /*private void OnCounterClicked(object sender, EventArgs e) - { - count++; + } + + async public Task Go_Home() + { + await Navigation.PushAsync(new MainPage()); + + } - if (count == 1) - CounterBtn.Text = $"Clicked {count} time"; - else - CounterBtn.Text = $"Clicked {count} times"; - SemanticScreenReader.Announce(CounterBtn.Text); - }*/ } diff --git a/Sources/Model/Album.cs b/Sources/Model/Album.cs index 7ececfb..2ca3032 100644 --- a/Sources/Model/Album.cs +++ b/Sources/Model/Album.cs @@ -53,7 +53,16 @@ namespace Model set { - if (value != null && value.Contains('.')) + if (value == null || !value.Contains('.')) + { + value = "none.png"; + imageURL = value; + } + if (value.Contains(' ')) + { + imageURL = value.Replace(' ', '_'); + } + else if (value.Contains('.')) { imageURL = value; } @@ -100,10 +109,7 @@ namespace Model public void RemoveTitle(Title title) { - foreach(var item in titles) - { - titles = titles.Where(item => item != title).ToList(); - } + titles.Remove(title); } public override bool Equals(object? obj) diff --git a/Sources/Model/CustomTitle.cs b/Sources/Model/CustomTitle.cs index ab7b192..c10039f 100644 --- a/Sources/Model/CustomTitle.cs +++ b/Sources/Model/CustomTitle.cs @@ -1,4 +1,5 @@ using Model.Stub; +using System.Runtime.CompilerServices; namespace Model; diff --git a/Sources/Model/IDataManager.cs b/Sources/Model/IDataManager.cs index e0907ce..af316ba 100644 --- a/Sources/Model/IDataManager.cs +++ b/Sources/Model/IDataManager.cs @@ -1,48 +1,48 @@ -namespace Model; - -public interface IDataManager +namespace Model; + +public interface IDataManager { // Create - void AddAlbum(Album album); - - void AddAlbums(List albumsList); - - void AddArtist(Artist artist); - - void AddArtists(List artistsList); - - void AddPlaylist(Playlist playlist); - - void AddPlaylists(List playlistsList); - - void AddCustomTitle(CustomTitle title); - - void AddCustomTitles(List customTitlesList); - + void AddAlbum(Album album); + + void AddAlbums(List albumsList); + + void AddArtist(Artist artist); + + void AddArtists(List artistsList); + + void AddPlaylist(Playlist playlist); + + void AddPlaylists(List playlistsList); + + void AddCustomTitle(CustomTitle title); + + void AddCustomTitles(List customTitlesList); + void AddInfoTitle(InfoTitle title); void AddInfoTitles(List infoTitlesList); // Read - List GetCustomTitles(); - - CustomTitle? GetCustomTitleByUrl(string custom); - - List GetInfoTitles(); - - InfoTitle? GetInfoTitleByUrl(string url); - - List GetAlbums(); - - Album? GetAlbumByUrl(string url); - - List GetArtists(); - - Artist? GetArtistByName(string name); - - List GetPlaylists(); - - Playlist? GetPlaylistByUrl(string url); + List GetCustomTitles(); + + CustomTitle? GetCustomTitleByUrl(string custom); + + List GetInfoTitles(); + + InfoTitle? GetInfoTitleByUrl(string url); + + List GetAlbums(); + + Album? GetAlbumByUrl(string url); + + List GetArtists(); + + Artist? GetArtistByName(string name); + + List GetPlaylists(); + + Playlist? GetPlaylistByUrl(string url); // Update @@ -75,49 +75,49 @@ public interface IDataManager void UpdateArtistByName(string name, string newName); // Delete - void RemoveAlbum(Album album); - - void RemoveAlbums(List albumsList); - - void RemoveArtist(Artist artist); - - void RemoveArtists(List artistsList); - - void RemovePlaylist(Playlist playlist); - - void RemovePlaylists(List playlistsList); - - void RemoveCustomTitle(CustomTitle title); - - void RemoveCustomTitles(List customTitlesList); - - void RemoveInfoTitle(InfoTitle title); - - void RemoveInfoTitles(List infoTitlesList); - - // Serialization - void LoadSerialization(); - - void SaveSerialization(); - - // Exists - bool ExistsPlaylist(Playlist playlist); - - bool ExistsPlaylistByUrl(string url); - - bool ExistsAlbum(Album album); - - bool ExistsAlbumByUrl(string url); - - bool ExistsArtist(Artist artist); - - bool ExistsArtistByName(string name); - - bool ExistsCustomTitle(CustomTitle title); - - bool ExistsCustomTitleByUrl(string url); - - bool ExistsInfoTitle(InfoTitle title); - - bool ExistsInfoTitleByUrl(string url); + void RemoveAlbum(Album album); + + void RemoveAlbums(List albumsList); + + void RemoveArtist(Artist artist); + + void RemoveArtists(List artistsList); + + void RemovePlaylist(Playlist playlist); + + void RemovePlaylists(List playlistsList); + + void RemoveCustomTitle(CustomTitle title); + + void RemoveCustomTitles(List customTitlesList); + + void RemoveInfoTitle(InfoTitle title); + + void RemoveInfoTitles(List infoTitlesList); + + // Serialization + void LoadSerialization(); + + void SaveSerialization(); + + // Exists + bool ExistsPlaylist(Playlist playlist); + + bool ExistsPlaylistByUrl(string url); + + bool ExistsAlbum(Album album); + + bool ExistsAlbumByUrl(string url); + + bool ExistsArtist(Artist artist); + + bool ExistsArtistByName(string name); + + bool ExistsCustomTitle(CustomTitle title); + + bool ExistsCustomTitleByUrl(string url); + + bool ExistsInfoTitle(InfoTitle title); + + bool ExistsInfoTitleByUrl(string url); } \ No newline at end of file diff --git a/Sources/Model/InfoTitle.cs b/Sources/Model/InfoTitle.cs index 1ee8b2f..a3483c7 100644 --- a/Sources/Model/InfoTitle.cs +++ b/Sources/Model/InfoTitle.cs @@ -87,4 +87,4 @@ public class InfoTitle : Title { return $"Name : {Name}, ImageUrl : {ImageURL}"; } -} +} \ No newline at end of file diff --git a/Sources/Model/Playlist.cs b/Sources/Model/Playlist.cs index efa68d8..356156f 100644 --- a/Sources/Model/Playlist.cs +++ b/Sources/Model/Playlist.cs @@ -35,22 +35,32 @@ public class Playlist private string description = Manager.DEFAULT_DESC; - private List morceaux = new List<Title>(); - - public IEnumerable<Title> Morceaux { - get + public IEnumerable<Title> Titles + { + get { - return morceaux.ToList(); - } + return titles; + } } + private readonly List<Title> titles = new List<Title>(); + public string ImageURL { get => imageURL; set { - if (value != null && value.Contains('.')) + if (value == null || !value.Contains('.')) + { + value = "none.png"; + imageURL = value; + } + if (value.Contains(' ')) + { + imageURL = value.Replace(' ', '_'); + } + else if (value.Contains('.')) { imageURL = value; } @@ -65,7 +75,7 @@ public class Playlist set { - if (value < morceaux.Count()) + if (value < titles.Count()) { index = value; } @@ -109,16 +119,17 @@ public class Playlist public Playlist() { + } public void AddTitle(CustomTitle morceau) { - morceaux.Add(morceau); + titles.Add(morceau); } public void RemoveTitle(CustomTitle morceau) { - morceaux.Remove(morceau); + titles.Remove(morceau); } public void NextTitle() @@ -135,7 +146,7 @@ public class Playlist } else { - Index = Aleatoire.Next(morceaux.Count()); + Index = Aleatoire.Next(titles.Count()); played.Add(Index); } } @@ -165,9 +176,9 @@ public class Playlist public Title? GetCurrentTitle() { - if (Index < morceaux.Count()) + if (Index < titles.Count()) { - return morceaux[Index]; + return titles[Index]; } else { diff --git a/Sources/Model/Title.cs b/Sources/Model/Title.cs index bc297a8..304eb89 100644 --- a/Sources/Model/Title.cs +++ b/Sources/Model/Title.cs @@ -26,7 +26,16 @@ namespace Model set { - if (value != null && value.Contains('.')) + if (value == null || !value.Contains('.')) + { + value = "none.png"; + imageURL = value; + } + if (value.Contains(' ')) + { + imageURL = value.Replace(' ', '_'); + } + else if (value.Contains('.')) { imageURL = value; } diff --git a/Sources/TestUnitaires/TU_Album.cs b/Sources/TestUnitaires/TU_Album.cs new file mode 100644 index 0000000..17a172f --- /dev/null +++ b/Sources/TestUnitaires/TU_Album.cs @@ -0,0 +1,46 @@ +using Model; +using Newtonsoft.Json.Linq; +using NuGet.Frameworks; + +namespace TestUnitaires +{ + public class TU_Album + { + [Theory] + [InlineData("Fenêtre sur Rue","album2. jpg","Un banger","Sortie : 2012")] + [InlineData("Adios Bahamas", "album.jpg", "Un banger", "Sortie : 2012")] + [InlineData(null, "album2.jpg", "Un banger", "Sortie : 2012")] + [InlineData("Dans La Légende", null, "Un banger", "Sortie : 2012")] + [InlineData("Dans La Légende","album1.jpg", null, "Sortie : 2012")] + [InlineData("Dans La Légende", "album1.jpg", "Un banger", null)] + [InlineData("Dans La Légende", "album1jpg", "Un banger", "Sortie : 2012")] + public void TU_Attributes(string nameAlbum, string url, string desc, string info) + { + Album album = new Album(nameAlbum, url, new Artist("test"), desc, info); + Assert.True(album.Name != null && album.Name.Length < 75); + Assert.True(album.ImageURL != null && album.ImageURL.Contains('.')); + Assert.False(album.ImageURL.Contains(' ')); + Assert.True(album.Description != null && album.Description.Length < 500); + Assert.True(album.Information != null && album.Information.Length < 500); + } + + [Theory] + [InlineData("Fenêtre sur Rue", "album2. jpg", "Un banger", "Sortie : 2012")] + [InlineData("Adios Bahamas", "album.jpg", "Un banger", "Sortie : 2012")] + [InlineData(null, "album2.jpg", "Un banger", "Sortie : 2012")] + [InlineData("Dans La Légende", null, "Un banger", "Sortie : 2012")] + [InlineData("Dans La Légende", "album1.jpg", null, "Sortie : 2012")] + [InlineData("Dans La Légende", "album1.jpg", "Un banger", null)] + [InlineData("Dans La Légende", "album1jpg", "Un banger", "Sortie : 2012")] + public void TU_Methods(string nameAlbum, string url, string desc, string info) + { + Album album = new Album(nameAlbum, url, new Artist("test"), desc, info); + Title t = new Title("Débitage", "test. mp3", "Banger"); + album.AddTitle(t); + Assert.Contains(t, album.Titles); + album.RemoveTitle(t); + Assert.DoesNotContain(t, album.Titles); + } + + } +} \ No newline at end of file diff --git a/Sources/TestUnitaires/TU_Artiste.cs b/Sources/TestUnitaires/TU_Artiste.cs new file mode 100644 index 0000000..6f6c19e --- /dev/null +++ b/Sources/TestUnitaires/TU_Artiste.cs @@ -0,0 +1,21 @@ +using Model; +using Newtonsoft.Json.Linq; +using NuGet.Frameworks; + +namespace TestUnitaires +{ + + public class TU_Artist + { + [Theory] + [InlineData("Hugo TSR")] + [InlineData(null)] + [InlineData("Hugo TSRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR")] + public void TU_Attributes(string name) + { + Artist a = new Artist(name); + Assert.True(a.Name != null && a.Name.Length < 75); + } + } + +} \ No newline at end of file diff --git a/Sources/TestUnitaires/TU_CustomTitle.cs b/Sources/TestUnitaires/TU_CustomTitle.cs new file mode 100644 index 0000000..5599ad1 --- /dev/null +++ b/Sources/TestUnitaires/TU_CustomTitle.cs @@ -0,0 +1,31 @@ +using Model; +using Newtonsoft.Json.Linq; +using NuGet.Frameworks; + +namespace TestUnitaires +{ + + public class TU_CustomTitle + { + [Theory] + [InlineData("Trajectoire","morceau1.png","Sortie : 2020", "Musique/test.mp3")] + [InlineData(null, "morceau1.png", "Sortie : 2020", "Musique/test.mp3")] + [InlineData("Trajectoire", null, "Sortie : 2020", "Musique/test.mp3")] + [InlineData("Trajectoire", "morceau1.png", null, "Musique/test.mp3")] + [InlineData("Trajectoire", "morceau1png", "Sortie : 2020", "Musique/test.mp3")] + [InlineData("Trajectoire", "morceau1. png", "Sortie : 2020", "Musique/test.mp3")] + [InlineData("Trajectoire", "morceau1.png", "Sortie : 2020", null)] + public void TU_Attributes(string name, string url, string info, string path) + { + CustomTitle ct = new CustomTitle(name, url, info, path); + Assert.True(ct.Name != null && ct.Name.Length < 75); + Assert.True(ct.ImageURL != null && ct.ImageURL.Contains('.')); + Assert.False(ct.ImageURL.Contains(' ')); + Assert.True(ct.Information != null && ct.Information.Length < 500); + Assert.True(ct.Path != null && ct.Path.Contains('.')); + Assert.False(ct.Path.Contains(' ')); + } + + } + +} \ No newline at end of file diff --git a/Sources/TestUnitaires/TU_InfoTitle.cs b/Sources/TestUnitaires/TU_InfoTitle.cs new file mode 100644 index 0000000..8463810 --- /dev/null +++ b/Sources/TestUnitaires/TU_InfoTitle.cs @@ -0,0 +1,45 @@ +using Model; +using Newtonsoft.Json.Linq; +using NuGet.Frameworks; + +namespace TestUnitaires +{ + + public class TU_InfoTitle + { + [Theory] + [InlineData("Trajectoire","morceau1.png","Sortie : 2020","Morceau de Népal",Genre.HIP_HOP)] + [InlineData(null, "morceau1.png", "Sortie : 2020", "Morceau de Népal", Genre.HIP_HOP)] + [InlineData("Trajectoire", null, "Sortie : 2020", "Morceau de Népal", Genre.HIP_HOP)] + [InlineData("Trajectoire", "morceau1.png", null, "Morceau de Népal", Genre.HIP_HOP)] + [InlineData("Trajectoire", "morceau1png", "Sortie : 2020", "Morceau de Népal", Genre.HIP_HOP)] + [InlineData("Trajectoire", "morceau1. png", "Sortie : 2020", "Morceau de Népal", Genre.HIP_HOP)] + public void TU_Attributes(string name, string url, string info, string desc, Genre g) + { + InfoTitle it = new InfoTitle(name, url, info, new Artist("test"), desc, g); + Assert.True(it.Name != null && it.Name.Length < 75); + Assert.True(it.ImageURL != null && it.ImageURL.Contains('.')); + Assert.False(it.ImageURL.Contains(' ')); + Assert.True(it.Information != null && it.Information.Length < 500); + Assert.True(it.Description != null && it.Description.Length < 500); + } + + [Theory] + [InlineData("Trajectoire", "morceau1.png", "Sortie : 2020", "Morceau de Népal", Genre.HIP_HOP)] + [InlineData(null, "morceau1.png", "Sortie : 2020", "Morceau de Népal", Genre.HIP_HOP)] + [InlineData("Trajectoire", null, "Sortie : 2020", "Morceau de Népal", Genre.HIP_HOP)] + [InlineData("Trajectoire", "morceau1.png", null, "Morceau de Népal", Genre.HIP_HOP)] + [InlineData("Trajectoire", "morceau1png", "Sortie : 2020", "Morceau de Népal", Genre.HIP_HOP)] + [InlineData("Trajectoire", "morceau1. png", "Sortie : 2020", "Morceau de Népal", Genre.HIP_HOP)] + public void TU_Methods(string name, string url, string info, string desc, Genre g) + { + InfoTitle it = new InfoTitle(name, url, info, new Artist("test"), desc, g); + Artist a = new Artist("Lahuiss"); + it.AddFeat(a); + Assert.Contains(a, it.Feat); + it.RemoveFeat(a); + Assert.DoesNotContain(a, it.Feat); + } + } + +} \ No newline at end of file diff --git a/Sources/TestUnitaires/TU_Manager.cs b/Sources/TestUnitaires/TU_Manager.cs new file mode 100644 index 0000000..3ff8d81 --- /dev/null +++ b/Sources/TestUnitaires/TU_Manager.cs @@ -0,0 +1,38 @@ +using Model; +using Model.Serialization; +using Model.Stub; +using Newtonsoft.Json.Linq; +using NuGet.Frameworks; +using System; + +namespace TestUnitaires +{ + + public class TU_Manager + { + [Theory] + [InlineData(null)] + [InlineData("Réference")] + public void TU_Methods(string? test) + { + IDataManager DataManager = new LINQ_XML_Serialization(); + Playlist p = new Playlist(test, "PlaceHolder", "place.holder"); + Album album = new Album(test, "place.holder", new Artist("test"), "PlaceHolder", "PlaceHolder"); + CustomTitle t = new CustomTitle(test, "test. mp3", "Banger", "path"); + Manager m = new Manager(DataManager); + m.AddCustomTitle(t); + m.AddPlaylist(p); + m.AddAlbum(album); + Assert.Contains(t, m.CustomTitles); + Assert.Contains(album, m.Albums); + Assert.Contains(p, m.Playlists); + m.RemovePlaylist(p); + m.RemoveAlbum(album); + m.RemoveCustomTitle(t); + Assert.DoesNotContain(t, m.CustomTitles); + Assert.DoesNotContain(p, m.Playlists); + Assert.DoesNotContain(album, m.Albums); + } + } + +} \ No newline at end of file diff --git a/Sources/TestUnitaires/TU_Playlist.cs b/Sources/TestUnitaires/TU_Playlist.cs new file mode 100644 index 0000000..ff8219e --- /dev/null +++ b/Sources/TestUnitaires/TU_Playlist.cs @@ -0,0 +1,45 @@ +using Model; +using Newtonsoft.Json.Linq; +using NuGet.Frameworks; + +namespace TestUnitaires +{ + + public class TU_Playlist + { + [Theory] + [InlineData("Sons Soirées","red-sky.png","Contient les sons que je mets quand je suis en soirée.")] + [InlineData(null, "red-sky.png", "Contient les sons que je mets quand je suis en soirée.")] + [InlineData("Sons Soirées", null, "Contient les sons que je mets quand je suis en soirée.")] + [InlineData("Sons Soirées", "red-sky.png", null)] + [InlineData("Sons Soirées", "redskypng", "Contient les sons que je mets quand je suis en soirée.")] + [InlineData("Sons Soirées", "red-sky .png", "Contient les sons que je mets quand je suis en soirée.")] + public void TU_Attributes(string name, string url, string desc) + { + Playlist p = new Playlist(name, desc, url); + Assert.True(p.Name != null && p.Name.Length < 75); + Assert.True(p.ImageURL != null && p.ImageURL.Contains('.')); + Assert.False(p.ImageURL.Contains(' ')); + Assert.True(p.Description != null && p.Description.Length < 500); + } + [Theory] + [InlineData("Sons Soirées", "red-sky.png", "Contient les sons que je mets quand je suis en soirée.")] + [InlineData(null, "red-sky.png", "Contient les sons que je mets quand je suis en soirée.")] + [InlineData("Sons Soirées", null, "Contient les sons que je mets quand je suis en soirée.")] + [InlineData("Sons Soirées", "red-sky.png", null)] + [InlineData("Sons Soirées", "redskypng", "Contient les sons que je mets quand je suis en soirée.")] + [InlineData("Sons Soirées", "red-sky .png", "Contient les sons que je mets quand je suis en soirée.")] + public void TU_Methods(string name, string url, string desc) + { + Playlist p = new Playlist(name, desc, url); + CustomTitle t = new CustomTitle("Débitage","test. mp3","Banger","path"); + p.AddTitle(t); + Assert.Contains(t,p.Titles); + p.RemoveTitle(t); + Assert.DoesNotContain(t,p.Titles); + + + } + } + +} \ No newline at end of file diff --git a/Sources/TestUnitaires/TU_Title.cs b/Sources/TestUnitaires/TU_Title.cs new file mode 100644 index 0000000..c22de93 --- /dev/null +++ b/Sources/TestUnitaires/TU_Title.cs @@ -0,0 +1,27 @@ +using Model; +using Newtonsoft.Json.Linq; +using NuGet.Frameworks; + +namespace TestUnitaires +{ + + public class TU_Title + { + [Theory] + [InlineData("Trajectoire","morceau1.png","Sortie : 2020")] + [InlineData(null, "morceau1.png", "Sortie : 2020")] + [InlineData("Trajectoire", null, "Sortie : 2020")] + [InlineData("Trajectoire", "morceau1.png", null)] + [InlineData("Trajectoire", "morceau1png", "Sortie : 2020")] + [InlineData("Trajectoire", "morceau1. png", "Sortie : 2020")] + public void TU_Attributes(string name, string url, string info) + { + Title t = new Title(name, url, info); + Assert.True(t.Name != null && t.Name.Length < 75); + Assert.True(t.ImageURL != null && t.ImageURL.Contains('.')); + Assert.False(t.ImageURL.Contains(' ')); + Assert.True(t.Information != null && t.Information.Length < 500); + } + } + +} \ No newline at end of file diff --git a/Sources/TestUnitaires/TestUnitaires.csproj b/Sources/TestUnitaires/TestUnitaires.csproj new file mode 100644 index 0000000..dedc487 --- /dev/null +++ b/Sources/TestUnitaires/TestUnitaires.csproj @@ -0,0 +1,28 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFramework>net7.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + + <IsPackable>false</IsPackable> + </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="..\Model\Model.csproj" /> + </ItemGroup> + +</Project> diff --git a/Sources/TestUnitaires/Usings.cs b/Sources/TestUnitaires/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/Sources/TestUnitaires/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file