public void EnsuresNonNullArguments() { var gitHubClient = Substitute.For<IGitHubClient>(); var client = new ObservableRepositoryContentsClient(gitHubClient); Assert.Throws<ArgumentNullException>(() => client.GetAllContentsByRef(null, "name", "ref")); Assert.Throws<ArgumentNullException>(() => client.GetAllContentsByRef("owner", null, "ref")); Assert.Throws<ArgumentNullException>(() => client.GetAllContentsByRef("owner", "name", null)); Assert.Throws<ArgumentNullException>(() => client.GetAllContentsByRef(null, "name", "path", "reference")); Assert.Throws<ArgumentNullException>(() => client.GetAllContentsByRef("owner", null, "path", "reference")); Assert.Throws<ArgumentNullException>(() => client.GetAllContentsByRef("owner", "name", null, "reference")); Assert.Throws<ArgumentNullException>(() => client.GetAllContentsByRef("owner", "name", "path", null)); Assert.Throws<ArgumentNullException>(() => client.GetAllContentsByRef(1, null, "reference")); Assert.Throws<ArgumentNullException>(() => client.GetAllContentsByRef(1, "path", null)); Assert.Throws<ArgumentNullException>(() => client.GetAllContentsByRef(1, null)); Assert.Throws<ArgumentException>(() => client.GetAllContentsByRef("", "name", "ref")); Assert.Throws<ArgumentException>(() => client.GetAllContentsByRef("owner", "", "ref")); Assert.Throws<ArgumentException>(() => client.GetAllContentsByRef("owner", "name", "")); Assert.Throws<ArgumentException>(() => client.GetAllContentsByRef("", "name", "path", "reference")); Assert.Throws<ArgumentException>(() => client.GetAllContentsByRef("owner", "", "path", "reference")); Assert.Throws<ArgumentException>(() => client.GetAllContentsByRef("owner", "name", "", "reference")); Assert.Throws<ArgumentException>(() => client.GetAllContentsByRef("owner", "name", "path", "")); Assert.Throws<ArgumentException>(() => client.GetAllContentsByRef(1, "", "reference")); Assert.Throws<ArgumentException>(() => client.GetAllContentsByRef(1, "path", "")); Assert.Throws<ArgumentException>(() => client.GetAllContentsByRef(1, "")); }
public async Task ReturnsAllContentsByRefWithRepositoryId() { var result = new List<RepositoryContent> { new RepositoryContent() }; var connection = Substitute.For<IConnection>(); var gitHubClient = new GitHubClient(connection); var contentsClient = new ObservableRepositoryContentsClient(gitHubClient); IApiResponse<List<RepositoryContent>> response = new ApiResponse<List<RepositoryContent>> ( new Response { ApiInfo = new ApiInfo(new Dictionary<string, Uri>(), new List<string>(), new List<string>(), "etag", new RateLimit()) }, result ); connection.Get<List<RepositoryContent>>(Args.Uri, null, null) .Returns(Task.FromResult(response)); var contents = await contentsClient.GetAllContentsByRef(1, "master").ToList(); connection.Received().Get<List<RepositoryContent>>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/contents/?ref=master"), null, null); Assert.Equal(1, contents.Count); }