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

                await AssertEx.Throws<ArgumentNullException>(async () => await client.Get(null, "name", 1));
                await AssertEx.Throws<ArgumentNullException>(async () => await client.Get("owner", null, 1));
            }
            public void RequestsCorrectUrl()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesClient(connection);

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

                connection.Received().Get<Issue>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42"));
            }
            public async Task EnsuresNonNullArguments()
            {
                var client = new IssuesClient(Substitute.For<IApiConnection>());

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOwnedAndMemberRepositories((ApiOptions)null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOwnedAndMemberRepositories((IssueRequest)null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOwnedAndMemberRepositories(null, new ApiOptions()));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOwnedAndMemberRepositories(new IssueRequest(), null));
            }
            public void RequestsCorrectUrl()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesClient(connection);

                client.GetAllForOwnedAndMemberRepositories();

                connection.Received().GetAll<Issue>(Arg.Is<Uri>(u => u.ToString() == "user/issues"),
                    Arg.Any<Dictionary<string, string>>());
            }
            public void RequestsCorrectUrl()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesClient(connection);

                client.GetAllForCurrent();

                connection.Received().GetAll<Issue>(Arg.Is<Uri>(u => u.ToString() == "issues"),
                    Arg.Any<Dictionary<string, string>>(), Args.ApiOptions);
            }
            public async Task RequestsCorrectUrlWithRepositoryId()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesClient(connection);

                await client.Get(1, 42);

                connection.Received().Get<Issue>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/issues/42"),
                    Arg.Any<Dictionary<string, string>>(),
                    "application/vnd.github.squirrel-girl-preview");
            }
            public async Task RequestsCorrectUrl()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesClient(connection);

                await client.GetAllForCurrent();

                connection.Received().GetAll<Issue>(Arg.Is<Uri>(u => u.ToString() == "issues"),
                    Arg.Any<Dictionary<string, string>>(),
                    "application/vnd.github.squirrel-girl-preview",
                    Args.ApiOptions);
            }
            public void SendsAppropriateParameters()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesClient(connection);

                client.GetAllForCurrent(new IssueRequest { SortDirection = SortDirection.Ascending });

                connection.Received().GetAll<Issue>(Arg.Is<Uri>(u => u.ToString() == "issues"),
                    Arg.Is<Dictionary<string, string>>(d => d.Count == 4
                        && d["filter"] == "assigned"
                        && d["sort"] == "created"
                        && d["state"] == "open"
                        && d["direction"] == "asc"));
            }
            public async Task SendsAppropriateParameters()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesClient(connection);

                await client.GetAllForCurrent(new IssueRequest { SortDirection = SortDirection.Ascending });

                connection.Received().GetAll<Issue>(Arg.Is<Uri>(u => u.ToString() == "issues"),
                    Arg.Is<Dictionary<string, string>>(d => d.Count == 4
                        && d["filter"] == "assigned"
                        && d["sort"] == "created"
                        && d["state"] == "open"
                        && d["direction"] == "asc"),
                    "application/vnd.github.squirrel-girl-preview",
                    Args.ApiOptions);
            }
Esempio n. 10
0
            public async Task EnsuresNonNullArguments()
            {
                var client = new IssuesClient(Substitute.For<IApiConnection>());

                var options = new ApiOptions();
                var request = new RepositoryIssueRequest();

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOrganization(null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOrganization(null, options));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOrganization(null, request));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOrganization(null, request, options));

                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForOrganization(""));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForOrganization("", options));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForOrganization("", request));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForOrganization("", request, options));

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOrganization("org", (ApiOptions)null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOrganization("org", (IssueRequest)null));

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOrganization("org", null, options));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOrganization("org", request, null));
            }
Esempio n. 11
0
            public void PostsToCorrectUrlWithRepositoryId()
            {
                var issueUpdate = new IssueUpdate();
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesClient(connection);

                client.Update(1, 42, issueUpdate);

                connection.Received().Patch<Issue>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/issues/42"),
                    issueUpdate);
            }
Esempio n. 12
0
            public async Task SendsAppropriateParametersWithRepositoryIdWithApiOptions()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesClient(connection);

                var options = new ApiOptions
                {
                    PageCount = 1,
                    StartPage = 1,
                    PageSize = 1
                };

                await client.GetAllForRepository(1, new RepositoryIssueRequest
                {
                    SortDirection = SortDirection.Ascending
                }, options);

                connection.Received().GetAll<Issue>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/issues"),
                    Arg.Is<Dictionary<string, string>>(d => d.Count == 4
                        && d["state"] == "open"
                        && d["direction"] == "asc"
                        && d["sort"] == "created"
                        && d["filter"] == "assigned"),
                    "application/vnd.github.squirrel-girl-preview",
                    options);
            }
Esempio n. 13
0
            public async Task EnsuresNonNullArguments()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesClient(connection);

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

                await Assert.ThrowsAsync<ArgumentException>(() => client.Unlock("", "name", 1));
                await Assert.ThrowsAsync<ArgumentException>(() => client.Unlock("owner", "", 1));
            }
            public void PostsToCorrectUrl()
            {
                var issueUpdate = new IssueUpdate();
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesClient(connection);

                client.Update("fake", "repo", 42, issueUpdate);

                connection.Received().Patch<Issue>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42"),
                    issueUpdate);
            }
            public async Task EnsuresArgumentsNotNull()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesClient(connection);

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.Update(null, "name", 1, new IssueUpdate()));
                await Assert.ThrowsAsync<ArgumentException>(() => client.Update("", "name", 1, new IssueUpdate()));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.Update("owner", null, 1, new IssueUpdate()));
                await Assert.ThrowsAsync<ArgumentException>(() => client.Update("owner", "", 1, new IssueUpdate()));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.Update("owner", "name", 1, null));
            }
            public async Task EnsuresArgumentsNotNull()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesClient(connection);

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetForRepository(null, "name", new RepositoryIssueRequest()));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetForRepository("", "name", new RepositoryIssueRequest()));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetForRepository("owner", null, new RepositoryIssueRequest()));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetForRepository("owner", "", new RepositoryIssueRequest()));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetForRepository("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);
            }
Esempio n. 18
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 BernieHttpClient(IssuesClient issuesClient, NewsClient newsClient)
 {
     _issuesClient = issuesClient;
     _newsClient = newsClient;
 }
Esempio n. 20
0
            public void PostsToCorrectUrlWithRepositoryId()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesClient(connection);

                client.Lock(1, 42);

                connection.Received().Put<Issue>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/issues/42/lock"), Arg.Any<object>(), Arg.Any<string>(), Arg.Is<string>(u => u.ToString() == "application/vnd.github.the-key-preview+json"));
            }
Esempio n. 21
0
            public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesClient(connection);

                var options = new ApiOptions
                {
                    PageCount = 1,
                    StartPage = 1,
                    PageSize = 1
                };

                await client.GetAllForRepository(1, options);

                connection.Received().GetAll<Issue>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/issues"),
                    Arg.Any<Dictionary<string, string>>(),
                    "application/vnd.github.squirrel-girl-preview",
                    options);
            }
            public void RequestsCorrectUrl()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesClient(connection);

                client.GetForRepository("fake", "repo");

                connection.Received().GetAll<Issue>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues"),
                    Arg.Any<Dictionary<string, string>>());
            }
Esempio n. 23
0
            public void PostsToCorrectUrl()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssuesClient(connection);

                client.Unlock("fake", "repo", 42);

                connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42/lock"), Arg.Any<object>(), Arg.Is<string>(u => u.ToString() == "application/vnd.github.the-key-preview+json"));
            }
Esempio n. 24
0
            public async Task EnsuresArgumentsNotNull()
            {
                var client = new IssuesClient(Substitute.For<IApiConnection>());

                var options = new ApiOptions();
                var request = new RepositoryIssueRequest();

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name"));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name", options));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name", request));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name", request, options));

                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name"));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name", options));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name", request));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name", request, options));

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null, options));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null, request));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null, request, options));

                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", ""));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", "", options));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", "", request));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", "", request, options));

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", (ApiOptions)null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", (RepositoryIssueRequest)null));

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null, options));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", request, null));
            }
Esempio n. 25
0
        public void GetProjectIssues10K_Success()
        {
            MockClient.
            Setup(x => x.ExecuteTaskAsync(It.Is <IRestRequest>(request => (request.Resource == "api/issues/search") && request.Parameters.Any(param => param.Name == "types" && param.Value.ToString() == "BUG")))).
            Returns((IRestRequest request) =>
            {
                var p  = request.Parameters.First(param => param.Name == "p").Value;
                var ps = request.Parameters.First(param => param.Name == "ps").Value;

                var issue = "{\"key\": \"AWDVIu_vf44sODN6PmH7\", \"rule\": \"cxx:UndocumentedApi\", \"severity\": \"INFO\", \"component\": " +
                            "\"ETAS:INCA:HWA:A1b:LIN/file.cpp\", \"project\": \"ETAS:INCA:HWA:A1b:LIN\", \"line\": 1, \"hash\": \"a133b69778aeed2e9f10f652bd6cffed\", " +
                            "\"textRange\": { \"startLine\": 1, \"endLine\": 1, \"startOffset\": 0, \"endOffset\": 1 }, " +
                            "\"flows\": [], \"status\": \"OPEN\", \"message\": \"Undocumented API: Matches\", \"effort\": \"5min\", " +
                            "\"debt\": \"5min\", \"author\": \"\", \"tags\": [\"convention\"], \"creationDate\": \"2018-01-08T10:37:27+0100\", \"updateDate\": \"2018-01-08T10:37:27+0100\", " +
                            "\"type\": \"BUG\", \"organization\": \"default-organization\" }";

                var response = $"{{\"total\": 1, \"p\": {p}, \"ps\": {ps}, \"paging\": {{ \"pageIndex\": {p}, \"pageSize\": {ps}, \"total\": 1 }}, \"issues\": [{issue}]}}";

                return(Task.FromResult(RestResponseFactory.Create(response, HttpStatusCode.OK)));
            });

            MockClient.
            Setup(x => x.ExecuteTaskAsync(It.Is <IRestRequest>(request => (request.Resource == "api/issues/search") && request.Parameters.Any(param => param.Name == "types" && param.Value.ToString() == "CODE_SMELL")))).
            Returns((IRestRequest request) =>
            {
                var p  = request.Parameters.First(param => param.Name == "p").Value;
                var ps = request.Parameters.First(param => param.Name == "ps").Value;

                var response = $"{{\"total\": 0, \"p\": {p}, \"ps\": {ps}, \"paging\": {{ \"pageIndex\": {p}, \"pageSize\": {ps}, \"total\": 0 }}, \"issues\": []}}";

                return(Task.FromResult(RestResponseFactory.Create(response, HttpStatusCode.OK)));
            });

            // Simulate 10k issue
            MockClient.
            Setup(x => x.ExecuteTaskAsync(It.Is <IRestRequest>(request => (request.Resource == "api/issues/search") && request.Parameters.Any(param => param.Name == "types" && param.Value.ToString() == "VULNERABILITY")))).
            Returns((IRestRequest request) =>
            {
                var p  = request.Parameters.First(param => param.Name == "p").Value;
                var ps = request.Parameters.First(param => param.Name == "ps").Value;

                var issue = "{\"key\": \"AWDVIu_vf44sODN6PmH7\", \"rule\": \"cxx:UndocumentedApi\", \"severity\": \"INFO\", \"component\": " +
                            "\"ETAS:INCA:HWA:A1b:LIN/file.cpp\", \"project\": \"ETAS:INCA:HWA:A1b:LIN\", \"line\": 1, \"hash\": \"a133b69778aeed2e9f10f652bd6cffed\", " +
                            "\"textRange\": { \"startLine\": 1, \"endLine\": 1, \"startOffset\": 0, \"endOffset\": 1 }, " +
                            "\"flows\": [], \"status\": \"OPEN\", \"message\": \"Undocumented API: Matches\", \"effort\": \"5min\", " +
                            "\"debt\": \"5min\", \"author\": \"\", \"tags\": [\"convention\"], \"creationDate\": \"2018-01-08T10:37:27+0100\", \"updateDate\": \"2018-01-08T10:37:27+0100\", " +
                            "\"type\": \"VULNERABILITY\", \"organization\": \"default-organization\" }";

                var issues = string.Join(",", Enumerable.Repeat(issue, int.Parse(ps.ToString())));

                var response = $"{{\"total\": 24866, \"p\": {p}, \"ps\": {ps}, \"paging\": {{ \"pageIndex\": {p}, \"pageSize\": {ps}, \"total\": 24866 }}, \"issues\": [{issues}]}}";

                return(Task.FromResult(RestResponseFactory.Create(response, HttpStatusCode.OK)));
            });

            var service = new IssuesClient(MockClient.Object);
            var actual  = service.GetProjectIssues("ETAS:INCA:HWA:A1b:LIN").Result;

            // 1 - BUG, 10000 - VULNERABILITY, 0 - CODE_SMELL
            Assert.That(actual.Count, Is.EqualTo(1 + 10000));
        }
Esempio n. 26
0
            public async Task EnsuresNonNullArguments()
            {
                var client = new IssuesClient(Substitute.For<IApiConnection>());

                var options = new ApiOptions();
                var request = new RepositoryIssueRequest();

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOrganization(null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOrganization(null, options));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOrganization(null, request));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOrganization(null, request, options));

                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForOrganization(""));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForOrganization("", options));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForOrganization("", request));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForOrganization("", request, options));

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOrganization("org", (ApiOptions)null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOrganization("org", (IssueRequest)null));

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOrganization("org", null, options));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOrganization("org", request, null));
            }