mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-06 07:16:09 +00:00
Implemented deserialization unit test for...
DeploymentStatus as well. These are technically already covered with the integration tests but this way they can be run without running the integration tests.
This commit is contained in:
86
Octokit.Tests/Models/DeploymentStatusTests.cs
Normal file
86
Octokit.Tests/Models/DeploymentStatusTests.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using Octokit.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Models
|
||||
{
|
||||
public class DeploymentStatusTests
|
||||
{
|
||||
[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 = "{\"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 =
|
||||
@"{
|
||||
""id"": 1,
|
||||
""url"": ""https://api.github.com/repos/octocat/example/deployments/1/statuses/42"",
|
||||
""state"": ""success"",
|
||||
""creator"": {
|
||||
""login"": ""octocat"",
|
||||
""id"": 1,
|
||||
""avatar_url"": ""https://github.com/images/error/octocat_happy.gif"",
|
||||
""gravatar_id"": ""somehexcode"",
|
||||
""url"": ""https://api.github.com/users/octocat"",
|
||||
""html_url"": ""https://github.com/octocat"",
|
||||
""followers_url"": ""https://api.github.com/users/octocat/followers"",
|
||||
""following_url"": ""https://api.github.com/users/octocat/following{/other_user}"",
|
||||
""gists_url"": ""https://api.github.com/users/octocat/gists{/gist_id}"",
|
||||
""starred_url"": ""https://api.github.com/users/octocat/starred{/owner}{/repo}"",
|
||||
""subscriptions_url"": ""https://api.github.com/users/octocat/subscriptions"",
|
||||
""organizations_url"": ""https://api.github.com/users/octocat/orgs"",
|
||||
""repos_url"": ""https://api.github.com/users/octocat/repos"",
|
||||
""events_url"": ""https://api.github.com/users/octocat/events{/privacy}"",
|
||||
""received_events_url"": ""https://api.github.com/users/octocat/received_events"",
|
||||
""type"": ""User"",
|
||||
""site_admin"": false
|
||||
},
|
||||
""payload"": ""{\""environment\"":\""production\""}"",
|
||||
""target_url"": ""https://gist.github.com/628b2736d379f"",
|
||||
""created_at"": ""2012-07-20T01:19:13Z"",
|
||||
""updated_at"": ""2012-07-20T01:19:13Z"",
|
||||
""description"": ""Deploy request from hubot""
|
||||
}";
|
||||
|
||||
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;
|
||||
|
||||
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 &&
|
||||
x.Description == y.Description;
|
||||
}
|
||||
|
||||
public int GetHashCode(DeploymentStatus obj)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -117,6 +117,7 @@
|
||||
<Compile Include="Http\ResponseTests.cs" />
|
||||
<Compile Include="Http\RequestTests.cs" />
|
||||
<Compile Include="Models\CommitTests.cs" />
|
||||
<Compile Include="Models\DeploymentStatusTests.cs" />
|
||||
<Compile Include="Models\DeploymentTests.cs" />
|
||||
<Compile Include="Models\NewReferenceTests.cs" />
|
||||
<Compile Include="Models\MilestoneRequestTests.cs" />
|
||||
|
||||
Reference in New Issue
Block a user