Ejemplo n.º 1
0
    public async Task ReturnsCorrectCountOfDeployKeysWithStart()
    {
        var deployKeys = await _fixture.GetAll(_context.RepositoryOwner, _context.RepositoryName);

        Assert.Equal(0, deployKeys.Count);

        var list            = new List <NewDeployKey>();
        var deployKeysCount = 5;

        for (int i = 0; i < deployKeysCount; i++)
        {
            var item = new NewDeployKey
            {
                Key   = "ssh-rsa A" + i, // here we should genereate ssh-key some how
                Title = "KeyTitle" + i
            };
            list.Add(item);
        }

        foreach (var key in list)
        {
            await _fixture.Create(_context.RepositoryOwner, _context.RepositoryName, key);
        }

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

        deployKeys = await _fixture.GetAll(_context.RepositoryOwner, _context.RepositoryName, options);

        Assert.Equal(1, deployKeys.Count);
    }
            public void CallsIntoClient()
            {
                var githubClient = Substitute.For<IGitHubClient>();
                var deployKeysClient = new ObservableRepositoryDeployKeysClient(githubClient);
                var data = new NewDeployKey { Key = "ABC123", Title = "user@repo" };

                deployKeysClient.Create("user", "repo", data);

                githubClient.Repository.DeployKeys.Received(1).Create("user", "repo", data);
            }
            public void CallsIntoClient()
            {
                var githubClient     = Substitute.For <IGitHubClient>();
                var deployKeysClient = new ObservableRepositoryDeployKeysClient(githubClient);
                var data             = new NewDeployKey {
                    Key = "ABC123", Title = "user@repo"
                };

                deployKeysClient.Create("user", "repo", data);

                githubClient.Repository.DeployKeys.Received(1).Create("user", "repo", data);
            }
Ejemplo n.º 4
0
            public void CreatesCorrectUrlWithRepositoryId()
            {
                var gitHubClient     = Substitute.For <IGitHubClient>();
                var deployKeysClient = new ObservableRepositoryDeployKeysClient(gitHubClient);
                var data             = new NewDeployKey {
                    Key = "ABC123", Title = "user@repo"
                };

                deployKeysClient.Create(1, data);

                gitHubClient.Repository.DeployKeys.Received(1).Create(1, data);
            }
Ejemplo n.º 5
0
            public void CreatesCorrectUrlWithRepositoryId()
            {
                var apiConnection    = Substitute.For <IApiConnection>();
                var deployKeysClient = new RepositoryDeployKeysClient(apiConnection);

                var newDeployKey = new NewDeployKey {
                    Key = "ABC123", Title = "user@repo"
                };

                deployKeysClient.Create(1, newDeployKey);

                apiConnection.Received().Post <DeployKey>(Arg.Is <Uri>(u => u.ToString() == "repositories/1/keys"),
                                                          newDeployKey);
            }
Ejemplo n.º 6
0
    public async Task CanCreateADeployKey()
    {
        var deployKey = new NewDeployKey
        {
            Key   = _key,
            Title = _keyTitle
        };

        var deployKeyResult = await _fixture.Create(_context.RepositoryOwner, _context.RepositoryName, deployKey);

        Assert.NotNull(deployKeyResult);
        Assert.Equal(_key, deployKeyResult.Key);
        Assert.Equal(_keyTitle, deployKeyResult.Title);
    }
        /// <summary>
        /// Creates a new deploy key for a repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="https://developer.github.com/v3/repos/keys/#create"> API documentation</a> for more information.
        /// </remarks>
        /// <param name="owner">The owner of the repository.</param>
        /// <param name="name">The name of the repository.</param>
        /// <param name="newDeployKey">The deploy key to create for the repository.</param>
        /// <returns></returns>
        public IObservable<DeployKey> Create(string owner, string name, NewDeployKey newDeployKey)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(newDeployKey, "newDeployKey");


            if (string.IsNullOrWhiteSpace(newDeployKey.Title))
                throw new ArgumentException("The new deploy key's title must not be null.");

            if (string.IsNullOrWhiteSpace(newDeployKey.Key))
                throw new ArgumentException("The new deploy key's key must not be null.");

            return _client.Create(owner, name, newDeployKey).ToObservable();
        }
Ejemplo n.º 8
0
    public async Task CanCreateADeployKey()
    {
        var deployKey = new NewDeployKey()
        {
            Key   = _key,
            Title = _keyTitle
        };

        var observable       = _client.Create(_owner, _repository.Name, deployKey);
        var createdDeployKey = await observable;

        Assert.NotNull(createdDeployKey);
        Assert.Equal(_key, createdDeployKey.Key);
        Assert.Equal(_keyTitle, createdDeployKey.Title);
    }
Ejemplo n.º 9
0
    public async Task CanRetrieveADeployKeyWithRepositoryId()
    {
        var newDeployKey = new NewDeployKey
        {
            Key   = _key,
            Title = _keyTitle
        };
        var deployKeyResult = await _fixture.Create(_context.Repository.Id, newDeployKey);

        var deployKey = await _fixture.Get(_context.Repository.Id, deployKeyResult.Id);

        Assert.NotNull(deployKey);
        Assert.Equal(deployKeyResult.Id, deployKey.Id);
        Assert.Equal(_key, deployKey.Key);
        Assert.Equal(_keyTitle, deployKey.Title);
    }
Ejemplo n.º 10
0
    public async Task CanRetrieveADeployKey()
    {
        var newDeployKey = new NewDeployKey()
        {
            Key   = _key,
            Title = _keyTitle
        };
        var deployKeyResult = await _fixture.Create(_owner, _repository.Name, newDeployKey);

        var deployKey = await _fixture.Get(_owner, _repository.Name, deployKeyResult.Id);

        Assert.NotNull(deployKey);
        Assert.Equal(deployKeyResult.Id, deployKey.Id);
        Assert.Equal(_key, deployKey.Key);
        Assert.Equal(_keyTitle, deployKey.Title);
    }
    public async Task CanRetrieveADeployKey()
    {
        var newDeployKey = new NewDeployKey
        {
            Key   = _key,
            Title = _keyTitle
        };

        var createdDeployKey = await _client.Create(_owner, _repository.Name, newDeployKey);

        var deployKey = await _client.Get(_owner, _repository.Name, createdDeployKey.Id);

        Assert.NotNull(deployKey);
        Assert.Equal(createdDeployKey.Id, deployKey.Id);
        Assert.Equal(_key, deployKey.Key);
        Assert.Equal(_keyTitle, deployKey.Title);
    }
        /// <summary>
        /// Creates a new deploy key for a repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="https://developer.github.com/v3/repos/keys/#create"> API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository.</param>
        /// <param name="newDeployKey">The deploy key to create for the repository.</param>
        public IObservable <DeployKey> Create(int repositoryId, NewDeployKey newDeployKey)
        {
            Ensure.ArgumentNotNull(newDeployKey, "newDeployKey");


            if (string.IsNullOrWhiteSpace(newDeployKey.Title))
            {
                throw new ArgumentException("The new deploy key's title must not be null.");
            }

            if (string.IsNullOrWhiteSpace(newDeployKey.Key))
            {
                throw new ArgumentException("The new deploy key's key must not be null.");
            }

            return(_client.Create(repositoryId, newDeployKey).ToObservable());
        }
Ejemplo n.º 13
0
        /// <inheritdoc/>
        protected override async Task <object> CallGitHubApi(DialogContext dc, Octokit.GitHubClient gitHubClient, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (Owner != null && Name != null && NewDeployKey != null)
            {
                var ownerValue        = Owner.GetValue(dc.State);
                var nameValue         = Name.GetValue(dc.State);
                var newDeployKeyValue = NewDeployKey.GetValue(dc.State);
                return(await gitHubClient.Repository.DeployKeys.Create(ownerValue, nameValue, newDeployKeyValue).ConfigureAwait(false));
            }
            if (RepositoryId != null && NewDeployKey != null)
            {
                var repositoryIdValue = RepositoryId.GetValue(dc.State);
                var newDeployKeyValue = NewDeployKey.GetValue(dc.State);
                return(await gitHubClient.Repository.DeployKeys.Create((Int64)repositoryIdValue, newDeployKeyValue).ConfigureAwait(false));
            }

            throw new ArgumentNullException("Required [newDeployKey] arguments missing for GitHubClient.Repository.DeployKeys.Create");
        }
        /// <summary>
        /// Creates a new deploy key for a repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="https://developer.github.com/v3/repos/keys/#create"> API documentation</a> for more information.
        /// </remarks>
        /// <param name="owner">The owner of the repository.</param>
        /// <param name="name">The name of the repository.</param>
        /// <param name="newDeployKey">The deploy key to create for the repository.</param>
        /// <returns></returns>
        public IObservable <DeployKey> Create(string owner, string name, NewDeployKey newDeployKey)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(newDeployKey, "newDeployKey");


            if (string.IsNullOrWhiteSpace(newDeployKey.Title))
            {
                throw new ArgumentException("The new deploy key's title must not be null.");
            }

            if (string.IsNullOrWhiteSpace(newDeployKey.Key))
            {
                throw new ArgumentException("The new deploy key's key must not be null.");
            }

            return(_client.Create(owner, name, newDeployKey).ToObservable());
        }
Ejemplo n.º 15
0
    public async Task CanRetrieveAllDeployKeys()
    {
        var deployKeys = await _client.GetAll(_owner, _repository.Name).ToList();

        Assert.Empty(deployKeys);

        var deployKey = new NewDeployKey()
        {
            Key   = _key,
            Title = _keyTitle
        };
        await _client.Create(_owner, _repository.Name, deployKey);

        deployKeys = await _client.GetAll(_owner, _repository.Name).ToList();

        Assert.Equal(1, deployKeys.Count);
        Assert.Equal(_key, deployKeys[0].Key);
        Assert.Equal(_keyTitle, deployKeys[0].Title);
    }
Ejemplo n.º 16
0
    public async Task CanRetrieveAllDeployKeys()
    {
        var deployKeys = await _fixture.GetAll(_context.RepositoryOwner, _context.RepositoryName);

        Assert.Equal(0, deployKeys.Count);

        var deployKey = new NewDeployKey
        {
            Key   = _key,
            Title = _keyTitle
        };

        await _fixture.Create(_context.RepositoryOwner, _context.RepositoryName, deployKey);

        deployKeys = await _fixture.GetAll(_context.RepositoryOwner, _context.RepositoryName);

        Assert.Equal(1, deployKeys.Count);
        Assert.Equal(_key, deployKeys[0].Key);
        Assert.Equal(_keyTitle, deployKeys[0].Title);
    }
Ejemplo n.º 17
0
    public async Task CanRemoveADeployKey()
    {
        var newDeployKey = new NewDeployKey()
        {
            Key   = _key,
            Title = _keyTitle
        };

        await _fixture.Create(_owner, _repository.Name, newDeployKey);

        var deployKeys = await _fixture.GetAll(_owner, _repository.Name);

        Assert.Equal(1, deployKeys.Count);
        Assert.Equal(_key, deployKeys[0].Key);
        Assert.Equal(_keyTitle, deployKeys[0].Title);

        await _fixture.Delete(_owner, _repository.Name, deployKeys[0].Id);

        deployKeys = await _fixture.GetAll(_owner, _repository.Name);

        Assert.Equal(0, deployKeys.Count);
    }
Ejemplo n.º 18
0
    public async Task ReturnsDistinctResultsBasedOnStartPage()
    {
        var list            = new List <NewDeployKey>();
        var deployKeysCount = 5;

        for (int i = 0; i < deployKeysCount; i++)
        {
            var item = new NewDeployKey
            {
                Key   = "ssh-rsa A" + i, // here we should genereate ssh-key some how
                Title = "KeyTitle" + i
            };
            list.Add(item);
        }

        foreach (var key in list)
        {
            await _fixture.Create(_context.RepositoryOwner, _context.RepositoryName, key);
        }

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

        var firstPage = await _fixture.GetAll(_context.RepositoryOwner, _context.RepositoryName, startOptions);

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

        var secondPage = await _fixture.GetAll(_context.RepositoryOwner, _context.RepositoryName, skipStartOptions);

        Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
    }
Ejemplo n.º 19
0
    public async Task CanRemoveADeployKeyWithRepositoryId()
    {
        var newDeployKey = new NewDeployKey
        {
            Key   = _key,
            Title = _keyTitle
        };

        await _fixture.Create(_context.Repository.Id, newDeployKey);

        var deployKeys = await _fixture.GetAll(_context.Repository.Id);

        Assert.Equal(1, deployKeys.Count);
        Assert.Equal(_key, deployKeys[0].Key);
        Assert.Equal(_keyTitle, deployKeys[0].Title);

        await _fixture.Delete(_context.Repository.Id, deployKeys[0].Id);

        deployKeys = await _fixture.GetAll(_context.Repository.Id);

        Assert.Equal(0, deployKeys.Count);
    }
            public void CreatesCorrectUrlWithRepositoryId()
            {
                var gitHubClient = Substitute.For<IGitHubClient>();
                var deployKeysClient = new ObservableRepositoryDeployKeysClient(gitHubClient);
                var data = new NewDeployKey { Key = "ABC123", Title = "user@repo" };

                deployKeysClient.Create(1, data);

                gitHubClient.Repository.DeployKeys.Received(1).Create(1, data);
            }
        /// <summary>
        /// Creates a new deploy key for a repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="https://developer.github.com/v3/repos/keys/#create"> API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository.</param>
        /// <param name="newDeployKey">The deploy key to create for the repository.</param>
        public IObservable<DeployKey> Create(int repositoryId, NewDeployKey newDeployKey)
        {
            Ensure.ArgumentNotNull(newDeployKey, "newDeployKey");


            if (string.IsNullOrWhiteSpace(newDeployKey.Title))
                throw new ArgumentException("The new deploy key's title must not be null.");

            if (string.IsNullOrWhiteSpace(newDeployKey.Key))
                throw new ArgumentException("The new deploy key's key must not be null.");

            return _client.Create(repositoryId, newDeployKey).ToObservable();
        }
            public void CreatesCorrectUrlWithRepositoryId()
            {
                var apiConnection = Substitute.For<IApiConnection>();
                var deployKeysClient = new RepositoryDeployKeysClient(apiConnection);

                var newDeployKey = new NewDeployKey { Key = "ABC123", Title = "user@repo" };

                deployKeysClient.Create(1, newDeployKey);

                apiConnection.Received().Post<DeployKey>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/keys"),
                    newDeployKey);
            }