diff --git a/Sources/Stim/App.xaml b/Sources/Stim/App.xaml index 9815e5e..80877b5 100644 --- a/Sources/Stim/App.xaml +++ b/Sources/Stim/App.xaml @@ -51,10 +51,14 @@ - - + + - diff --git a/Sources/Stim/DetailledPage.xaml.cs b/Sources/Stim/DetailledPage.xaml.cs index d3e6655..c04f1a3 100644 --- a/Sources/Stim/DetailledPage.xaml.cs +++ b/Sources/Stim/DetailledPage.xaml.cs @@ -48,7 +48,20 @@ public partial class DetailledPage : ContentPage private async void AddFollow(object sender, EventArgs e) { - await this.ShowPopupAsync(new MessagePopup("Jeu ajouté dans les suivis !")); - ((App)App.Current).Manager.CurrentUser.FollowAGame(currentGame); + bool flag = false; + foreach (Game game in ((App)App.Current).Manager.CurrentUser.Followed_Games) + { + if (game == null) throw new Exception(); + else if (currentGame == game) { flag = true; break; } + } + if (!flag) + { + await this.ShowPopupAsync(new MessagePopup("Jeu ajouté dans les suivis !")); + ((App)App.Current).Manager.CurrentUser.FollowAGame(currentGame); + } + else + { + await this.ShowPopupAsync(new MessagePopup("Jeu déjà suivis !")); + } } } \ No newline at end of file diff --git a/Sources/Stim/FollowPage.xaml b/Sources/Stim/FollowPage.xaml index c249f1a..beaa911 100644 --- a/Sources/Stim/FollowPage.xaml +++ b/Sources/Stim/FollowPage.xaml @@ -20,7 +20,6 @@ - \ No newline at end of file diff --git a/Sources/TestProject1/TestManager.cs b/Sources/TestProject1/TestManager.cs index fc12296..c93279f 100644 --- a/Sources/TestProject1/TestManager.cs +++ b/Sources/TestProject1/TestManager.cs @@ -36,5 +36,103 @@ namespace Test Assert.Contains(user, manager.Users); } + [Fact] + public void GetSetCurrentUser() + { + IPersistance persistance = new Stub(); + Manager manager = new(persistance); + manager.CurrentUser = new("", "username", "", "gmail@gmail.com", "Azerty123*"); + Assert.Equal(new("", "username", "", "gmail@gmail.com", "Azerty123*"), manager.CurrentUser); + User user = manager.CurrentUser; + Assert.Equal(manager.CurrentUser, user); + } + [Fact] + public void GetSetSelectedGame() + { + IPersistance persistance = new Stub(); + Manager manager = new(persistance); + manager.SelectedGame = new("game", "description", 2012, new List { "1", "2", "3" }, "cover", "www.link.com"); + Assert.Equal(new("game", "description", 2012, new List { "1", "2", "3" }, "cover", "www.link.com"), manager.SelectedGame); + Game game = manager.SelectedGame; + Assert.Equal(manager.SelectedGame, game); + } + [Fact] + public void FilterGames() + { + IPersistance persistance = new Stub(); + Manager manager = new(persistance); + + var compList = manager.FilterGames(null, null, null); + var list = manager.FilterGames(null,null,null); + Assert.Equal(list,manager.GameList); + + List compListAsList = compList.ToList(); + compListAsList.Clear(); + compList = compListAsList; + list = manager.FilterGames("Elden Ring",null, null); + foreach (var game in manager.GameList) + { + if (game.Name=="Elden Ring") + { + compListAsList = compList.ToList(); + compListAsList.Add(game); + compList = compListAsList; + break; + } + } + Assert.Equal(compList, list); + + compListAsList = compList.ToList(); + compListAsList.Clear(); + compList = compListAsList; + list = manager.FilterGames(null, "Action", null); + foreach (var game in manager.GameList) + { + if (game.Tags.Any(tag=>tag == "Action")) + { + compListAsList = compList.ToList(); + compListAsList.Add(game); + compList = compListAsList; + break; + } + } + Assert.Equal(compList, list); + + list = manager.FilterGames(null,null, "Action"); + Assert.Equal(compList, list); + + compListAsList = compList.ToList(); + compListAsList.Clear(); + compList = compListAsList; list = manager.FilterGames("Elden Ring", "Action", null); + foreach (var game in manager.GameList) + { + if (game.Name=="Elden Ring" && game.Tags.Any(tag => tag == "Action")) + { + compListAsList = compList.ToList(); + compListAsList.Add(game); + compList = compListAsList; + break; + } + } + Assert.Equal(compList, list); + + list = manager.FilterGames("Elden Ring", null, "Action"); + Assert.Equal(compList, list); + + compListAsList = compList.ToList(); + compListAsList.Clear(); + compList = compListAsList; list = manager.FilterGames("Elden Ring", "Action", "Solo"); + foreach (var game in manager.GameList) + { + if (game.Name=="Elden Ring" && game.Tags.Any(tag => tag == "Action" && game.Tags.Any(tag => tag == "Solo"))) + { + compListAsList = compList.ToList(); + compListAsList.Add(game); + compList = compListAsList; + break; + } + } + Assert.Equal(compList, list); + } } }