From 113a5232c1ae56d3faf2dcaa952684df252af613 Mon Sep 17 00:00:00 2001 From: takemyoxygen Date: Sun, 23 Nov 2014 18:52:39 +0100 Subject: [PATCH 1/6] ignored sln.ide folder --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9a40f6f..9900991 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,5 @@ obj/ _ReSharper*/ [Tt]est[Rr]esult* *.nupkg -packages/ \ No newline at end of file +packages/ +TrelloNet.sln.ide \ No newline at end of file From b86e73c17aef7009711450c3d3ffdf8d89959546 Mon Sep 17 00:00:00 2001 From: takemyoxygen Date: Sun, 23 Nov 2014 18:53:27 +0100 Subject: [PATCH 2/6] Added missing colors --- TrelloNet/Cards/Color.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/TrelloNet/Cards/Color.cs b/TrelloNet/Cards/Color.cs index c6a312c..48d481c 100644 --- a/TrelloNet/Cards/Color.cs +++ b/TrelloNet/Cards/Color.cs @@ -7,6 +7,10 @@ public enum Color Orange, Red, Purple, - Blue + Blue, + Pink, + Sky, + Lime, + Black } } \ No newline at end of file From f6fb2eba169fad4a46a790d817b5a90c82c9f55f Mon Sep 17 00:00:00 2001 From: takemyoxygen Date: Sun, 23 Nov 2014 19:00:12 +0100 Subject: [PATCH 3/6] Fixed several failing unit tests --- TrelloNet.Tests/BoardTests.cs | 6 +++++- TrelloNet.Tests/SearchTests.cs | 10 +++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/TrelloNet.Tests/BoardTests.cs b/TrelloNet.Tests/BoardTests.cs index bfdbf93..9d5526f 100644 --- a/TrelloNet.Tests/BoardTests.cs +++ b/TrelloNet.Tests/BoardTests.cs @@ -372,7 +372,7 @@ private static ExpectedObject CreateExpectedWelcomeBoard() Name = "Welcome Board", Desc = "A test description", IdOrganization = Constants.TestOrganizationId, - Pinned = true, + Pinned = false, Url = "https://trello.com/b/J9JUdoYV/welcome-board", Id = Constants.WelcomeBoardId, Prefs = new BoardPreferences @@ -395,6 +395,10 @@ private static Dictionary CreateExpectedWelcomeBoardLabels() { Color.Orange, "" }, { Color.Green, "label name" }, { Color.Blue, "" }, + { Color.Pink, "" }, + { Color.Sky, "" }, + { Color.Lime, "" }, + { Color.Black, "" }, }; } } diff --git a/TrelloNet.Tests/SearchTests.cs b/TrelloNet.Tests/SearchTests.cs index bc566cc..d01698e 100644 --- a/TrelloNet.Tests/SearchTests.cs +++ b/TrelloNet.Tests/SearchTests.cs @@ -50,7 +50,7 @@ public void Search_WithTestQuery_ReturnsCorrectBoard() Name = "Welcome Board", Desc = "A test description", IdOrganization = Constants.TestOrganizationId, - Pinned = true, + Pinned = false, Url = "https://trello.com/b/J9JUdoYV/welcome-board", Id = Constants.WelcomeBoardId, Prefs = new BoardPreferences @@ -62,12 +62,16 @@ public void Search_WithTestQuery_ReturnsCorrectBoard() }, LabelNames = new Dictionary { + { Color.Green, "label name" }, { Color.Yellow, "" }, + { Color.Orange, "" }, { Color.Red, "" }, { Color.Purple, "" }, - { Color.Orange, "" }, - { Color.Green, "label name" }, { Color.Blue, "" }, + { Color.Pink, "" }, + { Color.Sky, "" }, + { Color.Lime, "" }, + { Color.Black, "" }, } }.ToExpectedObject(); From 8cd10d871a9ed4c95785b3b05e54c9dc71a8d798 Mon Sep 17 00:00:00 2001 From: takemyoxygen Date: Sun, 23 Nov 2014 19:47:38 +0100 Subject: [PATCH 4/6] Introduced Color class instead of enumeration --- .../Internal/BoardsChangeLabelNameRequest.cs | 2 +- TrelloNet/Boards/Internal/ColorConverter.cs | 32 +++++++++ TrelloNet/Cards/Color.cs | 69 ++++++++++++++++--- .../Cards/Internal/CardsAddLabelRequest.cs | 2 +- .../Cards/Internal/CardsRemoveLabelRequest.cs | 2 +- .../Cards/Internal/CardsUpdateRequest.cs | 2 +- TrelloNet/TrelloNet.csproj | 1 + 7 files changed, 95 insertions(+), 15 deletions(-) create mode 100644 TrelloNet/Boards/Internal/ColorConverter.cs diff --git a/TrelloNet/Boards/Internal/BoardsChangeLabelNameRequest.cs b/TrelloNet/Boards/Internal/BoardsChangeLabelNameRequest.cs index 56c85bd..15b59ad 100644 --- a/TrelloNet/Boards/Internal/BoardsChangeLabelNameRequest.cs +++ b/TrelloNet/Boards/Internal/BoardsChangeLabelNameRequest.cs @@ -7,7 +7,7 @@ internal class BoardsChangeLabelNameRequest : BoardsRequest public BoardsChangeLabelNameRequest(IBoardId board, Color color, string name) : base(board, "labelNames/{color}", Method.PUT) { - AddParameter("color", color.ToTrelloString(), ParameterType.UrlSegment); + AddParameter("color", color.ColorName, ParameterType.UrlSegment); this.AddValue(name ?? ""); } } diff --git a/TrelloNet/Boards/Internal/ColorConverter.cs b/TrelloNet/Boards/Internal/ColorConverter.cs new file mode 100644 index 0000000..5ed32e7 --- /dev/null +++ b/TrelloNet/Boards/Internal/ColorConverter.cs @@ -0,0 +1,32 @@ +using System; +using System.ComponentModel; +using System.Globalization; + +namespace TrelloNet.Internal +{ + internal class ColorConverter : TypeConverter + { + public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + { + return sourceType == typeof (string); + } + + public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + { + if (value == null) return null; + + var colorName = value as string; + if (colorName != null) + { + return new Color(colorName); + } + else + { + throw new NotSupportedException( + string.Format( + "Conversion from {0} to Color is not supported", + value.GetType().Name)); + } + } + } +} \ No newline at end of file diff --git a/TrelloNet/Cards/Color.cs b/TrelloNet/Cards/Color.cs index 48d481c..f19fba7 100644 --- a/TrelloNet/Cards/Color.cs +++ b/TrelloNet/Cards/Color.cs @@ -1,16 +1,63 @@ +using System; +using System.ComponentModel; +using TrelloNet.Internal; + namespace TrelloNet { - public enum Color + [TypeConverter(typeof(ColorConverter))] + public class Color { - Green, - Yellow, - Orange, - Red, - Purple, - Blue, - Pink, - Sky, - Lime, - Black + public static readonly Color Green = new Color("green"); + public static readonly Color Yellow = new Color("yellow"); + public static readonly Color Orange = new Color("orange"); + public static readonly Color Red = new Color("red"); + public static readonly Color Purple = new Color("purple"); + public static readonly Color Blue = new Color("blue"); + public static readonly Color Pink = new Color("pink"); + public static readonly Color Sky = new Color("sky"); + public static readonly Color Lime = new Color("lime"); + public static readonly Color Black = new Color("black"); + + public string ColorName { get; private set; } + + public Color(string colorName) + { + if (colorName == null) throw new ArgumentNullException("colorName"); + + ColorName = colorName.ToLower(); + } + + public override string ToString() + { + return ColorName; + } + + protected bool Equals(Color other) + { + return string.Equals(ColorName, other.ColorName); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != GetType()) return false; + return Equals((Color)obj); + } + + public override int GetHashCode() + { + return (ColorName != null ? ColorName.GetHashCode() : 0); + } + + public static bool operator ==(Color left, Color right) + { + return Equals(left, right); + } + + public static bool operator !=(Color left, Color right) + { + return !Equals(left, right); + } } } \ No newline at end of file diff --git a/TrelloNet/Cards/Internal/CardsAddLabelRequest.cs b/TrelloNet/Cards/Internal/CardsAddLabelRequest.cs index 486933a..96df4ef 100644 --- a/TrelloNet/Cards/Internal/CardsAddLabelRequest.cs +++ b/TrelloNet/Cards/Internal/CardsAddLabelRequest.cs @@ -7,7 +7,7 @@ internal class CardsAddLabelRequest : CardsRequest public CardsAddLabelRequest(ICardId card, Color color) : base(card, "labels", Method.POST) { - this.AddValue(color.ToTrelloString()); + this.AddValue(color.ColorName); } } } \ No newline at end of file diff --git a/TrelloNet/Cards/Internal/CardsRemoveLabelRequest.cs b/TrelloNet/Cards/Internal/CardsRemoveLabelRequest.cs index 270cc18..bde37f9 100644 --- a/TrelloNet/Cards/Internal/CardsRemoveLabelRequest.cs +++ b/TrelloNet/Cards/Internal/CardsRemoveLabelRequest.cs @@ -7,7 +7,7 @@ internal class CardsRemoveLabelRequest : CardsRequest public CardsRemoveLabelRequest(ICardId card, Color color) : base(card, "labels/{color}", Method.DELETE) { - AddParameter("color", color.ToTrelloString(), ParameterType.UrlSegment); + AddParameter("color", color.ColorName, ParameterType.UrlSegment); } } } \ No newline at end of file diff --git a/TrelloNet/Cards/Internal/CardsUpdateRequest.cs b/TrelloNet/Cards/Internal/CardsUpdateRequest.cs index d1f20f4..b06859f 100644 --- a/TrelloNet/Cards/Internal/CardsUpdateRequest.cs +++ b/TrelloNet/Cards/Internal/CardsUpdateRequest.cs @@ -19,7 +19,7 @@ public CardsUpdateRequest(IUpdatableCard card) AddParameter("closed", card.Closed.ToTrelloString()); AddParameter("idList", card.IdList); AddParameter("due", card.Due == null ? null : new DateTimeOffset(card.Due.Value).ToString(CultureInfo.InvariantCulture)); - AddParameter("labels", string.Join(",", card.LabelColors.Select(c => c.ToTrelloString()))); + AddParameter("labels", string.Join(",", card.LabelColors.Select(c => c.ColorName))); } } } \ No newline at end of file diff --git a/TrelloNet/TrelloNet.csproj b/TrelloNet/TrelloNet.csproj index 9f99ff8..5f3921a 100644 --- a/TrelloNet/TrelloNet.csproj +++ b/TrelloNet/TrelloNet.csproj @@ -123,6 +123,7 @@ + From ac796bd93b4827b701479c7478cd3fa4a16ff70f Mon Sep 17 00:00:00 2001 From: takemyoxygen Date: Sun, 23 Nov 2014 19:58:22 +0100 Subject: [PATCH 5/6] Added some comments --- TrelloNet/Boards/Internal/ColorConverter.cs | 1 + TrelloNet/Cards/Color.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/TrelloNet/Boards/Internal/ColorConverter.cs b/TrelloNet/Boards/Internal/ColorConverter.cs index 5ed32e7..82bfc21 100644 --- a/TrelloNet/Boards/Internal/ColorConverter.cs +++ b/TrelloNet/Boards/Internal/ColorConverter.cs @@ -13,6 +13,7 @@ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceT public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { + // color can be null in uncolored label attached to a card. if (value == null) return null; var colorName = value as string; diff --git a/TrelloNet/Cards/Color.cs b/TrelloNet/Cards/Color.cs index f19fba7..8f8af5c 100644 --- a/TrelloNet/Cards/Color.cs +++ b/TrelloNet/Cards/Color.cs @@ -7,6 +7,7 @@ namespace TrelloNet [TypeConverter(typeof(ColorConverter))] public class Color { + // Known colors: public static readonly Color Green = new Color("green"); public static readonly Color Yellow = new Color("yellow"); public static readonly Color Orange = new Color("orange"); From 6a3b259fcc6ba749ad80d2fadab4693e0a92e57f Mon Sep 17 00:00:00 2001 From: takemyoxygen Date: Sun, 23 Nov 2014 20:57:47 +0100 Subject: [PATCH 6/6] Added null-checks in requests to ensure Color is not null. --- TrelloNet/Boards/Internal/BoardsChangeLabelNameRequest.cs | 2 ++ TrelloNet/Cards/Card.cs | 2 +- TrelloNet/Cards/Internal/CardsAddLabelRequest.cs | 2 ++ TrelloNet/Cards/Internal/CardsRemoveLabelRequest.cs | 2 ++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/TrelloNet/Boards/Internal/BoardsChangeLabelNameRequest.cs b/TrelloNet/Boards/Internal/BoardsChangeLabelNameRequest.cs index 15b59ad..37df939 100644 --- a/TrelloNet/Boards/Internal/BoardsChangeLabelNameRequest.cs +++ b/TrelloNet/Boards/Internal/BoardsChangeLabelNameRequest.cs @@ -7,6 +7,8 @@ internal class BoardsChangeLabelNameRequest : BoardsRequest public BoardsChangeLabelNameRequest(IBoardId board, Color color, string name) : base(board, "labelNames/{color}", Method.PUT) { + Guard.NotNull(color, "color"); + AddParameter("color", color.ColorName, ParameterType.UrlSegment); this.AddValue(name ?? ""); } diff --git a/TrelloNet/Cards/Card.cs b/TrelloNet/Cards/Card.cs index e4cc279..ef06ae9 100644 --- a/TrelloNet/Cards/Card.cs +++ b/TrelloNet/Cards/Card.cs @@ -25,7 +25,7 @@ public class Card : ICardId, IUpdatableCard public double Pos { get; set; } public DateTime DateLastActivity { get; set; } public List IdMembers { get; set; } - public IEnumerable LabelColors { get { return Labels == null ? Enumerable.Empty() : Labels.Select(l => l.Color); } } + public IEnumerable LabelColors { get { return Labels == null ? Enumerable.Empty() : Labels.Where(l => l.Color != null).Select(l => l.Color); } } public string GetCardId() { diff --git a/TrelloNet/Cards/Internal/CardsAddLabelRequest.cs b/TrelloNet/Cards/Internal/CardsAddLabelRequest.cs index 96df4ef..4ab6c66 100644 --- a/TrelloNet/Cards/Internal/CardsAddLabelRequest.cs +++ b/TrelloNet/Cards/Internal/CardsAddLabelRequest.cs @@ -7,6 +7,8 @@ internal class CardsAddLabelRequest : CardsRequest public CardsAddLabelRequest(ICardId card, Color color) : base(card, "labels", Method.POST) { + Guard.NotNull(color, "color"); + this.AddValue(color.ColorName); } } diff --git a/TrelloNet/Cards/Internal/CardsRemoveLabelRequest.cs b/TrelloNet/Cards/Internal/CardsRemoveLabelRequest.cs index bde37f9..af27ba4 100644 --- a/TrelloNet/Cards/Internal/CardsRemoveLabelRequest.cs +++ b/TrelloNet/Cards/Internal/CardsRemoveLabelRequest.cs @@ -7,6 +7,8 @@ internal class CardsRemoveLabelRequest : CardsRequest public CardsRemoveLabelRequest(ICardId card, Color color) : base(card, "labels/{color}", Method.DELETE) { + Guard.NotNull(color, "color"); + AddParameter("color", color.ColorName, ParameterType.UrlSegment); } }