コード例 #1
0
            public async Task ReturnsReadme()
            {
                string encodedContent = Convert.ToBase64String(Encoding.UTF8.GetBytes("Hello world"));
                var readmeInfo = new ReadmeResponse(
                    encodedContent,
                    "README.md",
                    "https://github.example.com/readme",
                    "https://github.example.com/readme.md",
                    "base64");
                var connection = Substitute.For<IApiConnection>();
                connection.Get<ReadmeResponse>(Args.Uri, null).Returns(Task.FromResult(readmeInfo));
                connection.GetHtml(Args.Uri, null).Returns(Task.FromResult("<html>README</html>"));
                var contentsClient = new RepositoryContentsClient(connection);

                var readme = await contentsClient.GetReadme("fake", "repo");

                Assert.Equal("README.md", readme.Name);
                connection.Received().Get<ReadmeResponse>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/readme"),
                    null);
                connection.DidNotReceive().GetHtml(Arg.Is<Uri>(u => u.ToString() == "https://github.example.com/readme"),
                    null);
                var htmlReadme = await readme.GetHtmlContent();
                Assert.Equal("<html>README</html>", htmlReadme);
                connection.Received().GetHtml(Arg.Is<Uri>(u => u.ToString() == "https://github.example.com/readme.md"), null);
            }
コード例 #2
0
            public async Task RequestsCorrectUrlWithRepositoryIdWithExplicitBase64()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new RepositoryContentsClient(connection);

                string expectedUri = "repositories/1/contents/path/to/file";
                await client.CreateFile(1, "path/to/file", new CreateFileRequest("message", "bXlmaWxlY29udGVudHM=", "mybranch", false));

                connection.Received().Put <RepositoryContentChangeSet>(Arg.Is <Uri>(u => u.ToString() == expectedUri), Arg.Any <object>());
            }
コード例 #3
0
            public async Task RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new RepositoryContentsClient(connection);

                string expectedUri = "repos/org/repo/contents/path/to/file";
                await client.DeleteFile("org", "repo", "path/to/file", new DeleteFileRequest("message", "1234abc", "mybranch"));

                connection.Received().Delete(Arg.Is <Uri>(u => u.ToString() == expectedUri), Arg.Any <object>());
            }
コード例 #4
0
            public async Task ReturnsReadmeHtml()
            {
                var connection = Substitute.For<IApiConnection>();
                connection.GetHtml(Args.Uri, null).Returns(Task.FromResult("<html>README</html>"));
                var contentsClient = new RepositoryContentsClient(connection);

                var readme = await contentsClient.GetReadmeHtml("fake", "repo");

                connection.Received().GetHtml(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/readme"), null);
                Assert.Equal("<html>README</html>", readme);
            }
コード例 #5
0
            public async Task ReturnsArchiveLinkAsZipball()
            {
                var connection = Substitute.For<IApiConnection>();
                connection.GetRedirect(Args.Uri).Returns(Task.FromResult("https://codeload.github.com/fake/repo/legacy.tar.gz/master"));
                var contentsClient = new RepositoryContentsClient(connection);

                var archiveLink = await contentsClient.GetArchiveLink("fake", "repo", ArchiveFormat.Zipball);

                connection.Received().GetRedirect(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/zipball/"));
                Assert.Equal("https://codeload.github.com/fake/repo/legacy.tar.gz/master", archiveLink);
            }
コード例 #6
0
            public async Task EnsuresNonNullArguments()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new RepositoryContentsClient(connection);

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

                await Assert.ThrowsAsync<ArgumentException>(() => client.GetReadme("", "name"));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetReadme("owner", ""));
            }
コード例 #7
0
            public void RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new RepositoryContentsClient(connection);

                string expectedUri = "repos/org/repo/contents/path/to/file";

                client.UpdateFile("org", "repo", "path/to/file", new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch"));

                connection.Received().Put <RepositoryContentChangeSet>(Arg.Is <Uri>(u => u.ToString() == expectedUri), Arg.Any <object>());
            }
コード例 #8
0
            public void EnsurePassingCorrectParameters()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new RepositoryContentsClient(connection);

                client.GetArchive("org", "repo", ArchiveFormat.Tarball, "dev");

                const string expectedUri      = "repos/org/repo/tarball/dev";
                var          expectedTimeSpan = TimeSpan.FromMinutes(60);

                connection.Connection.Received().Get <byte[]>(Arg.Is <Uri>(uri => uri.ToString() == expectedUri), Arg.Is <TimeSpan>(span => span == expectedTimeSpan));
            }
コード例 #9
0
            public async Task ReturnsReadmeHtmlWithRepositoryId()
            {
                var connection = Substitute.For <IApiConnection>();

                connection.GetHtml(Args.Uri, null).Returns(Task.FromResult("<html>README</html>"));
                var contentsClient = new RepositoryContentsClient(connection);

                var readme = await contentsClient.GetReadmeHtml(1);

                connection.Received().GetHtml(Arg.Is <Uri>(u => u.ToString() == "repositories/1/readme"), null);
                Assert.Equal("<html>README</html>", readme);
            }
コード例 #10
0
            public async Task RequestsCorrectUrl1()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new RepositoryContentsClient(connection);

                await client.GetArchive("org", "repo");

                const string expectedUri      = "repos/org/repo/tarball/";
                var          expectedTimeSpan = TimeSpan.FromMinutes(60);

                connection.Connection.Received().Get <byte[]>(Arg.Is <Uri>(uri => uri.ToString() == expectedUri), Arg.Is <TimeSpan>(span => span == expectedTimeSpan));
            }
コード例 #11
0
            public async Task RequestsCorrectUrl4WithRepositoryId()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new RepositoryContentsClient(connection);

                await client.GetArchive(1, ArchiveFormat.Zipball, "ref", TimeSpan.FromMinutes(60));

                const string expectedUri      = "repositories/1/zipball/ref";
                var          expectedTimeSpan = TimeSpan.FromMinutes(60);

                connection.Connection.Received().Get <byte[]>(Arg.Is <Uri>(uri => uri.ToString() == expectedUri), Arg.Is <TimeSpan>(span => span == expectedTimeSpan));
            }
コード例 #12
0
            public async Task ReturnsArchiveLinkWithSpecifiedValues()
            {
                var connection = Substitute.For <IApiConnection>();

                connection.GetRedirect(Args.Uri).Returns(Task.FromResult("https://codeload.github.com/fake/repo/legazy.zip/release"));
                var contentsClient = new RepositoryContentsClient(connection);

                var archiveLink = await contentsClient.GetArchiveLink("fake", "repo", ArchiveFormat.Zipball, "release");

                connection.Received().GetRedirect(Arg.Is <Uri>(u => u.ToString() == "repos/fake/repo/zipball/release"));
                Assert.Equal("https://codeload.github.com/fake/repo/legazy.zip/release", archiveLink);
            }
コード例 #13
0
            public async Task ReturnsArchiveLinkWithDefaults()
            {
                var connection = Substitute.For <IApiConnection>();

                connection.GetRedirect(Args.Uri).Returns(Task.FromResult("https://codeload.github.com/fake/repo/legacy.tar.gz/master"));
                var contentsClient = new RepositoryContentsClient(connection);

                var archiveLink = await contentsClient.GetArchiveLink("fake", "repo");

                connection.Received().GetRedirect(Arg.Is <Uri>(u => u.ToString() == "repos/fake/repo/tarball/"));
                Assert.Equal("https://codeload.github.com/fake/repo/legacy.tar.gz/master", archiveLink);
            }
コード例 #14
0
            public async Task ReturnsContentsByRef()
            {
                List<RepositoryContent> result = new List<RepositoryContent> { new RepositoryContent() };

                var connection = Substitute.For<IApiConnection>();
                connection.GetAll<RepositoryContent>(Args.Uri).Returns(Task.FromResult(result.AsReadOnly() as IReadOnlyList<RepositoryContent>));
                var contentsClient = new RepositoryContentsClient(connection);

                var contents = await contentsClient.GetAllContentsByRef("fake", "repo", "readme.md", "master");

                connection.Received().GetAll<RepositoryContent>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/contents/readme.md?ref=master"));
                Assert.Equal(1, contents.Count);
            }
コード例 #15
0
            public async Task EnsuresNonNullArguments()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new RepositoryContentsClient(connection);

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.UpdateFile(null, "repo", "path/to/file", new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch")));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.UpdateFile("org", null, "path/to/file", new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch")));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.UpdateFile("org", "repo", null, new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch")));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.UpdateFile("org", "repo", "path/to/file", null));
            }
コード例 #16
0
            public async Task EnsuresNonNullArguments()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new RepositoryContentsClient(connection);

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

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

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetReadme("", "name"));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetReadme("owner", ""));
            }
コード例 #17
0
            public async Task PassesRequestObjectWithExplicitBase64()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new RepositoryContentsClient(connection);

                await client.CreateFile("org", "repo", "path/to/file", new CreateFileRequest("message", "bXlmaWxlY29udGVudHM=", "mybranch", false));

                connection.Received().Put <RepositoryContentChangeSet>(
                    Arg.Any <Uri>(),
                    Arg.Is <CreateFileRequest>(a =>
                                               a.Message == "message" &&
                                               a.Content == "bXlmaWxlY29udGVudHM=" &&
                                               a.Branch == "mybranch"));
            }
コード例 #18
0
            public async Task ReturnsRawContent()
            {
                var result = new byte[] { 1, 2, 3 };

                var connection = Substitute.For <IApiConnection>();

                connection.GetRaw(Args.Uri, default).Returns(result);
                var contentsClient = new RepositoryContentsClient(connection);

                var rawContent = await contentsClient.GetRawContentByRef("fake", "repo", "path/to/file.txt", "reference");

                connection.Received().GetRaw(Arg.Is <Uri>(u => u.ToString() == "repos/fake/repo/contents/path/to/file.txt?ref=reference"), null);
                Assert.Same(result, rawContent);
            }
コード例 #19
0
            public async Task PassesRequestObjectWithRepositoryId()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new RepositoryContentsClient(connection);

                await client.CreateFile(1, "path/to/file", new CreateFileRequest("message", "myfilecontents", "mybranch"));

                connection.Received().Put <RepositoryContentChangeSet>(
                    Arg.Any <Uri>(),
                    Arg.Is <CreateFileRequest>(a =>
                                               a.Message == "message" &&
                                               a.Content == "myfilecontents" &&
                                               a.Branch == "mybranch"));
            }
コード例 #20
0
            public async Task PassesRequestObjectWithRepositoryId()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new RepositoryContentsClient(connection);

                await client.DeleteFile(1, "path/to/file", new DeleteFileRequest("message", "1234abc", "mybranch"));

                connection.Received().Delete(
                    Arg.Any <Uri>(),
                    Arg.Is <DeleteFileRequest>(a =>
                                               a.Message == "message" &&
                                               a.Sha == "1234abc" &&
                                               a.Branch == "mybranch"));
            }
コード例 #21
0
            public async Task EnsuresNonNullArguments()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new RepositoryContentsClient(connection);

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetArchive(null, "repo"));

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

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetArchive(null, "repo", ArchiveFormat.Tarball));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetArchive("org", null, ArchiveFormat.Tarball));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetArchive(null, "repo", ArchiveFormat.Tarball, "ref"));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetArchive("org", null, ArchiveFormat.Tarball, "ref"));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetArchive("org", "repo", ArchiveFormat.Tarball, null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetArchive(null, "repo", ArchiveFormat.Tarball, "ref", TimeSpan.MaxValue));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetArchive("org", null, ArchiveFormat.Tarball, "ref", TimeSpan.MaxValue));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetArchive("org", "repo", ArchiveFormat.Tarball, null, TimeSpan.MaxValue));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetArchive(1, ArchiveFormat.Tarball, null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetArchive(1, ArchiveFormat.Tarball, null, TimeSpan.MaxValue));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetArchive("", "repo"));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetArchive("org", ""));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetArchive("", "repo", ArchiveFormat.Tarball));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetArchive("org", "", ArchiveFormat.Tarball));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetArchive("", "repo", ArchiveFormat.Tarball, "ref"));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetArchive("org", "", ArchiveFormat.Tarball, "ref"));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetArchive("", "repo", ArchiveFormat.Tarball, "ref", TimeSpan.MaxValue));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetArchive("org", "", ArchiveFormat.Tarball, "ref", TimeSpan.MaxValue));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetArchive("org", "repo", ArchiveFormat.Tarball, "ref", TimeSpan.Zero));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetArchive(1, ArchiveFormat.Tarball, "ref", TimeSpan.Zero));
            }
コード例 #22
0
            public async Task PassesRequestObjectWithRepositoriesId()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new RepositoryContentsClient(connection);

                await client.UpdateFile(1, "path/to/file", new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch"));

                connection.Received().Put <RepositoryContentChangeSet>(
                    Arg.Any <Uri>(),
                    Arg.Is <UpdateFileRequest>(a =>
                                               a.Message == "message" &&
                                               a.Content == "bXlmaWxlY29udGVudHM=" &&
                                               a.Sha == "1234abc" &&
                                               a.Branch == "mybranch"));
            }
コード例 #23
0
            public void PassesRequestObject()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new RepositoryContentsClient(connection);

                client.UpdateFile("org", "repo", "path/to/file", new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch"));

                connection.Received().Put <RepositoryContentChangeSet>(
                    Arg.Any <Uri>(),
                    Arg.Is <UpdateFileRequest>(a =>
                                               a.Message == "message" &&
                                               a.Content == "myfilecontents" &&
                                               a.Sha == "1234abc" &&
                                               a.Branch == "mybranch"));
            }
コード例 #24
0
            public async Task ReturnsAllContentsByRefWithRepositoryId()
            {
                var result = new List <RepositoryContent> {
                    new RepositoryContent()
                };

                var connection = Substitute.For <IApiConnection>();

                connection.GetAll <RepositoryContent>(Args.Uri).Returns(Task.FromResult(result.AsReadOnly() as IReadOnlyList <RepositoryContent>));
                var contentsClient = new RepositoryContentsClient(connection);

                var contents = await contentsClient.GetAllContentsByRef(1, "master");

                connection.Received().GetAll <RepositoryContent>(Arg.Is <Uri>(u => u.ToString() == "repositories/1/contents/?ref=master"));
                Assert.Equal(1, contents.Count);
            }
コード例 #25
0
            public async Task ReturnsContents()
            {
                var result = new List <RepositoryContent> {
                    new RepositoryContent()
                };

                var connection = Substitute.For <IApiConnection>();

                connection.GetAll <RepositoryContent>(Args.Uri).Returns(Task.FromResult(result.AsReadOnly() as IReadOnlyList <RepositoryContent>));
                var contentsClient = new RepositoryContentsClient(connection);

                var contents = await contentsClient.GetAllContents("fake", "repo", "readme.md");

                connection.Received().GetAll <RepositoryContent>(Arg.Is <Uri>(u => u.ToString() == "repos/fake/repo/contents/readme.md"));
                Assert.Equal(1, contents.Count);
            }
コード例 #26
0
            public async Task EnsuresNonNullArguments()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new RepositoryContentsClient(connection);

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.UpdateFile(null, "repo", "path/to/file", new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch")));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.UpdateFile("org", null, "path/to/file", new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch")));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.UpdateFile("org", "repo", null, new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch")));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.UpdateFile("org", "repo", "path/to/file", null));
            }
コード例 #27
0
            public void PassesRequestObject()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new RepositoryContentsClient(connection);

                client.UpdateFile("org", "repo", "path/to/file", new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch"));

                connection.Received().Put<RepositoryContentChangeSet>(
                    Arg.Any<Uri>(),
                    Arg.Is<UpdateFileRequest>(a =>
                        a.Message == "message"
                        && a.Content == "myfilecontents"
                        && a.Sha == "1234abc"
                        && a.Branch == "mybranch"));
            }
コード例 #28
0
            public void RequestsCorrectUrl()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new RepositoryContentsClient(connection);

                string expectedUri = "repos/org/repo/contents/path/to/file";
                client.UpdateFile("org", "repo", "path/to/file", new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch"));

                connection.Received().Put<RepositoryContentChangeSet>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
            }
コード例 #29
0
            public async Task PassesRequestObjectWithRepositoryId()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new RepositoryContentsClient(connection);

                await client.CreateFile(1, "path/to/file", new CreateFileRequest("message", "myfilecontents", "mybranch"));

                connection.Received().Put<RepositoryContentChangeSet>(
                    Arg.Any<Uri>(),
                    Arg.Is<CreateFileRequest>(a =>
                        a.Message == "message"
                        && a.Content == "bXlmaWxlY29udGVudHM="
                        && a.Branch == "mybranch"));
            }
コード例 #30
0
            public async Task RequestsCorrectUrl4WithRepositoryId()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new RepositoryContentsClient(connection);

                await client.GetArchive(1, ArchiveFormat.Zipball, "ref", TimeSpan.FromMinutes(60));

                const string expectedUri = "repositories/1/zipball/ref";
                var expectedTimeSpan = TimeSpan.FromMinutes(60);

                connection.Connection.Received().Get<byte[]>(Arg.Is<Uri>(uri => uri.ToString() == expectedUri), Arg.Is<TimeSpan>(span => span == expectedTimeSpan));
            }
コード例 #31
0
            public async Task RequestsCorrectUrlWithRepositoryIdWithExplicitBase64()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new RepositoryContentsClient(connection);

                string expectedUri = "repositories/1/contents/path/to/file";
                await client.UpdateFile(1, "path/to/file", new UpdateFileRequest("message", "bXlmaWxlY29udGVudHM=", "1234abc", "mybranch", false));

                connection.Received().Put<RepositoryContentChangeSet>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
            }
コード例 #32
0
            public async Task PassesRequestObjectWithRepositoriesIdWithExplicitBase64()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new RepositoryContentsClient(connection);

                await client.UpdateFile(1, "path/to/file", new UpdateFileRequest("message", "bXlmaWxlY29udGVudHM=", "1234abc", "mybranch", false));

                connection.Received().Put<RepositoryContentChangeSet>(
                    Arg.Any<Uri>(),
                    Arg.Is<UpdateFileRequest>(a =>
                        a.Message == "message"
                        && a.Content == "bXlmaWxlY29udGVudHM="
                        && a.Sha == "1234abc"
                        && a.Branch == "mybranch"));
            }
コード例 #33
0
            public async Task RequestsCorrectUrl1()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new RepositoryContentsClient(connection);

                await client.GetArchive("org", "repo");

                const string expectedUri = "repos/org/repo/tarball/";
                var expectedTimeSpan = TimeSpan.FromMinutes(60);

                connection.Connection.Received().Get<byte[]>(Arg.Is<Uri>(uri => uri.ToString() == expectedUri), Arg.Is<TimeSpan>(span => span == expectedTimeSpan));
            }
コード例 #34
0
            public void EnsurePassingCorrectParameters()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new RepositoryContentsClient(connection);

                client.GetArchive("org", "repo", ArchiveFormat.Tarball, "dev");

                const string expectedUri = "repos/org/repo/tarball/dev";
                var expectedTimeSpan = TimeSpan.FromMinutes(60);

                connection.Connection.Received().Get<byte[]>(Arg.Is<Uri>(uri => uri.ToString() == expectedUri), Arg.Is<TimeSpan>(span => span == expectedTimeSpan));
            }
コード例 #35
0
            public async Task ReturnsAllContentsWithRepositoryId()
            {
                var result = new List<RepositoryContent> { new RepositoryContent() };

                var connection = Substitute.For<IApiConnection>();
                connection.GetAll<RepositoryContent>(Args.Uri).Returns(Task.FromResult(result.AsReadOnly() as IReadOnlyList<RepositoryContent>));
                var contentsClient = new RepositoryContentsClient(connection);

                var contents = await contentsClient.GetAllContents(1);

                connection.Received().GetAll<RepositoryContent>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/contents/"));
                Assert.Equal(1, contents.Count);
            }
コード例 #36
0
            public async Task PassesRequestObjectWithRepositoryId()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new RepositoryContentsClient(connection);

                await client.DeleteFile(1, "path/to/file", new DeleteFileRequest("message", "1234abc", "mybranch"));

                connection.Received().Delete(
                    Arg.Any<Uri>(),
                    Arg.Is<DeleteFileRequest>(a =>
                        a.Message == "message"
                        && a.Sha == "1234abc"
                        && a.Branch == "mybranch"));
            }
コード例 #37
0
            public async Task RequestsCorrectUrlWithRepositoryId()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new RepositoryContentsClient(connection);

                string expectedUri = "repositories/1/contents/path/to/file";
                await client.DeleteFile(1, "path/to/file", new DeleteFileRequest("message", "1234abc", "mybranch"));

                connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
            }
コード例 #38
0
            public async Task EnsuresNonNullArguments()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new RepositoryContentsClient(connection);

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetArchive(null, "repo"));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetArchive("org", null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetArchive(null, "repo", ArchiveFormat.Tarball));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetArchive("org", null, ArchiveFormat.Tarball));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetArchive(null, "repo", ArchiveFormat.Tarball, "ref"));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetArchive("org", null, ArchiveFormat.Tarball, "ref"));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetArchive("org", "repo", ArchiveFormat.Tarball, null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetArchive(null, "repo", ArchiveFormat.Tarball, "ref", TimeSpan.MaxValue));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetArchive("org", null, ArchiveFormat.Tarball, "ref", TimeSpan.MaxValue));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetArchive("org", "repo", ArchiveFormat.Tarball, null, TimeSpan.MaxValue));

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetArchive(1, ArchiveFormat.Tarball, null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetArchive(1, ArchiveFormat.Tarball, null, TimeSpan.MaxValue));

                await Assert.ThrowsAsync<ArgumentException>(() => client.GetArchive("", "repo"));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetArchive("org", ""));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetArchive("", "repo", ArchiveFormat.Tarball));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetArchive("org", "", ArchiveFormat.Tarball));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetArchive("", "repo", ArchiveFormat.Tarball, "ref"));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetArchive("org", "", ArchiveFormat.Tarball, "ref"));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetArchive("", "repo", ArchiveFormat.Tarball, "ref", TimeSpan.MaxValue));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetArchive("org", "", ArchiveFormat.Tarball, "ref", TimeSpan.MaxValue));

                await Assert.ThrowsAsync<ArgumentException>(() => client.GetArchive("org", "repo", ArchiveFormat.Tarball, "ref", TimeSpan.Zero));

                await Assert.ThrowsAsync<ArgumentException>(() => client.GetArchive(1, ArchiveFormat.Tarball, "ref", TimeSpan.Zero));
            }