mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-03 11:05:56 +00:00
Make DeploymentStatus readonly
This commit is contained in:
@@ -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<string, string> { { "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<DeploymentStatus>(json);
|
||||
|
||||
Assert.Equal(expected, actual, new DeploymentStatusEqualityComparer());
|
||||
}
|
||||
}
|
||||
|
||||
public class DeploymentStatusEqualityComparer : IEqualityComparer<DeploymentStatus>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,53 +8,47 @@ namespace Octokit
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class DeploymentStatus
|
||||
{
|
||||
public DeploymentStatus()
|
||||
{
|
||||
Payload = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Id of this deployment status.
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
public int Id { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// The API URL for this deployment status.
|
||||
/// </summary>
|
||||
public string Url { get; set; }
|
||||
public string Url { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// The state of this deployment status.
|
||||
/// </summary>
|
||||
public DeploymentState State { get; set; }
|
||||
public DeploymentState State { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// The <seealso cref="User"/> that created this deployment status.
|
||||
/// </summary>
|
||||
public User Creator { get; set; }
|
||||
public User Creator { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// JSON payload with extra information about the deployment.
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
|
||||
public IDictionary<string,string> Payload { get; set; }
|
||||
public IReadOnlyDictionary<string, string> Payload { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
public string TargetUrl { get; set; }
|
||||
public string TargetUrl { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// The date and time that the status was created.
|
||||
/// </summary>
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
public DateTimeOffset CreatedAt { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// The date and time that the status was updated.
|
||||
/// </summary>
|
||||
public DateTimeOffset UpdatedAt { get; set; }
|
||||
public DateTimeOffset UpdatedAt { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// A short description of the status.
|
||||
|
||||
Reference in New Issue
Block a user