From ac14c5e1a26d02fc2c9b36f36fa8ecd8f9108e1c Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Tue, 21 Jun 2016 18:34:27 +0200 Subject: [PATCH 1/9] fix serialization of enum values --- Octokit/Http/SimpleJsonSerializer.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Octokit/Http/SimpleJsonSerializer.cs b/Octokit/Http/SimpleJsonSerializer.cs index 5835bcac..07f59833 100644 --- a/Octokit/Http/SimpleJsonSerializer.cs +++ b/Octokit/Http/SimpleJsonSerializer.cs @@ -78,6 +78,16 @@ namespace Octokit.Internal Justification = "The API expects lowercase values")] protected override object SerializeEnum(Enum p) { + var type = p.GetType(); + var name = Enum.GetName(type, p); + var attr = type.GetField(name) + .GetCustomAttributes(false) + .OfType() + .SingleOrDefault(); + + if (attr != null) + return attr.Value; + return p.ToString().ToLowerInvariant(); } From c1a16ffc74d7284118b27ea0b97fea936429e28b Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Tue, 21 Jun 2016 19:40:16 +0200 Subject: [PATCH 2/9] get customAttribute for netfx --- Octokit/Http/SimpleJsonSerializer.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Octokit/Http/SimpleJsonSerializer.cs b/Octokit/Http/SimpleJsonSerializer.cs index 07f59833..825279b5 100644 --- a/Octokit/Http/SimpleJsonSerializer.cs +++ b/Octokit/Http/SimpleJsonSerializer.cs @@ -80,11 +80,14 @@ namespace Octokit.Internal { var type = p.GetType(); var name = Enum.GetName(type, p); +#if NETFX_CORE + var attr = type.GetTypeInfo().GetCustomAttribute(); +#else var attr = type.GetField(name) .GetCustomAttributes(false) .OfType() .SingleOrDefault(); - +#endif if (attr != null) return attr.Value; From bdc222132b865ecf2e1d425cafa5f4d23ef5a656 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Wed, 22 Jun 2016 08:32:44 +0200 Subject: [PATCH 3/9] test if all reactions can be created --- .../CommitCommentReactionsClientTests.cs | 38 ++++++++++++++++--- .../IssueCommentReactionsClientTests.cs | 37 +++++++++++++++--- .../Clients/IssueReactionsClientTests.cs | 37 +++++++++++++++--- ...equestReviewCommentReactionsClientTests.cs | 37 +++++++++++++++--- 4 files changed, 129 insertions(+), 20 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/CommitCommentReactionsClientTests.cs b/Octokit.Tests.Integration/Clients/CommitCommentReactionsClientTests.cs index 14e749b6..38e66eb4 100644 --- a/Octokit.Tests.Integration/Clients/CommitCommentReactionsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CommitCommentReactionsClientTests.cs @@ -56,14 +56,42 @@ public class CommitCommentReactionsClientTests Assert.NotNull(result); - var newReaction = new NewReaction(ReactionType.Confused); - var reaction = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReaction); + var newReactionConfused = new NewReaction(ReactionType.Confused); + var newReactionHeart = new NewReaction(ReactionType.Heart); + var newReactionHooray = new NewReaction(ReactionType.Hooray); + var newReactionLaugh = new NewReaction(ReactionType.Laugh); + var newReactionMinus1 = new NewReaction(ReactionType.Minus1); + var newReactionPlus1 = new NewReaction(ReactionType.Plus1); + var reactionConfused = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReactionConfused); + var reactionHeart = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReactionHeart); + var reactionHooray = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReactionHooray); + var reactionLaugh = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReactionLaugh); + var reactionMinus1 = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReactionMinus1); + var reactionPlus1 = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReactionPlus1); - Assert.IsType(reaction); + Assert.IsType(reactionConfused); + Assert.Equal(ReactionType.Confused, reactionConfused.Content); + Assert.Equal(result.User.Id, reactionConfused.User.Id); - Assert.Equal(ReactionType.Confused, reaction.Content); + Assert.IsType(reactionHeart); + Assert.Equal(ReactionType.Heart, reactionHeart.Content); + Assert.Equal(result.User.Id, reactionHeart.User.Id); - Assert.Equal(result.User.Id, reaction.User.Id); + Assert.IsType(reactionHooray); + Assert.Equal(ReactionType.Hooray, reactionHooray.Content); + Assert.Equal(result.User.Id, reactionHooray.User.Id); + + Assert.IsType(reactionLaugh); + Assert.Equal(ReactionType.Laugh, reactionLaugh.Content); + Assert.Equal(result.User.Id, reactionLaugh.User.Id); + + Assert.IsType(reactionMinus1); + Assert.Equal(ReactionType.Minus1, reactionMinus1.Content); + Assert.Equal(result.User.Id, reactionMinus1.User.Id); + + Assert.IsType(reactionPlus1); + Assert.Equal(ReactionType.Plus1, reactionPlus1.Content); + Assert.Equal(result.User.Id, reactionPlus1.User.Id); } public void Dispose() diff --git a/Octokit.Tests.Integration/Clients/IssueCommentReactionsClientTests.cs b/Octokit.Tests.Integration/Clients/IssueCommentReactionsClientTests.cs index 210a551e..c896af91 100644 --- a/Octokit.Tests.Integration/Clients/IssueCommentReactionsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssueCommentReactionsClientTests.cs @@ -33,15 +33,42 @@ public class IssueCommentReactionsClientTests Assert.NotNull(issueComment); - var issueCommentReaction = await _github.Reaction.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, new NewReaction(ReactionType.Heart)); + var newReactionConfused = new NewReaction(ReactionType.Confused); + var newReactionHeart = new NewReaction(ReactionType.Heart); + var newReactionHooray = new NewReaction(ReactionType.Hooray); + var newReactionLaugh = new NewReaction(ReactionType.Laugh); + var newReactionMinus1 = new NewReaction(ReactionType.Minus1); + var newReactionPlus1 = new NewReaction(ReactionType.Plus1); + var reactionConfused = await _github.Reaction.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReactionConfused); + var reactionHeart = await _github.Reaction.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReactionHeart); + var reactionHooray = await _github.Reaction.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReactionHooray); + var reactionLaugh = await _github.Reaction.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReactionLaugh); + var reactionMinus1 = await _github.Reaction.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReactionMinus1); + var reactionPlus1 = await _github.Reaction.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReactionPlus1); - Assert.NotNull(issueCommentReaction); + Assert.IsType(reactionConfused); + Assert.Equal(ReactionType.Confused, reactionConfused.Content); + Assert.Equal(issueComment.User.Id, reactionConfused.User.Id); - Assert.IsType(issueCommentReaction); + Assert.IsType(reactionHeart); + Assert.Equal(ReactionType.Heart, reactionHeart.Content); + Assert.Equal(issueComment.User.Id, reactionHeart.User.Id); - Assert.Equal(ReactionType.Heart, issueCommentReaction.Content); + Assert.IsType(reactionHooray); + Assert.Equal(ReactionType.Hooray, reactionHooray.Content); + Assert.Equal(issueComment.User.Id, reactionHooray.User.Id); - Assert.Equal(issueComment.User.Id, issueCommentReaction.User.Id); + Assert.IsType(reactionLaugh); + Assert.Equal(ReactionType.Laugh, reactionLaugh.Content); + Assert.Equal(issueComment.User.Id, reactionLaugh.User.Id); + + Assert.IsType(reactionMinus1); + Assert.Equal(ReactionType.Minus1, reactionMinus1.Content); + Assert.Equal(issueComment.User.Id, reactionMinus1.User.Id); + + Assert.IsType(reactionPlus1); + Assert.Equal(ReactionType.Plus1, reactionPlus1.Content); + Assert.Equal(issueComment.User.Id, reactionPlus1.User.Id); } public void Dispose() diff --git a/Octokit.Tests.Integration/Clients/IssueReactionsClientTests.cs b/Octokit.Tests.Integration/Clients/IssueReactionsClientTests.cs index 32f263fa..9bce57af 100644 --- a/Octokit.Tests.Integration/Clients/IssueReactionsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssueReactionsClientTests.cs @@ -29,15 +29,42 @@ public class IssueReactionsClientTests Assert.NotNull(issue); - var issueReaction = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new NewReaction(ReactionType.Heart)); + var newReactionConfused = new NewReaction(ReactionType.Confused); + var newReactionHeart = new NewReaction(ReactionType.Heart); + var newReactionHooray = new NewReaction(ReactionType.Hooray); + var newReactionLaugh = new NewReaction(ReactionType.Laugh); + var newReactionMinus1 = new NewReaction(ReactionType.Minus1); + var newReactionPlus1 = new NewReaction(ReactionType.Plus1); + var reactionConfused = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, newReactionConfused); + var reactionHeart = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, newReactionHeart); + var reactionHooray = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, newReactionHooray); + var reactionLaugh = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, newReactionLaugh); + var reactionMinus1 = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, newReactionMinus1); + var reactionPlus1 = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, newReactionPlus1); - Assert.NotNull(issueReaction); + Assert.IsType(reactionConfused); + Assert.Equal(ReactionType.Confused, reactionConfused.Content); + Assert.Equal(issue.User.Id, reactionConfused.User.Id); - Assert.IsType(issueReaction); + Assert.IsType(reactionHeart); + Assert.Equal(ReactionType.Heart, reactionHeart.Content); + Assert.Equal(issue.User.Id, reactionHeart.User.Id); - Assert.Equal(ReactionType.Heart, issueReaction.Content); + Assert.IsType(reactionHooray); + Assert.Equal(ReactionType.Hooray, reactionHooray.Content); + Assert.Equal(issue.User.Id, reactionHooray.User.Id); - Assert.Equal(issue.User.Id, issueReaction.User.Id); + Assert.IsType(reactionLaugh); + Assert.Equal(ReactionType.Laugh, reactionLaugh.Content); + Assert.Equal(issue.User.Id, reactionLaugh.User.Id); + + Assert.IsType(reactionMinus1); + Assert.Equal(ReactionType.Minus1, reactionMinus1.Content); + Assert.Equal(issue.User.Id, reactionMinus1.User.Id); + + Assert.IsType(reactionPlus1); + Assert.Equal(ReactionType.Plus1, reactionPlus1.Content); + Assert.Equal(issue.User.Id, reactionPlus1.User.Id); } public void Dispose() diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentReactionsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentReactionsClientTests.cs index b705bfa8..ea073a2e 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentReactionsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentReactionsClientTests.cs @@ -40,15 +40,42 @@ public class PullRequestReviewCommentReactionsClientTests : IDisposable AssertComment(commentFromGitHub, body, position); - var pullRequestReviewCommentReaction = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, new NewReaction(ReactionType.Heart)); + var newReactionConfused = new NewReaction(ReactionType.Confused); + var newReactionHeart = new NewReaction(ReactionType.Heart); + var newReactionHooray = new NewReaction(ReactionType.Hooray); + var newReactionLaugh = new NewReaction(ReactionType.Laugh); + var newReactionMinus1 = new NewReaction(ReactionType.Minus1); + var newReactionPlus1 = new NewReaction(ReactionType.Plus1); + var reactionConfused = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, newReactionConfused); + var reactionHeart = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, newReactionHeart); + var reactionHooray = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, newReactionHooray); + var reactionLaugh = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, newReactionLaugh); + var reactionMinus1 = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, newReactionMinus1); + var reactionPlus1 = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, newReactionPlus1); - Assert.NotNull(pullRequestReviewCommentReaction); + Assert.IsType(reactionConfused); + Assert.Equal(ReactionType.Confused, reactionConfused.Content); + Assert.Equal(commentFromGitHub.User.Id, reactionConfused.User.Id); - Assert.IsType(pullRequestReviewCommentReaction); + Assert.IsType(reactionHeart); + Assert.Equal(ReactionType.Heart, reactionHeart.Content); + Assert.Equal(commentFromGitHub.User.Id, reactionHeart.User.Id); - Assert.Equal(ReactionType.Heart, pullRequestReviewCommentReaction.Content); + Assert.IsType(reactionHooray); + Assert.Equal(ReactionType.Hooray, reactionHooray.Content); + Assert.Equal(commentFromGitHub.User.Id, reactionHooray.User.Id); - Assert.Equal(commentFromGitHub.User.Id, pullRequestReviewCommentReaction.User.Id); + Assert.IsType(reactionLaugh); + Assert.Equal(ReactionType.Laugh, reactionLaugh.Content); + Assert.Equal(commentFromGitHub.User.Id, reactionLaugh.User.Id); + + Assert.IsType(reactionMinus1); + Assert.Equal(ReactionType.Minus1, reactionMinus1.Content); + Assert.Equal(commentFromGitHub.User.Id, reactionMinus1.User.Id); + + Assert.IsType(reactionPlus1); + Assert.Equal(ReactionType.Plus1, reactionPlus1.Content); + Assert.Equal(commentFromGitHub.User.Id, reactionPlus1.User.Id); } /// From 4c05be81d43c38ae447db0e90d85fc44233a9d3d Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Wed, 22 Jun 2016 11:44:20 +0200 Subject: [PATCH 4/9] fix deserialization of enums with custom attributes --- Octokit/Http/SimpleJsonSerializer.cs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Octokit/Http/SimpleJsonSerializer.cs b/Octokit/Http/SimpleJsonSerializer.cs index 825279b5..d81dc258 100644 --- a/Octokit/Http/SimpleJsonSerializer.cs +++ b/Octokit/Http/SimpleJsonSerializer.cs @@ -80,17 +80,15 @@ namespace Octokit.Internal { var type = p.GetType(); var name = Enum.GetName(type, p); -#if NETFX_CORE - var attr = type.GetTypeInfo().GetCustomAttribute(); -#else - var attr = type.GetField(name) + + var attr = type.GetRuntimeField(name) .GetCustomAttributes(false) .OfType() .SingleOrDefault(); -#endif + if (attr != null) return attr.Value; - + return p.ToString().ToLowerInvariant(); } @@ -105,6 +103,17 @@ namespace Octokit.Internal { if (ReflectionUtils.GetTypeInfo(type).IsEnum) { + //first try to get all custom attributes + var fields = type.GetRuntimeFields(); + foreach (var field in fields) + { + var attribute = (ParameterAttribute)field.GetCustomAttribute(typeof(ParameterAttribute)); + if (attribute != null) + { + if (attribute.Value.Equals(value)) + return field.GetValue(null); + } + } // remove '-' from values coming in to be able to enum utf-8 stringValue = RemoveHyphenAndUnderscore(stringValue); return Enum.Parse(type, stringValue, ignoreCase: true); From d7004334402cb7b5a197404a54968977a2569c6e Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Wed, 22 Jun 2016 13:02:54 +0200 Subject: [PATCH 5/9] change NewReaction change NewReaction to inherit from RequestParamaters. Change all reaction clients. --- Octokit/Clients/CommitCommentReactionsClient.cs | 2 +- Octokit/Clients/IssueCommentReactionsClient.cs | 2 +- Octokit/Clients/IssueReactionsClient.cs | 2 +- .../PullRequestReviewCommentReactionsClient.cs | 2 +- Octokit/Http/SimpleJsonSerializer.cs | 11 ----------- Octokit/Models/Request/NewReaction.cs | 2 +- 6 files changed, 5 insertions(+), 16 deletions(-) diff --git a/Octokit/Clients/CommitCommentReactionsClient.cs b/Octokit/Clients/CommitCommentReactionsClient.cs index 000cddb5..8e867d24 100644 --- a/Octokit/Clients/CommitCommentReactionsClient.cs +++ b/Octokit/Clients/CommitCommentReactionsClient.cs @@ -25,7 +25,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(reaction, "reaction"); - return ApiConnection.Post(ApiUrls.CommitCommentReactions(owner, name, number), reaction, AcceptHeaders.ReactionsPreview); + return ApiConnection.Post(ApiUrls.CommitCommentReactions(owner, name, number), reaction.ToParametersDictionary(), AcceptHeaders.ReactionsPreview); } /// diff --git a/Octokit/Clients/IssueCommentReactionsClient.cs b/Octokit/Clients/IssueCommentReactionsClient.cs index 352475d5..37ee8370 100644 --- a/Octokit/Clients/IssueCommentReactionsClient.cs +++ b/Octokit/Clients/IssueCommentReactionsClient.cs @@ -26,7 +26,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(reaction, "reaction"); - return ApiConnection.Post(ApiUrls.IssueCommentReactions(owner, name, number), reaction, AcceptHeaders.ReactionsPreview); + return ApiConnection.Post(ApiUrls.IssueCommentReactions(owner, name, number), reaction.ToParametersDictionary(), AcceptHeaders.ReactionsPreview); } /// diff --git a/Octokit/Clients/IssueReactionsClient.cs b/Octokit/Clients/IssueReactionsClient.cs index d630bfce..5a9f9e01 100644 --- a/Octokit/Clients/IssueReactionsClient.cs +++ b/Octokit/Clients/IssueReactionsClient.cs @@ -26,7 +26,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(reaction, "reaction"); - return ApiConnection.Post(ApiUrls.IssueReactions(owner, name, number), reaction, AcceptHeaders.ReactionsPreview); + return ApiConnection.Post(ApiUrls.IssueReactions(owner, name, number), reaction.ToParametersDictionary(), AcceptHeaders.ReactionsPreview); } /// diff --git a/Octokit/Clients/PullRequestReviewCommentReactionsClient.cs b/Octokit/Clients/PullRequestReviewCommentReactionsClient.cs index 4c07dffa..71635150 100644 --- a/Octokit/Clients/PullRequestReviewCommentReactionsClient.cs +++ b/Octokit/Clients/PullRequestReviewCommentReactionsClient.cs @@ -26,7 +26,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(reaction, "reaction"); - return ApiConnection.Post(ApiUrls.PullRequestReviewCommentReaction(owner, name, number), reaction, AcceptHeaders.ReactionsPreview); + return ApiConnection.Post(ApiUrls.PullRequestReviewCommentReaction(owner, name, number), reaction.ToParametersDictionary(), AcceptHeaders.ReactionsPreview); } /// diff --git a/Octokit/Http/SimpleJsonSerializer.cs b/Octokit/Http/SimpleJsonSerializer.cs index d81dc258..b05db410 100644 --- a/Octokit/Http/SimpleJsonSerializer.cs +++ b/Octokit/Http/SimpleJsonSerializer.cs @@ -78,17 +78,6 @@ namespace Octokit.Internal Justification = "The API expects lowercase values")] protected override object SerializeEnum(Enum p) { - var type = p.GetType(); - var name = Enum.GetName(type, p); - - var attr = type.GetRuntimeField(name) - .GetCustomAttributes(false) - .OfType() - .SingleOrDefault(); - - if (attr != null) - return attr.Value; - return p.ToString().ToLowerInvariant(); } diff --git a/Octokit/Models/Request/NewReaction.cs b/Octokit/Models/Request/NewReaction.cs index 45607c14..d55f1721 100644 --- a/Octokit/Models/Request/NewReaction.cs +++ b/Octokit/Models/Request/NewReaction.cs @@ -4,7 +4,7 @@ using System.Globalization; namespace Octokit { [DebuggerDisplay("{DebuggerDisplay,nq}")] - public class NewReaction + public class NewReaction : RequestParameters { /// /// Initializes a new instance of the class. From f7a464cc3aba781ee0b246c38dfe3d80302f9dce Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Thu, 23 Jun 2016 08:35:04 +0200 Subject: [PATCH 6/9] foreach loop for reaction types in integration tests --- .../CommitCommentReactionsClientTests.cs | 42 ++++--------------- .../IssueCommentReactionsClientTests.cs | 42 ++++--------------- .../Clients/IssueReactionsClientTests.cs | 42 ++++--------------- ...equestReviewCommentReactionsClientTests.cs | 42 ++++--------------- 4 files changed, 32 insertions(+), 136 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/CommitCommentReactionsClientTests.cs b/Octokit.Tests.Integration/Clients/CommitCommentReactionsClientTests.cs index 38e66eb4..679070a6 100644 --- a/Octokit.Tests.Integration/Clients/CommitCommentReactionsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CommitCommentReactionsClientTests.cs @@ -56,42 +56,16 @@ public class CommitCommentReactionsClientTests Assert.NotNull(result); - var newReactionConfused = new NewReaction(ReactionType.Confused); - var newReactionHeart = new NewReaction(ReactionType.Heart); - var newReactionHooray = new NewReaction(ReactionType.Hooray); - var newReactionLaugh = new NewReaction(ReactionType.Laugh); - var newReactionMinus1 = new NewReaction(ReactionType.Minus1); - var newReactionPlus1 = new NewReaction(ReactionType.Plus1); - var reactionConfused = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReactionConfused); - var reactionHeart = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReactionHeart); - var reactionHooray = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReactionHooray); - var reactionLaugh = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReactionLaugh); - var reactionMinus1 = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReactionMinus1); - var reactionPlus1 = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReactionPlus1); + foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) + { + var newReaction = new NewReaction(reactionType); - Assert.IsType(reactionConfused); - Assert.Equal(ReactionType.Confused, reactionConfused.Content); - Assert.Equal(result.User.Id, reactionConfused.User.Id); + var reaction = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReaction); - Assert.IsType(reactionHeart); - Assert.Equal(ReactionType.Heart, reactionHeart.Content); - Assert.Equal(result.User.Id, reactionHeart.User.Id); - - Assert.IsType(reactionHooray); - Assert.Equal(ReactionType.Hooray, reactionHooray.Content); - Assert.Equal(result.User.Id, reactionHooray.User.Id); - - Assert.IsType(reactionLaugh); - Assert.Equal(ReactionType.Laugh, reactionLaugh.Content); - Assert.Equal(result.User.Id, reactionLaugh.User.Id); - - Assert.IsType(reactionMinus1); - Assert.Equal(ReactionType.Minus1, reactionMinus1.Content); - Assert.Equal(result.User.Id, reactionMinus1.User.Id); - - Assert.IsType(reactionPlus1); - Assert.Equal(ReactionType.Plus1, reactionPlus1.Content); - Assert.Equal(result.User.Id, reactionPlus1.User.Id); + Assert.IsType(reaction); + Assert.Equal(reactionType, reaction.Content); + Assert.Equal(result.User.Id, reaction.User.Id); + } } public void Dispose() diff --git a/Octokit.Tests.Integration/Clients/IssueCommentReactionsClientTests.cs b/Octokit.Tests.Integration/Clients/IssueCommentReactionsClientTests.cs index c896af91..6502e867 100644 --- a/Octokit.Tests.Integration/Clients/IssueCommentReactionsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssueCommentReactionsClientTests.cs @@ -33,42 +33,16 @@ public class IssueCommentReactionsClientTests Assert.NotNull(issueComment); - var newReactionConfused = new NewReaction(ReactionType.Confused); - var newReactionHeart = new NewReaction(ReactionType.Heart); - var newReactionHooray = new NewReaction(ReactionType.Hooray); - var newReactionLaugh = new NewReaction(ReactionType.Laugh); - var newReactionMinus1 = new NewReaction(ReactionType.Minus1); - var newReactionPlus1 = new NewReaction(ReactionType.Plus1); - var reactionConfused = await _github.Reaction.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReactionConfused); - var reactionHeart = await _github.Reaction.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReactionHeart); - var reactionHooray = await _github.Reaction.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReactionHooray); - var reactionLaugh = await _github.Reaction.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReactionLaugh); - var reactionMinus1 = await _github.Reaction.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReactionMinus1); - var reactionPlus1 = await _github.Reaction.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReactionPlus1); + foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) + { + var newReaction = new NewReaction(reactionType); - Assert.IsType(reactionConfused); - Assert.Equal(ReactionType.Confused, reactionConfused.Content); - Assert.Equal(issueComment.User.Id, reactionConfused.User.Id); + var reaction = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReaction); - Assert.IsType(reactionHeart); - Assert.Equal(ReactionType.Heart, reactionHeart.Content); - Assert.Equal(issueComment.User.Id, reactionHeart.User.Id); - - Assert.IsType(reactionHooray); - Assert.Equal(ReactionType.Hooray, reactionHooray.Content); - Assert.Equal(issueComment.User.Id, reactionHooray.User.Id); - - Assert.IsType(reactionLaugh); - Assert.Equal(ReactionType.Laugh, reactionLaugh.Content); - Assert.Equal(issueComment.User.Id, reactionLaugh.User.Id); - - Assert.IsType(reactionMinus1); - Assert.Equal(ReactionType.Minus1, reactionMinus1.Content); - Assert.Equal(issueComment.User.Id, reactionMinus1.User.Id); - - Assert.IsType(reactionPlus1); - Assert.Equal(ReactionType.Plus1, reactionPlus1.Content); - Assert.Equal(issueComment.User.Id, reactionPlus1.User.Id); + Assert.IsType(reaction); + Assert.Equal(reactionType, reaction.Content); + Assert.Equal(issueComment.User.Id, reaction.User.Id); + } } public void Dispose() diff --git a/Octokit.Tests.Integration/Clients/IssueReactionsClientTests.cs b/Octokit.Tests.Integration/Clients/IssueReactionsClientTests.cs index 9bce57af..e6b9b806 100644 --- a/Octokit.Tests.Integration/Clients/IssueReactionsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssueReactionsClientTests.cs @@ -29,42 +29,16 @@ public class IssueReactionsClientTests Assert.NotNull(issue); - var newReactionConfused = new NewReaction(ReactionType.Confused); - var newReactionHeart = new NewReaction(ReactionType.Heart); - var newReactionHooray = new NewReaction(ReactionType.Hooray); - var newReactionLaugh = new NewReaction(ReactionType.Laugh); - var newReactionMinus1 = new NewReaction(ReactionType.Minus1); - var newReactionPlus1 = new NewReaction(ReactionType.Plus1); - var reactionConfused = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, newReactionConfused); - var reactionHeart = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, newReactionHeart); - var reactionHooray = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, newReactionHooray); - var reactionLaugh = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, newReactionLaugh); - var reactionMinus1 = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, newReactionMinus1); - var reactionPlus1 = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, newReactionPlus1); + foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) + { + var newReaction = new NewReaction(reactionType); - Assert.IsType(reactionConfused); - Assert.Equal(ReactionType.Confused, reactionConfused.Content); - Assert.Equal(issue.User.Id, reactionConfused.User.Id); + var reaction = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Id, newReaction); - Assert.IsType(reactionHeart); - Assert.Equal(ReactionType.Heart, reactionHeart.Content); - Assert.Equal(issue.User.Id, reactionHeart.User.Id); - - Assert.IsType(reactionHooray); - Assert.Equal(ReactionType.Hooray, reactionHooray.Content); - Assert.Equal(issue.User.Id, reactionHooray.User.Id); - - Assert.IsType(reactionLaugh); - Assert.Equal(ReactionType.Laugh, reactionLaugh.Content); - Assert.Equal(issue.User.Id, reactionLaugh.User.Id); - - Assert.IsType(reactionMinus1); - Assert.Equal(ReactionType.Minus1, reactionMinus1.Content); - Assert.Equal(issue.User.Id, reactionMinus1.User.Id); - - Assert.IsType(reactionPlus1); - Assert.Equal(ReactionType.Plus1, reactionPlus1.Content); - Assert.Equal(issue.User.Id, reactionPlus1.User.Id); + Assert.IsType(reaction); + Assert.Equal(reactionType, reaction.Content); + Assert.Equal(issue.User.Id, reaction.User.Id); + } } public void Dispose() diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentReactionsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentReactionsClientTests.cs index ea073a2e..84afbcda 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentReactionsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentReactionsClientTests.cs @@ -40,42 +40,16 @@ public class PullRequestReviewCommentReactionsClientTests : IDisposable AssertComment(commentFromGitHub, body, position); - var newReactionConfused = new NewReaction(ReactionType.Confused); - var newReactionHeart = new NewReaction(ReactionType.Heart); - var newReactionHooray = new NewReaction(ReactionType.Hooray); - var newReactionLaugh = new NewReaction(ReactionType.Laugh); - var newReactionMinus1 = new NewReaction(ReactionType.Minus1); - var newReactionPlus1 = new NewReaction(ReactionType.Plus1); - var reactionConfused = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, newReactionConfused); - var reactionHeart = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, newReactionHeart); - var reactionHooray = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, newReactionHooray); - var reactionLaugh = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, newReactionLaugh); - var reactionMinus1 = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, newReactionMinus1); - var reactionPlus1 = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, newReactionPlus1); + foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) + { + var newReaction = new NewReaction(reactionType); - Assert.IsType(reactionConfused); - Assert.Equal(ReactionType.Confused, reactionConfused.Content); - Assert.Equal(commentFromGitHub.User.Id, reactionConfused.User.Id); + var reaction = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, newReaction); - Assert.IsType(reactionHeart); - Assert.Equal(ReactionType.Heart, reactionHeart.Content); - Assert.Equal(commentFromGitHub.User.Id, reactionHeart.User.Id); - - Assert.IsType(reactionHooray); - Assert.Equal(ReactionType.Hooray, reactionHooray.Content); - Assert.Equal(commentFromGitHub.User.Id, reactionHooray.User.Id); - - Assert.IsType(reactionLaugh); - Assert.Equal(ReactionType.Laugh, reactionLaugh.Content); - Assert.Equal(commentFromGitHub.User.Id, reactionLaugh.User.Id); - - Assert.IsType(reactionMinus1); - Assert.Equal(ReactionType.Minus1, reactionMinus1.Content); - Assert.Equal(commentFromGitHub.User.Id, reactionMinus1.User.Id); - - Assert.IsType(reactionPlus1); - Assert.Equal(ReactionType.Plus1, reactionPlus1.Content); - Assert.Equal(commentFromGitHub.User.Id, reactionPlus1.User.Id); + Assert.IsType(reaction); + Assert.Equal(reactionType, reaction.Content); + Assert.Equal(commentFromGitHub.User.Id, reaction.User.Id); + } } /// From 844be5586dc00e3a6326e97fb0462a0f2c552572 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Thu, 23 Jun 2016 09:45:22 +0200 Subject: [PATCH 7/9] revert NewReaction client and fix SimpleJsonSerializer --- Octokit/Clients/CommitCommentReactionsClient.cs | 2 +- Octokit/Clients/IssueCommentReactionsClient.cs | 2 +- Octokit/Clients/IssueReactionsClient.cs | 2 +- Octokit/Clients/PullRequestReviewCommentReactionsClient.cs | 2 +- Octokit/Http/SimpleJsonSerializer.cs | 2 +- Octokit/Models/Request/NewReaction.cs | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Octokit/Clients/CommitCommentReactionsClient.cs b/Octokit/Clients/CommitCommentReactionsClient.cs index 8e867d24..000cddb5 100644 --- a/Octokit/Clients/CommitCommentReactionsClient.cs +++ b/Octokit/Clients/CommitCommentReactionsClient.cs @@ -25,7 +25,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(reaction, "reaction"); - return ApiConnection.Post(ApiUrls.CommitCommentReactions(owner, name, number), reaction.ToParametersDictionary(), AcceptHeaders.ReactionsPreview); + return ApiConnection.Post(ApiUrls.CommitCommentReactions(owner, name, number), reaction, AcceptHeaders.ReactionsPreview); } /// diff --git a/Octokit/Clients/IssueCommentReactionsClient.cs b/Octokit/Clients/IssueCommentReactionsClient.cs index 37ee8370..352475d5 100644 --- a/Octokit/Clients/IssueCommentReactionsClient.cs +++ b/Octokit/Clients/IssueCommentReactionsClient.cs @@ -26,7 +26,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(reaction, "reaction"); - return ApiConnection.Post(ApiUrls.IssueCommentReactions(owner, name, number), reaction.ToParametersDictionary(), AcceptHeaders.ReactionsPreview); + return ApiConnection.Post(ApiUrls.IssueCommentReactions(owner, name, number), reaction, AcceptHeaders.ReactionsPreview); } /// diff --git a/Octokit/Clients/IssueReactionsClient.cs b/Octokit/Clients/IssueReactionsClient.cs index 5a9f9e01..d630bfce 100644 --- a/Octokit/Clients/IssueReactionsClient.cs +++ b/Octokit/Clients/IssueReactionsClient.cs @@ -26,7 +26,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(reaction, "reaction"); - return ApiConnection.Post(ApiUrls.IssueReactions(owner, name, number), reaction.ToParametersDictionary(), AcceptHeaders.ReactionsPreview); + return ApiConnection.Post(ApiUrls.IssueReactions(owner, name, number), reaction, AcceptHeaders.ReactionsPreview); } /// diff --git a/Octokit/Clients/PullRequestReviewCommentReactionsClient.cs b/Octokit/Clients/PullRequestReviewCommentReactionsClient.cs index 71635150..4c07dffa 100644 --- a/Octokit/Clients/PullRequestReviewCommentReactionsClient.cs +++ b/Octokit/Clients/PullRequestReviewCommentReactionsClient.cs @@ -26,7 +26,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(reaction, "reaction"); - return ApiConnection.Post(ApiUrls.PullRequestReviewCommentReaction(owner, name, number), reaction.ToParametersDictionary(), AcceptHeaders.ReactionsPreview); + return ApiConnection.Post(ApiUrls.PullRequestReviewCommentReaction(owner, name, number), reaction, AcceptHeaders.ReactionsPreview); } /// diff --git a/Octokit/Http/SimpleJsonSerializer.cs b/Octokit/Http/SimpleJsonSerializer.cs index b05db410..fcc4371b 100644 --- a/Octokit/Http/SimpleJsonSerializer.cs +++ b/Octokit/Http/SimpleJsonSerializer.cs @@ -78,7 +78,7 @@ namespace Octokit.Internal Justification = "The API expects lowercase values")] protected override object SerializeEnum(Enum p) { - return p.ToString().ToLowerInvariant(); + return p.ToParameter(); } private string _type; diff --git a/Octokit/Models/Request/NewReaction.cs b/Octokit/Models/Request/NewReaction.cs index d55f1721..7434da0c 100644 --- a/Octokit/Models/Request/NewReaction.cs +++ b/Octokit/Models/Request/NewReaction.cs @@ -4,7 +4,7 @@ using System.Globalization; namespace Octokit { [DebuggerDisplay("{DebuggerDisplay,nq}")] - public class NewReaction : RequestParameters + public class NewReaction { /// /// Initializes a new instance of the class. @@ -18,7 +18,7 @@ namespace Octokit /// /// The reaction type (required) /// - public ReactionType Content { get; private set; } + public ReactionType Content { get; private set; } internal string DebuggerDisplay { From 63629d50293e5bbef0adb467893a837f7fe04f32 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Fri, 24 Jun 2016 10:36:00 +0200 Subject: [PATCH 8/9] add method to check attributes --- Octokit/Http/SimpleJsonSerializer.cs | 59 +++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/Octokit/Http/SimpleJsonSerializer.cs b/Octokit/Http/SimpleJsonSerializer.cs index fcc4371b..d0305f78 100644 --- a/Octokit/Http/SimpleJsonSerializer.cs +++ b/Octokit/Http/SimpleJsonSerializer.cs @@ -24,6 +24,7 @@ namespace Octokit.Internal class GitHubSerializerStrategy : PocoJsonSerializerStrategy { readonly List _membersWhichShouldPublishNull = new List(); + Dictionary> _cachedEnums = new Dictionary>(); protected override string MapClrMemberToJsonFieldName(MemberInfo member) { @@ -88,24 +89,62 @@ namespace Octokit.Internal { var stringValue = value as string; var jsonValue = value as JsonObject; + object attributeValue = null; if (stringValue != null) { if (ReflectionUtils.GetTypeInfo(type).IsEnum) { - //first try to get all custom attributes - var fields = type.GetRuntimeFields(); - foreach (var field in fields) + //first try get value from cache + if (_cachedEnums.ContainsKey(type)) { - var attribute = (ParameterAttribute)field.GetCustomAttribute(typeof(ParameterAttribute)); - if (attribute != null) + if (_cachedEnums[type].ContainsKey(value)) { - if (attribute.Value.Equals(value)) - return field.GetValue(null); + return _cachedEnums[type][value]; + } + else + { + //dictionary does not contain enum value and has no attribute (see below). So add it for future loops and return value + // remove '-' from values coming in to be able to enum utf-8 + stringValue = RemoveHyphenAndUnderscore(stringValue); + var parsed = Enum.Parse(type, stringValue, ignoreCase: true); + _cachedEnums[type].Add(value, parsed); + return parsed; } } - // remove '-' from values coming in to be able to enum utf-8 - stringValue = RemoveHyphenAndUnderscore(stringValue); - return Enum.Parse(type, stringValue, ignoreCase: true); + else + { + //First add type to Dictionary + _cachedEnums.Add(type, new Dictionary()); + //then try to get all custom attributes, this happens only once per type + var fields = type.GetRuntimeFields(); + foreach (var field in fields) + { + if (field.Name == "value__") + continue; + var attribute = (ParameterAttribute)field.GetCustomAttribute(typeof(ParameterAttribute)); + if (attribute != null) + { + if (attribute.Value.Equals(value)) + attributeValue = field.GetValue(null);//Store value that we can return it after loop + _cachedEnums[type].Add(attribute.Value, field.GetValue(null)); + + } + } + } + //Check if we have a match for attribute + if (attributeValue != null) + { + return attributeValue; + } + else + { + //Fallback for any reason we have no match. This sould also happens once + // remove '-' from values coming in to be able to enum utf-8 + stringValue = RemoveHyphenAndUnderscore(stringValue); + var parsed = Enum.Parse(type, stringValue, ignoreCase: true); + _cachedEnums[type].Add(value, parsed); + return parsed; + } } if (ReflectionUtils.IsNullableType(type)) From d650f2a406f16d53c319461d302c0a3daf7f8890 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Mon, 27 Jun 2016 09:15:26 +0200 Subject: [PATCH 9/9] [WIP] deserialization --- Octokit/Http/SimpleJsonSerializer.cs | 31 ++++++---------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/Octokit/Http/SimpleJsonSerializer.cs b/Octokit/Http/SimpleJsonSerializer.cs index d0305f78..8253bdad 100644 --- a/Octokit/Http/SimpleJsonSerializer.cs +++ b/Octokit/Http/SimpleJsonSerializer.cs @@ -89,29 +89,12 @@ namespace Octokit.Internal { var stringValue = value as string; var jsonValue = value as JsonObject; - object attributeValue = null; + if (stringValue != null) { if (ReflectionUtils.GetTypeInfo(type).IsEnum) { - //first try get value from cache - if (_cachedEnums.ContainsKey(type)) - { - if (_cachedEnums[type].ContainsKey(value)) - { - return _cachedEnums[type][value]; - } - else - { - //dictionary does not contain enum value and has no attribute (see below). So add it for future loops and return value - // remove '-' from values coming in to be able to enum utf-8 - stringValue = RemoveHyphenAndUnderscore(stringValue); - var parsed = Enum.Parse(type, stringValue, ignoreCase: true); - _cachedEnums[type].Add(value, parsed); - return parsed; - } - } - else + if (!_cachedEnums.ContainsKey(type)) { //First add type to Dictionary _cachedEnums.Add(type, new Dictionary()); @@ -125,20 +108,18 @@ namespace Octokit.Internal if (attribute != null) { if (attribute.Value.Equals(value)) - attributeValue = field.GetValue(null);//Store value that we can return it after loop - _cachedEnums[type].Add(attribute.Value, field.GetValue(null)); + _cachedEnums[type].Add(attribute.Value, field.GetValue(null)); } } } - //Check if we have a match for attribute - if (attributeValue != null) + if (_cachedEnums[type].ContainsKey(value)) { - return attributeValue; + return _cachedEnums[type][value]; } else { - //Fallback for any reason we have no match. This sould also happens once + //dictionary does not contain enum value and has no custom attribute. So add it for future loops and return value // remove '-' from values coming in to be able to enum utf-8 stringValue = RemoveHyphenAndUnderscore(stringValue); var parsed = Enum.Parse(type, stringValue, ignoreCase: true);