public async Task CanCreateDeploymentStatus()
    {
        var newStatus = new NewDeploymentStatus { State = DeploymentState.Success };

        var status = await _deploymentsClient.Status.Create(_repositoryOwner, _repository.Name, _deployment.Id, newStatus);

        Assert.NotNull(status);
        Assert.Equal(DeploymentState.Success, status.State);
    }
    public async Task CanCreateDeploymentStatusWithRepositoryId()
    {
        var newStatus = new NewDeploymentStatus(DeploymentState.Success);

        var status = await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus);

        Assert.NotNull(status);
        Assert.Equal(DeploymentState.Success, status.State);
    }
        /// <summary>
        /// Creates a new status for the given deployment. Users with push access can create deployment
        /// statuses for a given deployment.
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/repos/deployments/#create-a-deployment-status
        /// </remarks>
        /// <param name="owner">The owner of the repository.</param>
        /// <param name="name">The name of the repository.</param>
        /// <param name="deploymentId">The id of the deployment.</param>
        /// <param name="newDeploymentStatus"></param>
        /// <returns></returns>
        public Task<DeploymentStatus> Create(string owner, string name, int deploymentId, NewDeploymentStatus newDeploymentStatus)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(newDeploymentStatus, "newDeploymentStatus");

            return ApiConnection.Post<DeploymentStatus>(ApiUrls.DeploymentStatuses(owner, name, deploymentId),
                                                        newDeploymentStatus);
        }
    public async Task CanReadDeploymentStatuses()
    {
        var newStatus = new NewDeploymentStatus { State = DeploymentState.Success };
        await _deploymentsClient.Status.Create(_repositoryOwner, _repository.Name, _deployment.Id, newStatus);

        var statuses = await _deploymentsClient.Status.GetAll(_repositoryOwner, _repository.Name, _deployment.Id);

        Assert.NotEmpty(statuses);
        Assert.Equal(DeploymentState.Success, statuses[0].State);
    }
    public async Task CanReadDeploymentStatusesWithRepositoryId()
    {
        var newStatus = new NewDeploymentStatus(DeploymentState.Success);
        await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus);

        var statuses = await _deploymentsClient.Status.GetAll(_context.Repository.Id, _deployment.Id);

        Assert.NotEmpty(statuses);
        Assert.Equal(DeploymentState.Success, statuses[0].State);
    }
    public async Task CanReadDeploymentStatuses()
    {
        var newStatus = new NewDeploymentStatus(DeploymentState.Success) { LogUrl = "http://test.com/log", EnvironmentUrl = "http:test.com/staging" };
        await _deploymentsClient.Status.Create(_context.RepositoryOwner, _context.RepositoryName, _deployment.Id, newStatus);

        var statuses = await _deploymentsClient.Status.GetAll(_context.RepositoryOwner, _context.RepositoryName, _deployment.Id);

        Assert.NotEmpty(statuses);
        Assert.Equal(DeploymentState.Success, statuses[0].State);
        Assert.Equal(newStatus.LogUrl, statuses[0].LogUrl);
        Assert.Equal(newStatus.EnvironmentUrl, statuses[0].EnvironmentUrl);
    }
    public async Task ReturnsCorrectCountOfDeploymentStatusesWithoutStart()
    {
        var newStatus1 = new NewDeploymentStatus(DeploymentState.Success);
        var newStatus2 = new NewDeploymentStatus(DeploymentState.Success);
        var newStatus3 = new NewDeploymentStatus(DeploymentState.Success);
        await _deploymentsClient.Status.Create(_context.RepositoryOwner, _context.RepositoryName, _deployment.Id, newStatus1);
        await _deploymentsClient.Status.Create(_context.RepositoryOwner, _context.RepositoryName, _deployment.Id, newStatus2);
        await _deploymentsClient.Status.Create(_context.RepositoryOwner, _context.RepositoryName, _deployment.Id, newStatus3);

        var options = new ApiOptions
        {
            PageSize = 3,
            PageCount = 1
        };

        var deploymentStatuses = await _deploymentsClient.Status.GetAll(_context.RepositoryOwner, _context.RepositoryName, _deployment.Id, options);

        Assert.Equal(3, deploymentStatuses.Count);
    }
        /// <summary>
        /// Creates a new status for the given deployment. Users with push access can create deployment
        /// statuses for a given deployment.
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/repos/deployments/#create-a-deployment-status
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository.</param>
        /// <param name="deploymentId">The id of the deployment.</param>
        /// <param name="newDeploymentStatus">The new deployment status to create.</param>
        public Task<DeploymentStatus> Create(long repositoryId, int deploymentId, NewDeploymentStatus newDeploymentStatus)
        {
            Ensure.ArgumentNotNull(newDeploymentStatus, "newDeploymentStatus");

            return ApiConnection.Post<DeploymentStatus>(ApiUrls.DeploymentStatuses(repositoryId, deploymentId),
                                                        newDeploymentStatus);
        }
    public async Task ReturnsDistinctDeploymentStatusesBasedOnStartPage()
    {
        var newStatus1 = new NewDeploymentStatus(DeploymentState.Success);
        var newStatus2 = new NewDeploymentStatus(DeploymentState.Success);
        var newStatus3 = new NewDeploymentStatus(DeploymentState.Success);
        await _deploymentsClient.Status.Create(_context.RepositoryOwner, _context.RepositoryName, _deployment.Id, newStatus1);
        await _deploymentsClient.Status.Create(_context.RepositoryOwner, _context.RepositoryName, _deployment.Id, newStatus2);
        await _deploymentsClient.Status.Create(_context.RepositoryOwner, _context.RepositoryName, _deployment.Id, newStatus3);

        var startOptions = new ApiOptions
        {
            PageSize = 1,
            PageCount = 1
        };

        var firstPage = await _deploymentsClient.Status.GetAll(_context.RepositoryOwner, _context.RepositoryName, _deployment.Id, startOptions);

        var skipStartOptions = new ApiOptions
        {
            PageSize = 1,
            PageCount = 1,
            StartPage = 2
        };

        var secondPage = await _deploymentsClient.Status.GetAll(_context.RepositoryOwner, _context.RepositoryName, _deployment.Id, skipStartOptions);

        Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
    }