示例#1
0
        public async Task UnprotectsBranch()
        {
            await CreateTheWorld();

            // Unprotect branch
            // Deliberately set Enforcement and Contexts to some values (these should be ignored)
            var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Everyone, new List <string> {
                "check1"
            });

            var update = new BranchUpdate();

            update.Protection = new BranchProtection(false, requiredStatusChecks);

            var branch = await _fixture.Edit(_context.Repository.Owner.Login, _context.Repository.Name, "master", update);

            // Ensure a branch object was returned
            Assert.NotNull(branch);

            // Retrieve master branch
            branch = await _fixture.Get(_context.Repository.Owner.Login, _context.Repository.Name, "master");

            // Assert the branch is unprotected, and enforcement/contexts are cleared
            Assert.Equal(branch.Protection.Enabled, false);
            Assert.Equal(branch.Protection.RequiredStatusChecks.EnforcementLevel, EnforcementLevel.Off);
            Assert.Equal(branch.Protection.RequiredStatusChecks.Contexts.Count, 0);
        }
示例#2
0
        public async Task RemoveStatusCheckEnforcement()
        {
            await CreateTheWorld();

            // Remove status check enforcement
            var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Off, new List <string> {
                "check1"
            });

            var update = new BranchUpdate();

            update.Protection = new BranchProtection(true, requiredStatusChecks);

            var branch = await _fixture.Edit(_context.Repository.Owner.Login, _context.Repository.Name, "master", update);

            // Ensure a branch object was returned
            Assert.NotNull(branch);

            // Retrieve master branch
            branch = await _fixture.Get(_context.Repository.Owner.Login, _context.Repository.Name, "master");

            // Assert the changes were made
            Assert.Equal(branch.Protection.Enabled, true);
            Assert.Equal(branch.Protection.RequiredStatusChecks.EnforcementLevel, EnforcementLevel.Off);
            Assert.Equal(branch.Protection.RequiredStatusChecks.Contexts.Count, 1);
        }
示例#3
0
        public IObservable <Branch> Edit(long repositoryId, string branch, BranchUpdate update)
        {
            Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
            Ensure.ArgumentNotNull(update, "update");

            return(_client.Edit(repositoryId, branch, update).ToObservable());
        }
        public async Task ProtectsBranch()
        {
            // Set master branch to be protected, with some status checks
            var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Everyone, new List <string>()
            {
                "check1", "check2", "check3"
            });

            var update = new BranchUpdate();

            update.Protection = new BranchProtection(true, requiredStatusChecks);

            var branch = await _fixture.EditBranch(_context.Repository.Owner.Login, _context.Repository.Name, "master", update);

            // Ensure a branch object was returned
            Assert.NotNull(branch);

            // Retrieve master branch
            branch = await _fixture.GetBranch(_context.Repository.Owner.Login, _context.Repository.Name, "master");

            // Assert the changes were made
            Assert.Equal(branch.Protection.Enabled, true);
            Assert.Equal(branch.Protection.RequiredStatusChecks.EnforcementLevel, EnforcementLevel.Everyone);
            Assert.Equal(branch.Protection.RequiredStatusChecks.Contexts.Count, 3);
        }
示例#5
0
        public IObservable <Branch> EditBranch(int repositoryId, string branch, BranchUpdate update)
        {
            Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
            Ensure.ArgumentNotNull(update, "update");

            return(Branch.Edit(repositoryId, branch, update));
        }
            public async Task EnsuresNonNullArguments()
            {
                var client = new RepositoryBranchesClient(Substitute.For <IApiConnection>());
                var update = new BranchUpdate();

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.Edit(null, "repo", "branch", update));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.Edit("owner", null, "branch", update));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.Edit("owner", "repo", null, update));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.Edit("owner", "repo", "branch", null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.Edit(1, null, update));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.Edit(1, "branch", null));

                await Assert.ThrowsAsync <ArgumentException>(() => client.Edit("", "repo", "branch", update));

                await Assert.ThrowsAsync <ArgumentException>(() => client.Edit("owner", "", "branch", update));

                await Assert.ThrowsAsync <ArgumentException>(() => client.Edit("owner", "repo", "", update));

                await Assert.ThrowsAsync <ArgumentException>(() => client.Edit(1, "", update));
            }
示例#7
0
        public IObservable <Branch> Edit(string owner, string name, string branch, BranchUpdate update)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
            Ensure.ArgumentNotNull(update, "update");

            return(_client.Edit(owner, name, branch, update).ToObservable());
        }
示例#8
0
            public void CallsIntoClient()
            {
                var github = Substitute.For <IGitHubClient>();
                var client = new ObservableRepositoriesClient(github);
                var update = new BranchUpdate();

                client.EditBranch("owner", "repo", "branch", update);

                github.Repository.Received(1).EditBranch("owner", "repo", "branch", update);
            }
            public void RequestsTheCorrectUrl()
            {
                var github = Substitute.For <IGitHubClient>();
                var client = new ObservableRepositoryBranchesClient(github);
                var update = new BranchUpdate();

                client.Edit("owner", "repo", "branch", update);

                github.Repository.Branch.Received(1).Edit("owner", "repo", "branch", update);
            }
            public void PatchsTheCorrectUrlWithRepositoryId()
            {
                var github = Substitute.For <IGitHubClient>();
                var client = new ObservableRepositoriesClient(github);
                var update = new BranchUpdate();

                client.EditBranch(1, "branch", update);

                github.Repository.Branch.Received(1).Edit(1, "branch", update);
            }
示例#11
0
            public void GetsCorrectUrl()
            {
                var          connection           = Substitute.For <IApiConnection>();
                var          client               = new RepositoriesClient(connection);
                var          update               = new BranchUpdate();
                const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";

                client.EditBranch("owner", "repo", "branch", update);

                connection.Received()
                .Patch <Branch>(Arg.Is <Uri>(u => u.ToString() == "repos/owner/repo/branches/branch"), Arg.Any <BranchUpdate>(), previewAcceptsHeader);
            }
示例#12
0
        public async Task CreateTheWorld()
        {
            // Set master branch to be protected, with some status checks
            var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Everyone, new List <string> {
                "check1", "check2"
            });

            var update = new BranchUpdate();

            update.Protection = new BranchProtection(true, requiredStatusChecks);

            var newBranch = await _fixture.Edit(_context.Repository.Owner.Login, _context.Repository.Name, "master", update);
        }
示例#13
0
            public async Task EnsuresArguments()
            {
                var github            = Substitute.For <IGitHubClient>();
                var nonreactiveClient = new RepositoriesClient(Substitute.For <IApiConnection>());

                github.Repository.Returns(nonreactiveClient);
                var client = new ObservableRepositoriesClient(github);
                var update = new BranchUpdate();

                Assert.Throws <ArgumentNullException>(() => client.EditBranch(null, "repo", "branch", update));
                Assert.Throws <ArgumentNullException>(() => client.EditBranch("owner", null, "branch", update));
                Assert.Throws <ArgumentNullException>(() => client.EditBranch("owner", "repo", null, update));
                Assert.Throws <ArgumentNullException>(() => client.EditBranch("owner", "repo", "branch", null));
                Assert.Throws <ArgumentException>(() => client.EditBranch("", "repo", "branch", update));
                Assert.Throws <ArgumentException>(() => client.EditBranch("owner", "", "branch", update));
                Assert.Throws <ArgumentException>(() => client.EditBranch("owner", "repo", "", update));
            }
            public async Task EnsuresNonNullArguments()
            {
                var client = new ObservableRepositoriesClient(Substitute.For <IGitHubClient>());
                var update = new BranchUpdate();

                Assert.Throws <ArgumentNullException>(() => client.EditBranch(null, "repo", "branch", update));
                Assert.Throws <ArgumentNullException>(() => client.EditBranch("owner", null, "branch", update));
                Assert.Throws <ArgumentNullException>(() => client.EditBranch("owner", "repo", null, update));
                Assert.Throws <ArgumentNullException>(() => client.EditBranch("owner", "repo", "branch", null));

                Assert.Throws <ArgumentNullException>(() => client.EditBranch(1, null, update));
                Assert.Throws <ArgumentNullException>(() => client.EditBranch(1, "branch", null));

                Assert.Throws <ArgumentException>(() => client.EditBranch("", "repo", "branch", update));
                Assert.Throws <ArgumentException>(() => client.EditBranch("owner", "", "branch", update));
                Assert.Throws <ArgumentException>(() => client.EditBranch("owner", "repo", "", update));

                Assert.Throws <ArgumentException>(() => client.EditBranch(1, "", update));
            }
            public async Task EnsuresNonNullArguments()
            {
                var client = new ObservableRepositoryBranchesClient(Substitute.For<IGitHubClient>());
                var update = new BranchUpdate();

                Assert.Throws<ArgumentNullException>(() => client.Edit(null, "repo", "branch", update));
                Assert.Throws<ArgumentNullException>(() => client.Edit("owner", null, "branch", update));
                Assert.Throws<ArgumentNullException>(() => client.Edit("owner", "repo", null, update));
                Assert.Throws<ArgumentNullException>(() => client.Edit("owner", "repo", "branch", null));

                Assert.Throws<ArgumentNullException>(() => client.Edit(1, null, update));
                Assert.Throws<ArgumentNullException>(() => client.Edit(1, "branch", null));

                Assert.Throws<ArgumentException>(() => client.Edit("", "repo", "branch", update));
                Assert.Throws<ArgumentException>(() => client.Edit("owner", "", "branch", update));
                Assert.Throws<ArgumentException>(() => client.Edit("owner", "repo", "", update));

                Assert.Throws<ArgumentException>(() => client.Edit(1, "", update));
            }
        public IObservable<Branch> EditBranch(string owner, string name, string branch, BranchUpdate update)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
            Ensure.ArgumentNotNull(update, "update");

            return Branch.Edit(owner, name, branch, update);
        }
 /// <summary>
 /// Edit the specified branch with the values given in <paramref name="update"/>
 /// </summary>
 /// <param name="owner">The owner of the repository</param>
 /// <param name="name">The name of the repository</param>
 /// <param name="branch">The name of the branch</param>
 /// <param name="update">New values to update the branch with</param>
 /// <returns>The updated <see cref="T:Octokit.Branch"/></returns>
 public IObservable <Branch> EditBranch(string owner, string name, string branch, BranchUpdate update)
 {
     return(_client.EditBranch(owner, name, branch, update).ToObservable());
 }
        public IObservable<Branch> EditBranch(long repositoryId, string branch, BranchUpdate update)
        {
            Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
            Ensure.ArgumentNotNull(update, "update");

            return Branch.Edit(repositoryId, branch, update);
        }
            public async Task EnsuresNonNullArguments()
            {
                var client = new RepositoriesClient(Substitute.For<IApiConnection>());
                var update = new BranchUpdate();

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.EditBranch(null, "repo", "branch", update));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.EditBranch("owner", null, "branch", update));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.EditBranch("owner", "repo", null, update));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.EditBranch("owner", "repo", "branch", null));

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.EditBranch(1, null, update));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.EditBranch(1, "branch", null));

                await Assert.ThrowsAsync<ArgumentException>(() => client.EditBranch("", "repo", "branch", update));
                await Assert.ThrowsAsync<ArgumentException>(() => client.EditBranch("owner", "", "branch", update));
                await Assert.ThrowsAsync<ArgumentException>(() => client.EditBranch("owner", "repo", "", update));

                await Assert.ThrowsAsync<ArgumentException>(() => client.EditBranch(1, "", update));
            }
        /// <summary>
        /// Edit the specified branch with the values given in <paramref name="update"/>
        /// </summary>
        /// <param name="repositoryId">The ID of the repository</param>
        /// <param name="branch">The name of the branch</param>
        /// <param name="update">New values to update the branch with</param>
        /// <returns>The updated <see cref="T:Octokit.Branch"/></returns>
        public IObservable<Branch> EditBranch(int repositoryId, string branch, BranchUpdate update)
        {
            Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
            Ensure.ArgumentNotNull(update, "update");

            return _client.EditBranch(repositoryId, branch, update).ToObservable();
        }
            public void RequestsTheCorrectUrlWithRepositoryId()
            {
                var github = Substitute.For<IGitHubClient>();
                var client = new ObservableRepositoryBranchesClient(github);
                var update = new BranchUpdate();

                client.Edit(1, "branch", update);

                github.Repository.Branch.Received(1).Edit(1, "branch", update);
            }
            public void CallsIntoClient()
            {
                var github = Substitute.For<IGitHubClient>();
                var client = new ObservableRepositoriesClient(github);
                var update = new BranchUpdate();

                client.EditBranch("owner", "repo", "branch", update);

                github.Repository.Received(1).EditBranch("owner", "repo", "branch", update);
            }
            public async Task EnsuresArguments()
            {
                var github = Substitute.For<IGitHubClient>();
                var nonreactiveClient = new RepositoriesClient(Substitute.For<IApiConnection>());
                github.Repository.Returns(nonreactiveClient);
                var client = new ObservableRepositoriesClient(github);
                var update = new BranchUpdate();

                Assert.Throws<ArgumentNullException>(() => client.EditBranch(null, "repo", "branch", update));
                Assert.Throws<ArgumentNullException>(() => client.EditBranch("owner", null, "branch", update));
                Assert.Throws<ArgumentNullException>(() => client.EditBranch("owner", "repo", null, update));
                Assert.Throws<ArgumentNullException>(() => client.EditBranch("owner", "repo", "branch", null));
                Assert.Throws<ArgumentException>(() => client.EditBranch("", "repo", "branch", update));
                Assert.Throws<ArgumentException>(() => client.EditBranch("owner", "", "branch", update));
                Assert.Throws<ArgumentException>(() => client.EditBranch("owner", "repo", "", update));
            }
 /// <summary>
 /// Edit the specified branch with the values given in <paramref name="update"/>
 /// </summary>
 /// <param name="owner">The owner of the repository</param>
 /// <param name="name">The name of the repository</param>
 /// <param name="branch">The name of the branch</param>
 /// <param name="update">New values to update the branch with</param>
 /// <returns>The updated <see cref="T:Octokit.Branch"/></returns>
 public IObservable<Branch> EditBranch(string owner, string name, string branch, BranchUpdate update)
 {
     return _client.EditBranch(owner, name, branch, update).ToObservable();
 }
            public void RequestsTheCorrectUrlWithRepositoryId()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new RepositoriesClient(connection);
                var update = new BranchUpdate();
                const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";

                client.EditBranch(1, "branch", update);

                connection.Received()
                    .Patch<Branch>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/branches/branch"), Arg.Any<BranchUpdate>(), previewAcceptsHeader);
            }