public async Task EnsuresNonNullArguments()
            {
                var client = new IssuesLabelsClient(Substitute.For<IApiConnection>());

                await AssertEx.Throws<ArgumentNullException>(async () => await client.Get(null, "name", "label"));
                await AssertEx.Throws<ArgumentNullException>(async () => await client.Get("owner", null, "label"));
            }
            public async Task EnsuresNonNullArguments()
            {
                var client = new IssuesLabelsClient(Substitute.For <IApiConnection>());

                await AssertEx.Throws <ArgumentNullException>(async() => await client.Get(null, "name", "label"));

                await AssertEx.Throws <ArgumentNullException>(async() => await client.Get("owner", null, "label"));
            }
Esempio n. 3
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]");
                }
            }
        }
            public void RequestsCorrectUrl()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesLabelsClient(connection);

                client.Get("fake", "repo", "label");

                connection.Received().Get<Label>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/labels/label"));
            }
Esempio n. 5
0
            public async Task RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new IssuesLabelsClient(connection);

                await client.Get("fake", "repo", "label");

                connection.Received().Get <Label>(Arg.Is <Uri>(u => u.ToString() == "repos/fake/repo/labels/label"));
            }
Esempio n. 6
0
            public async Task RequestsCorrectUrlWithRepositoryId()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new IssuesLabelsClient(connection);

                await client.Get(1, "label");

                connection.Received().Get <Label>(Arg.Is <Uri>(u => u.ToString() == "repositories/1/labels/label"));
            }
            public async Task RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new IssuesLabelsClient(connection);

                await client.Get("fake", "repo", "label");

                connection.Received().Get <Label>(Arg.Is <Uri>(u => u.ToString() == "repos/fake/repo/labels/label"), null, "application/vnd.github.symmetra-preview+json");
            }
            public async Task RequestsCorrectUrlWithRepositoryId()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesLabelsClient(connection);

                await client.Get(1, "label");

                connection.Received().Get<Label>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/labels/label"));
            }