static IEnterpriseCapabilitiesService CreateCapabilties(EnterpriseProbeResult probeResult) { var result = Substitute.For <IEnterpriseCapabilitiesService>(); result.Probe(null).ReturnsForAnyArgs(probeResult); return(result); }
public async Task ReturnsTrueWhenEnterpriseProbeReturnsOk(EnterpriseProbeResult probeResult, bool expected) { var gitHubHost = HostAddress.GitHubDotComHostAddress; var gitHubClient = Substitute.For <IGitHubClient>(); var repository = CreateRepository(42, true); gitHubClient.Repository.Get("github", "visualstudio").Returns(Task.FromResult(repository)); var enterpriseProbe = Substitute.For <IEnterpriseProbeTask>(); enterpriseProbe.ProbeAsync(Args.Uri) .Returns(_ => Task.FromResult(probeResult), _ => { throw new Exception("Only call it once"); }); var wikiProbe = Substitute.For <IWikiProbe>(); var client = new SimpleApiClient( gitHubHost, "https://github.com/github/visualstudio", gitHubClient, new Lazy <IEnterpriseProbeTask>(() => enterpriseProbe), new Lazy <IWikiProbe>(() => wikiProbe)); await client.GetRepository(); var result = client.IsEnterprise(); Assert.Equal(expected, result); Assert.Equal(expected, client.IsEnterprise()); }
/// <summary> /// GitHubへのアクセス情報を登録する。 /// </summary> private async void Register() { isRegistering = true; bool hasError = false; RegisterCommand.RaiseCanExecuteChanged(); ((App)App.Current).notificationService.Stop(); ProductHeaderValue phv = new ProductHeaderValue("GitHubNotifier"); Uri uri = new Uri(StrRootUrl); Credentials tokenAuth = new Credentials(StrToken); // URLが有効かチェック if (!uri.Host.Equals("github.com", StringComparison.OrdinalIgnoreCase) && !uri.Host.Equals("api.github.com", StringComparison.OrdinalIgnoreCase)) { Properties.Settings.Default.IsEnterprise = true; EnterpriseProbe probe = new EnterpriseProbe(phv); EnterpriseProbeResult result = await probe.Probe(uri); switch (result) { case EnterpriseProbeResult.Failed: StrError = Properties.Resources.NetworkErrorText; hasError = true; break; case EnterpriseProbeResult.NotFound: StrError = Properties.Resources.ServerErrorText; hasError = true; break; } } else { Properties.Settings.Default.IsEnterprise = false; } if (!hasError) { // 通知を取得する GitHubClient client = new GitHubClient(phv, uri) { Credentials = tokenAuth }; try { IReadOnlyList <Notification> notifications = await client.Activity.Notifications.GetAllForCurrent(); } catch (AuthorizationException) { StrError = Properties.Resources.TokenErrorText; hasError = true; } catch (ForbiddenException) { StrError = Properties.Resources.PermissionErrorText; hasError = true; } } if (hasError) { Properties.Settings.Default.IsValidated = false; } else { // 入力値を保存する Properties.Settings.Default.RootURL = StrRootUrl; Properties.Settings.Default.Token = StrToken; Properties.Settings.Default.IsValidated = true; Properties.Settings.Default.Save(); // NotificationServiceを開始する ((App)App.Current).notificationService.Run(); // ウィンドウを閉じる App.Current.MainWindow.Close(); } isRegistering = false; RegisterCommand.RaiseCanExecuteChanged(); }
public async Task ReturnsTrueWhenEnterpriseProbeReturnsOk(EnterpriseProbeResult probeResult, bool expected) { var gitHubHost = HostAddress.GitHubDotComHostAddress; var gitHubClient = Substitute.For<IGitHubClient>(); var repository = CreateRepository(42, true); gitHubClient.Repository.Get("github", "visualstudio").Returns(Task.FromResult(repository)); var enterpriseProbe = Substitute.For<IEnterpriseProbeTask>(); enterpriseProbe.ProbeAsync(Args.Uri) .Returns(_ => Task.FromResult(probeResult), _ => { throw new Exception("Only call it once"); }); var wikiProbe = Substitute.For<IWikiProbe>(); var client = new SimpleApiClient( "https://github.com/github/visualstudio", gitHubClient, new Lazy<IEnterpriseProbeTask>(() => enterpriseProbe), new Lazy<IWikiProbe>(() => wikiProbe)); await client.GetRepository(); var result = client.IsEnterprise(); Assert.Equal(expected, result); Assert.Equal(expected, client.IsEnterprise()); }