From 5aad8b81b5cc2417c5c36df265a121ca170a7f84 Mon Sep 17 00:00:00 2001 From: Jade_VAN_BRABANDT Date: Tue, 6 Jun 2023 10:12:46 +0200 Subject: [PATCH] Fix : Croisade contre les nullables inutiles; update Researched Game. --- Sources/Stim.Model/Game.cs | 28 ++++++++++++++-------------- Sources/Stim.Model/Review.cs | 2 +- Sources/Stim.Model/User.cs | 18 +++++++++--------- Sources/Stim/MainPage.xaml.cs | 5 +++++ Sources/TestProject1/TestGame.cs | 6 +++--- Sources/TestProject1/TestUser.cs | 2 +- 6 files changed, 33 insertions(+), 28 deletions(-) diff --git a/Sources/Stim.Model/Game.cs b/Sources/Stim.Model/Game.cs index 144f429..7ef01fb 100644 --- a/Sources/Stim.Model/Game.cs +++ b/Sources/Stim.Model/Game.cs @@ -12,7 +12,7 @@ namespace Model [DataMember] public string Name { - get => name; + get => name ?? "Default"; private set { if (string.IsNullOrWhiteSpace(value)) name="Default"; @@ -23,12 +23,12 @@ namespace Model } } } - private string? name; + private string name; [DataMember] - public string? Description + public string Description { - get => description; + get => description ?? "Pas de description"; private set { if (string.IsNullOrWhiteSpace(value)) return; @@ -39,7 +39,7 @@ namespace Model } } } - private string? description; + private string description; [DataMember] public int Year @@ -58,9 +58,9 @@ namespace Model private int year; [DataMember] - public string? Cover + public string Cover { - get => cover; + get => cover ?? "no_cover.png"; private set { if (string.IsNullOrWhiteSpace(value)) cover="no_cover.png"; @@ -71,7 +71,7 @@ namespace Model } } } - private string? cover; + private string cover; [DataMember] public ObservableCollection Tags @@ -95,13 +95,13 @@ namespace Model public double Average => AverageCalc(); public double AverageCalc() { - if (Reviews.Count > 0) return Math.Round((double)Reviews.Select(review => review.Rate).Average(), 1); // FAUT FIX POUR QUAND Y'A PAS DE REVIEWS + if (Reviews.Count > 0) return Math.Round((double)Reviews.Select(review => review.Rate).Average(), 1); else return 0; } [DataMember] - public string? Lien { - get => lien; + public string Lien { + get => lien ?? "Pas de lien"; private set { if (string.IsNullOrWhiteSpace(value)) return; @@ -112,20 +112,20 @@ namespace Model } } } - private string? lien; + private string lien; public Game(string name, string description, int year, List c_tags, string cover, string c_lien) { if (string.IsNullOrWhiteSpace(name)) Name = "Default"; else Name = name; - if (string.IsNullOrWhiteSpace(description)) Description = "Default"; + if (string.IsNullOrWhiteSpace(description)) Description = "Pas de description"; else Description = description; Year = year; if (c_tags is not null) tags = new ObservableCollection(c_tags); else tags = new ObservableCollection(); if (string.IsNullOrWhiteSpace(cover)) Cover = "no_cover.png"; else Cover = cover; - if (string.IsNullOrWhiteSpace(c_lien)) Lien = "Default"; + if (string.IsNullOrWhiteSpace(c_lien)) Lien = "Pas de lien"; else Lien = c_lien; Reviews = new List(); } diff --git a/Sources/Stim.Model/Review.cs b/Sources/Stim.Model/Review.cs index 486fe47..f898001 100644 --- a/Sources/Stim.Model/Review.cs +++ b/Sources/Stim.Model/Review.cs @@ -30,7 +30,7 @@ namespace Model private string? text; [DataMember] - public string? AuthorName { get; set; } + public string AuthorName { get; set; } public Review(string username, float rate, string text) { diff --git a/Sources/Stim.Model/User.cs b/Sources/Stim.Model/User.cs index 6ac5f94..e26b0fc 100644 --- a/Sources/Stim.Model/User.cs +++ b/Sources/Stim.Model/User.cs @@ -24,14 +24,14 @@ namespace Model } } } - private string? username; + private string username; [DataMember] - public string? Biographie + public string Biographie { - get => biographie; + get => biographie ?? "Pas de biographie"; private set { - if (string.IsNullOrWhiteSpace(value)) biographie = "Default"; + if (string.IsNullOrWhiteSpace(value)) biographie = "Pas de biographie"; else { biographie = value; @@ -39,9 +39,9 @@ namespace Model } } } - private string? biographie; + private string biographie; [DataMember] - public string? Email + public string Email { get => email; private set @@ -55,9 +55,9 @@ namespace Model else email = "Default"; } } - private string? email; + private string email; [DataMember] - public string? Password + public string Password { get => password; private set @@ -71,7 +71,7 @@ namespace Model } } } - private string? password; + private string password; public event PropertyChangedEventHandler? PropertyChanged; diff --git a/Sources/Stim/MainPage.xaml.cs b/Sources/Stim/MainPage.xaml.cs index bc19e83..8ebdfa7 100644 --- a/Sources/Stim/MainPage.xaml.cs +++ b/Sources/Stim/MainPage.xaml.cs @@ -36,4 +36,9 @@ public partial class MainPage : ContentPage BindingContext=((App)App.Current).Manager.FilterGames(GameText, Tag1Text, Tag2Text); } + protected override void OnAppearing() + { + SearchBar_GameChanged(null,null); + base.OnAppearing(); + } } diff --git a/Sources/TestProject1/TestGame.cs b/Sources/TestProject1/TestGame.cs index 10c013b..2d81b34 100644 --- a/Sources/TestProject1/TestGame.cs +++ b/Sources/TestProject1/TestGame.cs @@ -40,7 +40,7 @@ namespace Test Assert.False(game.Description == ""); Game game2 = new("name", null, 2012, new List {"1","2","3"}, "cover", "www.link.com"); - Assert.True(game2.Description=="Default"); + Assert.True(game2.Description=="Pas de description"); Game game3 = new("name", "good", 2012, new List {"1","2","3"}, "cover", "www.link.com"); Assert.Equal("good", game3.Description); @@ -82,9 +82,9 @@ namespace Test Game game = new("name", "description", 2012, new List { "1", "2", "3" }, "cover", "www.link.com"); Assert.NotNull(game.Lien); Game game2 = new("name", "description", 2012, new List { "1", "2", "3" }, "cover", null); - Assert.Equal("Default", game2.Lien); + Assert.Equal("Pas de lien", game2.Lien); Game game3 = new("name", "description", 2012, new List { "1", "2", "3" }, "cover", ""); - Assert.Equal("Default", game3.Lien); + Assert.Equal("Pas de lien", game3.Lien); } [Fact] diff --git a/Sources/TestProject1/TestUser.cs b/Sources/TestProject1/TestUser.cs index 9f13231..6b75a09 100644 --- a/Sources/TestProject1/TestUser.cs +++ b/Sources/TestProject1/TestUser.cs @@ -25,7 +25,7 @@ namespace Test public void Biographie() { User user = new(null, "username", "", "adresse.mail@gmail.com", "Azerty123*"); - Assert.Equal("Default", user.Biographie); + Assert.Equal("Pas de biographie", user.Biographie); User user2 = new(null, "username", null, "adresse.mail@gmail.com", "Azerty123*"); Assert.Equal("Default", user2.Biographie);