8000 Remove RepositoryHost(s) by grokys · Pull Request #1283 · github/VisualStudio · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Remove RepositoryHost(s) #1283

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
WIP: Removing RepositoryHost(s) from tests.
  • Loading branch information
grokys committed Oct 26, 2017
commit 038f232749618892a9a4a4257f925c661b53dc6f
2 changes: 1 addition & 1 deletion src/GitHub.App/ViewModels/RepositoryCloneViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class RepositoryCloneViewModel : DialogViewModelBase, IRepositoryCloneVie
bool loadingFailed;

[ImportingConstructor]
RepositoryCloneViewModel(
public RepositoryCloneViewModel(
IConnection connection,
IModelServiceFactory modelServiceFactory,
IRepositoryCloneService cloneService,
Expand Down
2 changes: 1 addition & 1 deletion src/GitHub.App/ViewModels/RepositoryCreationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class RepositoryCreationViewModel : RepositoryFormViewModel, IRepositoryC
readonly IUsageTracker usageTracker;

[ImportingConstructor]
RepositoryCreationViewModel(
public RepositoryCreationViewModel(
IConnection connection,
IModelServiceFactory modelServiceFactory,
IOperatingSystem operatingSystem,
Expand Down
87 changes: 33 additions & 54 deletions src/UnitTests/GitHub.App/Controllers/UIControllerTests.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
using System;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Reactive;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using GitHub.App.Factories;
using GitHub.Controllers;
using GitHub.Extensions;
using GitHub.Extensions.Reactive;
using GitHub.Models;
using GitHub.Services;
using GitHub.UI;
using NSubstitute;
using Xunit;
using UnitTests;
using GitHub.ViewModels;
using NSubstitute;
using ReactiveUI;
using System.Collections.Generic;
using System.Reactive.Subjects;
using GitHub.Primitives;
using System.ComponentModel;
using System.Collections.ObjectModel;
using GitHub.App.Factories;
using System.Reactive;
using GitHub.Extensions.Reactive;
using System.Threading.Tasks;
using GitHub.Extensions;
using UnitTests;
using Xunit;

public class UIControllerTests
{
Expand All @@ -29,10 +25,9 @@ public class TheDisposeMethod : TestBaseClass
public void WithMultipleCallsDoesNotThrowException()
{
var uiProvider = Substitute.For<IGitHubServiceProvider>();
var hosts = Substitute.For<IRepositoryHosts>();
var factory = Substitute.For<IUIFactory>();
var cm = Substitutes.ConnectionManager;
var uiController = new UIController(uiProvider, hosts, factory, cm);
var uiController = new UIController(uiProvider, factory, cm);

uiController.Dispose();
uiController.Dispose();
Expand Down Expand Up @@ -99,13 +94,10 @@ protected IUIFactory SetupFactory(IServiceProvider provider)
return new UIFactory(factory);
}

protected IConnection SetupConnection(IServiceProvider provider, IRepositoryHosts hosts,
IRepositoryHost host, bool loggedIn = true)
protected IConnection SetupConnection(IServiceProvider provider, bool loggedIn = true)
{
var connection = provider.GetConnection();
hosts.LookupHost(connection.HostAddress).Returns(host);
connection.IsLoggedIn.Returns(loggedIn);
host.IsLoggedIn.Returns(loggedIn);
return connection;
}

Expand All @@ -127,15 +119,14 @@ public class AuthFlow : UIControllerTestBase
public void RunningNonAuthFlowWithoutBeingLoggedInRunsAuthFlow()
{
var provider = Substitutes.GetFullyMockedServiceProvider();
var hosts = provider.GetRepositoryHosts();
var factory = SetupFactory(provider);
var cm = provider.GetConnectionManager();
var cons = new ObservableCollectionEx<IConnection>();

cm.Connections.Returns(cons);
cm.GetLoadedConnections().Returns(cons);

using (var uiController = new UIController((IGitHubServiceProvider)provider, hosts, factory, cm))
using (var uiController = new UIController((IGitHubServiceProvider)provider, factory, cm))
{
var count = 0;
var flow = uiController.Configure(UIControllerFlow.Clone);
Expand All @@ -162,7 +153,6 @@ public void RunningNonAuthFlowWhenLoggedInRunsNonAuthFlow()

{
var provider = Substitutes.GetFullyMockedServiceProvider();
var hosts = provider.GetRepositoryHosts();
var factory = SetupFactory(provider);
var cm = provider.GetConnectionManager();
var cons = new ObservableCollectionEx<IConnection>();
Expand All @@ -171,9 +161,9 @@ public void RunningNonAuthFlowWhenLoggedInRunsNonAuthFlow()
cm.GetLoadedConnections().Returns(cons);

// simulate being logged in
cons.Add(SetupConnection(provider, hosts, hosts.GitHubHost));
cons.Add(SetupConnection(provider));

using (var uiController = new UIController((IGitHubServiceProvider)provider, hosts, factory, cm))
using (var uiController = new UIController((IGitHubServiceProvider)provider, factory, cm))
{
var count = 0;
var flow = uiController.Configure(UIControllerFlow.Clone);
Expand All @@ -199,15 +189,14 @@ public void RunningNonAuthFlowWhenLoggedInRunsNonAuthFlow()
public void RunningAuthFlowWithoutBeingLoggedInRunsAuthFlow()
{
var provider = Substitutes.GetFullyMockedServiceProvider();
var hosts = provider.GetRepositoryHosts();
var factory = SetupFactory(provider);
var cm = provider.GetConnectionManager();
var cons = new ObservableCollectionEx<IConnection>();

cm.Connections.Returns(cons);
cm.GetLoadedConnections().Returns(cons);

using (var uiController = new UIController((IGitHubServiceProvider)provider, hosts, factory, cm))
using (var uiController = new UIController((IGitHubServiceProvider)provider, factory, cm))
{
var count = 0;
var flow = uiController.Configure(UIControllerFlow.Authentication);
Expand All @@ -233,19 +222,17 @@ public void RunningAuthFlowWithoutBeingLoggedInRunsAuthFlow()
public void RunningAuthFlowWhenLoggedInRunsAuthFlow()
{
var provider = Substitutes.GetFullyMockedServiceProvider();
var hosts = provider.GetRepositoryHosts();
var factory = SetupFactory(provider);
var cm = provider.GetConnectionManager();

// simulate being logged in
var host = hosts.GitHubHost;
var connection = SetupConnection(provider, hosts, host);
var connection = SetupConnection(provider);
var cons = new ObservableCollectionEx<IConnection> { connection };

cm.Connections.Returns(cons);
cm.GetLoadedConnections().Returns(cons);

using (var uiController = new UIController((IGitHubServiceProvider)provider, hosts, factory, cm))
using (var uiController = new UIController((IGitHubServiceProvider)provider, factory, cm))
{
var count = 0;
var flow = uiController.Configure(UIControllerFlow.Authentication);
Expand All @@ -271,15 +258,14 @@ public void RunningAuthFlowWhenLoggedInRunsAuthFlow()
public void AuthFlowWithout2FA()
{
var provider = Substitutes.GetFullyMockedServiceProvider();
var hosts = provider.GetRepositoryHosts();
var factory = SetupFactory(provider);
var cm = provider.GetConnectionManager();
var cons = new ObservableCollectionEx<IConnection>();

cm.Connections.Returns(cons);
cm.GetLoadedConnections().Returns(cons);

using (var uiController = new UIController((IGitHubServiceProvider)provider, hosts, factory, cm))
using (var uiController = new UIController((IGitHubServiceProvider)provider, factory, cm))
{
var count = 0;
var flow = uiController.Configure(UIControllerFlow.Clone);
Expand All @@ -291,7 +277,7 @@ public void AuthFlowWithout2FA()
case 1:
Assert.IsAssignableFrom<IViewFor<ILoginControlViewModel>>(uc);
// login
cons.Add(SetupConnection(provider, hosts, hosts.GitHubHost));
cons.Add(SetupConnection(provider));
TriggerDone(data.View.ViewModel);
break;
case 2:
Expand All @@ -311,15 +297,14 @@ public void AuthFlowWithout2FA()
public void AuthFlowWith2FA()
{
var provider = Substitutes.GetFullyMockedServiceProvider();
var hosts = provider.GetRepositoryHosts();
var factory = SetupFactory(provider);
var cm = provider.GetConnectionManager();
var cons = new ObservableCollectionEx<IConnection>();

cm.Connections.Returns(cons);
cm.GetLoadedConnections().Returns(cons);

using (var uiController = new UIController((IGitHubServiceProvider)provider, hosts, factory, cm))
using (var uiController = new UIController((IGitHubServiceProvider)provider, factory, cm))
{
var count = 0;
var flow = uiController.Configure(UIControllerFlow.Clone);
Expand All @@ -337,7 +322,7 @@ public void AuthFlowWith2FA()
case 2:
Assert.IsAssignableFrom<IViewFor<ITwoFactorDialogViewModel>>(uc);
// login
cons.Add(SetupConnection(provider, hosts, hosts.GitHubHost));
cons.Add(SetupConnection(provider));
// continue by triggering done on login view
var vm2 = factory.CreateViewAndViewModel(GitHub.Exports.UIViewType.Login).ViewModel;
TriggerDone(vm2);
Expand All @@ -359,15 +344,14 @@ public void AuthFlowWith2FA()
public void BackAndForth()
{
var provider = Substitutes.GetFullyMockedServiceProvider();
var hosts = provider.GetRepositoryHosts();
var factory = SetupFactory(provider);
var cm = provider.GetConnectionManager();
var cons = new ObservableCollectionEx<IConnection>();

cm.Connections.Returns(cons);
cm.GetLoadedConnections().Returns(cons);

using (var uiController = new UIController((IGitHubServiceProvider)provider, hosts, factory, cm))
using (var uiController = new UIController((IGitHubServiceProvider)provider, factory, cm))
{
var count = 0;
var flow = uiController.Configure(UIControllerFlow.Clone);
Expand Down Expand Up @@ -401,7 +385,7 @@ public void BackAndForth()
case 4: {
Assert.IsAssignableFrom<IViewFor<ITwoFactorDialogViewModel>>(uc);
// login
cons.Add(SetupConnection(provider, hosts, hosts.GitHubHost));
cons.Add(SetupConnection(provider));
var vm2 = factory.CreateViewAndViewModel(GitHub.Exports.UIViewType.Login).ViewModel;
TriggerDone(vm2);
break;
Expand All @@ -427,7 +411,6 @@ public class CloneFlow : UIControllerTestBase
public void Flow()
{
var provider = Substitutes.GetFullyMockedServiceProvider();
var hosts = provider.GetRepositoryHosts();
var factory = SetupFactory(provider);
var cm = provider.GetConnectionManager();
var cons = new ObservableCollectionEx<IConnection>();
Expand All @@ -436,9 +419,9 @@ public void Flow()
cm.GetLoadedConnections().Returns(cons);

// simulate being logged in
cons.Add(SetupConnection(provider, hosts, hosts.GitHubHost));
cons.Add(SetupConnection(provider));

using (var uiController = new UIController((IGitHubServiceProvider)provider, hosts, factory, cm))
using (var uiController = new UIController((IGitHubServiceProvider)provider, factory, cm))
{
var count = 0;
var flow = uiController.Configure(UIControllerFlow.Clone);
Expand Down Expand Up @@ -467,7 +450,6 @@ public class CreateFlow : UIControllerTestBase
public void Flow()
{
var provider = Substitutes.GetFullyMockedServiceProvider();
var hosts = provider.GetRepositoryHosts();
var factory = SetupFactory(provider);
var cm = provider.GetConnectionManager();
var cons = new ObservableCollectionEx<IConnection>();
Expand All @@ -476,9 +458,9 @@ public void Flow()
cm.GetLoadedConnections().Returns(cons);

// simulate being logged in
cons.Add(SetupConnection(provider, hosts, hosts.GitHubHost));
cons.Add(SetupConnection(provider));

using (var uiController = new UIController((IGitHubServiceProvider)provider, hosts, factory, cm))
using (var uiController = new UIController((IGitHubServiceProvider)provider, factory, cm))
{
var count = 0;
var flow = uiController.Configure(UIControllerFlow.Create);
Expand Down Expand Up @@ -507,17 +489,16 @@ public class PublishFlow : UIControllerTestBase
public void FlowWithConnection()
{
var provider = Substitutes.GetFullyMockedServiceProvider();
var hosts = provider.GetRepositoryHosts();
var factory = SetupFactory(provider);
var cm = provider.GetConnectionManager();
var cons = new ObservableCollectionEx<IConnection>();
cm.Connections.Returns(cons);
var connection = SetupConnection(provider, hosts, hosts.GitHubHost);
var connection = SetupConnection(provider);

// simulate being logged in
cons.Add(connection);

using (var uiController = new UIController((IGitHubServiceProvider)provider, hosts, factory, cm))
using (var uiController = new UIController((IGitHubServiceProvider)provider, factory, cm))
{
var count = 0;
var flow = uiController.Configure(UIControllerFlow.Publish, connection);
Expand All @@ -544,20 +525,19 @@ public void FlowWithConnection()
public void FlowWithoutConnection()
{
var provider = Substitutes.GetFullyMockedServiceProvider();
var hosts = provider.GetRepositoryHosts();
var factory = SetupFactory(provider);
var cm = provider.GetConnectionManager();
var cons = new ObservableCollectionEx<IConnection>();

cm.Connections.Returns(cons);
cm.GetLoadedConnections().Returns(cons);

var connection = SetupConnection(provider, hosts, hosts.GitHubHost);
var connection = SetupConnection(provider);

// simulate being logged in
cons.Add(connection);

using (var uiController = new UIController((IGitHubServiceProvider)provider, hosts, factory, cm))
using (var uiController = new UIController((IGitHubServiceProvider)provider, factory, cm))
{
var count = 0;
var flow = uiController.Configure(UIControllerFlow.Publish);
Expand Down Expand Up @@ -587,7 +567,6 @@ public class GistFlow : UIControllerTestBase
public void ShowsGistDialog()
{
var provider = Substitutes.GetFullyMockedServiceProvider();
var hosts = provider.GetRepositoryHosts();
var factory = SetupFactory(provider);
var cm = provider.GetConnectionManager();
var cons = new ObservableCollectionEx<IConnection>();
Expand All @@ -596,9 +575,9 @@ public void ShowsGistDialog()
cm.GetLoadedConnections().Returns(cons);

// simulate being logged in
cons.Add(SetupConnection(provider, hosts, hosts.GitHubHost, true));
cons.Add(SetupConnection(provider, true));

using (var uiController = new UIController((IGitHubServiceProvider)provider, hosts, factory, cm))
using (var uiController = new UIController((IGitHubServiceProvider)provider, factory, cm))
{
var count = 0;
bool? success = null;
Expand Down
20 changes: 10 additions & 10 deletions src/UnitTests/GitHub.App/Services/PullRequestServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,36 +224,36 @@ public void CreatePullRequestAllArgsMandatory()
var serviceProvider = Substitutes.ServiceProvider;
var service = new PullRequestService(Substitute.For<IGitClient>(), serviceProvider.GetGitService(), serviceProvider.GetOperatingSystem(), Substitute.For<IUsageTracker>());

IRepositoryHost host = null;
IModelService ms = null;
ILocalRepositoryModel sourceRepo = null;
ILocalRepositoryModel targetRepo = null;
string title = null;
string body = null;
IBranch source = null;
IBranch target = null;

Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body));
Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(ms, sourceRepo, targetRepo, source, target, title, body));

host = serviceProvider.GetRepositoryHosts().GitHubHost;
Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body));
ms = Substitute.For<IModelService>();
Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(ms, sourceRepo, targetRepo, source, target, title, body));

sourceRepo = new LocalRepositoryModel("name", new GitHub.Primitives.UriString("http://github.com/github/stuff"), "c:\\path");
Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body));
Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(ms, sourceRepo, targetRepo, source, target, title, body));

targetRepo = new LocalRepositoryModel("name", new GitHub.Primitives.UriString("http://github.com/github/stuff"), "c:\\path");
Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body));
Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(ms, sourceRepo, targetRepo, source, target, title, body));

title = "a title";
Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body));
Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(ms, sourceRepo, targetRepo, source, target, title, body));

body = "a body";
Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body));
Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(ms, sourceRepo, targetRepo, source, target, title, body));

source = new BranchModel("source", sourceRepo);
Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body));
Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(ms, sourceRepo, targetRepo, source, target, title, body));

target = new BranchModel("target", targetRepo);
var pr = service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body);
var pr = service.CreatePullRequest(ms, sourceRepo, targetRepo, source, target, title, body);

Assert.NotNull(pr);
}
Expand Down
Loading
0