Merge branch 'master' of https://codefirst.iut.uca.fr/git/jeremy.mouyon/sae201_qwirkle
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
commit
da8f3e9274
@ -1,162 +0,0 @@
|
||||
// Pas de console.WriteLine() dans les classes
|
||||
|
||||
// Mot clé abstract dans la déclaration de la méthode et la déclaration de la classe pour faire une méthode virtuelle pure et une classe abstraite
|
||||
// => ON utilise pas normalement
|
||||
|
||||
using panier;
|
||||
|
||||
namespace Animaux // Héritage
|
||||
{
|
||||
public class Animal
|
||||
{
|
||||
public string Name {get; private set;}
|
||||
|
||||
public Animal(string name)
|
||||
{
|
||||
this.Name = name;
|
||||
}
|
||||
|
||||
public virtual string Crie()
|
||||
{
|
||||
return "GRR";
|
||||
}
|
||||
}
|
||||
|
||||
public class Chien : Animal
|
||||
{
|
||||
public Chien(string name) : base(name) {}
|
||||
|
||||
public override string Crie()
|
||||
{
|
||||
return $"{base.Crie()} + Wouf";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace panier // Interfaces
|
||||
{
|
||||
public class Article : IEqualTable<Article>
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public float Price { get; set; }
|
||||
|
||||
public Article(string name, float price)
|
||||
{
|
||||
Name = name;
|
||||
Price = price;
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if(ReferenceEquals(obj, null)) return false;
|
||||
if(ReferenceEquals(obj, this)) return true;
|
||||
if(obj.GetType() != typeof(Article)) return false;
|
||||
return Equals(obj as Article);
|
||||
}
|
||||
|
||||
public bool Equals(Article? other)
|
||||
{
|
||||
return other.Name.Equals(Name);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public class PanierDAchat
|
||||
{
|
||||
|
||||
/*
|
||||
1) Créer une collection privée readonly
|
||||
2) Créer une ReadOnlyCollection public avec un set privé
|
||||
3) On l'initialise dans le constructeur
|
||||
*/
|
||||
|
||||
public ReadOnlyCollection<Article> Articles { get; private set; };
|
||||
private List<Article> Articles = new List<Article>();
|
||||
|
||||
public ICalculPromo Promo {get; private set; }
|
||||
|
||||
public float TotalPrice()
|
||||
{
|
||||
return Promo.GetTotal(this);
|
||||
}
|
||||
|
||||
public void AddArticle(Article article)
|
||||
{
|
||||
if(!Articles.Contains(article))
|
||||
{
|
||||
Articles.Add(article);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface ICalculPromo
|
||||
{
|
||||
float GetTotal(PanierDAchat panier);
|
||||
}
|
||||
|
||||
public class SansPromotion : ICalculPromo
|
||||
{
|
||||
public float GetTotal(PanierDAchat panier)
|
||||
{
|
||||
return panier.Articles.Sum(a => a.Price);
|
||||
}
|
||||
}
|
||||
|
||||
public class SansTVA : ICalculPromo
|
||||
{
|
||||
public float GetTotal(PanierDAchat panier)
|
||||
{
|
||||
return panier.Articles.Sum(a => a.Price) * 0.8f;
|
||||
}
|
||||
}
|
||||
|
||||
public class TroisPourLePrixDeDeux : ICalculPromo
|
||||
{
|
||||
public float GetTotal(PanierDAchat panier)
|
||||
{
|
||||
var sortedArticles = panier.Articles.OrderByDescending(a => a.Price);
|
||||
int count = sortedArticles.count();
|
||||
sortedArticles.take((int)(count / 3) * 3).Sum(a => a.Price);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PanierDAchat p = new PanierDAchat();
|
||||
|
||||
p.Promo = new SansPromotion();
|
||||
p.Promo = new SansTVA();
|
||||
|
||||
|
||||
|
||||
namespace TestUnitairePanier
|
||||
{
|
||||
public class UnitTest1
|
||||
{
|
||||
[Fact]
|
||||
public void Test_AddArticle()
|
||||
{
|
||||
PanierDAchat p = new PanierDAchat();
|
||||
bool result = p.AddArticle(new Article("Jp", 0.4))
|
||||
Assert.True(result);
|
||||
}
|
||||
}
|
||||
|
||||
public class UnitTest2
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(true, "Jp", 0.5)]
|
||||
[InlineData(false, "Jp", -0.5)]
|
||||
public void Test_AddArticle(bool expectedResult, string name, float price)
|
||||
{
|
||||
PanierDAchat p = new PanierDAchat();
|
||||
bool result = p.AddArticle(new Article("Jp", 0.4))
|
||||
Assert.True(result);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
// DataBinding Baby !!
|
||||
|
||||
// Applcation se basant sur le site wtatennis.com
|
||||
|
||||
// class : Player, Place (Birth Places), Manager, IPersistanceManager
|
||||
// enum : Hand (lfet-handed or right-handed)
|
||||
|
||||
// Player.cs
|
||||
|
||||
public string FirstName
|
||||
{
|
||||
get => firstName;
|
||||
set
|
||||
{
|
||||
if(value == firstName) return;
|
||||
firstName = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private string firstName;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
<!-- Player Page -->
|
||||
|
||||
<Grid ColumnDefinition="*, *" RowDefinition="Auto, *">
|
||||
<Grid BackgroundColor="Blue">
|
||||
<VerticalStackLayout>
|
||||
<Label Text="Ranking"/>
|
||||
<Label Text="{Binding Rank}"/>
|
||||
<Label Text="Singles"/>
|
||||
</VerticalStackLayout>
|
||||
</Grid>
|
||||
<Grid BackgroundColor="Blue" Grid.Column="1">
|
||||
<VerticalStackLayout>
|
||||
<Entry Text="{Binding Player.FirstName, Mode=OneWayToSource}"/>
|
||||
<Label Text="{Binding Player.FirstName}, Mode=(OneWay, TwoWay, OneWayToSource)"/> <!-- Automatically subscribed to the source's property change -->
|
||||
<Label Text="{Binding Player.LastName}"/>
|
||||
<Label Text="{Binding Player.Height, StringFormat=\{0\}m}"/>
|
||||
<Button Text="=>" Clicked="ButtonClicked"/>
|
||||
</VerticalStackLayout>
|
||||
</Grid>
|
||||
<Image Grid.RowSpan="2" Source="{Binding Player.ImageLarge}"/>
|
||||
</Grid>
|
||||
|
||||
<!-- =================== -->
|
||||
|
||||
<!-- Players Page -->
|
||||
|
||||
<ListView ItemsSource="{Binding Players}">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ViewCell>
|
||||
<HorizontalStackLayout>
|
||||
<Label Text="{Binding FirstName}"/>
|
||||
<Label Text="{Binding LastName}"/>
|
||||
<Label Text="{Binding Points}"/>
|
||||
</HorizontalStackLayout>
|
||||
</ViewCell>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
|
||||
<!-- =================== -->
|
@ -1,80 +0,0 @@
|
||||
// Code Behind for PlayerPage
|
||||
|
||||
public partial class PlayerPage : ContentPage
|
||||
{
|
||||
public Manager Mgr { get; set; } = new Manager(new Stub());
|
||||
|
||||
public int PlayerIndex { get; set; } = 0;
|
||||
|
||||
public RankedPlayer RankedPlayer { get; set; }
|
||||
|
||||
public PlayerPage()
|
||||
{
|
||||
Mgr.LoadPlayers();
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
RankedPlayer = new RankedPlayer(Mgr.Players.ElementAt(2), Mgr);
|
||||
BindingContext = RankedPlayer;
|
||||
}
|
||||
|
||||
public void ButtonClicked(object sender, EventArgs e)
|
||||
{
|
||||
PlayerIndex++;
|
||||
RankedPlayer.Player = Mgr.Players.ElementAt(PlayerIndex); // Source's property changed, not the source itself
|
||||
}
|
||||
}
|
||||
|
||||
public class RankedPlayer : INotifyPropertyChanged
|
||||
{
|
||||
public RankedPlayer(Player player, Manager mgr)
|
||||
{
|
||||
Mgr = mgr;
|
||||
Player = player;
|
||||
}
|
||||
|
||||
private Manager Mgr { get; set; }
|
||||
|
||||
public Player thePlayer
|
||||
{
|
||||
get => thePlayer;
|
||||
set
|
||||
{
|
||||
if(value == thePlayer) return;
|
||||
thePlayer = value;
|
||||
OnPropertyChanged("ThePlayer");
|
||||
OnPropertyChanged(nameof(Rank));
|
||||
}
|
||||
}
|
||||
|
||||
private Player thePlayer;
|
||||
|
||||
public int Rank => Mgr.Players.OrderingByDescending(p => p.Points).ToList().IndexOf(Player) + 1;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
|
||||
// ===============================
|
||||
|
||||
// Code behind for Players Page
|
||||
|
||||
public partial class PlayersPage : ContentPage
|
||||
{
|
||||
public Manager Mgr { get; set; } = new Manager(new Stub());
|
||||
|
||||
public PlayersPage()
|
||||
{
|
||||
Mgr.LoadPlayers();
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
BindingContext = Mgr;
|
||||
}
|
||||
}
|
||||
|
||||
// ===============================
|
Loading…
Reference in new issue