From 8d1bda2172614b30fa5aeb8741546bc61a8d87c3 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Thu, 6 Mar 2014 10:30:25 +1100 Subject: [PATCH] updated deployment payload to support custom JSON --- Octokit.Tests/Models/DeploymentStatusTests.cs | 18 ++++++++++++++---- Octokit.Tests/Models/DeploymentTests.cs | 18 ++++++++++++++---- Octokit/Models/Response/Deployment.cs | 4 +++- Octokit/Models/Response/DeploymentStatus.cs | 10 +++++++++- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/Octokit.Tests/Models/DeploymentStatusTests.cs b/Octokit.Tests/Models/DeploymentStatusTests.cs index 5a8b295d..c904d6b8 100644 --- a/Octokit.Tests/Models/DeploymentStatusTests.cs +++ b/Octokit.Tests/Models/DeploymentStatusTests.cs @@ -1,4 +1,5 @@ -using Octokit.Internal; +using System.Linq; +using Octokit.Internal; using System; using System.Collections.Generic; using Xunit; @@ -15,7 +16,7 @@ namespace Octokit.Tests.Models Id = 1, Url = "https://api.github.com/repos/octocat/example/deployments/1/statuses/42", State = DeploymentState.Success, - Payload = "{\"environment\":\"production\"}", + Payload = new Dictionary { { "environment", "production" } }, TargetUrl = "https://gist.github.com/628b2736d379f", CreatedAt = DateTimeOffset.Parse("2012-07-20T01:19:13Z"), UpdatedAt = DateTimeOffset.Parse("2012-07-20T01:19:13Z"), @@ -46,7 +47,7 @@ namespace Octokit.Tests.Models ""type"": ""User"", ""site_admin"": false }, - ""payload"": ""{\""environment\"":\""production\""}"", + ""payload"": { ""environment"":""production""}, ""target_url"": ""https://gist.github.com/628b2736d379f"", ""created_at"": ""2012-07-20T01:19:13Z"", ""updated_at"": ""2012-07-20T01:19:13Z"", @@ -68,10 +69,19 @@ namespace Octokit.Tests.Models if (x == null || y == null) return false; + if (x.Payload.Keys.Any(key => x.Payload[key] != y.Payload[key])) + { + return false; + } + + if (y.Payload.Keys.Any(key => x.Payload[key] != y.Payload[key])) + { + return false; + } + return x.Id == y.Id && x.Url == y.Url && x.State == y.State && - x.Payload == y.Payload && x.TargetUrl == y.TargetUrl && x.CreatedAt == y.CreatedAt && x.UpdatedAt == y.UpdatedAt && diff --git a/Octokit.Tests/Models/DeploymentTests.cs b/Octokit.Tests/Models/DeploymentTests.cs index c408c759..824b3c4e 100644 --- a/Octokit.Tests/Models/DeploymentTests.cs +++ b/Octokit.Tests/Models/DeploymentTests.cs @@ -1,4 +1,5 @@ -using Octokit.Internal; +using System.Linq; +using Octokit.Internal; using System; using System.Collections.Generic; using Xunit; @@ -14,7 +15,7 @@ namespace Octokit.Tests.Models Id = 1, Sha = "topic-branch", Url = "https://api.github.com/repos/octocat/example/deployments/1", - Payload = "{\"environment\":\"production\"}", + Payload = new Dictionary{{ "environment", "production"}}, CreatedAt = DateTimeOffset.Parse("2012-07-20T01:19:13Z"), UpdatedAt = DateTimeOffset.Parse("2012-07-20T01:19:13Z"), Description = "Deploy request from hubot", @@ -45,7 +46,7 @@ namespace Octokit.Tests.Models ""type"": ""User"", ""site_admin"": false }, - ""payload"": ""{\""environment\"":\""production\""}"", + ""payload"": { ""environment"":""production""}, ""created_at"": ""2012-07-20T01:19:13Z"", ""updated_at"": ""2012-07-20T01:19:13Z"", ""description"": ""Deploy request from hubot"", @@ -71,10 +72,19 @@ namespace Octokit.Tests.Models if (x == null || y == null) return false; + if (x.Payload.Keys.Any(key => x.Payload[key] != y.Payload[key])) + { + return false; + } + + if (y.Payload.Keys.Any(key => x.Payload[key] != y.Payload[key])) + { + return false; + } + return x.Id == y.Id && x.Sha == y .Sha && x.Url == y.Url && - x.Payload == y.Payload && x.CreatedAt == y.CreatedAt && x.UpdatedAt == y.UpdatedAt && x.Description == y.Description && diff --git a/Octokit/Models/Response/Deployment.cs b/Octokit/Models/Response/Deployment.cs index 541a4862..fd99b3b4 100644 --- a/Octokit/Models/Response/Deployment.cs +++ b/Octokit/Models/Response/Deployment.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; @@ -33,7 +34,8 @@ namespace Octokit /// /// JSON payload with extra information about the deployment. /// - public object Payload { get; set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public IDictionary Payload { get; set; } /// /// Date and time that the deployment was created. diff --git a/Octokit/Models/Response/DeploymentStatus.cs b/Octokit/Models/Response/DeploymentStatus.cs index 133c92fc..f361074c 100644 --- a/Octokit/Models/Response/DeploymentStatus.cs +++ b/Octokit/Models/Response/DeploymentStatus.cs @@ -1,4 +1,6 @@ using System; +using System.Collections; +using System.Collections.Generic; using System.Diagnostics; using System.Globalization; @@ -7,6 +9,11 @@ namespace Octokit [DebuggerDisplay("{DebuggerDisplay,nq}")] public class DeploymentStatus { + public DeploymentStatus() + { + Payload = new Dictionary(); + } + /// /// Id of this deployment status. /// @@ -30,7 +37,8 @@ namespace Octokit /// /// JSON payload with extra information about the deployment. /// - public object Payload { get; set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public IDictionary Payload { get; set; } /// /// The target URL of this deployment status. This URL should contain