Пример #1
0
            public void TestingTheRepoQualifier()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new SearchClient(connection);
                var request = new SearchCodeRequest("something");
                request.Repo = "octokit.net";

                client.SearchCode(request);

                connection.Received().Get<SearchCodeResult>(
                    Arg.Is<Uri>(u => u.ToString() == "search/code"),
                    Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+repo:octokit.net"));
            }
Пример #2
0
            public void TestingTheRepoAndPathAndExtensionQualifiers()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new SearchClient(connection);
                var request = new SearchCodeRequest("something");
                request.Repo = "octokit.net";
                request.Path = "tools/FAKE.core";
                request.Extension = "fs";

                client.SearchCode(request);

                connection.Received().Get<SearchCodeResult>(
                    Arg.Is<Uri>(u => u.ToString() == "search/code"),
                    Arg.Is<Dictionary<string, string>>(d => 
                        d["q"] == "something+path:tools/FAKE.core+extension:fs+repo:octokit.net"));
            }
Пример #3
0
            public void TestingTheLanguageQualifier()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new SearchClient(connection);
                var request = new SearchCodeRequest("something");
                request.Language = Language.CSharp;

                client.SearchCode(request);

                connection.Received().Get<SearchCodeResult>(
                    Arg.Is<Uri>(u => u.ToString() == "search/code"),
                    Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+language:C#"));
            }
Пример #4
0
            public void TestingTheSizeQualifier_Range()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new SearchClient(connection);
                var request = new SearchCodeRequest("something");
                request.Size = new Range(10, 100);

                client.SearchCode(request);

                connection.Received().Get<SearchCodeResult>(
                    Arg.Is<Uri>(u => u.ToString() == "search/code"),
                    Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+size:10..100"));
            }
Пример #5
0
            public void TestingTheDefaultOrderParameter()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new SearchClient(connection);
                var request = new SearchCodeRequest("something");

                client.SearchCode(request);

                connection.Received().Get<SearchCodeResult>(
                    Arg.Is<Uri>(u => u.ToString() == "search/code"),
                    Arg.Is<Dictionary<string, string>>(d => d["order"] == "desc"));
            }
Пример #6
0
            public void TestingTheInQualifier_Multiple()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new SearchClient(connection);
                var request = new SearchCodeRequest("something");
                request.In = new[] { CodeInQualifier.File, CodeInQualifier.Path };

                client.SearchCode(request);

                connection.Received().Get<SearchCodeResult>(
                    Arg.Is<Uri>(u => u.ToString() == "search/code"),
                    Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+in:file,path"));
            }
Пример #7
0
 public void EnsuresNonNullArguments()
 {
     var client = new SearchClient(Substitute.For<IApiConnection>());
     Assert.Throws<ArgumentNullException>(() => client.SearchCode(null));
 }
Пример #8
0
            public void TestingTheOrderParameter()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new SearchClient(connection);
                var request = new SearchCodeRequest("something");
                request.SortField = CodeSearchSort.Indexed;
                request.Order = SortDirection.Ascending;

                client.SearchCode(request);

                connection.Received().Get<SearchCodeResult>(
                    Arg.Is<Uri>(u => u.ToString() == "search/code"),
                    Arg.Is<Dictionary<string, string>>(d =>
                        d["sort"] == "indexed" &&
                        d["order"] == "asc"));
            }
            public async Task ErrorOccursWhenSpecifyingInvalidFormatForRepos()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new SearchClient(connection);

                var request = new SearchCodeRequest("windows");
                request.Repos = new RepositoryCollection {
                    "haha-business"
                };

                request.Order = SortDirection.Descending;

                await Assert.ThrowsAsync<RepositoryFormatException>(
                    async () => await client.SearchCode(request));
            }
Пример #10
0
 public void RequestsTheCorrectUrl()
 {
     var connection = Substitute.For<IApiConnection>();
     var client = new SearchClient(connection);
     client.SearchCode(new SearchCodeRequest("something"));
     connection.Received().Get<SearchCodeResult>(
         Arg.Is<Uri>(u => u.ToString() == "search/code"),
         Arg.Any<Dictionary<string, string>>());
 }
            public void TestingTheFileNameQualifier()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new SearchClient(connection);
                var request = new SearchCodeRequest("something");
                request.FileName = "packages.config";

                client.SearchCode(request);

                connection.Received().Get<SearchCodeResult>(
                    Arg.Is<Uri>(u => u.ToString() == "search/code"),
                    Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+filename:packages.config"));
            }
 public async Task EnsuresNonNullArguments()
 {
     var client = new SearchClient(Substitute.For<IApiConnection>());
     await Assert.ThrowsAsync<ArgumentNullException>(() => client.SearchCode(null));
 }
Пример #13
0
            public void TestingTheUserQualifier()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new SearchClient(connection);
                var request = new SearchCodeRequest("something");
                request.User = "******";

                client.SearchCode(request);

                connection.Received().GetAll<SearchCode>(
                    Arg.Is<Uri>(u => u.ToString() == "search/code"),
                    Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+user:alfhenrik"));
            }
Пример #14
0
            public void TestingTheSizeQualifier_LessThanOrEqual()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new SearchClient(connection);
                var request = new SearchCodeRequest("something");
                request.Size = Range.LessThanOrEquals(10);

                client.SearchCode(request);

                connection.Received().GetAll<SearchCode>(
                    Arg.Is<Uri>(u => u.ToString() == "search/code"),
                    Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+size:<=10"));
            }
Пример #15
0
            public void TestingTheSortParameter()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new SearchClient(connection);
                var request = new SearchCodeRequest("something");
                request.SortField = CodeSearchSort.Indexed;

                client.SearchCode(request);

                connection.Received().GetAll<SearchCode>(
                    Arg.Is<Uri>(u => u.ToString() == "search/code"),
                    Arg.Is<Dictionary<string, string>>(d => d["sort"] == "indexed"));
            }