feat : binding tag
continuous-integration/drone/push Build is failing Details

Popup_qui_marche_pas
Jade VAN BRABANDT 2 years ago
parent d3b2ce4b12
commit 000eecc4ea

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -53,28 +54,28 @@ namespace Model
} }
private string cover; private string cover;
public string[] Tags public ObservableCollection<string> Tags
{ {
get => tags; get => tags;
set set
{ {
if (value == null || value.Length != 3) return; if (value == null || value.Count != 3) return;
tags = value; tags = value;
} }
} }
private string[]? tags; private ObservableCollection<string> tags;
public event PropertyChangedEventHandler? PropertyChanged; public event PropertyChangedEventHandler? PropertyChanged;
public List<Review> Reviews { get; private init; } public List<Review> Reviews { get; private init; }
public Game(string name, string description, int year, string[] tags, string cover) public Game(string name, string description, int year, List<string> c_tags, string cover)
{ {
Name = name; Name = name;
Description = description; Description = description;
Year = year; Year = year;
tags = new string[3]; if (c_tags != null) tags = new ObservableCollection<string>(c_tags);
Tags = tags; else tags = new ObservableCollection<string>();
Cover= cover; Cover= cover;
Reviews = new List<Review>(); Reviews = new List<Review>();
} }
@ -102,9 +103,9 @@ namespace Model
{ {
description = newdesc; description = newdesc;
} }
public void TagChange(string[] newtag) public void TagChange(List<string> newtag)
{ {
tags=newtag; if (newtag != null && newtag.Count==3) tags = new ObservableCollection<string>(newtag);
} }
public void NameChange(string newname) public void NameChange(string newname)
{ {

@ -15,10 +15,10 @@ namespace Model
public Manager(IPersistance persistance) public Manager(IPersistance persistance)
{ {
_persistance = persistance; _persistance = persistance;
Games.Add(new("Elden Ring", "description", 2010, new string[3] { "1", "2", "3" }, "elden_ring.jpg")); Games.Add(new("Elden Ring", "description", 2010, new List<string> { "1","2","3"}, "elden_ring.jpg"));
Games.Add(new("Minecraft", "description", 2010, new string[3] { "1", "2", "3" }, "minecraft.jpeg")); Games.Add(new("Minecraft", "description", 2010, new List<string> { "1", "2", "3" }, "minecraft.jpeg"));
Games.Add(new("Celeste", "description", 2010, new string[3] { "1", "2", "3" }, "celeste.png")); Games.Add(new("Celeste", "description", 2010, new List<string> { "1", "2", "3" }, "celeste.png"));
Games.Add(new("GTA V", "description", 2010, new string[3] { "1", "2", "3" }, "gta_v.png")); Games.Add(new("GTA V", "description", 2010, new List<string> { "1", "2", "3" }, "gta_v.png"));
} }
} }
} }

@ -35,7 +35,7 @@
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Image Source="{Binding Cover}" Aspect="AspectFit" Margin="0,0,0,0" /> <Image Source="{Binding Cover}" Aspect="AspectFit" Margin="0,0,0,0" WidthRequest="600" HeightRequest="750"/>
<Label TextColor="White" FontAttributes="Bold" FontSize="30" Margin="5" FontFamily="arial" Text="{Binding Name}" Grid.Row="1" HorizontalTextAlignment="Center"/> <Label TextColor="White" FontAttributes="Bold" FontSize="30" Margin="5" FontFamily="arial" Text="{Binding Name}" Grid.Row="1" HorizontalTextAlignment="Center"/>
<Grid Grid.Row="2"> <Grid Grid.Row="2">
@ -52,9 +52,13 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Label TextColor="White" FontSize="15" Margin="5" FontFamily="arial" Text="Tag :" Grid.Row="0"/> <Label TextColor="White" FontSize="15" Margin="5" FontFamily="arial" Text="Tag :" Grid.Row="0"/>
<Label TextColor="White" FontSize="15" Margin="5" FontFamily="arial" Text=" - Game of the year" Grid.Row="1"/> <CollectionView ItemsSource="{Binding Tags}" SelectionMode="Single" ItemsLayout="HorizontalGrid, 3" Grid.Row="1" Grid.Column="0">
<Label TextColor="White" FontSize="15" Margin="5" FontFamily="arial" Text=" - RPG" Grid.Row="2"/> <CollectionView.ItemTemplate>
<Label TextColor="White" FontSize="15" Margin="5" FontFamily="arial" Text=" - Souls" Grid.Row="3"/> <DataTemplate>
<Label TextColor="White" FontSize="15" Margin="5" FontFamily="arial" Text="{Binding}"/>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</Grid> </Grid>
<Label TextColor="White" FontSize="15" Margin="5" FontFamily="arial" Text="{Binding Year}" Grid.Column="2" HorizontalTextAlignment="End" VerticalTextAlignment="End"/> <Label TextColor="White" FontSize="15" Margin="5" FontFamily="arial" Text="{Binding Year}" Grid.Column="2" HorizontalTextAlignment="End" VerticalTextAlignment="End"/>
</Grid> </Grid>

@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test
{
internal class TestAdmin
{
}
}

@ -7,73 +7,74 @@ namespace Test
[Fact] [Fact]
public void Constructeur() public void Constructeur()
{ {
string[] tags = { "1", "2", "3"};
Game game = new("game", "description", 2012, tags, "cover"); Game game = new("game", "description", 2012, new List<String> {"1","2","3"}, "cover");
Assert.NotNull(game); Assert.NotNull(game);
} }
[Fact] [Fact]
public void Name() public void Name()
{ {
string[] tags = { "1", "2", "3" };
Game game = new("", "description", 2012, tags, "cover"); Game game = new("", "description", 2012, new List<String> {"1","2","3"}, "cover");
Assert.Null(game.Name); Assert.Null(game.Name);
Game game2 = new(null, "description", 2012, tags, "cover"); Game game2 = new(null, "description", 2012, new List<String> {"1","2","3"}, "cover");
Assert.Null(game2.Name); Assert.Null(game2.Name);
Game game3 = new("good", "description", 2012, tags, "cover"); Game game3 = new("good", "description", 2012, new List<String> {"1","2","3"}, "cover");
Assert.Equal("good", game3.Name); Assert.Equal("good", game3.Name);
} }
[Fact] [Fact]
public void Description() public void Description()
{ {
string[] tags = { "1", "2", "3" };
Game game = new("name", "", 2012, tags, "cover"); Game game = new("name", "", 2012, new List<String> {"1","2","3"}, "cover");
Assert.Null(game.Description); Assert.Null(game.Description);
Game game2 = new("name", null, 2012, tags, "cover"); Game game2 = new("name", null, 2012, new List<String> {"1","2","3"}, "cover");
Assert.Null(game2.Description); Assert.Null(game2.Description);
Game game3 = new("name", "good", 2012, tags, "cover"); Game game3 = new("name", "good", 2012, new List<String> {"1","2","3"}, "cover");
Assert.Equal("good", game3.Description); Assert.Equal("good", game3.Description);
} }
[Fact] [Fact]
public void Year() public void Year()
{ {
string[] tags = { "1", "2", "3" };
Game game = new("name", "description", 1111, tags, "cover"); Game game = new("name", "description", 1111, new List<String> {"1","2","3"}, "cover");
Assert.Equal(0, game.Year); Assert.Equal(0, game.Year);
Game game2 = new("name", "description", 9999, tags, "cover"); Game game2 = new("name", "description", 9999, new List<String> {"1","2","3"}, "cover");
Assert.Equal(0, game2.Year); Assert.Equal(0, game2.Year);
Game game3 = new("name", "description", 2012, tags, "cover"); Game game3 = new("name", "description", 2012, new List<String> {"1","2","3"}, "cover");
Assert.Equal(2012, game3.Year); Assert.Equal(2012, game3.Year);
} }
[Fact] [Fact]
public void Tags() public void Tags()
{ {
string[] tags = { "1", "2" }, tags2 = { "1", "2", "3" }; Game game = new("name", "description", 2012, new List<String> {"1","2","3"}, "cover");
Game game = new("name", "description", 2012, tags, "cover"); Assert.NotNull(game.Tags);
Assert.All(game.Tags, Assert.Null);
Game game2 = new("name", "description", 2012, null, "cover"); Game game2 = new("name", "description", 2012, null, "cover");
Assert.All(game.Tags, Assert.Null); Assert.NotNull(game2.Tags);
Assert.Empty(game2.Tags);
Game game3 = new("name", "description", 2012, tags2, "cover"); Game game3 = new("name", "description", 2012, new List<String> {"1","2"}, "cover");
Assert.NotNull(game3.Tags); Assert.NotNull(game3.Tags);
Assert.Empty(game3.Tags);
} }
[Fact] [Fact]
public void AddReview() public void AddReview()
{ {
Review r1 = new(2.5f, "cool"), r2 = new(4, "tres cool"), r3 = new(1, "pas cool"); Review r1 = new(2.5f, "cool"), r2 = new(4, "tres cool"), r3 = new(1, "pas cool");
string[] tags = { "1", "2", "3" };
Game game = new("name", "description", 2012, tags, "cover"); Game game = new("name", "description", 2012, new List<String> {"1","2","3"}, "cover");
game.AddReview(r1); game.AddReview(r1);
game.AddReview(r2); game.AddReview(r2);
@ -86,8 +87,8 @@ namespace Test
public void RemoveReview() public void RemoveReview()
{ {
Review r1 = new(2.5f, "cool"), r2 = new(4, "tres cool"), r3 = new(1, "pas cool"); Review r1 = new(2.5f, "cool"), r2 = new(4, "tres cool"), r3 = new(1, "pas cool");
string[] tags = { "1", "2", "3" };
Game game = new("name", "description", 2012, tags, "cover"); Game game = new("name", "description", 2012, new List<String> {"1","2","3"}, "cover");
game.AddReview(r1); game.AddReview(r1);
game.AddReview(r2); game.AddReview(r2);
@ -100,8 +101,8 @@ namespace Test
[Fact] [Fact]
public void ChangeName() public void ChangeName()
{ {
string[] tags = { "1", "2", "3" };
Game game = new("name", "description", 2012, tags, "cover"); Game game = new("name", "description", 2012, new List<String> {"1","2","3"}, "cover");
game.NameChange("newName"); game.NameChange("newName");
Assert.Equal("newName", game.Name); Assert.Equal("newName", game.Name);
@ -110,8 +111,8 @@ namespace Test
[Fact] [Fact]
public void ChangeDescription() public void ChangeDescription()
{ {
string[] tags = { "1", "2", "3" };
Game game = new("name", "description", 2012, tags, "cover"); Game game = new("name", "description", 2012, new List<String> {"1","2","3"}, "cover");
game.DescChange("newDesc"); game.DescChange("newDesc");
Assert.Equal("newDesc", game.Description); Assert.Equal("newDesc", game.Description);
@ -120,8 +121,8 @@ namespace Test
[Fact] [Fact]
public void ChangeYear() public void ChangeYear()
{ {
string[] tags = { "1", "2", "3" };
Game game = new("name", "description", 2012, tags, "cover"); Game game = new("name", "description", 2012, new List<String> {"1","2","3"}, "cover");
game.YearChange(2020); game.YearChange(2020);
Assert.Equal(2020, game.Year); Assert.Equal(2020, game.Year);
@ -130,19 +131,18 @@ namespace Test
[Fact] [Fact]
public void ChangeTags() public void ChangeTags()
{ {
string[] tags = { "1", "2", "3" }, tags2 = { "2", "3" }; Game game = new("name", "description", 2012, new List<String> { "1", "2", "3" }, "cover");
Game game = new("name", "description", 2012, tags, "cover");
game.NameChange("newName"); game.NameChange("newName");
game.TagChange(tags2); game.TagChange(new List<String> { "1", "2" });
Assert.DoesNotContain("1", game.Tags); Assert.Empty(game.Tags);
} }
[Fact] [Fact]
public void Average() public void Average()
{ {
Review r1 = new(2.5f, "cool"), r2 = new(4, "tres cool"), r3 = new(1, "pas cool"); Review r1 = new(2.5f, "cool"), r2 = new(4, "tres cool"), r3 = new(1, "pas cool");
string[] tags = { "1", "2", "3" };
Game game = new("name", "description", 2012, tags, "cover"); Game game = new("name", "description", 2012, new List<String> {"1","2","3"}, "cover");
game.AddReview(r1); game.AddReview(r1);
game.AddReview(r2); game.AddReview(r2);

@ -66,7 +66,7 @@ namespace Test
Assert.NotNull(user); Assert.NotNull(user);
Assert.Empty(user.Followed_Games); Assert.Empty(user.Followed_Games);
Game game = new("name", "description", 2012, new string[] { "1", "2", "3" }, "cover"); Game game = new("name", "description", 2012, new List<String> { "1", "2", "3" }, "cover");
Assert.NotNull(game); Assert.NotNull(game);
user.FollowAGame(game); user.FollowAGame(game);
Assert.Single(user.Followed_Games); Assert.Single(user.Followed_Games);

Loading…
Cancel
Save