From 5e2e3a4d7e2c5e95094b4b4ad1062d4edcf473fe Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE Date: Tue, 13 Jun 2023 15:48:58 +0200 Subject: [PATCH] Add StubManager UT --- Sources/TestUnitaires/TU_StubManager.cs | 174 +++++++++++++++++++++++- 1 file changed, 167 insertions(+), 7 deletions(-) diff --git a/Sources/TestUnitaires/TU_StubManager.cs b/Sources/TestUnitaires/TU_StubManager.cs index a714827..e09a4db 100644 --- a/Sources/TestUnitaires/TU_StubManager.cs +++ b/Sources/TestUnitaires/TU_StubManager.cs @@ -21,11 +21,6 @@ namespace TestUnitaires Artist artist = new Artist(test); StubManager stub = new StubManager(); InfoTitle info = new InfoTitle(test, "urstub.test", "infos", "desc", Genre.POP, 345); - /*Assert.NotEmpty(stub.Albums); - Assert.NotEmpty(stub.Artists); - Assert.NotEmpty(stub.InfoTitles); - Assert.NotEmpty(stub.Playlists); - Assert.NotEmpty(stub.CustomTitles);*/ stub.AddCustomTitle(t); stub.AddPlaylist(p); stub.AddAlbum(album); @@ -40,6 +35,7 @@ namespace TestUnitaires stub.RemoveAlbum(album); stub.RemoveCustomTitle(t); stub.RemoveInfoTitle(info); + stub.RemoveArtist(artist); Assert.DoesNotContain(t, stub.StubCustomTitle.CustomTitles); Assert.DoesNotContain(p, stub.StubPlaylist.Playlists); Assert.DoesNotContain(album, stub.StubAlbum.Albums); @@ -68,7 +64,7 @@ namespace TestUnitaires Assert.True(stub.ExistsPlaylistByName(test)); Assert.True(stub.ExistsInfoTitleByName(test)); Assert.True(stub.ExistsCustomTitleByName(test)); - /*stub.RemovePlaylist(p); + stub.RemovePlaylist(p); stub.RemoveAlbum(album); stub.RemoveCustomTitle(t); stub.RemoveInfoTitle(info); @@ -82,9 +78,173 @@ namespace TestUnitaires Assert.False(stub.ExistsArtistByName(test)); Assert.False(stub.ExistsPlaylistByName(test)); Assert.False(stub.ExistsInfoTitleByName(test)); - Assert.False(stub.ExistsCustomTitleByName(test));*/ + Assert.False(stub.ExistsCustomTitleByName(test)); + stub.SaveSerialization(); + stub.LoadSerialization(); + StubManager.AddFeat(info, new Artist("artist2")); + stub.AddCustomTitle(t); + var res = stub.GetCustomTitleByPath(t.Path); + Assert.Equal(t, res); + } + + [Fact] + public void TU_RemoveAddMultiple() + { + Artist a = new("artist"); + List albums = new() + { + new Album("album1", "img1.png", new Artist("artist"), "desc", "info"), + new Album("album2", "img2.png", new Artist("artist"), "desc", "info"), + new Album("album3", "img3.png", new Artist("artist"), "desc", "info") + }; + List artists = new() + { + new Artist("artist1"), + new Artist("artist2"), + new Artist("artist3") + }; + List infoTitles = new() + { + new InfoTitle("it1", "img1.png", "desc", "info", Genre.POP, 0), + new InfoTitle("it2", "img2.png", "desc", "info", Genre.POP, 0), + new InfoTitle("it3", "img3.png", "desc", "info", Genre.POP, 0) + }; + List customTitles = new() + { + new CustomTitle("ct1", "img1.png", "info", "path1.mp3"), + new CustomTitle("ct2", "img2.png", "info", "path2.mp3"), + new CustomTitle("ct3", "img3.png", "info", "path3.mp3") + }; + List playlists = new() + { + new Playlist("nom1", "desc", "img1.png"), + new Playlist("nom2", "desc", "img2.png"), + new Playlist("nom3", "desc", "img3.png") + }; + StubManager stubManager = new(); + stubManager.AddAlbums(albums); + stubManager.AddArtists(artists); + stubManager.AddInfoTitles(infoTitles); + stubManager.AddCustomTitles(customTitles); + stubManager.AddPlaylists(playlists); + + stubManager.RemoveAlbums(albums); + stubManager.RemoveArtists(artists); + stubManager.RemoveInfoTitles(infoTitles); + stubManager.RemoveCustomTitles(customTitles); + stubManager.RemovePlaylists(playlists); + + stubManager.AddArtist(a); + stubManager.RemoveArtist(a); + } + + [Theory] + [InlineData("nom", "url2.png", "artist", "desc", "info", Genre.POP, "path.mp3")] + [InlineData("nom", "url2.png", "", "desc", "info", Genre.POP, "path.mp3")] + [InlineData("nom", "url2.png", "artist", "", "info", Genre.POP, "path.mp3")] + [InlineData("nom", "url2.png", "artist", "desc", "", Genre.POP, "path.mp3")] + [InlineData("nom", "url2.png", "artist", "desc", "", Genre.POP, "")] + public void TU_Update(string nom, string url, string artistName, string description, string info, Genre genre, string path) + { + StubManager l = new(); + + Album album = new("album1", "img1.png", new Artist("artist1"), "desc", "info"); + Album album2 = new("album2", "img2.png", new Artist("artist1"), "desc", "info"); + + Artist artist = new("artist1"); + Artist artist2 = new("artist2"); + + InfoTitle infoTitle = new("it1", "img1.png", "desc", "info", Genre.RAP, 0); + InfoTitle infoTitle2 = new("it12", "img12.png", "desc", "info", Genre.RAP, 0); + + CustomTitle customTitle = new("nom1", "img1.png", "info", "path1.mp3"); + CustomTitle customTitle2 = new("nom2", "img2.png", "info", "path2.mp3"); + + Playlist playlist = new("nom1", "desc", "img1.png"); + Playlist playlist2 = new("nom2", "desc", "img2.png"); + + + l.AddAlbum(album); + l.AddAlbum(album2); + l.AddArtist(artist); + l.AddArtist(artist2); + l.AddInfoTitle(infoTitle); + l.AddInfoTitle(infoTitle2); + l.AddCustomTitle(customTitle); + l.AddCustomTitle(customTitle2); + l.AddPlaylist(playlist); + l.AddPlaylist(playlist2); + + l.UpdateAlbum(album, nom, url, new Artist(artistName), description, info); + l.UpdateAlbumByName(album2.Name, nom, url, new Artist(artistName), description, info); + + l.UpdateArtist(artist, nom); + l.UpdateArtistByName(artist2.Name, nom); + + l.UpdateInfoTitle(infoTitle, nom, url, info, new Artist(artistName), description, genre); + l.UpdateInfoTitleByName(infoTitle2.Name, nom, url, info, new Artist(artistName), description, genre); + + l.UpdateCustomTitle(customTitle, nom, url, info, path); + l.UpdateCustomTitleByPath(customTitle2.Path, nom, url, info, path); + + l.UpdatePlaylist(playlist, nom, description, url); + l.UpdatePlaylistByName(playlist2.Name, nom, description, url); + + List albums = new() + { + album, album2 + }; + List artists = new() + { + artist, artist2 + }; + List infoTitles = new() + { + infoTitle, infoTitle2 + }; + List customTitles = new() + { + customTitle, customTitle2 + }; + List playlists = new() + { + playlist, playlist2 + }; + foreach (Album a in albums) + { + Assert.Equal(nom, a.Name); + Assert.Equal(url, a.ImageURL); + Assert.Equal(artistName, a.Artist.Name); + Assert.Equal(description, a.Description); + Assert.Equal(info, a.Information); + } + foreach (Artist a in artists) + { + Assert.Equal(nom, a.Name); + } + foreach (InfoTitle it in infoTitles) + { + Assert.Equal(nom, it.Name); + Assert.Equal(url, it.ImageURL); + Assert.Equal(description, it.Description); + Assert.Equal(info, it.Information); + Assert.Equal(genre, it.Genre); + } + foreach (CustomTitle ct in customTitles) + { + Assert.Equal(nom, ct.Name); + Assert.Equal(url, ct.ImageURL); + Assert.Equal(info, ct.Information); + Assert.Equal(path, ct.Path); + } + foreach (Playlist p in playlists) + { + Assert.Equal(nom, p.Name); + Assert.Equal(description, p.Description); + Assert.Equal(url, p.ImageURL); + } } }