Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/GitHub.App/ViewModels/LoginControlViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public LoginControlViewModel(

}).ToProperty(this, x => x.LoginMode);

AuthenticationResults = Observable.Amb(
AuthenticationResults = Observable.Merge(
loginToGitHubViewModel.Login,
EnterpriseLogin.Login);
CancelCommand = ReactiveCommand.Create();
Expand Down
49 changes: 49 additions & 0 deletions src/UnitTests/GitHub.App/ViewModels/LoginControlViewModelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Net;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using GitHub.Authentication;
using GitHub.Info;
using GitHub.Models;
using GitHub.Primitives;
using GitHub.Services;
using GitHub.ViewModels;
using NSubstitute;
using Octokit;
using ReactiveUI;
using Xunit;

public class LoginControlViewModelTests
{
public class TheAuthenticationResultsCommand : TestBaseClass
{
[Fact]
public async void AllowsLoginFromEnterpriseAfterGitHubLoginHasFailed()
{
var repositoryHosts = Substitute.For<IRepositoryHosts>();

var gitHubLogin = Substitute.For<ILoginToGitHubViewModel>();
var gitHubLoginCommand = ReactiveCommand.CreateAsyncObservable(_ =>
Observable.Return(AuthenticationResult.CredentialFailure));
gitHubLogin.Login.Returns(gitHubLoginCommand);

var enterpriseLogin = Substitute.For<ILoginToGitHubForEnterpriseViewModel>();
var enterpriseLoginCommand = ReactiveCommand.CreateAsyncObservable(_ =>
Observable.Return(AuthenticationResult.Success));
enterpriseLogin.Login.Returns(enterpriseLoginCommand);

var loginViewModel = new LoginControlViewModel(repositoryHosts, gitHubLogin, enterpriseLogin);
var success = false;

loginViewModel.AuthenticationResults
.Where(x => x == AuthenticationResult.Success)
.Subscribe(_ => success = true);

await gitHubLoginCommand.ExecuteAsync();
await enterpriseLoginCommand.ExecuteAsync();

Assert.True(success);
}
}
}

1 change: 1 addition & 0 deletions src/UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
<Compile Include="GitHub.App\Services\GitClientTests.cs" />
<Compile Include="GitHub.App\Services\RepositoryCloneServiceTests.cs" />
<Compile Include="GitHub.App\Services\RepositoryCreationServiceTests.cs" />
<Compile Include="GitHub.App\ViewModels\LoginControlViewModelTests.cs" />
<Compile Include="GitHub.App\ViewModels\LoginToGitHubViewModelTests.cs" />
<Compile Include="GitHub.App\ViewModels\RepositoryCloneViewModelTests.cs" />
<Compile Include="GitHub.App\ViewModels\RepositoryCreationViewModelTests.cs" />
Expand Down