Esempio n. 1
0
            public void EnsuresArgumentsNotNull()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new IssuesClient(connection);

                Assert.Throws <ArgumentNullException>(() => client.Create(null, "name", new NewIssue("title")));
                Assert.Throws <ArgumentException>(() => client.Create("", "name", new NewIssue("x")));
                Assert.Throws <ArgumentNullException>(() => client.Create("owner", null, new NewIssue("x")));
                Assert.Throws <ArgumentException>(() => client.Create("owner", "", new NewIssue("x")));
                Assert.Throws <ArgumentNullException>(() => client.Create("owner", "name", null));
            }
        public ActionResult CreateIssue(IssueViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }


            IIssuesClient issues = new IssuesClient(
                new ApiConnection(
                    new Connection(
                        new ProductHeaderValue(_productName),
                        new InMemoryCredentialStore(
                            new Credentials(_userName, _userPass)))));
            var iss = new NewIssue(model.Title)
            {
                Body = model.Body
            };

            foreach (var label in model.Labels)
            {
                iss.Labels.Add(label);
            }

            issues.Create(_userName, _productName, iss);
            return(Redirect(model.BaseUri));
        }
 public async Task <Issue> CreateIssue(long repositoryId, NewIssue newIssueDetails, GitHubClient authorizedGitHubClient)
 {
     if (_issuesClient == null)
     {
         _issuesClient = new IssuesClient(new ApiConnection(authorizedGitHubClient.Connection));
     }
     return(await _issuesClient.Create(repositoryId, newIssueDetails));
 }
Esempio n. 4
0
            public void PostsToCorrectUrl()
            {
                var newIssue   = new NewIssue("some title");
                var connection = Substitute.For <IApiConnection>();
                var client     = new IssuesClient(connection);

                client.Create("fake", "repo", newIssue);

                connection.Received().Post <Issue>(Arg.Is <Uri>(u => u.ToString() == "repos/fake/repo/issues"), newIssue);
            }
Esempio n. 5
0
            public async Task EnsuresNonNullArguments()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesClient(connection);

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(null, "name", new NewIssue("x")));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", null, new NewIssue("x")));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", "name", null));

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

                await Assert.ThrowsAsync<ArgumentException>(() => client.Create("", "name", new NewIssue("x")));
                await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "", new NewIssue("x")));
            }
            public async Task EnsuresArgumentsNotNull()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesClient(connection);

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(null, "name", new NewIssue("title")));
                await Assert.ThrowsAsync<ArgumentException>(() => client.Create("", "name", new NewIssue("x")));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", null, new NewIssue("x")));
                await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "", new NewIssue("x")));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", "name", null));
            }
            public void PostsToCorrectUrl()
            {
                var newIssue = new NewIssue("some title");
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesClient(connection);

                client.Create("fake", "repo", newIssue);

                connection.Received().Post<Issue>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues"),
                    newIssue);
            }