public async Task ReturnsContents()
            {
                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.GetAllContents("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);
            }
            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);
            }
Exemplo n.º 3
0
            public async Task ReturnsContents()
            {
                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.GetAllContents("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);
            }
            public async Task EnsuresNonNullArguments()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new RepositoryContentsClient(connection);

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

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

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

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

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

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

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

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllContents("owner", ""));

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

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllContents("owner", "", "path"));

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

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllContents(1, ""));
            }
            public async Task EnsuresNonNullArguments()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new RepositoryContentsClient(connection);

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

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

                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllContents("", "name"));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllContents("owner", ""));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllContents("", "name", "path"));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllContents("owner", "", "path"));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllContents("owner", "name", ""));

                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllContents(1, ""));
            }
            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);
            }