diff --git a/Octokit.Tests/Models/DeploymentStatusTests.cs b/Octokit.Tests/Models/DeploymentStatusTests.cs index c904d6b8..8f24a681 100644 --- a/Octokit.Tests/Models/DeploymentStatusTests.cs +++ b/Octokit.Tests/Models/DeploymentStatusTests.cs @@ -1,7 +1,5 @@ -using System.Linq; +using System; using Octokit.Internal; -using System; -using System.Collections.Generic; using Xunit; namespace Octokit.Tests.Models @@ -11,20 +9,7 @@ namespace Octokit.Tests.Models [Fact] public void CanDeserialize() { - var expected = new DeploymentStatus - { - Id = 1, - Url = "https://api.github.com/repos/octocat/example/deployments/1/statuses/42", - State = DeploymentState.Success, - 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"), - Description = "Deploy request from hubot" - }; - - var json = - @"{ + const string json = @"{ ""id"": 1, ""url"": ""https://api.github.com/repos/octocat/example/deployments/1/statuses/42"", ""state"": ""success"", @@ -56,41 +41,15 @@ namespace Octokit.Tests.Models var actual = new SimpleJsonSerializer().Deserialize(json); - Assert.Equal(expected, actual, new DeploymentStatusEqualityComparer()); - } - } - - public class DeploymentStatusEqualityComparer : IEqualityComparer - { - public bool Equals(DeploymentStatus x, DeploymentStatus y) - { - if (x == null && y == null) - return true; - 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.TargetUrl == y.TargetUrl && - x.CreatedAt == y.CreatedAt && - x.UpdatedAt == y.UpdatedAt && - x.Description == y.Description; - } - - public int GetHashCode(DeploymentStatus obj) - { - throw new System.NotImplementedException(); + Assert.Equal(1, actual.Id); + Assert.Equal("https://api.github.com/repos/octocat/example/deployments/1/statuses/42", actual.Url); + Assert.Equal(DeploymentState.Success, actual.State); + Assert.Equal(1, actual.Payload.Count); + Assert.Equal("production", actual.Payload["environment"]); + Assert.Equal("https://gist.github.com/628b2736d379f", actual.TargetUrl); + Assert.Equal(DateTimeOffset.Parse("2012-07-20T01:19:13Z"), actual.CreatedAt); + Assert.Equal(DateTimeOffset.Parse("2012-07-20T01:19:13Z"), actual.UpdatedAt); + Assert.Equal("Deploy request from hubot", actual.Description); } } } diff --git a/Octokit/Models/Response/DeploymentStatus.cs b/Octokit/Models/Response/DeploymentStatus.cs index 6b89576b..1a14a094 100644 --- a/Octokit/Models/Response/DeploymentStatus.cs +++ b/Octokit/Models/Response/DeploymentStatus.cs @@ -8,53 +8,47 @@ namespace Octokit [DebuggerDisplay("{DebuggerDisplay,nq}")] public class DeploymentStatus { - public DeploymentStatus() - { - Payload = new Dictionary(); - } - /// /// Id of this deployment status. /// - public int Id { get; set; } + public int Id { get; protected set; } /// /// The API URL for this deployment status. /// - public string Url { get; set; } + public string Url { get; protected set; } /// /// The state of this deployment status. /// - public DeploymentState State { get; set; } + public DeploymentState State { get; protected set; } /// /// The that created this deployment status. /// - public User Creator { get; set; } + public User Creator { get; protected set; } /// /// JSON payload with extra information about the deployment. /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] - public IDictionary Payload { get; set; } + public IReadOnlyDictionary Payload { get; protected set; } /// /// The target URL of this deployment status. This URL should contain /// output to keep the user updated while the task is running or serve /// as historical information for what happened in the deployment /// - public string TargetUrl { get; set; } + public string TargetUrl { get; protected set; } /// /// The date and time that the status was created. /// - public DateTimeOffset CreatedAt { get; set; } + public DateTimeOffset CreatedAt { get; protected set; } /// /// The date and time that the status was updated. /// - public DateTimeOffset UpdatedAt { get; set; } + public DateTimeOffset UpdatedAt { get; protected set; } /// /// A short description of the status.