public async Task HydrateGhUserReposDisplayVm_IfNoReposAfterFilter_ShouldGetSimplyInitdRetClass() { // Arrange mockGHReposSvc.Setup(o => o.GetGitHubReposAsync( It.IsAny <HttpClient>(), It.IsAny <string>())).ReturnsAsync(() => new List <GhUserRepo> { new GhUserRepo { name = "test1", @private = true }, new GhUserRepo { name = "test2", @private = true } }); apiCallServices = new GitHubApiCallServices( mockHttpClientProvider.Object, mockHCAuthConfigr.Object, mockGHReposSvc.Object, mockGHPRsSvc.Object, mockCredentialsReader.Object); var ghUserReposSvcs = new GhUserReposServices(apiCallServices); // Act GhUserReposDisplayVm callResult = await ghUserReposSvcs.HydrateGhUserReposDisplayVmAsync("username"); Assert.IsInstanceOfType(callResult, typeof(GhUserReposDisplayVm)); Assert.AreEqual("username", callResult.GitHubUsername); Assert.IsNotNull(callResult.Repositories); Assert.IsInstanceOfType(callResult.Repositories, typeof(List <RepoListItem>)); Assert.AreEqual(0, callResult.Repositories.Count); }
public void CallOfGetReposByUsername_ReturnsListOfGhUserRepo_ShouldPass() { // Arrange var mockHttpClientProvider = new Mock <IHttpClientProvider>(); mockHttpClientProvider.Setup(o => o.GetHttpClientInstance()).Returns(new HttpClient()); var mockHCAuthConfigr = new Mock <IHttpClientAuthorizeConfigurator>(); mockHCAuthConfigr.Setup(o => o.AddBasicAuthorizationHeaderValue( It.IsAny <HttpClient>(), It.IsAny <string>(), It.IsAny <string>())).Returns(true); var mockGHReposSvc = new Mock <IGitHubRepos>(); // will be calling ghRepos.GetGitHubReposAsync(httpClient, ghUsername); // The method will return an empty collection if there are any // problems, or no public repos are found, so set it up to return // a List containing a single item. mockGHReposSvc.Setup(o => o.GetGitHubReposAsync( It.IsAny <HttpClient>(), It.IsAny <string>())).ReturnsAsync(() => new List <GhUserRepo> { new GhUserRepo() }); var mockGHPRsSvc = new Mock <IGitHubPullReqs>(); // Act GitHubApiCallServices apiCallServices = new GitHubApiCallServices( mockHttpClientProvider.Object, mockHCAuthConfigr.Object, mockGHReposSvc.Object, mockGHPRsSvc.Object, mockCredentialsReader.Object); var taskOfListOfGhUserRepos = apiCallServices.GetPublicGhUserReposByUsername("github"); var returnedList = taskOfListOfGhUserRepos.Result; // Assert Assert.IsNotNull(returnedList); Assert.IsInstanceOfType(returnedList, typeof(List <GhUserRepo>)); Assert.AreEqual(1, returnedList.Count); }
public void MyTestInitialize() { mockHttpClientProvider = new Mock <IHttpClientProvider>(); mockHCAuthConfigr = new Mock <IHttpClientAuthorizeConfigurator>(); mockHCAuthConfigr.Setup(o => o.AddBasicAuthorizationHeaderValue( It.IsAny <HttpClient>(), It.IsAny <string>(), It.IsAny <string>())).Returns(true); mockGHReposSvc = new Mock <IGitHubRepos>(); // The HydrateGhUserReposDisplayVmAsync method is going to call the // following, so I need a mocked version in order to test the // 'private filter' functionality mockGHReposSvc.Setup(o => o.GetGitHubReposAsync( It.IsAny <HttpClient>(), It.IsAny <string>())).ReturnsAsync(() => new List <GhUserRepo> { new GhUserRepo { name = "test1", @private = false }, new GhUserRepo { name = "test2", @private = true }, new GhUserRepo { name = "test3", @private = false } }); mockGHPRsSvc = new Mock <IGitHubPullReqs>(); mockCredentialsReader = new Mock <IGitHubAPICredentialsReader>(); mockCredentialsReader.Setup(o => o.GetUsername()).Returns("username"); mockCredentialsReader.Setup(o => o.GetPassword()).Returns("password"); apiCallServices = new GitHubApiCallServices( mockHttpClientProvider.Object, mockHCAuthConfigr.Object, mockGHReposSvc.Object, mockGHPRsSvc.Object, mockCredentialsReader.Object); }
public void CallingGetOpenPRsByGhUserRepo_WithNonNullOrWsParams_ReturnsNon0int_ShouldPass() { // Arrange var mockHttpClientProvider = new Mock <IHttpClientProvider>(); mockHttpClientProvider.Setup(o => o.GetHttpClientInstance()).Returns(new HttpClient()); var mockHCAuthConfigr = new Mock <IHttpClientAuthorizeConfigurator>(); mockHCAuthConfigr.Setup(o => o.AddBasicAuthorizationHeaderValue( It.IsAny <HttpClient>(), It.IsAny <string>(), It.IsAny <string>())).Returns(true); var mockGHReposSvc = new Mock <IGitHubRepos>(); var mockGHPRsSvc = new Mock <IGitHubPullReqs>(); // The apiCallServices.GetOpenPRsByGhUserRepo() method calls // async Task<int> GetGitHubRepoOpenPRCountAsync(HttpClient, string, string) // which is the method that actually makes the GitHub API call, // so it definitely needs to be mocked out. mockGHPRsSvc.Setup(o => o.GetGitHubRepoOpenPRCountAsync( It.IsAny <HttpClient>(), It.IsAny <string>(), It.IsAny <string>() )).ReturnsAsync(2); // Act GitHubApiCallServices apiCallServices = new GitHubApiCallServices( mockHttpClientProvider.Object, mockHCAuthConfigr.Object, mockGHReposSvc.Object, mockGHPRsSvc.Object, mockCredentialsReader.Object); var methodCallResultTask = apiCallServices.GetOpenPRsByGhUserRepo("username", "TestGhRepoName"); var methodCallResult = methodCallResultTask.Result; // Assert Assert.IsInstanceOfType(methodCallResult, typeof(int)); Assert.AreEqual(2, methodCallResult); }
public void InstantiationOf_GitHubApiCallServices_WithAnyNullParameter_ShouldThrow() { // Arrange var mockHttpClientProvider = new Mock <IHttpClientProvider>(); HttpClientAuthorizeConfigurator mockHCAuthConfigr = null; var mockGHReposSvc = new Mock <IGitHubRepos>(); var mockGHPRsSvc = new Mock <IGitHubPullReqs>(); // Act GitHubApiCallServices apiCallServices = new GitHubApiCallServices( mockHttpClientProvider.Object, // ReSharper disable once ExpressionIsAlwaysNull mockHCAuthConfigr, mockGHReposSvc.Object, mockGHPRsSvc.Object, mockCredentialsReader.Object); // Assert // Should throw, so nothing here. }
public void InstantiationOf_GitHubApiCallServices_WithProperParameters_ShouldPass() { // Arrange var mockHttpClientProvider = new Mock <IHttpClientProvider>(); var mockHCAuthConfigr = new Mock <IHttpClientAuthorizeConfigurator>(); var mockGHReposSvc = new Mock <IGitHubRepos>(); var mockGHPRsSvc = new Mock <IGitHubPullReqs>(); // Act GitHubApiCallServices apiCallServices = new GitHubApiCallServices( mockHttpClientProvider.Object, mockHCAuthConfigr.Object, mockGHReposSvc.Object, mockGHPRsSvc.Object, mockCredentialsReader.Object); // Assert Assert.IsNotNull(apiCallServices); Assert.IsInstanceOfType(apiCallServices, typeof(IGitHubApiCallServices)); }
public async Task CallingGetOpenPRsByGhUserRepo_WithNullOrWsRepoNameParam_ShouldThrow() { // Arrange var mockHttpClientProvider = new Mock <IHttpClientProvider>(); var mockHCAuthConfigr = new Mock <IHttpClientAuthorizeConfigurator>(); var mockGHReposSvc = new Mock <IGitHubRepos>(); var mockGHPRsSvc = new Mock <IGitHubPullReqs>(); // Act GitHubApiCallServices apiCallServices = new GitHubApiCallServices( mockHttpClientProvider.Object, mockHCAuthConfigr.Object, mockGHReposSvc.Object, mockGHPRsSvc.Object, mockCredentialsReader.Object); var taskOfListOfGhUserRepos = await apiCallServices.GetOpenPRsByGhUserRepo("NonNullValue", " "); // Should have thrown. }
public async Task CallOfGetReposByUsername_WithEmptyUsername_ShouldThrow() { // Arrange var mockHttpClientProvider = new Mock <IHttpClientProvider>(); var mockHCAuthConfigr = new Mock <IHttpClientAuthorizeConfigurator>(); var mockGHReposSvc = new Mock <IGitHubRepos>(); var mockGHPRsSvc = new Mock <IGitHubPullReqs>(); // Act GitHubApiCallServices apiCallServices = new GitHubApiCallServices( mockHttpClientProvider.Object, mockHCAuthConfigr.Object, mockGHReposSvc.Object, mockGHPRsSvc.Object, mockCredentialsReader.Object); var taskOfListOfGhUserRepos = await apiCallServices.GetPublicGhUserReposByUsername(" "); // Should have thrown. }
public async Task IfGetGitHubRepoOpenPRCount_ThrowsException_GetOpenPRsShouldAlso() { // Arrange var mockHttpClientProvider = new Mock <IHttpClientProvider>(); mockHttpClientProvider.Setup(o => o.GetHttpClientInstance()).Returns(new HttpClient()); var mockHCAuthConfigr = new Mock <IHttpClientAuthorizeConfigurator>(); mockHCAuthConfigr.Setup(o => o.AddBasicAuthorizationHeaderValue( It.IsAny <HttpClient>(), It.IsAny <string>(), It.IsAny <string>())).Returns(true); var mockGHReposSvc = new Mock <IGitHubRepos>(); var mockGHPRsSvc = new Mock <IGitHubPullReqs>(); // The apiCallServices.GetOpenPRsByGhUserRepo() method calls // async Task<int> GetGitHubRepoOpenPRCountAsync(HttpClient, string, string) // which is the method that actually makes the GitHub API call, // so it definitely needs to be mocked out. mockGHPRsSvc.Setup(o => o.GetGitHubRepoOpenPRCountAsync( It.IsAny <HttpClient>(), It.IsAny <string>(), It.IsAny <string>() )).ThrowsAsync(new Exception()); // Act GitHubApiCallServices apiCallServices = new GitHubApiCallServices( mockHttpClientProvider.Object, mockHCAuthConfigr.Object, mockGHReposSvc.Object, mockGHPRsSvc.Object, mockCredentialsReader.Object); var methodCallResultTask = await apiCallServices.GetOpenPRsByGhUserRepo("username", "TestGhRepoName"); // should have thrown }
public async Task IfGetGitHubReposCall_ThrowsPlainException_GetPublicGhUserReposShouldHandleAndThrow() { // Arrange var mockHttpClientProvider = new Mock <IHttpClientProvider>(); mockHttpClientProvider.Setup(o => o.GetHttpClientInstance()).Returns(new HttpClient()); var mockHCAuthConfigr = new Mock <IHttpClientAuthorizeConfigurator>(); mockHCAuthConfigr.Setup(o => o.AddBasicAuthorizationHeaderValue( It.IsAny <HttpClient>(), It.IsAny <string>(), It.IsAny <string>())).Returns(true); var mockGHReposSvc = new Mock <IGitHubRepos>(); // will be calling ghRepos.GetGitHubReposAsync(httpClient, ghUsername); // The method will return an empty collection if there are any // problems, or no public repos are found, so set it up to return // a List containing a single item. mockGHReposSvc.Setup(o => o.GetGitHubReposAsync( It.IsAny <HttpClient>(), It.IsAny <string>())).ThrowsAsync(new Exception()); var mockGHPRsSvc = new Mock <IGitHubPullReqs>(); // Act GitHubApiCallServices apiCallServices = new GitHubApiCallServices( mockHttpClientProvider.Object, mockHCAuthConfigr.Object, mockGHReposSvc.Object, mockGHPRsSvc.Object, mockCredentialsReader.Object); var taskOfListOfGhUserRepos = await apiCallServices.GetPublicGhUserReposByUsername("github"); // should have thrown }