예제 #1
0
            public async Task EnsuresNonNullArguments()
            {
                var client      = new IssuesLabelsClient(Substitute.For <IApiConnection>());
                var labelUpdate = new LabelUpdate("name", "FF0000");

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.Update(null, "name", "labelName", labelUpdate));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.Update("owner", null, "labelName", labelUpdate));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.Update("owner", "name", null, labelUpdate));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.Update("owner", "name", "labelName", null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.Update(1, null, labelUpdate));

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

                await Assert.ThrowsAsync <ArgumentException>(() => client.Update("", "name", "labelName", labelUpdate));

                await Assert.ThrowsAsync <ArgumentException>(() => client.Update("owner", "", "labelName", labelUpdate));

                await Assert.ThrowsAsync <ArgumentException>(() => client.Update("owner", "name", "", labelUpdate));

                await Assert.ThrowsAsync <ArgumentException>(() => client.Update(1, "", labelUpdate));
            }
예제 #2
0
        public static async Task CreateOrUpdateLabelAsync(this GitHubClient client, RepositoryInfo repository, Models.Objects.Label label)
        {
            IssuesLabelsClient ilc = new IssuesLabelsClient(new ApiConnection(client.Connection));

            Colorizer.WriteLine("Creating or updating label [Cyan!{0}] in repo [Yellow!{1}]", $"Title: {label.Title}, Description: {label.Description}, Color: {label.Color}", repository);

            try
            {
                Label existingLabel = await ilc.Get(repository.Owner, repository.Name, label.Title);

                // try to update the label
                Colorizer.WriteLine("Label found, updating");
                LabelUpdate updateOperation = new LabelUpdate(label.Title, label.Color);
                updateOperation.Description = label.Description;
                await ilc.Update(repository.Owner, repository.Name, label.Title, updateOperation);

                Colorizer.WriteLine("[Green!Success]");
            }
            catch (NotFoundException ex)
            {
                if (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    Colorizer.WriteLine("Label not found, creating");
                    // try to create the label
                    await CreateLabelAsync(client, repository, label);

                    Colorizer.WriteLine("[Green!Success]");
                }
            }
        }
예제 #3
0
            public void UpdatesCorrectUrlWithRepositoryId()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new IssuesLabelsClient(connection);

                var labelUpdate = new LabelUpdate("name", "FF0000");

                client.Update(1, "labelName", labelUpdate);

                connection.Received().Post <Label>(Arg.Is <Uri>(u => u.ToString() == "repositories/1/labels/labelName"), labelUpdate);
            }
            public void UpdatesCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new IssuesLabelsClient(connection);

                var labelUpdate = new LabelUpdate("name", "FF0000");

                client.Update("fake", "repo", "labelName", labelUpdate);

                connection.Received().Post <Label>(Arg.Is <Uri>(u => u.ToString() == "repos/fake/repo/labels/labelName"), labelUpdate, "application/vnd.github.symmetra-preview+json");
            }
            public async Task EnsuresNonNullArguments()
            {
                var client = new IssuesLabelsClient(Substitute.For<IApiConnection>());
                var labelUpdate = new LabelUpdate("name", "FF0000");

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.Update(null, "name", "labelName", labelUpdate));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.Update("owner", null, "labelName", labelUpdate));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.Update("owner", "name", null, labelUpdate));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.Update("owner", "name", "labelName", null));

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.Update(1, null, labelUpdate));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.Update(1, "labelName", null));

                await Assert.ThrowsAsync<ArgumentException>(() => client.Update("", "name", "labelName", labelUpdate));
                await Assert.ThrowsAsync<ArgumentException>(() => client.Update("owner", "", "labelName", labelUpdate));
                await Assert.ThrowsAsync<ArgumentException>(() => client.Update("owner", "name", "", labelUpdate));

                await Assert.ThrowsAsync<ArgumentException>(() => client.Update(1, "", labelUpdate));
            }
            public void UpdatesCorrectUrlWithRepositoryId()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesLabelsClient(connection);

                var labelUpdate = new LabelUpdate("name", "FF0000");

                client.Update(1, "labelName", labelUpdate);

                connection.Received().Post<Label>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/labels/labelName"), labelUpdate);
            }