public async Task EnsuresNonNullArguments() { var client = new ObservableIssuesEventsClient(Substitute.For<IGitHubClient>()); Assert.Throws<ArgumentNullException>(() => client.GetAllForIssue(null, "name", 1)); Assert.Throws<ArgumentNullException>(() => client.GetAllForIssue("owner", null, 1)); Assert.Throws<ArgumentNullException>(() => client.GetAllForIssue(null, "name", 1, ApiOptions.None)); Assert.Throws<ArgumentNullException>(() => client.GetAllForIssue("owner", null, 1, ApiOptions.None)); Assert.Throws<ArgumentNullException>(() => client.GetAllForIssue("owner", "name", 1, null)); }
public async Task RequestsCorrectUrlWithApiOptions() { var result = new List<EventInfo> { new EventInfo() }; var connection = Substitute.For<IConnection>(); var gitHubClient = new GitHubClient(connection); var client = new ObservableIssuesEventsClient(gitHubClient); var options = new ApiOptions { StartPage = 1, PageCount = 1, PageSize = 1 }; IApiResponse<List<EventInfo>> response = new ApiResponse<List<EventInfo>>( new Response { ApiInfo = new ApiInfo(new Dictionary<string, Uri>(), new List<string>(), new List<string>(), "etag", new RateLimit()), }, result); gitHubClient.Connection.Get<List<EventInfo>>(Args.Uri, Arg.Is<Dictionary<string, string>>(d => d.Count == 2), null) .Returns(Task.FromResult(response)); var eventInfos = await client.GetAllForIssue("fake", "repo", 42, options).ToList(); connection.Received().Get<List<EventInfo>>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42/events"), Arg.Is<Dictionary<string, string>>(d => d.Count == 2), null); Assert.Equal(1, eventInfos.Count); }
public async Task RequestsCorrectUrlWithRepositoryId() { var result = new List<EventInfo> { new EventInfo() }; var connection = Substitute.For<IConnection>(); var gitHubClient = new GitHubClient(connection); var client = new ObservableIssuesEventsClient(gitHubClient); IApiResponse<List<EventInfo>> response = new ApiResponse<List<EventInfo>>( new Response { ApiInfo = new ApiInfo(new Dictionary<string, Uri>(), new List<string>(), new List<string>(), "etag", new RateLimit()), }, result); gitHubClient.Connection.Get<List<EventInfo>>(Args.Uri, Args.EmptyDictionary, null) .Returns(Task.FromResult(response)); var eventInfos = await client.GetAllForIssue(1, 42).ToList(); connection.Received().Get<List<EventInfo>>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/issues/42/events"), Args.EmptyDictionary, null); Assert.Equal(1, eventInfos.Count); }