public ObservableRespositoryDeployKeysClientTests()
    {
        var github = Helper.GetAuthenticatedClient();

        _client = new ObservableRepositoryDeployKeysClient(github);
        var repoName = Helper.MakeNameWithTimestamp("public-repo");
        var result   = github.Repository.Create(new NewRepository(repoName)
        {
            AutoInit = true
        }).Result;

        _repository = result;
        _owner      = _repository.Owner.Login;
    }
            public void EnsuresNonNullArguments()
            {
                var deployKeysClient = new ObservableRepositoryDeployKeysClient(Substitute.For <IGitHubClient>());

                Assert.Throws <ArgumentNullException>(() => deployKeysClient.Create(null, "repo", new NewDeployKey()));
                Assert.Throws <ArgumentException>(() => deployKeysClient.Create("", "repo", new NewDeployKey()));
                Assert.Throws <ArgumentNullException>(() => deployKeysClient.Create("user", null, new NewDeployKey()));
                Assert.Throws <ArgumentException>(() => deployKeysClient.Create("user", "", new NewDeployKey()));
                Assert.Throws <ArgumentNullException>(() => deployKeysClient.Create("user", "repo", null));
                Assert.Throws <ArgumentException>(() => deployKeysClient.Create("user", "repo", new NewDeployKey {
                    Title = "user@repo"
                }));
                Assert.Throws <ArgumentException>(() => deployKeysClient.Create("user", "repo", new NewDeployKey {
                    Key = "ABC123"
                }));
            }
Beispiel #3
0
    public ObservableRespositoryDeployKeysClientTests()
    {
        var github = new GitHubClient(new ProductHeaderValue("OctokitTests"))
        {
            Credentials = Helper.Credentials
        };

        _client = new ObservableRepositoryDeployKeysClient(github);
        var repoName = Helper.MakeNameWithTimestamp("public-repo");
        var result   = github.Repository.Create(new NewRepository()
        {
            Name = repoName, AutoInit = true
        }).Result;

        _repository = result;
        _owner      = _repository.Owner.Login;
    }
Beispiel #4
0
            public void EnsuresNonNullArguments()
            {
                var deployKeysClient = new ObservableRepositoryDeployKeysClient(Substitute.For <IGitHubClient>());

                Assert.Throws <ArgumentNullException>(() => deployKeysClient.GetAll(null, "repo"));
                Assert.Throws <ArgumentNullException>(() => deployKeysClient.GetAll("user", null));
                Assert.Throws <ArgumentNullException>(() => deployKeysClient.GetAll(null, "repo", ApiOptions.None));
                Assert.Throws <ArgumentNullException>(() => deployKeysClient.GetAll("user", null, ApiOptions.None));
                Assert.Throws <ArgumentNullException>(() => deployKeysClient.GetAll("user", "repo", null));

                Assert.Throws <ArgumentNullException>(() => deployKeysClient.GetAll(1, null));

                Assert.Throws <ArgumentException>(() => deployKeysClient.GetAll("user", ""));
                Assert.Throws <ArgumentException>(() => deployKeysClient.GetAll("", "repo"));
                Assert.Throws <ArgumentException>(() => deployKeysClient.GetAll("", "repo", ApiOptions.None));
                Assert.Throws <ArgumentException>(() => deployKeysClient.GetAll("user", "", ApiOptions.None));
            }
            public void GetsCorrectUrlWithApiOptions()
            {
                var gitHubClient     = Substitute.For <IGitHubClient>();
                var deployKeysClient = new ObservableRepositoryDeployKeysClient(gitHubClient);
                var expectedUrl      = string.Format("repos/{0}/{1}/keys", "user", "repo");

                // all properties are setted => only 2 options (StartPage, PageSize) in dictionary
                var options = new ApiOptions
                {
                    StartPage = 1,
                    PageCount = 1,
                    PageSize  = 1
                };

                deployKeysClient.GetAll("user", "repo", options);
                gitHubClient.Connection.Received(1)
                .Get <List <DeployKey> >(Arg.Is <Uri>(u => u.ToString() == expectedUrl),
                                         Arg.Is <IDictionary <string, string> >(dictionary => dictionary.Count == 2),
                                         null);

                // StartPage is setted => only 1 option (StartPage) in dictionary
                options = new ApiOptions
                {
                    StartPage = 1
                };

                deployKeysClient.GetAll("user", "repo", options);
                gitHubClient.Connection.Received(1)
                .Get <List <DeployKey> >(Arg.Is <Uri>(u => u.ToString() == expectedUrl),
                                         Arg.Is <IDictionary <string, string> >(dictionary => dictionary.Count == 1),
                                         null);

                // PageCount is setted => none of options in dictionary
                options = new ApiOptions
                {
                    PageCount = 1
                };

                deployKeysClient.GetAll("user", "repo", options);
                gitHubClient.Connection.Received(1)
                .Get <List <DeployKey> >(Arg.Is <Uri>(u => u.ToString() == expectedUrl),
                                         Arg.Is <IDictionary <string, string> >(dictionary => dictionary.Count == 0),
                                         null);
            }