From 1a9cf92cb62ee68d7179c0b76ee5be6d42f0cbe2 Mon Sep 17 00:00:00 2001 From: Geoff Lamrock Date: Tue, 14 Oct 2025 08:16:39 +1100 Subject: [PATCH 1/3] Reorganise stack persistence and model folder structure --- .../Branch/AddBranchCommandHandlerTests.cs | 25 ++-- .../Branch/MoveBranchCommandHandlerTests.cs | 30 ++--- .../Branch/NewBranchCommandHandlerTests.cs | 49 ++++--- .../Branch/RemoveBranchCommandHandlerTests.cs | 63 +++++---- .../InputProviderExtensionMethodsTests.cs | 57 ++++---- .../Commands/Helpers/StackActionsTests.cs | 34 ++--- .../CreatePullRequestsCommandHandlerTests.cs | 26 ++-- .../OpenPullRequestsCommandHandlerTests.cs | 13 +- .../Remote/PullStackCommandHandlerTests.cs | 13 +- .../Remote/PushStackCommandHandlerTests.cs | 15 +-- .../Remote/SyncStackCommandHandlerTests.cs | 97 +++++++------- .../Stack/CleanupStackCommandHandlerTests.cs | 21 ++- .../Stack/DeleteStackCommandHandlerTests.cs | 13 +- .../Stack/NewStackCommandHandlerTests.cs | 25 ++-- .../Stack/RenameStackCommandHandlerTests.cs | 6 +- .../Stack/StackStatusCommandHandlerTests.cs | 5 +- .../Stack/StackSwitchCommandHandlerTests.cs | 3 +- .../Stack/UpdateStackCommandHandlerTests.cs | 29 ++-- .../Git/CachingGitHubClientTests.cs | 1 - .../Git/ConflictResolutionDetectorTests.cs | 8 +- src/Stack.Tests/Git/GitClientTests.cs | 4 +- src/Stack.Tests/Helpers/Some.cs | 2 - .../Helpers/TestDisplayProvider.cs | 1 - .../Helpers/TestGitRepositoryBuilder.cs | 2 - .../Helpers/TestStackRepositoryBuilder.cs | 19 ++- .../Integration/StackActionsTests.cs | 6 +- .../FileStackConfigTests.cs | 10 +- .../StackRepositoryTests.cs | 5 +- .../{Config => Persistence}/StackTests.cs | 124 +++++++++--------- src/Stack/Commands/Branch/AddBranchCommand.cs | 3 +- .../Commands/Branch/MoveBranchCommand.cs | 2 +- src/Stack/Commands/Branch/NewBranchCommand.cs | 3 +- .../Commands/Branch/RemoveBranchCommand.cs | 14 +- .../Commands/Config/OpenConfigCommand.cs | 2 +- .../Helpers/HumanizeEnumExtensionMethods.cs | 2 + .../Helpers/InputProviderExtensionMethods.cs | 10 +- src/Stack/Commands/Helpers/StackActions.cs | 24 ++-- src/Stack/Commands/Helpers/StackHelpers.cs | 14 +- .../PullRequests/CreatePullRequestsCommand.cs | 2 +- .../PullRequests/OpenPullRequestsCommand.cs | 2 +- src/Stack/Commands/Remote/PullStackCommand.cs | 2 +- src/Stack/Commands/Remote/PushStackCommand.cs | 2 +- src/Stack/Commands/Remote/SyncStackCommand.cs | 3 +- .../Commands/Stack/CleanupStackCommand.cs | 8 +- .../Commands/Stack/DeleteStackCommand.cs | 8 +- src/Stack/Commands/Stack/ListStacksCommand.cs | 3 +- src/Stack/Commands/Stack/NewStackCommand.cs | 5 +- .../Commands/Stack/RenameStackCommand.cs | 2 +- .../Commands/Stack/StackStatusCommand.cs | 4 +- .../Commands/Stack/StackSwitchCommand.cs | 3 +- .../Commands/Stack/UpdateStackCommand.cs | 2 +- src/Stack/Git/GitClient.cs | 3 - src/Stack/Git/GitHubClient.cs | 2 - src/Stack/Git/ProcessHelpers.cs | 1 - src/Stack/Git/SafeGitHubClient.cs | 1 - .../Commands/CommandWithOutput.cs | 1 - .../HostApplicationBuilderExtensions.cs | 10 +- src/Stack/{Config => Model}/Stack.cs | 13 +- .../StackExtensionMethods.cs | 4 +- .../{Config => Persistence}/StackConfig.cs | 33 ++--- .../{Config => Persistence}/StackConstants.cs | 2 +- .../StackRepository.cs | 14 +- 62 files changed, 435 insertions(+), 475 deletions(-) rename src/Stack.Tests/{Config => Persistence}/FileStackConfigTests.cs (97%) rename src/Stack.Tests/{Config => Persistence}/StackRepositoryTests.cs (99%) rename src/Stack.Tests/{Config => Persistence}/StackTests.cs (70%) rename src/Stack/{Config => Model}/Stack.cs (97%) rename src/Stack/{Config => Model}/StackExtensionMethods.cs (94%) rename src/Stack/{Config => Persistence}/StackConfig.cs (82%) rename src/Stack/{Config => Persistence}/StackConstants.cs (95%) rename src/Stack/{Config => Persistence}/StackRepository.cs (81%) diff --git a/src/Stack.Tests/Commands/Branch/AddBranchCommandHandlerTests.cs b/src/Stack.Tests/Commands/Branch/AddBranchCommandHandlerTests.cs index b19fcee4..71b46d62 100644 --- a/src/Stack.Tests/Commands/Branch/AddBranchCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/Branch/AddBranchCommandHandlerTests.cs @@ -3,7 +3,6 @@ using NSubstitute; using Stack.Commands; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; @@ -53,9 +52,9 @@ public async Task WhenNoInputsProvided_AsksForStackAndBranchAndParentBranchAndCo await handler.Handle(new AddBranchCommandInputs(null, null, null), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { - new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Config.Branch(firstBranch, [new Config.Branch(childBranch, []), new Config.Branch(branchToAdd, [])])]), + new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Model.Branch(firstBranch, [new Model.Branch(childBranch, []), new Model.Branch(branchToAdd, [])])]), new("Stack2", stackRepository.RemoteUri, sourceBranch, []) }); } @@ -95,9 +94,9 @@ public async Task WhenStackNameProvided_DoesNotAskForStackName_AddsBranchFromSta // Assert await inputProvider.DidNotReceive().Select(Questions.SelectStack, Arg.Any(), Arg.Any()); - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { - new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Config.Branch(anotherBranch, [new Config.Branch(branchToAdd, [])])]), + new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Model.Branch(anotherBranch, [new Model.Branch(branchToAdd, [])])]), new("Stack2", stackRepository.RemoteUri, sourceBranch, []) }); } @@ -136,9 +135,9 @@ public async Task WhenOnlyOneStackExists_DoesNotAskForStackName_AddsBranchFromSt // Assert await inputProvider.DidNotReceive().Select(Questions.SelectStack, Arg.Any(), Arg.Any()); - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { - new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Config.Branch(anotherBranch, [new Config.Branch(branchToAdd, [])])]) + new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Model.Branch(anotherBranch, [new Model.Branch(branchToAdd, [])])]) }); } @@ -211,9 +210,9 @@ public async Task WhenBranchNameProvided_DoesNotAskForBranchName_AddsBranchFromS await handler.Handle(new AddBranchCommandInputs(null, branchToAdd, null), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { - new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Config.Branch(anotherBranch, [new Config.Branch(branchToAdd, [])])]), + new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Model.Branch(anotherBranch, [new Model.Branch(branchToAdd, [])])]), new("Stack2", stackRepository.RemoteUri, sourceBranch, []) }); await inputProvider.DidNotReceive().Select(Questions.SelectBranch, Arg.Any(), Arg.Any()); @@ -326,9 +325,9 @@ public async Task WhenAllInputsProvided_DoesNotAskForAnything_AddsBranchFromStac await handler.Handle(new AddBranchCommandInputs("Stack1", branchToAdd, anotherBranch), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { - new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Config.Branch(anotherBranch, [new Config.Branch(branchToAdd, [])])]), + new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Model.Branch(anotherBranch, [new Model.Branch(branchToAdd, [])])]), new("Stack2", stackRepository.RemoteUri, sourceBranch, []) }); inputProvider.ReceivedCalls().Should().BeEmpty(); @@ -371,9 +370,9 @@ public async Task WhenParentBranchProvided_DoesNotAskForParentBranch_CreatesNewB await handler.Handle(new AddBranchCommandInputs(null, null, firstBranch), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { - new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Config.Branch(firstBranch, [new Config.Branch(childBranch, []), new Config.Branch(branchToAdd, [])])]), + new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Model.Branch(firstBranch, [new Model.Branch(childBranch, []), new Model.Branch(branchToAdd, [])])]), new("Stack2", stackRepository.RemoteUri, sourceBranch, []) }); diff --git a/src/Stack.Tests/Commands/Branch/MoveBranchCommandHandlerTests.cs b/src/Stack.Tests/Commands/Branch/MoveBranchCommandHandlerTests.cs index df64dbac..c6e36c57 100644 --- a/src/Stack.Tests/Commands/Branch/MoveBranchCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/Branch/MoveBranchCommandHandlerTests.cs @@ -1,13 +1,13 @@ using FluentAssertions; -using NSubstitute; using Meziantou.Extensions.Logging.Xunit; +using NSubstitute; using Stack.Commands; using Stack.Commands.Helpers; using Stack.Git; using Stack.Infrastructure; +using Stack.Infrastructure.Settings; using Stack.Tests.Helpers; using Xunit.Abstractions; -using Stack.Infrastructure.Settings; namespace Stack.Tests.Commands.Branch; @@ -50,11 +50,11 @@ public async Task WhenMovingBranchWithoutChildren_MovesBranchToNewParent() await handler.Handle(new MoveBranchCommandInputs(null, null, null, null), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new("Stack1", stackRepository.RemoteUri, sourceBranch, [ - new Config.Branch(firstBranch, [new Config.Branch(branchToMove, [])]), - new Config.Branch(secondBranch, []) + new Model.Branch(firstBranch, [new Model.Branch(branchToMove, [])]), + new Model.Branch(secondBranch, []) ]) }); } @@ -98,10 +98,10 @@ public async Task WhenMovingBranchWithChildren_AndMoveChildrenOption_MovesBranch await handler.Handle(new MoveBranchCommandInputs(null, null, null, null), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new("Stack1", stackRepository.RemoteUri, sourceBranch, [ - new Config.Branch(firstBranch, [new Config.Branch(branchToMove, [new Config.Branch(childBranch, [])])]) + new Model.Branch(firstBranch, [new Model.Branch(branchToMove, [new Model.Branch(childBranch, [])])]) ]) }); } @@ -145,11 +145,11 @@ public async Task WhenMovingBranchWithChildren_AndReParentChildrenOption_MovesBr await handler.Handle(new MoveBranchCommandInputs(null, null, null, null), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new("Stack1", stackRepository.RemoteUri, sourceBranch, [ - new Config.Branch(firstBranch, [new Config.Branch(branchToMove, [])]), - new Config.Branch(childBranch, []) + new Model.Branch(firstBranch, [new Model.Branch(branchToMove, [])]), + new Model.Branch(childBranch, []) ]) }); } @@ -189,11 +189,11 @@ public async Task WhenMovingBranchToSourceBranch_MovesBranchToRootLevel() await handler.Handle(new MoveBranchCommandInputs(null, null, null, null), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new("Stack1", stackRepository.RemoteUri, sourceBranch, [ - new Config.Branch(firstBranch, []), - new Config.Branch(branchToMove, []) + new Model.Branch(firstBranch, []), + new Model.Branch(branchToMove, []) ]) }); } @@ -229,10 +229,10 @@ public async Task WhenAllInputsProvided_DoesNotPromptUser() await handler.Handle(new MoveBranchCommandInputs("Stack1", branchToMove, firstBranch, MoveBranchChildAction.MoveChildren), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new("Stack1", stackRepository.RemoteUri, sourceBranch, [ - new Config.Branch(firstBranch, [new Config.Branch(branchToMove, [])]) + new Model.Branch(firstBranch, [new Model.Branch(branchToMove, [])]) ]) }); diff --git a/src/Stack.Tests/Commands/Branch/NewBranchCommandHandlerTests.cs b/src/Stack.Tests/Commands/Branch/NewBranchCommandHandlerTests.cs index 6e3c9c6c..3c30e08b 100644 --- a/src/Stack.Tests/Commands/Branch/NewBranchCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/Branch/NewBranchCommandHandlerTests.cs @@ -3,7 +3,6 @@ using NSubstitute; using Stack.Commands; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; @@ -44,7 +43,7 @@ public async Task WhenNoInputsProvided_AsksForStackAndBranchAndParentBranch_Crea inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); inputProvider.Text(Questions.BranchName, Arg.Any(), Arg.Any()).Returns(newBranch); - inputProvider.Select(Questions.SelectParentBranch, Arg.Any(), Arg.Any()).Returns(firstBranch); gitClient.GetCurrentBranch().Returns(sourceBranch); + inputProvider.Select(Questions.SelectParentBranch, Arg.Any(), Arg.Any()).Returns(firstBranch); gitClient.GetCurrentBranch().Returns(sourceBranch); gitClient.GetLocalBranchesOrderedByMostRecentCommitterDate().Returns(new[] { sourceBranch, firstBranch, childBranch }); gitClient.DoesLocalBranchExist(newBranch).Returns(false); @@ -52,9 +51,9 @@ public async Task WhenNoInputsProvided_AsksForStackAndBranchAndParentBranch_Crea await handler.Handle(new NewBranchCommandInputs(null, null, null), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { - new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Config.Branch(firstBranch, [new Config.Branch(childBranch, []), new Config.Branch(newBranch, [])])]), + new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Model.Branch(firstBranch, [new Model.Branch(childBranch, []), new Model.Branch(newBranch, [])])]), new("Stack2", stackRepository.RemoteUri, sourceBranch, []) }); gitClient.Received().CreateNewBranch(newBranch, firstBranch); @@ -89,7 +88,7 @@ public async Task WhenStackNameProvided_DoesNotAskForStackName_CreatesAndAddsBra gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); inputProvider.Text(Questions.BranchName, Arg.Any(), Arg.Any()).Returns(newBranch); - inputProvider.Select(Questions.SelectParentBranch, Arg.Any(), Arg.Any()).Returns(anotherBranch); gitClient.GetCurrentBranch().Returns(sourceBranch); + inputProvider.Select(Questions.SelectParentBranch, Arg.Any(), Arg.Any()).Returns(anotherBranch); gitClient.GetCurrentBranch().Returns(sourceBranch); gitClient.GetLocalBranchesOrderedByMostRecentCommitterDate().Returns(new[] { sourceBranch, anotherBranch }); gitClient.DoesLocalBranchExist(newBranch).Returns(false); @@ -98,9 +97,9 @@ public async Task WhenStackNameProvided_DoesNotAskForStackName_CreatesAndAddsBra // Assert await inputProvider.DidNotReceive().Select(Questions.SelectStack, Arg.Any(), Arg.Any()); - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { - new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Config.Branch(anotherBranch, [new Config.Branch(newBranch, [])])]), + new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Model.Branch(anotherBranch, [new Model.Branch(newBranch, [])])]), new("Stack2", stackRepository.RemoteUri, sourceBranch, []) }); } @@ -130,7 +129,7 @@ public async Task WhenOnlyOneStackExists_DoesNotAskForStackName_CreatesAndAddsBr gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); inputProvider.Text(Questions.BranchName, Arg.Any(), Arg.Any()).Returns(newBranch); - inputProvider.Select(Questions.SelectParentBranch, Arg.Any(), Arg.Any()).Returns(anotherBranch); gitClient.GetCurrentBranch().Returns(sourceBranch); + inputProvider.Select(Questions.SelectParentBranch, Arg.Any(), Arg.Any()).Returns(anotherBranch); gitClient.GetCurrentBranch().Returns(sourceBranch); gitClient.GetLocalBranchesOrderedByMostRecentCommitterDate().Returns(new[] { sourceBranch, anotherBranch }); gitClient.DoesLocalBranchExist(newBranch).Returns(false); @@ -139,9 +138,9 @@ public async Task WhenOnlyOneStackExists_DoesNotAskForStackName_CreatesAndAddsBr // Assert await inputProvider.DidNotReceive().Select(Questions.SelectStack, Arg.Any(), Arg.Any()); - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { - new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Config.Branch(anotherBranch, [new Config.Branch(newBranch, [])])]), + new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Model.Branch(anotherBranch, [new Model.Branch(newBranch, [])])]), }); } @@ -170,7 +169,7 @@ public async Task WhenStackNameProvided_ButStackDoesNotExist_Throws() var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new NewBranchCommandHandler(inputProvider, logger, displayProvider, gitClientFactory, executionContext, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); gitClient.GetLocalBranchesOrderedByMostRecentCommitterDate().Returns(new[] { sourceBranch, anotherBranch }); // Act and assert @@ -209,7 +208,7 @@ public async Task WhenBranchNameProvided_DoesNotAskForBranchName_CreatesAndAddsB gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); - inputProvider.Select(Questions.SelectParentBranch, Arg.Any(), Arg.Any()).Returns(anotherBranch); gitClient.GetCurrentBranch().Returns(sourceBranch); + inputProvider.Select(Questions.SelectParentBranch, Arg.Any(), Arg.Any()).Returns(anotherBranch); gitClient.GetCurrentBranch().Returns(sourceBranch); gitClient.GetLocalBranchesOrderedByMostRecentCommitterDate().Returns(new[] { sourceBranch, anotherBranch }); gitClient.DoesLocalBranchExist(newBranch).Returns(false); @@ -217,9 +216,9 @@ public async Task WhenBranchNameProvided_DoesNotAskForBranchName_CreatesAndAddsB await handler.Handle(new NewBranchCommandInputs(null, newBranch, null), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { - new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Config.Branch(anotherBranch, [new Config.Branch(newBranch, [])])]), + new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Model.Branch(anotherBranch, [new Model.Branch(newBranch, [])])]), new("Stack2", stackRepository.RemoteUri, sourceBranch, []) }); await inputProvider.DidNotReceive().Text(Questions.BranchName, Arg.Any(), Arg.Any()); @@ -250,7 +249,7 @@ public async Task WhenBranchNameProvided_ButBranchAlreadyExistLocally_Throws() gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); - inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); gitClient.GetCurrentBranch().Returns(sourceBranch); + inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); gitClient.GetCurrentBranch().Returns(sourceBranch); gitClient.GetLocalBranchesOrderedByMostRecentCommitterDate().Returns(new[] { sourceBranch, anotherBranch }); gitClient.DoesLocalBranchExist(anotherBranch).Returns(true); @@ -290,7 +289,7 @@ public async Task WhenBranchNameProvided_ButBranchAlreadyExistsInStack_Throws() gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); - inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); gitClient.GetCurrentBranch().Returns(sourceBranch); + inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); gitClient.GetCurrentBranch().Returns(sourceBranch); gitClient.GetLocalBranchesOrderedByMostRecentCommitterDate().Returns(new[] { sourceBranch, anotherBranch }); gitClient.DoesLocalBranchExist(newBranch).Returns(false); @@ -332,7 +331,7 @@ public async Task WhenPushToTheRemoteFails_StillCreatesTheBranchLocallyAndAddsIt inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); inputProvider.Text(Questions.BranchName, Arg.Any(), Arg.Any()).Returns(newBranch); - inputProvider.Select(Questions.SelectParentBranch, Arg.Any(), Arg.Any()).Returns(anotherBranch); gitClient.GetCurrentBranch().Returns(sourceBranch); + inputProvider.Select(Questions.SelectParentBranch, Arg.Any(), Arg.Any()).Returns(anotherBranch); gitClient.GetCurrentBranch().Returns(sourceBranch); gitClient.GetLocalBranchesOrderedByMostRecentCommitterDate().Returns(new[] { sourceBranch, anotherBranch }); gitClient.DoesLocalBranchExist(newBranch).Returns(false); @@ -340,9 +339,9 @@ public async Task WhenPushToTheRemoteFails_StillCreatesTheBranchLocallyAndAddsIt await handler.Handle(new NewBranchCommandInputs(null, null, null), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { - new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Config.Branch(anotherBranch, [new Config.Branch(newBranch, [])])]), + new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Model.Branch(anotherBranch, [new Model.Branch(newBranch, [])])]), new("Stack2", stackRepository.RemoteUri, sourceBranch, []) }); gitClient.Received().CreateNewBranch(newBranch, anotherBranch); @@ -379,7 +378,7 @@ public async Task WhenParentBranchNotProvided_AsksForParentBranch_CreatesNewBran inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); inputProvider.Text(Questions.BranchName, Arg.Any(), Arg.Any()).Returns(newBranch); - inputProvider.Select(Questions.SelectParentBranch, Arg.Any(), Arg.Any()).Returns(firstBranch); gitClient.GetCurrentBranch().Returns(sourceBranch); + inputProvider.Select(Questions.SelectParentBranch, Arg.Any(), Arg.Any()).Returns(firstBranch); gitClient.GetCurrentBranch().Returns(sourceBranch); gitClient.GetLocalBranchesOrderedByMostRecentCommitterDate().Returns(new[] { sourceBranch, firstBranch, childBranch }); gitClient.DoesLocalBranchExist(newBranch).Returns(false); @@ -387,9 +386,9 @@ public async Task WhenParentBranchNotProvided_AsksForParentBranch_CreatesNewBran await handler.Handle(new NewBranchCommandInputs(null, null, null), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { - new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Config.Branch(firstBranch, [new Config.Branch(childBranch, []), new Config.Branch(newBranch, [])])]), + new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Model.Branch(firstBranch, [new Model.Branch(childBranch, []), new Model.Branch(newBranch, [])])]), new("Stack2", stackRepository.RemoteUri, sourceBranch, []) }); gitClient.Received().CreateNewBranch(newBranch, firstBranch); @@ -425,7 +424,7 @@ public async Task WhenParentBranchProvided_DoesNotAskForParentBranch_CreatesNewB gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); - inputProvider.Text(Questions.BranchName, Arg.Any(), Arg.Any()).Returns(newBranch); gitClient.GetCurrentBranch().Returns(sourceBranch); + inputProvider.Text(Questions.BranchName, Arg.Any(), Arg.Any()).Returns(newBranch); gitClient.GetCurrentBranch().Returns(sourceBranch); gitClient.GetLocalBranchesOrderedByMostRecentCommitterDate().Returns(new[] { sourceBranch, firstBranch, childBranch }); gitClient.DoesLocalBranchExist(newBranch).Returns(false); @@ -433,9 +432,9 @@ public async Task WhenParentBranchProvided_DoesNotAskForParentBranch_CreatesNewB await handler.Handle(new NewBranchCommandInputs(null, null, firstBranch), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { - new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Config.Branch(firstBranch, [new Config.Branch(childBranch, []), new Config.Branch(newBranch, [])])]), + new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Model.Branch(firstBranch, [new Model.Branch(childBranch, []), new Model.Branch(newBranch, [])])]), new("Stack2", stackRepository.RemoteUri, sourceBranch, []) }); gitClient.Received().CreateNewBranch(newBranch, firstBranch); diff --git a/src/Stack.Tests/Commands/Branch/RemoveBranchCommandHandlerTests.cs b/src/Stack.Tests/Commands/Branch/RemoveBranchCommandHandlerTests.cs index d993f615..297606d8 100644 --- a/src/Stack.Tests/Commands/Branch/RemoveBranchCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/Branch/RemoveBranchCommandHandlerTests.cs @@ -1,9 +1,8 @@ using FluentAssertions; -using NSubstitute; using Meziantou.Extensions.Logging.Xunit; +using NSubstitute; using Stack.Commands; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; @@ -37,7 +36,7 @@ public async Task WhenNoInputsProvided_AsksForAllInputsAndConfirms_RemovesBranch var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new RemoveBranchCommandHandler(inputProvider, logger, gitClientFactory, executionContext, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); inputProvider.SelectGrouped(Questions.SelectBranch, Arg.Any[]>(), Arg.Any()).Returns(branchToRemove); @@ -49,10 +48,10 @@ public async Task WhenNoInputsProvided_AsksForAllInputsAndConfirms_RemovesBranch await handler.Handle(RemoveBranchCommandInputs.Empty, CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { - new Config.Stack("Stack1", stackRepository.RemoteUri, sourceBranch, []), - new Config.Stack("Stack2", stackRepository.RemoteUri, sourceBranch, []) + new Model.Stack("Stack1", stackRepository.RemoteUri, sourceBranch, []), + new Model.Stack("Stack2", stackRepository.RemoteUri, sourceBranch, []) }); } @@ -79,7 +78,7 @@ public async Task WhenStackNameProvided_DoesNotAskForStackName_RemovesBranchFrom var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new RemoveBranchCommandHandler(inputProvider, logger, gitClientFactory, executionContext, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); inputProvider.SelectGrouped(Questions.SelectBranch, Arg.Any[]>(), Arg.Any()).Returns(branchToRemove); inputProvider.Confirm(Questions.ConfirmRemoveBranch, Arg.Any()).Returns(true); @@ -89,7 +88,7 @@ public async Task WhenStackNameProvided_DoesNotAskForStackName_RemovesBranchFrom // Assert await inputProvider.DidNotReceive().Select(Questions.SelectStack, Arg.Any(), Arg.Any()); - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new("Stack1", stackRepository.RemoteUri, sourceBranch, []), new("Stack2", stackRepository.RemoteUri, sourceBranch, []) @@ -119,7 +118,7 @@ public async Task WhenStackNameProvided_ButStackDoesNotExist_Throws() var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new RemoveBranchCommandHandler(inputProvider, logger, gitClientFactory, executionContext, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); // Act and assert var invalidStackName = Some.Name(); @@ -152,7 +151,7 @@ public async Task WhenBranchNameProvided_DoesNotAskForBranchName_RemovesBranchFr var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new RemoveBranchCommandHandler(inputProvider, logger, gitClientFactory, executionContext, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); inputProvider.Confirm(Questions.ConfirmRemoveBranch, Arg.Any()).Returns(true); @@ -161,7 +160,7 @@ public async Task WhenBranchNameProvided_DoesNotAskForBranchName_RemovesBranchFr await handler.Handle(new RemoveBranchCommandInputs(null, branchToRemove, false), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new("Stack1", stackRepository.RemoteUri, sourceBranch, []), new("Stack2", stackRepository.RemoteUri, sourceBranch, []) @@ -192,7 +191,7 @@ public async Task WhenBranchNameProvided_ButBranchDoesNotExistInStack_Throws() var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new RemoveBranchCommandHandler(inputProvider, logger, gitClientFactory, executionContext, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); @@ -224,7 +223,7 @@ public async Task WhenOnlyOneStackExists_DoesNotAskForStackName() var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new RemoveBranchCommandHandler(inputProvider, logger, gitClientFactory, executionContext, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); inputProvider.SelectGrouped(Questions.SelectBranch, Arg.Any[]>(), Arg.Any()).Returns(branchToRemove); inputProvider.Confirm(Questions.ConfirmRemoveBranch, Arg.Any()).Returns(true); @@ -233,7 +232,7 @@ public async Task WhenOnlyOneStackExists_DoesNotAskForStackName() await handler.Handle(RemoveBranchCommandInputs.Empty, CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new("Stack1", stackRepository.RemoteUri, sourceBranch, []) }); @@ -264,7 +263,7 @@ public async Task WhenConfirmProvided_DoesNotAskForConfirmation_RemovesBranchFro var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new RemoveBranchCommandHandler(inputProvider, logger, gitClientFactory, executionContext, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); inputProvider.SelectGrouped(Questions.SelectBranch, Arg.Any[]>(), Arg.Any()).Returns(branchToRemove); @@ -273,7 +272,7 @@ public async Task WhenConfirmProvided_DoesNotAskForConfirmation_RemovesBranchFro await handler.Handle(new RemoveBranchCommandInputs(null, null, true), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new("Stack1", stackRepository.RemoteUri, sourceBranch, []), new("Stack2", stackRepository.RemoteUri, sourceBranch, []) @@ -302,7 +301,7 @@ public async Task WhenChildActionIsMoveChildrenToParent_RemovesBranchAndMovesChi var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new RemoveBranchCommandHandler(inputProvider, logger, gitClientFactory, executionContext, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); inputProvider.SelectGrouped(Questions.SelectBranch, Arg.Any[]>(), Arg.Any()).Returns(branchToRemove); @@ -314,9 +313,9 @@ public async Task WhenChildActionIsMoveChildrenToParent_RemovesBranchAndMovesChi await handler.Handle(RemoveBranchCommandInputs.Empty, CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { - new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Config.Branch(childBranch, [])]) + new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Model.Branch(childBranch, [])]) }); } @@ -341,7 +340,7 @@ public async Task WhenChildActionIsRemoveChildren_RemovesBranchAndDeletesChildre var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new RemoveBranchCommandHandler(inputProvider, logger, gitClientFactory, executionContext, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); inputProvider.SelectGrouped(Questions.SelectBranch, Arg.Any[]>(), Arg.Any()).Returns(branchToRemove); @@ -353,7 +352,7 @@ public async Task WhenChildActionIsRemoveChildren_RemovesBranchAndDeletesChildre await handler.Handle(RemoveBranchCommandInputs.Empty, CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new("Stack1", stackRepository.RemoteUri, sourceBranch, []) }); @@ -380,7 +379,7 @@ public async Task WhenRemoveChildrenIsProvided_RemovesBranchAndDeletesChildren() var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new RemoveBranchCommandHandler(inputProvider, logger, gitClientFactory, executionContext, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); inputProvider.SelectGrouped(Questions.SelectBranch, Arg.Any[]>(), Arg.Any()).Returns(branchToRemove); @@ -390,7 +389,7 @@ public async Task WhenRemoveChildrenIsProvided_RemovesBranchAndDeletesChildren() await handler.Handle(new RemoveBranchCommandInputs(null, null, false, RemoveBranchChildAction.RemoveChildren), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new("Stack1", stackRepository.RemoteUri, sourceBranch, []) }); @@ -419,7 +418,7 @@ public async Task WhenMoveChildrenToParentIsProvided_RemovesBranchAndMovesChildr var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new RemoveBranchCommandHandler(inputProvider, logger, gitClientFactory, executionContext, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); inputProvider.SelectGrouped(Questions.SelectBranch, Arg.Any[]>(), Arg.Any()).Returns(branchToRemove); @@ -429,9 +428,9 @@ public async Task WhenMoveChildrenToParentIsProvided_RemovesBranchAndMovesChildr await handler.Handle(new RemoveBranchCommandInputs(null, null, false, RemoveBranchChildAction.MoveChildrenToParent), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { - new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Config.Branch(childBranch, [])]) + new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Model.Branch(childBranch, [])]) }); await inputProvider.DidNotReceive().Select(Questions.RemoveBranchChildAction, Arg.Any(), Arg.Any(), Arg.Any>()); @@ -457,7 +456,7 @@ public async Task WhenBranchHasNoChildren_DoesNotAskForChildAction() var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new RemoveBranchCommandHandler(inputProvider, logger, gitClientFactory, executionContext, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); inputProvider.SelectGrouped(Questions.SelectBranch, Arg.Any[]>(), Arg.Any()).Returns(branchToRemove); @@ -467,7 +466,7 @@ public async Task WhenBranchHasNoChildren_DoesNotAskForChildAction() await handler.Handle(RemoveBranchCommandInputs.Empty, CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new("Stack1", stackRepository.RemoteUri, sourceBranch, []) }); @@ -496,7 +495,7 @@ public async Task WhenBranchHasNoChildrenButRemoveChildrenIsProvided_DoesNotAskF var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new RemoveBranchCommandHandler(inputProvider, logger, gitClientFactory, executionContext, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); inputProvider.SelectGrouped(Questions.SelectBranch, Arg.Any[]>(), Arg.Any()).Returns(branchToRemove); @@ -506,7 +505,7 @@ public async Task WhenBranchHasNoChildrenButRemoveChildrenIsProvided_DoesNotAskF await handler.Handle(new RemoveBranchCommandInputs(null, null, false, RemoveBranchChildAction.RemoveChildren), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new("Stack1", stackRepository.RemoteUri, sourceBranch, []) }); @@ -535,7 +534,7 @@ public async Task WhenBranchHasNoChildrenButMoveChildrenToParentIsProvided_DoesN var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new RemoveBranchCommandHandler(inputProvider, logger, gitClientFactory, executionContext, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); inputProvider.SelectGrouped(Questions.SelectBranch, Arg.Any[]>(), Arg.Any()).Returns(branchToRemove); @@ -545,7 +544,7 @@ public async Task WhenBranchHasNoChildrenButMoveChildrenToParentIsProvided_DoesN await handler.Handle(new RemoveBranchCommandInputs(null, null, false, RemoveBranchChildAction.MoveChildrenToParent), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new("Stack1", stackRepository.RemoteUri, sourceBranch, []) }); diff --git a/src/Stack.Tests/Commands/Helpers/InputProviderExtensionMethodsTests.cs b/src/Stack.Tests/Commands/Helpers/InputProviderExtensionMethodsTests.cs index c5e71452..ef9d4c61 100644 --- a/src/Stack.Tests/Commands/Helpers/InputProviderExtensionMethodsTests.cs +++ b/src/Stack.Tests/Commands/Helpers/InputProviderExtensionMethodsTests.cs @@ -1,10 +1,7 @@ -using System.Threading.Tasks; using FluentAssertions; -using Microsoft.Extensions.Logging; -using NSubstitute; using Meziantou.Extensions.Logging.Xunit; +using NSubstitute; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Infrastructure; using Stack.Tests.Helpers; using Xunit.Abstractions; @@ -21,13 +18,13 @@ public async Task SelectStack_WhenNameIsProvided_ReturnsStackByName() var sourceBranch = Some.BranchName(); var currentBranch = Some.BranchName(); var stackName = "TestStack"; - - var stacks = new List + + var stacks = new List { new(stackName, remoteUri, sourceBranch, []), new("OtherStack", remoteUri, sourceBranch, []) }; - + var inputProvider = Substitute.For(); var logger = XUnitLogger.CreateLogger(testOutputHelper); @@ -48,12 +45,12 @@ public async Task SelectStack_WhenOnlyOneStackExists_AutoSelectsStack() var sourceBranch = Some.BranchName(); var currentBranch = Some.BranchName(); var stackName = "OnlyStack"; - - var stacks = new List + + var stacks = new List { new(stackName, remoteUri, sourceBranch, []) }; - + var inputProvider = Substitute.For(); var logger = XUnitLogger.CreateLogger(testOutputHelper); @@ -75,13 +72,13 @@ public async Task SelectStack_WhenCurrentBranchIsInOnlyOneStack_AutoSelectsThatS var currentBranch = Some.BranchName(); var stackWithCurrentBranch = "StackWithBranch"; var stackWithoutCurrentBranch = "StackWithoutBranch"; - - var stacks = new List + + var stacks = new List { - new(stackWithCurrentBranch, remoteUri, sourceBranch, [new Config.Branch(currentBranch, [])]), - new(stackWithoutCurrentBranch, remoteUri, sourceBranch, [new Config.Branch(Some.BranchName(), [])]) + new(stackWithCurrentBranch, remoteUri, sourceBranch, [new Model.Branch(currentBranch, [])]), + new(stackWithoutCurrentBranch, remoteUri, sourceBranch, [new Model.Branch(Some.BranchName(), [])]) }; - + var inputProvider = Substitute.For(); var logger = XUnitLogger.CreateLogger(testOutputHelper); @@ -103,16 +100,16 @@ public async Task SelectStack_WhenCurrentBranchIsInMultipleStacks_PromptsUser() var currentBranch = Some.BranchName(); var stack1Name = "Stack1"; var stack2Name = "Stack2"; - - var stacks = new List + + var stacks = new List { - new(stack1Name, remoteUri, sourceBranch, [new Config.Branch(currentBranch, [])]), - new(stack2Name, remoteUri, sourceBranch, [new Config.Branch(currentBranch, [])]) + new(stack1Name, remoteUri, sourceBranch, [new Model.Branch(currentBranch, [])]), + new(stack2Name, remoteUri, sourceBranch, [new Model.Branch(currentBranch, [])]) }; - + var inputProvider = Substitute.For(); var logger = XUnitLogger.CreateLogger(testOutputHelper); - + inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()) .Returns(stack1Name); @@ -134,16 +131,16 @@ public async Task SelectStack_WhenCurrentBranchIsInNoStacks_PromptsUser() var currentBranch = Some.BranchName(); var stack1Name = "Stack1"; var stack2Name = "Stack2"; - - var stacks = new List + + var stacks = new List { - new(stack1Name, remoteUri, sourceBranch, [new Config.Branch(Some.BranchName(), [])]), - new(stack2Name, remoteUri, sourceBranch, [new Config.Branch(Some.BranchName(), [])]) + new(stack1Name, remoteUri, sourceBranch, [new Model.Branch(Some.BranchName(), [])]), + new(stack2Name, remoteUri, sourceBranch, [new Model.Branch(Some.BranchName(), [])]) }; - + var inputProvider = Substitute.For(); var logger = XUnitLogger.CreateLogger(testOutputHelper); - + inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()) .Returns(stack1Name); @@ -165,13 +162,13 @@ public async Task SelectStack_WhenCurrentBranchIsSourceBranchInOnlyOneStack_Auto var currentBranch = sourceBranch; // Current branch is the source branch var stackWithCurrentAsSource = "StackWithSourceBranch"; var stackWithDifferentSource = "StackWithDifferentSource"; - - var stacks = new List + + var stacks = new List { new(stackWithCurrentAsSource, remoteUri, sourceBranch, []), new(stackWithDifferentSource, remoteUri, Some.BranchName(), []) }; - + var inputProvider = Substitute.For(); var logger = XUnitLogger.CreateLogger(testOutputHelper); diff --git a/src/Stack.Tests/Commands/Helpers/StackActionsTests.cs b/src/Stack.Tests/Commands/Helpers/StackActionsTests.cs index 42c09c1b..4460e06c 100644 --- a/src/Stack.Tests/Commands/Helpers/StackActionsTests.cs +++ b/src/Stack.Tests/Commands/Helpers/StackActionsTests.cs @@ -23,7 +23,7 @@ public async Task UpdateStack_UsingMerge_WhenConflictResolutionAborted_ThrowsAbo var gitClient = Substitute.For(); var gitHubClient = Substitute.For(); var conflictResolutionDetector = Substitute.For(); - var stack = new Config.Stack("Stack1", Some.HttpsUri().ToString(), sourceBranch, new List { new(feature, []) }); + var stack = new Model.Stack("Stack1", Some.HttpsUri().ToString(), sourceBranch, new List { new(feature, []) }); gitClient.GetBranchStatuses(Arg.Any()).Returns(new Dictionary { @@ -61,7 +61,7 @@ public async Task UpdateStack_UsingMerge_WhenConflictsResolved_CompletesSuccessf var gitClient = Substitute.For(); var gitHubClient = Substitute.For(); var conflictResolutionDetector = Substitute.For(); - var stack = new Config.Stack("Stack1", Some.HttpsUri().ToString(), sourceBranch, new List { new(feature, []) }); + var stack = new Model.Stack("Stack1", Some.HttpsUri().ToString(), sourceBranch, new List { new(feature, []) }); gitClient.GetBranchStatuses(Arg.Any()).Returns(new Dictionary { @@ -109,11 +109,11 @@ public async Task UpdateStack_UsingMerge_WhenBranchHasMergedPullRequest_SkipsBra gitClient.GetBranchStatuses(Arg.Any()).Returns(branchStatuses); - var stack = new Config.Stack( + var stack = new Model.Stack( "Stack1", Some.HttpsUri().ToString(), sourceBranch, - new List { new(inactiveBranch, []) }); + new List { new(inactiveBranch, []) }); var executionContext = new CliExecutionContext { WorkingDirectory = "/repo" }; var factory = Substitute.For(); @@ -151,11 +151,11 @@ public async Task UpdateStack_UsingMerge_WhenBranchHasNoRemoteTrackingBranch_IsU gitClient.GetBranchStatuses(Arg.Any()).Returns(branchStatuses); - var stack = new Config.Stack( + var stack = new Model.Stack( "Stack1", Some.HttpsUri().ToString(), sourceBranch, - new List { new(localOnlyBranch, []) }); + new List { new(localOnlyBranch, []) }); var executionContext = new CliExecutionContext { WorkingDirectory = "/repo" }; var factory = Substitute.For(); @@ -184,7 +184,7 @@ public async Task UpdateStack_UsingRebase_WhenConflictResolutionAborted_ThrowsAb var gitClient = Substitute.For(); var gitHubClient = Substitute.For(); var conflictResolutionDetector = Substitute.For(); - var stack = new Config.Stack("Stack1", Some.HttpsUri().ToString(), source, new List { new(feature, []) }); + var stack = new Model.Stack("Stack1", Some.HttpsUri().ToString(), source, new List { new(feature, []) }); gitClient.GetBranchStatuses(Arg.Any()).Returns(new Dictionary { @@ -221,7 +221,7 @@ public async Task UpdateStack_UsingRebase_WhenConflictsResolved_CompletesSuccess var gitClient = Substitute.For(); var gitHubClient = Substitute.For(); var conflictResolutionDetector = Substitute.For(); - var stack = new Config.Stack("Stack1", Some.HttpsUri().ToString(), source, new List { new(feature, []) }); + var stack = new Model.Stack("Stack1", Some.HttpsUri().ToString(), source, new List { new(feature, []) }); gitClient.GetBranchStatuses(Arg.Any()).Returns(new Dictionary { @@ -269,11 +269,11 @@ public async Task UpdateStack_UsingRebase_WhenBranchHasMergedPullRequest_SkipsBr gitClient.GetBranchStatuses(Arg.Any()).Returns(branchStatuses); - var stack = new Config.Stack( + var stack = new Model.Stack( "Stack1", Some.HttpsUri().ToString(), sourceBranch, - new List { new(inactiveBranch, []) }); + new List { new(inactiveBranch, []) }); var executionContext = new CliExecutionContext { WorkingDirectory = "/repo" }; var factory = Substitute.For(); @@ -312,11 +312,11 @@ public async Task UpdateStack_UsingRebase_WhenBranchHasNoRemoteTrackingBranch_Is gitClient.GetBranchStatuses(Arg.Any()).Returns(branchStatuses); - var stack = new Config.Stack( + var stack = new Model.Stack( "Stack1", Some.HttpsUri().ToString(), sourceBranch, - new List { new(localOnlyBranch, []) }); + new List { new(localOnlyBranch, []) }); var executionContext = new CliExecutionContext { WorkingDirectory = "/repo" }; var factory = Substitute.For(); @@ -917,11 +917,11 @@ public async Task UpdateStack_UsingMerge_WhenBranchIsInWorktree_UsesWorktreeGitC }; gitClient.GetBranchStatuses(Arg.Any()).Returns(branchStatuses); - var stack = new Config.Stack( + var stack = new Model.Stack( "Stack1", Some.HttpsUri().ToString(), sourceBranch, - new List { new Config.Branch(branchInWorktree, new List()) } + new List { new Model.Branch(branchInWorktree, new List()) } ); var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; @@ -965,11 +965,11 @@ public async Task UpdateStack_UsingRebase_WhenBranchIsInWorktree_UsesWorktreeGit }; gitClient.GetBranchStatuses(Arg.Any()).Returns(branchStatuses); - var stack = new Config.Stack( + var stack = new Model.Stack( "Stack1", Some.HttpsUri().ToString(), sourceBranch, - new List { new Config.Branch(branchInWorktree, new List()) } + new List { new Model.Branch(branchInWorktree, new List()) } ); var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; @@ -1008,7 +1008,7 @@ public async Task UpdateStack_WhenCheckingPullRequests_AndGitHubClientIsNotAvail }; gitClient.GetBranchStatuses(Arg.Any()).Returns(branchStatuses); - var stack = new Config.Stack( + var stack = new Model.Stack( "Stack1", Some.HttpsUri().ToString(), sourceBranch, diff --git a/src/Stack.Tests/Commands/PullRequests/CreatePullRequestsCommandHandlerTests.cs b/src/Stack.Tests/Commands/PullRequests/CreatePullRequestsCommandHandlerTests.cs index 2faa0566..0701ea0e 100644 --- a/src/Stack.Tests/Commands/PullRequests/CreatePullRequestsCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/PullRequests/CreatePullRequestsCommandHandlerTests.cs @@ -1,13 +1,13 @@ using FluentAssertions; using FluentAssertions.Equivalency; -using NSubstitute; using Meziantou.Extensions.Logging.Xunit; +using NSubstitute; using Stack.Commands; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; +using Stack.Persistence; using Stack.Tests.Helpers; using Xunit.Abstractions; using static Stack.Commands.CreatePullRequestsCommandHandler; @@ -40,7 +40,7 @@ public async Task WhenNoPullRequestsExistForAStackWithMultipleBranches_CreatesPu var displayProvider = new TestDisplayProvider(testOutputHelper); var outputProvider = Substitute.For(); var fileOperations = new FileOperations(); - var gitClient = Substitute.For(); gitClient.GetCurrentBranch().Returns(sourceBranch); + var gitClient = Substitute.For(); gitClient.GetCurrentBranch().Returns(sourceBranch); gitClient.GetRootOfRepository().Returns(TemporaryDirectory.CreatePath()); gitClient.CompareBranches(Arg.Any(), Arg.Any()).Returns((0, 0)); gitClient.GetBranchStatuses(Arg.Any()).Returns(new Dictionary @@ -110,7 +110,7 @@ public async Task WhenCreatingPullRequestsForAStackWithMultipleBranches_EachPull var displayProvider = new TestDisplayProvider(testOutputHelper); var outputProvider = Substitute.For(); var fileOperations = new FileOperations(); - var gitClient = Substitute.For(); gitClient.GetCurrentBranch().Returns(sourceBranch); + var gitClient = Substitute.For(); gitClient.GetCurrentBranch().Returns(sourceBranch); gitClient.GetRootOfRepository().Returns(TemporaryDirectory.CreatePath()); gitClient.CompareBranches(Arg.Any(), Arg.Any()).Returns((0, 0)); gitClient.GetBranchStatuses(Arg.Any()).Returns(new Dictionary @@ -171,7 +171,7 @@ public async Task WhenAPullRequestExistForABranch_AndNoneForAnotherBranch_Create var displayProvider = new TestDisplayProvider(testOutputHelper); var outputProvider = Substitute.For(); var fileOperations = new FileOperations(); - var gitClient = Substitute.For(); gitClient.GetCurrentBranch().Returns(sourceBranch); + var gitClient = Substitute.For(); gitClient.GetCurrentBranch().Returns(sourceBranch); gitClient.GetRootOfRepository().Returns(TemporaryDirectory.CreatePath()); gitClient.CompareBranches(Arg.Any(), Arg.Any()).Returns((0, 0)); gitClient.GetBranchStatuses(Arg.Any()).Returns(new Dictionary @@ -229,7 +229,7 @@ public async Task WhenStackNameIsProvided_PullRequestsAreCreatedForThatStack() var displayProvider = new TestDisplayProvider(testOutputHelper); var outputProvider = Substitute.For(); var fileOperations = new FileOperations(); - var gitClient = Substitute.For(); gitClient.GetCurrentBranch().Returns(sourceBranch); + var gitClient = Substitute.For(); gitClient.GetCurrentBranch().Returns(sourceBranch); gitClient.GetRootOfRepository().Returns(TemporaryDirectory.CreatePath()); gitClient.CompareBranches(Arg.Any(), Arg.Any()).Returns((0, 0)); gitClient.GetBranchStatuses(Arg.Any()).Returns(new Dictionary @@ -290,7 +290,7 @@ public async Task WhenOnlyOneStackExists_DoesNotAskForStackName_PullRequestsAreC var displayProvider = new TestDisplayProvider(testOutputHelper); var outputProvider = Substitute.For(); var fileOperations = new FileOperations(); - var gitClient = Substitute.For(); gitClient.GetCurrentBranch().Returns(sourceBranch); + var gitClient = Substitute.For(); gitClient.GetCurrentBranch().Returns(sourceBranch); gitClient.GetRootOfRepository().Returns(TemporaryDirectory.CreatePath()); gitClient.CompareBranches(Arg.Any(), Arg.Any()).Returns((0, 0)); gitClient.GetBranchStatuses(Arg.Any()).Returns(new Dictionary @@ -354,7 +354,7 @@ public async Task WhenStackNameIsProvided_ButTheStackDoesNotExist_Throws() var displayProvider = new TestDisplayProvider(testOutputHelper); var outputProvider = Substitute.For(); var fileOperations = new FileOperations(); - var gitClient = Substitute.For(); gitClient.GetCurrentBranch().Returns(sourceBranch); + var gitClient = Substitute.For(); gitClient.GetCurrentBranch().Returns(sourceBranch); gitClient.GetRootOfRepository().Returns(TemporaryDirectory.CreatePath()); gitClient.CompareBranches(Arg.Any(), Arg.Any()).Returns((0, 0)); gitClient.GetBranchStatuses(Arg.Any()).Returns(new Dictionary @@ -407,7 +407,7 @@ public async Task WhenAPullRequestExistForABranch_AndHasBeenMerged_AndNoneForAno var displayProvider = new TestDisplayProvider(testOutputHelper); var outputProvider = Substitute.For(); var fileOperations = new FileOperations(); - var gitClient = Substitute.For(); gitClient.GetCurrentBranch().Returns(sourceBranch); + var gitClient = Substitute.For(); gitClient.GetCurrentBranch().Returns(sourceBranch); gitClient.GetRootOfRepository().Returns(TemporaryDirectory.CreatePath()); gitClient.CompareBranches(Arg.Any(), Arg.Any()).Returns((0, 0)); gitClient.GetBranchStatuses(Arg.Any()).Returns(new Dictionary @@ -471,7 +471,7 @@ public async Task WhenAPullRequestTemplateExistsInTheRepo_ItIsUsedAsTheBodyOfANe var displayProvider = new TestDisplayProvider(testOutputHelper); var outputProvider = Substitute.For(); var fileOperations = new FileOperations(); - var gitClient = Substitute.For(); gitClient.GetCurrentBranch().Returns(sourceBranch); + var gitClient = Substitute.For(); gitClient.GetCurrentBranch().Returns(sourceBranch); using var tempRepo = TemporaryDirectory.Create(); gitClient.GetRootOfRepository().Returns(tempRepo.DirectoryPath); gitClient.CompareBranches(Arg.Any(), Arg.Any()).Returns((0, 0)); @@ -537,7 +537,7 @@ public async Task WhenAPullRequestTemplateDoesNotExistInTheRepo_TheStackPrListMa var displayProvider = new TestDisplayProvider(testOutputHelper); var outputProvider = Substitute.For(); var fileOperations = new FileOperations(); - var gitClient = Substitute.For(); gitClient.CompareBranches(Arg.Any(), Arg.Any()).Returns((0, 0)); + var gitClient = Substitute.For(); gitClient.CompareBranches(Arg.Any(), Arg.Any()).Returns((0, 0)); gitClient.GetBranchStatuses(Arg.Any()).Returns(new Dictionary { [sourceBranch] = new GitBranchStatus(sourceBranch, $"origin/{sourceBranch}", true, false, 0, 0, new Commit(Some.Sha(), "msg")), @@ -599,7 +599,7 @@ public async Task WhenAskedWhetherToCreateAPullRequestAsADraft_AndTheAnswerIsYes var displayProvider = new TestDisplayProvider(testOutputHelper); var outputProvider = Substitute.For(); var fileOperations = new FileOperations(); - var gitClient = Substitute.For(); gitClient.GetCurrentBranch().Returns(sourceBranch); + var gitClient = Substitute.For(); gitClient.GetCurrentBranch().Returns(sourceBranch); gitClient.GetRootOfRepository().Returns(TemporaryDirectory.CreatePath()); gitClient.CompareBranches(Arg.Any(), Arg.Any()).Returns((0, 0)); gitClient.GetBranchStatuses(Arg.Any()).Returns(new Dictionary @@ -654,7 +654,7 @@ public async Task WhenOnlySelectingSomeBranchesToCreatePullRequestsFor_OnlyThose var displayProvider = new TestDisplayProvider(testOutputHelper); var outputProvider = Substitute.For(); var fileOperations = new FileOperations(); - var gitClient = Substitute.For(); gitClient.GetCurrentBranch().Returns(sourceBranch); + var gitClient = Substitute.For(); gitClient.GetCurrentBranch().Returns(sourceBranch); gitClient.GetRootOfRepository().Returns(TemporaryDirectory.CreatePath()); gitClient.CompareBranches(Arg.Any(), Arg.Any()).Returns((0, 0)); gitClient.GetBranchStatuses(Arg.Any()).Returns(new Dictionary diff --git a/src/Stack.Tests/Commands/PullRequests/OpenPullRequestsCommandHandlerTests.cs b/src/Stack.Tests/Commands/PullRequests/OpenPullRequestsCommandHandlerTests.cs index 38e3ae6f..1e6cc2a7 100644 --- a/src/Stack.Tests/Commands/PullRequests/OpenPullRequestsCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/PullRequests/OpenPullRequestsCommandHandlerTests.cs @@ -1,9 +1,8 @@ using FluentAssertions; -using NSubstitute; using Meziantou.Extensions.Logging.Xunit; +using NSubstitute; using Stack.Commands; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; @@ -40,7 +39,7 @@ public async Task WhenThereAreMultiplePullRequestsInAStack_OpensAllPullRequests( var gitClientFactory = Substitute.For(); var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new OpenPullRequestsCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); @@ -88,7 +87,7 @@ public async Task WhenThereAreSomePullRequestsInAStack_OpensAllPullRequests() var gitClientFactory = Substitute.For(); var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new OpenPullRequestsCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); @@ -133,7 +132,7 @@ public async Task WhenStackNameIsProvided_OpensAllPullRequestsForTheStack() var gitClientFactory = Substitute.For(); var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new OpenPullRequestsCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); var prForBranch1 = new GitHubPullRequest(1, "PR Title", string.Empty, GitHubPullRequestStates.Open, Some.HttpsUri(), false, branch1); gitHubClient @@ -176,7 +175,7 @@ public async Task WhenOnlyOneStackExists_DoesNotAskForStackName_OpensAllPullRequ var gitClientFactory = Substitute.For(); var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new OpenPullRequestsCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); var prForBranch1 = new GitHubPullRequest(1, "PR Title", string.Empty, GitHubPullRequestStates.Open, Some.HttpsUri(), false, branch1); gitHubClient @@ -222,7 +221,7 @@ public async Task WhenStackNameIsProvided_ButItStackDoesNotExist_Throws() var gitClientFactory = Substitute.For(); var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new OpenPullRequestsCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); // Act and assert var invalidStackName = Some.Name(); diff --git a/src/Stack.Tests/Commands/Remote/PullStackCommandHandlerTests.cs b/src/Stack.Tests/Commands/Remote/PullStackCommandHandlerTests.cs index f4b15193..75b70988 100644 --- a/src/Stack.Tests/Commands/Remote/PullStackCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/Remote/PullStackCommandHandlerTests.cs @@ -1,13 +1,12 @@ using FluentAssertions; -using NSubstitute; using Meziantou.Extensions.Logging.Xunit; +using NSubstitute; using Stack.Commands; -using Stack.Config; +using Stack.Commands.Helpers; using Stack.Git; -using Stack.Tests.Helpers; using Stack.Infrastructure; using Stack.Infrastructure.Settings; -using Stack.Commands.Helpers; +using Stack.Tests.Helpers; using Xunit.Abstractions; namespace Stack.Tests.Commands.Remote; @@ -40,7 +39,7 @@ public async Task WhenNoStackNameIsProvided_AsksForStack_PullsChangesForTheCorre var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new PullStackCommandHandler(inputProvider, logger, displayProvider, gitClientFactory, executionContext, stackRepository, stackActions); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(branch1); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(branch1); inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); @@ -80,7 +79,7 @@ public async Task WhenNameIsProvided_DoesNotAskForName_PullsChangesForTheCorrect var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new PullStackCommandHandler(inputProvider, logger, displayProvider, gitClientFactory, executionContext, stackRepository, stackActions); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(branch1); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(branch1); // Act await handler.Handle(new PullStackCommandInputs("Stack1"), CancellationToken.None); @@ -119,7 +118,7 @@ public async Task WhenNameIsProvided_ButStackDoesNotExist_Throws() var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new PullStackCommandHandler(inputProvider, logger, displayProvider, gitClientFactory, executionContext, stackRepository, stackActions); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(branch1); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(branch1); // Act and assert var invalidStackName = Some.Name(); diff --git a/src/Stack.Tests/Commands/Remote/PushStackCommandHandlerTests.cs b/src/Stack.Tests/Commands/Remote/PushStackCommandHandlerTests.cs index d284c162..70602844 100644 --- a/src/Stack.Tests/Commands/Remote/PushStackCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/Remote/PushStackCommandHandlerTests.cs @@ -1,13 +1,12 @@ using FluentAssertions; -using NSubstitute; using Meziantou.Extensions.Logging.Xunit; +using NSubstitute; using Stack.Commands; -using Stack.Config; +using Stack.Commands.Helpers; using Stack.Git; -using Stack.Tests.Helpers; using Stack.Infrastructure; using Stack.Infrastructure.Settings; -using Stack.Commands.Helpers; +using Stack.Tests.Helpers; using Xunit.Abstractions; namespace Stack.Tests.Commands.Remote; @@ -54,7 +53,7 @@ public async Task WhenChangesExistLocally_TheyArePushedToTheRemote() await handler.Handle(PushStackCommandInputs.Default, CancellationToken.None); // Assert - stackActions.Received(1).PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); + stackActions.Received(1).PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); } [Fact] @@ -97,7 +96,7 @@ public async Task WhenNameIsProvided_DoesNotAskForName_PushesChangesToRemoteForB await handler.Handle(new PushStackCommandInputs("Stack1", 5, false), CancellationToken.None); // Assert - stackActions.Received(1).PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); + stackActions.Received(1).PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); await inputProvider.DidNotReceive().Select(Questions.SelectStack, Arg.Any(), Arg.Any()); } @@ -184,7 +183,7 @@ public async Task WhenNumberOfBranchesIsGreaterThanMaxBatchSize_ChangesAreSucces await handler.Handle(new PushStackCommandInputs(null, 1, false), CancellationToken.None); // Assert - stackActions.Received(1).PushChanges(Arg.Is(s => s.Name == "Stack1"), 1, false); + stackActions.Received(1).PushChanges(Arg.Is(s => s.Name == "Stack1"), 1, false); } [Fact] @@ -227,6 +226,6 @@ public async Task WhenUsingForceWithLease_ChangesAreForcePushedToTheRemote() await handler.Handle(new PushStackCommandInputs(null, 5, true), CancellationToken.None); // Assert - stackActions.Received(1).PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, true); + stackActions.Received(1).PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, true); } } diff --git a/src/Stack.Tests/Commands/Remote/SyncStackCommandHandlerTests.cs b/src/Stack.Tests/Commands/Remote/SyncStackCommandHandlerTests.cs index b6067798..b6258ee9 100644 --- a/src/Stack.Tests/Commands/Remote/SyncStackCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/Remote/SyncStackCommandHandlerTests.cs @@ -1,13 +1,12 @@ using FluentAssertions; -using NSubstitute; using Meziantou.Extensions.Logging.Xunit; +using NSubstitute; using Stack.Commands; -using Stack.Config; +using Stack.Commands.Helpers; using Stack.Git; -using Stack.Tests.Helpers; using Stack.Infrastructure; using Stack.Infrastructure.Settings; -using Stack.Commands.Helpers; +using Stack.Tests.Helpers; using Xunit.Abstractions; namespace Stack.Tests.Commands.Remote; @@ -59,9 +58,9 @@ public async Task WhenNameIsProvided_DoesNotAskForName_SyncsCorrectStack() await handler.Handle(new SyncStackCommandInputs("Stack1", 5, false, false, false, false, false), CancellationToken.None); // Assert - stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); - stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); + stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); + stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); gitClient.Received().ChangeBranch(branch1); await inputProvider.DidNotReceive().Select(Questions.SelectStack, Arg.Any(), Arg.Any()); } @@ -153,9 +152,9 @@ public async Task WhenOnASpecificBranchInTheStack_TheSameBranchIsSetAsCurrentAft await handler.Handle(new SyncStackCommandInputs(null, 5, false, false, false, false, false), CancellationToken.None); // Assert - stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); - stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); + stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); + stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); gitClient.Received().ChangeBranch(branch1); } @@ -201,9 +200,9 @@ public async Task WhenOnlyASingleStackExists_DoesNotAskForStackName_SyncsStack() await handler.Handle(new SyncStackCommandInputs(null, 5, false, false, false, false, false), CancellationToken.None); // Assert - stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); - stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); + stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); + stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); gitClient.Received().ChangeBranch(branch1); _ = inputProvider.DidNotReceive().Select(Questions.SelectStack, Arg.Any(), Arg.Any()); @@ -252,9 +251,9 @@ public async Task WhenRebaseIsProvided_SyncsStackUsingRebase() await handler.Handle(new SyncStackCommandInputs(null, 5, true, false, false, false, false), CancellationToken.None); // Assert - stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Rebase, Arg.Any()); - stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, true); + stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Rebase, Arg.Any()); + stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, true); await inputProvider.DidNotReceive().Select(Questions.SelectUpdateStrategy, Arg.Any(), Arg.Any()); gitClient.Received().ChangeBranch(branch1); } @@ -302,9 +301,9 @@ public async Task WhenMergeIsProvided_SyncsStackUsingMerge() await handler.Handle(new SyncStackCommandInputs(null, 5, false, true, false, false, false), CancellationToken.None); // Assert - stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); - stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); + stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); + stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); gitClient.Received().ChangeBranch(branch1); } @@ -352,9 +351,9 @@ public async Task WhenNotSpecifyingRebaseOrMerge_AndUpdateSettingIsRebase_SyncsS await handler.Handle(new SyncStackCommandInputs(null, 5, null, null, false, false, false), CancellationToken.None); // Assert - stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Rebase, Arg.Any()); - stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, true); + stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Rebase, Arg.Any()); + stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, true); gitClient.Received().ChangeBranch(branch1); } @@ -402,9 +401,9 @@ public async Task WhenNotSpecifyingRebaseOrMerge_AndUpdateSettingIsMerge_SyncsSt await handler.Handle(new SyncStackCommandInputs(null, 5, null, null, false, false, false), CancellationToken.None); // Assert - stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); - stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); + stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); + stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); gitClient.Received().ChangeBranch(branch1); } @@ -452,9 +451,9 @@ public async Task WhenGitConfigValueIsSetToMerge_ButRebaseIsSpecified_SyncsStack await handler.Handle(new SyncStackCommandInputs(null, 5, true, null, false, false, false), CancellationToken.None); // Assert - stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Rebase, Arg.Any()); - stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, true); + stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Rebase, Arg.Any()); + stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, true); gitClient.Received().ChangeBranch(branch1); } @@ -502,9 +501,9 @@ public async Task WhenGitConfigValueIsSetToRebase_ButMergeIsSpecified_SyncsStack await handler.Handle(new SyncStackCommandInputs(null, 5, null, true, false, false, false), CancellationToken.None); // Assert - stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); - stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); + stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); + stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); gitClient.Received().ChangeBranch(branch1); } @@ -553,9 +552,9 @@ public async Task WhenNotSpecifyingRebaseOrMerge_AndNoUpdateSettingExists_AndMer await handler.Handle(new SyncStackCommandInputs(null, 5, null, null, false, false, false), CancellationToken.None); // Assert - stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); - stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); + stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); + stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); gitClient.Received().ChangeBranch(branch1); } @@ -604,9 +603,9 @@ public async Task WhenNotSpecifyingRebaseOrMerge_AndNoUpdateSettingsExists_AndRe await handler.Handle(new SyncStackCommandInputs(null, 5, null, null, false, false, false), CancellationToken.None); // Assert - stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Rebase, Arg.Any()); - stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, true); + stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Rebase, Arg.Any()); + stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, true); gitClient.Received().ChangeBranch(branch1); } @@ -679,9 +678,9 @@ public async Task WhenConfirmOptionIsProvided_DoesNotAskForConfirmation() await handler.Handle(new SyncStackCommandInputs(null, 5, false, false, true, false, false), CancellationToken.None); // Assert - stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); - stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); + stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); + stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); gitClient.Received().ChangeBranch(branch1); await inputProvider.DidNotReceive().Confirm(Questions.ConfirmSyncStack, Arg.Any()); } @@ -731,9 +730,9 @@ public async Task WhenNoPushOptionIsProvided_DoesNotPushChangesToRemote() await handler.Handle(new SyncStackCommandInputs(null, 5, false, false, false, true, false), CancellationToken.None); // Assert - stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); - stackActions.DidNotReceive().PushChanges(Arg.Any(), Arg.Any(), Arg.Any()); + stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); + stackActions.DidNotReceive().PushChanges(Arg.Any(), Arg.Any(), Arg.Any()); gitClient.Received().ChangeBranch(branch1); } @@ -779,9 +778,9 @@ public async Task WhenCheckPullRequestsIsTrue_UpdatesStackWithCheckPullRequestsE await handler.Handle(new SyncStackCommandInputs("Stack1", 5, false, false, false, false, true), CancellationToken.None); // Assert - stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any(), true); - stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); + stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any(), true); + stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); gitClient.Received().ChangeBranch(branch1); } @@ -827,9 +826,9 @@ public async Task WhenCheckPullRequestsIsFalse_UpdatesStackWithCheckPullRequests await handler.Handle(new SyncStackCommandInputs("Stack1", 5, false, false, false, false, false), CancellationToken.None); // Assert - stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any(), false); - stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); + stackActions.Received().PullChanges(Arg.Is(s => s.Name == "Stack1")); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any(), false); + stackActions.Received().PushChanges(Arg.Is(s => s.Name == "Stack1"), 5, false); gitClient.Received().ChangeBranch(branch1); } } diff --git a/src/Stack.Tests/Commands/Stack/CleanupStackCommandHandlerTests.cs b/src/Stack.Tests/Commands/Stack/CleanupStackCommandHandlerTests.cs index 9af3bd90..bf0bd4fe 100644 --- a/src/Stack.Tests/Commands/Stack/CleanupStackCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/Stack/CleanupStackCommandHandlerTests.cs @@ -1,9 +1,8 @@ using FluentAssertions; -using NSubstitute; using Meziantou.Extensions.Logging.Xunit; +using NSubstitute; using Stack.Commands; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; @@ -40,7 +39,7 @@ public async Task WhenBranchExistsLocally_ButHasNotBeenPushedToTheRemote_BranchI var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new CleanupStackCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); // Setup branch statuses - branch without remote tracking should not be cleaned up var branchStatuses = new Dictionary @@ -87,7 +86,7 @@ public async Task WhenBranchExistsLocally_AndHasBeenDeletedFromTheRemote_BranchI var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new CleanupStackCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); // Setup branch statuses - branchToCleanup has been deleted from remote var branchStatuses = new Dictionary @@ -134,7 +133,7 @@ public async Task WhenBranchExistsLocally_AndInRemote_BranchIsNotDeletedLocally( var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new CleanupStackCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); // Setup branch statuses - all branches exist in remote var branchStatuses = new Dictionary @@ -182,7 +181,7 @@ public async Task WhenConfirmationIsFalse_DoesNotDeleteAnyBranches() var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new CleanupStackCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); // Setup branch statuses - branchToCleanup has remote tracking but remote branch was deleted var branchStatuses = new Dictionary @@ -229,7 +228,7 @@ public async Task WhenStackNameIsProvided_ItIsNotAskedFor() var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new CleanupStackCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); // Setup branch statuses - branchToCleanup has remote tracking but remote branch was deleted var branchStatuses = new Dictionary @@ -275,7 +274,7 @@ public async Task WhenStackNameIsProvided_ButStackDoesNotExist_Throws() var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new CleanupStackCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); inputProvider.Confirm(Questions.ConfirmDeleteBranches, Arg.Any()).Returns(true); @@ -310,7 +309,7 @@ public async Task WhenOnlyASingleStackExists_StackIsSelectedAutomatically() var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new CleanupStackCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); // Setup branch statuses - branchToCleanup has remote tracking but remote branch was deleted var branchStatuses = new Dictionary @@ -356,7 +355,7 @@ public async Task WhenConfirmIsProvided_DoesNotAskForConfirmation_DeletesBranche var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new CleanupStackCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); // Setup branch statuses - branchToCleanup has been deleted from remote var branchStatuses = new Dictionary @@ -404,7 +403,7 @@ public async Task WhenChildBranchExistsLocally_AndHasBeenDeletedFromTheRemote_Br var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new CleanupStackCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); // Setup branch statuses - branchToCleanup has been deleted from remote var branchStatuses = new Dictionary diff --git a/src/Stack.Tests/Commands/Stack/DeleteStackCommandHandlerTests.cs b/src/Stack.Tests/Commands/Stack/DeleteStackCommandHandlerTests.cs index 2e356b5b..882a3ffb 100644 --- a/src/Stack.Tests/Commands/Stack/DeleteStackCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/Stack/DeleteStackCommandHandlerTests.cs @@ -1,9 +1,8 @@ using FluentAssertions; -using NSubstitute; using Meziantou.Extensions.Logging.Xunit; +using NSubstitute; using Stack.Commands; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; @@ -49,7 +48,7 @@ public async Task WhenNoInputsAreProvided_AsksForName_AndConfirmation_AndDeletes await handler.Handle(DeleteStackCommandInputs.Empty, CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new("Stack2", stackRepository.RemoteUri, sourceBranch, []) }); @@ -89,7 +88,7 @@ public async Task WhenConfirmationIsFalse_DoesNotDeleteStack() await handler.Handle(DeleteStackCommandInputs.Empty, CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new("Stack1", stackRepository.RemoteUri, sourceBranch, []), new("Stack2", stackRepository.RemoteUri, sourceBranch, []) @@ -129,7 +128,7 @@ public async Task WhenNameIsProvided_AsksForConfirmation_AndDeletesStack() await handler.Handle(new DeleteStackCommandInputs("Stack1", false), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new("Stack2", stackRepository.RemoteUri, sourceBranch, []) }); @@ -229,7 +228,7 @@ public async Task WhenThereAreLocalBranchesThatAreDeletedInTheRemote_AsksToClean await handler.Handle(DeleteStackCommandInputs.Empty, CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new("Stack2", stackRepository.RemoteUri, sourceBranch, []) }); @@ -305,7 +304,7 @@ public async Task WhenConfirmIsProvided_DoesNotAskForConfirmation_DeletesStack() await handler.Handle(new DeleteStackCommandInputs(null, true), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new("Stack2", stackRepository.RemoteUri, sourceBranch, []) }); diff --git a/src/Stack.Tests/Commands/Stack/NewStackCommandHandlerTests.cs b/src/Stack.Tests/Commands/Stack/NewStackCommandHandlerTests.cs index ed0e79c6..881044cf 100644 --- a/src/Stack.Tests/Commands/Stack/NewStackCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/Stack/NewStackCommandHandlerTests.cs @@ -1,9 +1,8 @@ using FluentAssertions; -using NSubstitute; using Meziantou.Extensions.Logging.Xunit; +using NSubstitute; using Stack.Commands; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; @@ -44,9 +43,9 @@ public async Task WithAnExistingBranch_TheStackIsCreatedAndTheCurrentBranchIsCha await handler.Handle(NewStackCommandInputs.Empty, CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { - new(stackName, stackRepository.RemoteUri, sourceBranch, [new Config.Branch(existingBranch, [])]) + new(stackName, stackRepository.RemoteUri, sourceBranch, [new Model.Branch(existingBranch, [])]) }); gitClient.Received().ChangeBranch(existingBranch); } @@ -80,7 +79,7 @@ public async Task WithNoBranch_TheStackIsCreatedAndTheCurrentBranchIsNotChanged( await handler.Handle(NewStackCommandInputs.Empty, CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new(stackName, stackRepository.RemoteUri, sourceBranch, []) }); @@ -116,7 +115,7 @@ public async Task WhenStackNameIsProvidedInInputs_TheProviderIsNotAskedForAName_ await handler.Handle(inputs, CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new(stackName, stackRepository.RemoteUri, sourceBranch, []) }); @@ -151,7 +150,7 @@ public async Task WhenSourceBranchIsProvidedInInputs_TheProviderIsNotAskedForThe await handler.Handle(inputs, CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { new("Stack1", stackRepository.RemoteUri, sourceBranch, []) }); @@ -187,9 +186,9 @@ public async Task WhenBranchNameIsProvidedInInputs_TheProviderIsNotAskedForTheBr await handler.Handle(inputs, CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { - new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Config.Branch(newBranch, [])]) + new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Model.Branch(newBranch, [])]) }); gitClient.Received().CreateNewBranch(newBranch, sourceBranch); gitClient.Received().PushNewBranch(newBranch); @@ -225,9 +224,9 @@ public async Task WithANewBranch_TheStackIsCreatedAndTheBranchExistsOnTheRemote( await handler.Handle(new NewStackCommandInputs(null, null, null), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { - new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Config.Branch(newBranch, [])]) + new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Model.Branch(newBranch, [])]) }); gitClient.Received().CreateNewBranch(newBranch, sourceBranch); gitClient.Received().PushNewBranch(newBranch); @@ -265,9 +264,9 @@ public async Task WithANewBranch_AndThePushFails_TheStackIsStillCreatedSuccessfu await handler.Handle(new NewStackCommandInputs(null, null, null), CancellationToken.None); // Assert - stackRepository.Stacks.Should().BeEquivalentTo(new List + stackRepository.Stacks.Should().BeEquivalentTo(new List { - new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Config.Branch(newBranch, [])]) + new("Stack1", stackRepository.RemoteUri, sourceBranch, [new Model.Branch(newBranch, [])]) }); gitClient.Received().CreateNewBranch(newBranch, sourceBranch); gitClient.Received().PushNewBranch(newBranch); diff --git a/src/Stack.Tests/Commands/Stack/RenameStackCommandHandlerTests.cs b/src/Stack.Tests/Commands/Stack/RenameStackCommandHandlerTests.cs index c9e54377..5aa1d415 100644 --- a/src/Stack.Tests/Commands/Stack/RenameStackCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/Stack/RenameStackCommandHandlerTests.cs @@ -1,15 +1,13 @@ using FluentAssertions; -using NSubstitute; using Meziantou.Extensions.Logging.Xunit; -using Microsoft.Extensions.Logging; +using NSubstitute; using Stack.Commands; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; +using Stack.Infrastructure.Settings; using Stack.Tests.Helpers; using Xunit.Abstractions; -using Stack.Infrastructure.Settings; namespace Stack.Tests.Commands.Stack; diff --git a/src/Stack.Tests/Commands/Stack/StackStatusCommandHandlerTests.cs b/src/Stack.Tests/Commands/Stack/StackStatusCommandHandlerTests.cs index c8c68abc..3b6f7dce 100644 --- a/src/Stack.Tests/Commands/Stack/StackStatusCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/Stack/StackStatusCommandHandlerTests.cs @@ -2,12 +2,11 @@ using Meziantou.Extensions.Logging.Xunit; using NSubstitute; using Stack.Commands; -using Stack.Config; +using Stack.Commands.Helpers; using Stack.Git; -using Stack.Tests.Helpers; using Stack.Infrastructure; using Stack.Infrastructure.Settings; -using Stack.Commands.Helpers; +using Stack.Tests.Helpers; using Xunit.Abstractions; namespace Stack.Tests.Commands.Stack; diff --git a/src/Stack.Tests/Commands/Stack/StackSwitchCommandHandlerTests.cs b/src/Stack.Tests/Commands/Stack/StackSwitchCommandHandlerTests.cs index 91b36dbc..16e824cc 100644 --- a/src/Stack.Tests/Commands/Stack/StackSwitchCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/Stack/StackSwitchCommandHandlerTests.cs @@ -1,9 +1,8 @@ using FluentAssertions; -using NSubstitute; using Meziantou.Extensions.Logging.Xunit; +using NSubstitute; using Stack.Commands; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; diff --git a/src/Stack.Tests/Commands/Stack/UpdateStackCommandHandlerTests.cs b/src/Stack.Tests/Commands/Stack/UpdateStackCommandHandlerTests.cs index beef8b47..1affd49f 100644 --- a/src/Stack.Tests/Commands/Stack/UpdateStackCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/Stack/UpdateStackCommandHandlerTests.cs @@ -1,13 +1,12 @@ using FluentAssertions; -using NSubstitute; using Meziantou.Extensions.Logging.Xunit; +using NSubstitute; using Stack.Commands; -using Stack.Config; +using Stack.Commands.Helpers; using Stack.Git; -using Stack.Tests.Helpers; using Stack.Infrastructure; using Stack.Infrastructure.Settings; -using Stack.Commands.Helpers; +using Stack.Tests.Helpers; using Xunit.Abstractions; namespace Stack.Tests.Commands.Stack; @@ -48,7 +47,7 @@ public async Task WhenNameIsProvided_DoesNotAskForName_UpdatesCorrectStack() // Assert await inputProvider.DidNotReceive().Select(Questions.SelectStack, Arg.Any(), Arg.Any()); - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); } [Fact] @@ -157,7 +156,7 @@ public async Task WhenOnlyASingleStackExists_DoesNotAskForStackName_UpdatesStack // Assert await inputProvider.DidNotReceive().Select(Questions.SelectStack, Arg.Any(), Arg.Any()); - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); } [Fact] @@ -195,7 +194,7 @@ public async Task WhenRebaseIsSpecified_StackIsUpdatedUsingRebase() await handler.Handle(new UpdateStackCommandInputs(null, true, false, false), CancellationToken.None); // Assert - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Rebase, Arg.Any()); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Rebase, Arg.Any()); } [Fact] @@ -234,7 +233,7 @@ public async Task WhenGitConfigValueIsSetToRebase_StackIsUpdatedUsingRebase() await handler.Handle(new UpdateStackCommandInputs(null, null, null, false), CancellationToken.None); // Assert - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Rebase, Arg.Any()); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Rebase, Arg.Any()); } [Fact] @@ -272,7 +271,7 @@ public async Task WhenGitConfigValueIsSetToRebase_ButMergeIsSpecified_StackIsUpd await handler.Handle(new UpdateStackCommandInputs(null, null, true, false), CancellationToken.None); // Assert - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); } [Fact] @@ -311,7 +310,7 @@ public async Task WhenGitConfigValueIsSetToMerge_StackIsUpdatedUsingMerge() await handler.Handle(new UpdateStackCommandInputs(null, null, null, false), CancellationToken.None); // Assert - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); } [Fact] @@ -350,7 +349,7 @@ public async Task WhenGitConfigValueIsSetToMerge_ButRebaseIsSpecified_StackIsUpd await handler.Handle(new UpdateStackCommandInputs(null, true, null, false), CancellationToken.None); // Assert - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Rebase, Arg.Any()); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Rebase, Arg.Any()); } [Fact] @@ -390,7 +389,7 @@ public async Task WhenGitConfigValueDoesNotExist_AndRebaseIsSelected_StackIsUpda await handler.Handle(new UpdateStackCommandInputs(null, null, null, false), CancellationToken.None); // Assert - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Rebase, Arg.Any()); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Rebase, Arg.Any()); } [Fact] @@ -430,7 +429,7 @@ public async Task WhenGitConfigValueDoesNotExist_AndMergeIsSelected_StackIsUpdat await handler.Handle(new UpdateStackCommandInputs(null, null, null, false), CancellationToken.None); // Assert - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any()); } [Fact] @@ -466,7 +465,7 @@ public async Task WhenCheckPullRequestsIsTrue_StackIsUpdatedWithCheckPullRequest await handler.Handle(new UpdateStackCommandInputs(null, null, null, true), CancellationToken.None); // Assert - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any(), true); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any(), true); } [Fact] @@ -502,7 +501,7 @@ public async Task WhenCheckPullRequestsIsFalse_StackIsUpdatedWithCheckPullReques await handler.Handle(new UpdateStackCommandInputs(null, null, null, false), CancellationToken.None); // Assert - await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any(), false); + await stackActions.Received().UpdateStack(Arg.Is(s => s.Name == "Stack1"), UpdateStrategy.Merge, Arg.Any(), false); } [Fact] diff --git a/src/Stack.Tests/Git/CachingGitHubClientTests.cs b/src/Stack.Tests/Git/CachingGitHubClientTests.cs index 86e4db99..6c892bb9 100644 --- a/src/Stack.Tests/Git/CachingGitHubClientTests.cs +++ b/src/Stack.Tests/Git/CachingGitHubClientTests.cs @@ -1,4 +1,3 @@ -using System; using FluentAssertions; using Microsoft.Extensions.Caching.Memory; using NSubstitute; diff --git a/src/Stack.Tests/Git/ConflictResolutionDetectorTests.cs b/src/Stack.Tests/Git/ConflictResolutionDetectorTests.cs index 4bfaa843..f6ba105c 100644 --- a/src/Stack.Tests/Git/ConflictResolutionDetectorTests.cs +++ b/src/Stack.Tests/Git/ConflictResolutionDetectorTests.cs @@ -1,14 +1,10 @@ -using System.Threading; -using System.Threading.Tasks; +using System.Diagnostics; using FluentAssertions; -using Microsoft.Extensions.Logging; using Meziantou.Extensions.Logging.Xunit; +using Microsoft.Extensions.Logging; using Stack.Git; using Stack.Tests.Helpers; -using Xunit; using Xunit.Abstractions; -using System.IO; -using System.Diagnostics; namespace Stack.Tests.Git; diff --git a/src/Stack.Tests/Git/GitClientTests.cs b/src/Stack.Tests/Git/GitClientTests.cs index df9a3d4d..6d483fdb 100644 --- a/src/Stack.Tests/Git/GitClientTests.cs +++ b/src/Stack.Tests/Git/GitClientTests.cs @@ -1,10 +1,8 @@ using FluentAssertions; using FluentAssertions.Execution; -using LibGit2Sharp; -using Stack.Git; using Meziantou.Extensions.Logging.Xunit; +using Stack.Git; using Stack.Tests.Helpers; -using System.IO; using Xunit.Abstractions; namespace Stack.Tests.Git; diff --git a/src/Stack.Tests/Helpers/Some.cs b/src/Stack.Tests/Helpers/Some.cs index e3dc5e17..eb403dba 100644 --- a/src/Stack.Tests/Helpers/Some.cs +++ b/src/Stack.Tests/Helpers/Some.cs @@ -1,5 +1,3 @@ -using System; - namespace Stack.Tests.Helpers; public static class Some diff --git a/src/Stack.Tests/Helpers/TestDisplayProvider.cs b/src/Stack.Tests/Helpers/TestDisplayProvider.cs index 661a0f22..dff957bb 100644 --- a/src/Stack.Tests/Helpers/TestDisplayProvider.cs +++ b/src/Stack.Tests/Helpers/TestDisplayProvider.cs @@ -1,4 +1,3 @@ -using MoreLinq.Experimental; using Stack.Infrastructure; using Xunit.Abstractions; diff --git a/src/Stack.Tests/Helpers/TestGitRepositoryBuilder.cs b/src/Stack.Tests/Helpers/TestGitRepositoryBuilder.cs index 025a399f..fa301026 100644 --- a/src/Stack.Tests/Helpers/TestGitRepositoryBuilder.cs +++ b/src/Stack.Tests/Helpers/TestGitRepositoryBuilder.cs @@ -1,7 +1,5 @@ using System.Text; using LibGit2Sharp; -using Stack.Git; -using Stack.Infrastructure.Settings; namespace Stack.Tests.Helpers; diff --git a/src/Stack.Tests/Helpers/TestStackRepositoryBuilder.cs b/src/Stack.Tests/Helpers/TestStackRepositoryBuilder.cs index ccc3c332..ad6b78fc 100644 --- a/src/Stack.Tests/Helpers/TestStackRepositoryBuilder.cs +++ b/src/Stack.Tests/Helpers/TestStackRepositoryBuilder.cs @@ -1,6 +1,5 @@ -using System; -using NSubstitute; -using Stack.Config; +using Stack.Model; +using Stack.Persistence; namespace Stack.Tests.Helpers; @@ -66,7 +65,7 @@ public TestStackBuilder WithBranch(Action branchBuilder) return this; } - public Config.Stack Build() + public Model.Stack Build() { var branches = branchBuilders .Select(builder => @@ -77,7 +76,7 @@ public Config.Stack Build() }) .ToList(); - var stack = new Config.Stack(name ?? Some.Name(), remoteUri ?? Some.HttpsUri().ToString(), sourceBranch ?? Some.BranchName(), branches); + var stack = new Model.Stack(name ?? Some.Name(), remoteUri ?? Some.HttpsUri().ToString(), sourceBranch ?? Some.BranchName(), branches); return stack; } @@ -118,7 +117,7 @@ public class TestStackConfig(StackData initialData) : IStackConfig { StackData stackData = initialData; - public List Stacks => stackData.Stacks; + public List Stacks => stackData.Stacks; public string GetConfigPath() => throw new NotImplementedException("TestStackConfig does not support GetConfigPath."); @@ -143,7 +142,7 @@ public TestStackRepository(StackData initialData, string remoteUri) public string RemoteUri => remoteUri; - public List GetStacks() + public List GetStacks() { if (string.IsNullOrEmpty(remoteUri)) { @@ -155,12 +154,12 @@ public TestStackRepository(StackData initialData, string remoteUri) .ToList(); } - public void AddStack(Config.Stack stack) + public void AddStack(Model.Stack stack) { stackData.Stacks.Add(stack); } - public void RemoveStack(Config.Stack stack) + public void RemoveStack(Model.Stack stack) { stackData.Stacks.Remove(stack); } @@ -170,5 +169,5 @@ public void SaveChanges() // No-op for testing - changes are already in memory } - public List Stacks => stackData.Stacks; + public List Stacks => stackData.Stacks; } diff --git a/src/Stack.Tests/Integration/StackActionsTests.cs b/src/Stack.Tests/Integration/StackActionsTests.cs index 735802df..676f77c2 100644 --- a/src/Stack.Tests/Integration/StackActionsTests.cs +++ b/src/Stack.Tests/Integration/StackActionsTests.cs @@ -1,11 +1,11 @@ using FluentAssertions; -using NSubstitute; using Meziantou.Extensions.Logging.Xunit; +using NSubstitute; using Stack.Commands.Helpers; using Stack.Git; -using Xunit.Abstractions; -using Stack.Tests.Helpers; using Stack.Infrastructure.Settings; +using Stack.Tests.Helpers; +using Xunit.Abstractions; namespace Stack.Tests.Integration; diff --git a/src/Stack.Tests/Config/FileStackConfigTests.cs b/src/Stack.Tests/Persistence/FileStackConfigTests.cs similarity index 97% rename from src/Stack.Tests/Config/FileStackConfigTests.cs rename to src/Stack.Tests/Persistence/FileStackConfigTests.cs index 9ba05b34..c9dbee5a 100644 --- a/src/Stack.Tests/Config/FileStackConfigTests.cs +++ b/src/Stack.Tests/Persistence/FileStackConfigTests.cs @@ -1,8 +1,6 @@ -using System; -using System.IO; using System.Text.Json; using FluentAssertions; -using Stack.Config; +using Stack.Persistence; using Stack.Tests.Helpers; // Deliberately using a different namespace here to avoid needing to @@ -52,7 +50,7 @@ public void Load_WhenConfigFileIsInV1Format_LoadsCorrectly_MigratesAndSavesFileI File.WriteAllText(configPath, v1Json); var fileStackConfig = new FileStackConfig(tempDirectory.DirectoryPath); - var expectedStack = new Config.Stack( + var expectedStack = new Model.Stack( stackName, remoteUri, sourceBranch, @@ -149,7 +147,7 @@ public void Load_WhenConfigFileIsInV2Format_LoadsCorrectly() var fileStackConfig = new FileStackConfig(tempDirectory.DirectoryPath); - var expectedStack = new Config.Stack( + var expectedStack = new Model.Stack( stackName, remoteUri, sourceBranch, @@ -191,7 +189,7 @@ public void Save_WhenConfigFileIsInV1Format_AndStackIsChangedToHaveTreeStructure ]"; File.WriteAllText(configPath, v1Json); - var stack = new Config.Stack( + var stack = new Model.Stack( stackName, remoteUri, sourceBranch, diff --git a/src/Stack.Tests/Config/StackRepositoryTests.cs b/src/Stack.Tests/Persistence/StackRepositoryTests.cs similarity index 99% rename from src/Stack.Tests/Config/StackRepositoryTests.cs rename to src/Stack.Tests/Persistence/StackRepositoryTests.cs index 417798f9..5244b146 100644 --- a/src/Stack.Tests/Config/StackRepositoryTests.cs +++ b/src/Stack.Tests/Persistence/StackRepositoryTests.cs @@ -1,11 +1,10 @@ using FluentAssertions; -using FluentAssertions.Execution; using NSubstitute; -using Stack.Config; using Stack.Git; using Stack.Infrastructure.Settings; +using Stack.Persistence; using Stack.Tests.Helpers; -using StackModel = Stack.Config.Stack; +using StackModel = Stack.Model.Stack; namespace Stack.Tests; diff --git a/src/Stack.Tests/Config/StackTests.cs b/src/Stack.Tests/Persistence/StackTests.cs similarity index 70% rename from src/Stack.Tests/Config/StackTests.cs rename to src/Stack.Tests/Persistence/StackTests.cs index f42bf85f..17a7b9c0 100644 --- a/src/Stack.Tests/Config/StackTests.cs +++ b/src/Stack.Tests/Persistence/StackTests.cs @@ -19,19 +19,19 @@ public void GetAllBranchLines_ReturnsAllRootToLeafPaths() // - E // - F // - G - var stack = new Config.Stack( + var stack = new Model.Stack( "TestStack", Some.HttpsUri().ToString(), "main", [ - new Config.Branch("A", [ - new Config.Branch("B", [ - new Config.Branch("C", []), - new Config.Branch("D", []) + new Model.Branch("A", [ + new Model.Branch("B", [ + new Model.Branch("C", []), + new Model.Branch("D", []) ]), - new Config.Branch("E", []), - new Config.Branch("F", [ - new Config.Branch("G", []) + new Model.Branch("E", []), + new Model.Branch("F", [ + new Model.Branch("G", []) ]) ]) ] @@ -58,14 +58,14 @@ public void MoveBranch_WhenMovingBranchWithoutChildren_MovesBranchToNewLocation( // - A // - B // - C - var stack = new Config.Stack( + var stack = new Model.Stack( "TestStack", Some.HttpsUri().ToString(), "main", [ - new Config.Branch("A", []), - new Config.Branch("B", [ - new Config.Branch("C", []) + new Model.Branch("A", []), + new Model.Branch("B", [ + new Model.Branch("C", []) ]) ] ); @@ -78,8 +78,8 @@ public void MoveBranch_WhenMovingBranchWithoutChildren_MovesBranchToNewLocation( // - C // - B stack.Branches.Should().BeEquivalentTo([ - new Config.Branch("A", [new Config.Branch("C", [])]), - new Config.Branch("B", []) + new Model.Branch("A", [new Model.Branch("C", [])]), + new Model.Branch("B", []) ]); } @@ -89,13 +89,13 @@ public void MoveBranch_WhenMovingBranchToSourceBranch_MovesBranchToRootLevel() // Arrange: Structure: // - A // - B - var stack = new Config.Stack( + var stack = new Model.Stack( "TestStack", Some.HttpsUri().ToString(), "main", [ - new Config.Branch("A", [ - new Config.Branch("B", []) + new Model.Branch("A", [ + new Model.Branch("B", []) ]) ] ); @@ -107,8 +107,8 @@ public void MoveBranch_WhenMovingBranchToSourceBranch_MovesBranchToRootLevel() // - A // - B stack.Branches.Should().BeEquivalentTo([ - new Config.Branch("A", []), - new Config.Branch("B", []) + new Model.Branch("A", []), + new Model.Branch("B", []) ]); } @@ -120,15 +120,15 @@ public void MoveBranch_WhenMovingBranchWithChildren_AndMoveChildrenAction_MovesB // - B // - C // - D - var stack = new Config.Stack( + var stack = new Model.Stack( "TestStack", Some.HttpsUri().ToString(), "main", [ - new Config.Branch("A", []), - new Config.Branch("B", [ - new Config.Branch("C", [ - new Config.Branch("D", []) + new Model.Branch("A", []), + new Model.Branch("B", [ + new Model.Branch("C", [ + new Model.Branch("D", []) ]) ]) ] @@ -143,12 +143,12 @@ public void MoveBranch_WhenMovingBranchWithChildren_AndMoveChildrenAction_MovesB // - D // - B stack.Branches.Should().BeEquivalentTo([ - new Config.Branch("A", [ - new Config.Branch("C", [ - new Config.Branch("D", []) + new Model.Branch("A", [ + new Model.Branch("C", [ + new Model.Branch("D", []) ]) ]), - new Config.Branch("B", []) + new Model.Branch("B", []) ]); } @@ -161,16 +161,16 @@ public void MoveBranch_WhenMovingBranchWithChildren_AndReParentChildrenAction_Mo // - C // - D // - E - var stack = new Config.Stack( + var stack = new Model.Stack( "TestStack", Some.HttpsUri().ToString(), "main", [ - new Config.Branch("A", []), - new Config.Branch("B", [ - new Config.Branch("C", [ - new Config.Branch("D", []), - new Config.Branch("E", []) + new Model.Branch("A", []), + new Model.Branch("B", [ + new Model.Branch("C", [ + new Model.Branch("D", []), + new Model.Branch("E", []) ]) ]) ] @@ -186,12 +186,12 @@ public void MoveBranch_WhenMovingBranchWithChildren_AndReParentChildrenAction_Mo // - D // - E stack.Branches.Should().BeEquivalentTo([ - new Config.Branch("A", [ - new Config.Branch("C", []) + new Model.Branch("A", [ + new Model.Branch("C", []) ]), - new Config.Branch("B", [ - new Config.Branch("D", []), - new Config.Branch("E", []) + new Model.Branch("B", [ + new Model.Branch("D", []), + new Model.Branch("E", []) ]) ]); } @@ -205,19 +205,19 @@ public void MoveBranch_WhenMovingDeepNestedBranch_CorrectlyMovesFromAnyDepth() // - C // - D // - E - var stack = new Config.Stack( + var stack = new Model.Stack( "TestStack", Some.HttpsUri().ToString(), "main", [ - new Config.Branch("A", [ - new Config.Branch("B", [ - new Config.Branch("C", [ - new Config.Branch("D", []) + new Model.Branch("A", [ + new Model.Branch("B", [ + new Model.Branch("C", [ + new Model.Branch("D", []) ]) ]) ]), - new Config.Branch("E", []) + new Model.Branch("E", []) ] ); @@ -231,13 +231,13 @@ public void MoveBranch_WhenMovingDeepNestedBranch_CorrectlyMovesFromAnyDepth() // - E // - D stack.Branches.Should().BeEquivalentTo([ - new Config.Branch("A", [ - new Config.Branch("B", [ - new Config.Branch("C", []) + new Model.Branch("A", [ + new Model.Branch("B", [ + new Model.Branch("C", []) ]) ]), - new Config.Branch("E", [ - new Config.Branch("D", []) + new Model.Branch("E", [ + new Model.Branch("D", []) ]) ]); } @@ -246,12 +246,12 @@ public void MoveBranch_WhenMovingDeepNestedBranch_CorrectlyMovesFromAnyDepth() public void MoveBranch_WhenBranchNotFound_ThrowsException() { // Arrange - var stack = new Config.Stack( + var stack = new Model.Stack( "TestStack", Some.HttpsUri().ToString(), "main", [ - new Config.Branch("A", []) + new Model.Branch("A", []) ] ); @@ -266,13 +266,13 @@ public void MoveBranch_WhenBranchNotFound_ThrowsException() public void MoveBranch_WhenNewParentNotFound_ThrowsException() { // Arrange - var stack = new Config.Stack( + var stack = new Model.Stack( "TestStack", Some.HttpsUri().ToString(), "main", [ - new Config.Branch("A", [ - new Config.Branch("B", []) + new Model.Branch("A", [ + new Model.Branch("B", []) ]) ] ); @@ -291,15 +291,15 @@ public void MoveBranch_WhenMovingRootLevelBranchWithChildrenToAnotherRootLevelBr // - A // - B // - C - var stack = new Config.Stack( + var stack = new Model.Stack( "TestStack", Some.HttpsUri().ToString(), "main", [ - new Config.Branch("A", [ - new Config.Branch("B", []) + new Model.Branch("A", [ + new Model.Branch("B", []) ]), - new Config.Branch("C", []) + new Model.Branch("C", []) ] ); @@ -311,9 +311,9 @@ public void MoveBranch_WhenMovingRootLevelBranchWithChildrenToAnotherRootLevelBr // - A // - B stack.Branches.Should().BeEquivalentTo([ - new Config.Branch("C", [ - new Config.Branch("A", [ - new Config.Branch("B", []) + new Model.Branch("C", [ + new Model.Branch("A", [ + new Model.Branch("B", []) ]) ]) ]); diff --git a/src/Stack/Commands/Branch/AddBranchCommand.cs b/src/Stack/Commands/Branch/AddBranchCommand.cs index e3d9bb70..4452f53b 100644 --- a/src/Stack/Commands/Branch/AddBranchCommand.cs +++ b/src/Stack/Commands/Branch/AddBranchCommand.cs @@ -1,10 +1,11 @@ using System.CommandLine; using Microsoft.Extensions.Logging; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; +using Stack.Model; +using Stack.Persistence; namespace Stack.Commands; diff --git a/src/Stack/Commands/Branch/MoveBranchCommand.cs b/src/Stack/Commands/Branch/MoveBranchCommand.cs index 31140260..385db098 100644 --- a/src/Stack/Commands/Branch/MoveBranchCommand.cs +++ b/src/Stack/Commands/Branch/MoveBranchCommand.cs @@ -2,10 +2,10 @@ using System.ComponentModel; using Microsoft.Extensions.Logging; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; +using Stack.Persistence; namespace Stack.Commands; diff --git a/src/Stack/Commands/Branch/NewBranchCommand.cs b/src/Stack/Commands/Branch/NewBranchCommand.cs index 69cb622a..e2f02373 100644 --- a/src/Stack/Commands/Branch/NewBranchCommand.cs +++ b/src/Stack/Commands/Branch/NewBranchCommand.cs @@ -3,10 +3,11 @@ using MoreLinq; using MoreLinq.Extensions; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; +using Stack.Model; +using Stack.Persistence; namespace Stack.Commands; diff --git a/src/Stack/Commands/Branch/RemoveBranchCommand.cs b/src/Stack/Commands/Branch/RemoveBranchCommand.cs index 1c8fecc9..2261d18b 100644 --- a/src/Stack/Commands/Branch/RemoveBranchCommand.cs +++ b/src/Stack/Commands/Branch/RemoveBranchCommand.cs @@ -1,12 +1,11 @@ using System.CommandLine; - -using System.ComponentModel; using Microsoft.Extensions.Logging; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; +using Stack.Model; +using Stack.Persistence; namespace Stack.Commands; @@ -130,15 +129,6 @@ public override async Task Handle(RemoveBranchCommandInputs inputs, Cancellation } } -public enum RemoveBranchChildAction -{ - [Description("Move children branches to parent branch")] - MoveChildrenToParent, - - [Description("Remove children branches")] - RemoveChildren -} - internal static partial class LoggerExtensionMethods { [LoggerMessage(Level = LogLevel.Information, Message = "Branch {Branch} removed from stack \"{Stack}\"")] diff --git a/src/Stack/Commands/Config/OpenConfigCommand.cs b/src/Stack/Commands/Config/OpenConfigCommand.cs index fe39fb9f..e6bd3fae 100644 --- a/src/Stack/Commands/Config/OpenConfigCommand.cs +++ b/src/Stack/Commands/Config/OpenConfigCommand.cs @@ -1,9 +1,9 @@ using System.CommandLine; using System.Diagnostics; using Microsoft.Extensions.Logging; -using Stack.Config; using Stack.Infrastructure; using Stack.Infrastructure.Settings; +using Stack.Persistence; namespace Stack.Commands; diff --git a/src/Stack/Commands/Helpers/HumanizeEnumExtensionMethods.cs b/src/Stack/Commands/Helpers/HumanizeEnumExtensionMethods.cs index 58b2be93..9d79e013 100644 --- a/src/Stack/Commands/Helpers/HumanizeEnumExtensionMethods.cs +++ b/src/Stack/Commands/Helpers/HumanizeEnumExtensionMethods.cs @@ -1,3 +1,5 @@ +using Stack.Model; + namespace Stack.Commands; public static class HumanizeEnumExtensionMethods diff --git a/src/Stack/Commands/Helpers/InputProviderExtensionMethods.cs b/src/Stack/Commands/Helpers/InputProviderExtensionMethods.cs index 6833951b..571d259e 100644 --- a/src/Stack/Commands/Helpers/InputProviderExtensionMethods.cs +++ b/src/Stack/Commands/Helpers/InputProviderExtensionMethods.cs @@ -1,8 +1,8 @@ using Microsoft.Extensions.Logging; using Spectre.Console; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Infrastructure; +using Stack.Model; namespace Stack.Commands.Helpers; @@ -56,11 +56,11 @@ public static async Task MultiSelect( return [.. selection]; } - public static async Task SelectStack( + public static async Task SelectStack( this IInputProvider inputProvider, ILogger logger, string? name, - List stacks, + List stacks, string currentBranch, CancellationToken cancellationToken) { @@ -112,7 +112,7 @@ public static async Task SelectBranch( this IInputProvider inputProvider, ILogger logger, string? name, - Config.Stack stack, + Model.Stack stack, CancellationToken cancellationToken) { void GetBranchNamesWithIndentation(Branch branch, List names, int level = 0) @@ -146,7 +146,7 @@ public static async Task SelectParentBranch( this IInputProvider inputProvider, ILogger logger, string? name, - Config.Stack stack, + Model.Stack stack, CancellationToken cancellationToken) { void GetBranchNamesWithIndentation(Branch branch, List names, int level = 0) diff --git a/src/Stack/Commands/Helpers/StackActions.cs b/src/Stack/Commands/Helpers/StackActions.cs index 1f32939d..b70478c6 100644 --- a/src/Stack/Commands/Helpers/StackActions.cs +++ b/src/Stack/Commands/Helpers/StackActions.cs @@ -1,17 +1,17 @@ -using Stack.Config; -using Stack.Infrastructure; -using Stack.Infrastructure.Settings; -using Stack.Git; using Microsoft.Extensions.Logging; using Spectre.Console; +using Stack.Git; +using Stack.Infrastructure; +using Stack.Infrastructure.Settings; +using Stack.Model; namespace Stack.Commands.Helpers { public interface IStackActions { - void PullChanges(Config.Stack stack); - void PushChanges(Config.Stack stack, int maxBatchSize, bool forceWithLease); - Task UpdateStack(Config.Stack stack, UpdateStrategy strategy, CancellationToken cancellationToken, bool checkPullRequests = false); + void PullChanges(Model.Stack stack); + void PushChanges(Model.Stack stack, int maxBatchSize, bool forceWithLease); + Task UpdateStack(Model.Stack stack, UpdateStrategy strategy, CancellationToken cancellationToken, bool checkPullRequests = false); } @@ -47,7 +47,7 @@ private IGitClient GetGitClientForBranch(string branchName, Dictionary allBranchesInStacks = [stack.SourceBranch, .. stack.AllBranchNames]; @@ -104,7 +104,7 @@ public void PullChanges(Config.Stack stack) } public void PushChanges( - Config.Stack stack, + Model.Stack stack, int maxBatchSize, bool forceWithLease) { @@ -140,7 +140,7 @@ public void PushChanges( } } - public async Task UpdateStack(Config.Stack stack, UpdateStrategy strategy, CancellationToken cancellationToken, bool checkPullRequests = false) + public async Task UpdateStack(Model.Stack stack, UpdateStrategy strategy, CancellationToken cancellationToken, bool checkPullRequests = false) { var gitClient = GetDefaultGitClient(); @@ -181,7 +181,7 @@ await displayProvider.DisplayStatus("Checking status of pull requests...", async } private async Task UpdateStackUsingMerge( - Config.Stack stack, + Model.Stack stack, Dictionary branchStatuses, Dictionary pullRequests, CancellationToken cancellationToken) @@ -253,7 +253,7 @@ private async Task MergeFromSourceBranch(string branch, string sourceBranchName, } private async Task UpdateStackUsingRebase( - Config.Stack stack, + Model.Stack stack, Dictionary branchStatuses, Dictionary pullRequests, CancellationToken cancellationToken) diff --git a/src/Stack/Commands/Helpers/StackHelpers.cs b/src/Stack/Commands/Helpers/StackHelpers.cs index 4b6413e8..4e17d3a0 100644 --- a/src/Stack/Commands/Helpers/StackHelpers.cs +++ b/src/Stack/Commands/Helpers/StackHelpers.cs @@ -1,11 +1,11 @@ using System.Text; -using System.Threading.Tasks; using Microsoft.Extensions.Logging; using MoreLinq; using Spectre.Console; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; +using Stack.Model; +using Stack.Persistence; using static Stack.Commands.CreatePullRequestsCommandHandler; namespace Stack.Commands.Helpers; @@ -102,7 +102,7 @@ public record ParentBranchStatus(string Name, int Ahead, int Behind); public static class StackHelpers { public static List GetStackStatus( - List stacks, + List stacks, string currentBranch, ILogger logger, IGitClient gitClient, @@ -129,7 +129,7 @@ public static List GetStackStatus( return stacksToReturnStatusFor; - static void EvaluateBranchStatusDetails(ILogger logger, IGitClient gitClient, IGitHubClient gitHubClient, bool includePullRequestStatus, List stacksToReturnStatusFor, IOrderedEnumerable stacksOrderedByCurrentBranch, Dictionary branchStatuses) + static void EvaluateBranchStatusDetails(ILogger logger, IGitClient gitClient, IGitHubClient gitHubClient, bool includePullRequestStatus, List stacksToReturnStatusFor, IOrderedEnumerable stacksOrderedByCurrentBranch, Dictionary branchStatuses) { foreach (var stack in stacksOrderedByCurrentBranch) { @@ -219,7 +219,7 @@ branchStatus.RemoteTrackingBranchName is not null } public static StackStatus GetStackStatus( - Config.Stack stack, + Model.Stack stack, string currentBranch, ILogger logger, IGitClient gitClient, @@ -523,7 +523,7 @@ public static async Task GetUpdateStrategy( return strategy; } - public static string[] GetBranchesNeedingCleanup(Config.Stack stack, ILogger logger, IGitClient gitClient, IGitHubClient gitHubClient) + public static string[] GetBranchesNeedingCleanup(Model.Stack stack, ILogger logger, IGitClient gitClient, IGitHubClient gitHubClient) { var currentBranch = gitClient.GetCurrentBranch(); var stackStatus = GetStackStatus(stack, currentBranch, logger, gitClient, gitHubClient, false); @@ -553,7 +553,7 @@ public static void CleanupBranches(IGitClient gitClient, ILogger logger, string[ public static void UpdateStackPullRequestList( ILogger logger, IGitHubClient gitHubClient, - Config.Stack stack, + Model.Stack stack, List pullRequestsInStack) { var prListBuilder = new StringBuilder(); diff --git a/src/Stack/Commands/PullRequests/CreatePullRequestsCommand.cs b/src/Stack/Commands/PullRequests/CreatePullRequestsCommand.cs index 62c9f8ea..52292d79 100644 --- a/src/Stack/Commands/PullRequests/CreatePullRequestsCommand.cs +++ b/src/Stack/Commands/PullRequests/CreatePullRequestsCommand.cs @@ -3,10 +3,10 @@ using MoreLinq; using Spectre.Console; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; +using Stack.Persistence; namespace Stack.Commands; diff --git a/src/Stack/Commands/PullRequests/OpenPullRequestsCommand.cs b/src/Stack/Commands/PullRequests/OpenPullRequestsCommand.cs index 8fca4624..210d4a01 100644 --- a/src/Stack/Commands/PullRequests/OpenPullRequestsCommand.cs +++ b/src/Stack/Commands/PullRequests/OpenPullRequestsCommand.cs @@ -1,10 +1,10 @@ using System.CommandLine; using Microsoft.Extensions.Logging; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; +using Stack.Persistence; namespace Stack.Commands; diff --git a/src/Stack/Commands/Remote/PullStackCommand.cs b/src/Stack/Commands/Remote/PullStackCommand.cs index 227f0c47..aa24cbc5 100644 --- a/src/Stack/Commands/Remote/PullStackCommand.cs +++ b/src/Stack/Commands/Remote/PullStackCommand.cs @@ -1,10 +1,10 @@ using System.CommandLine; using Microsoft.Extensions.Logging; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; +using Stack.Persistence; namespace Stack.Commands; diff --git a/src/Stack/Commands/Remote/PushStackCommand.cs b/src/Stack/Commands/Remote/PushStackCommand.cs index 091018fe..0b37957f 100644 --- a/src/Stack/Commands/Remote/PushStackCommand.cs +++ b/src/Stack/Commands/Remote/PushStackCommand.cs @@ -1,10 +1,10 @@ using System.CommandLine; using Microsoft.Extensions.Logging; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; +using Stack.Persistence; namespace Stack.Commands; diff --git a/src/Stack/Commands/Remote/SyncStackCommand.cs b/src/Stack/Commands/Remote/SyncStackCommand.cs index 15c899f2..14538967 100644 --- a/src/Stack/Commands/Remote/SyncStackCommand.cs +++ b/src/Stack/Commands/Remote/SyncStackCommand.cs @@ -1,11 +1,10 @@ using System.CommandLine; -using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; +using Stack.Persistence; namespace Stack.Commands; diff --git a/src/Stack/Commands/Stack/CleanupStackCommand.cs b/src/Stack/Commands/Stack/CleanupStackCommand.cs index 1c9aefd9..3badc6c9 100644 --- a/src/Stack/Commands/Stack/CleanupStackCommand.cs +++ b/src/Stack/Commands/Stack/CleanupStackCommand.cs @@ -1,10 +1,10 @@ -using Stack.Config; +using System.CommandLine; +using Microsoft.Extensions.Logging; +using Stack.Commands.Helpers; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; -using Stack.Commands.Helpers; -using System.CommandLine; -using Microsoft.Extensions.Logging; +using Stack.Persistence; namespace Stack.Commands; diff --git a/src/Stack/Commands/Stack/DeleteStackCommand.cs b/src/Stack/Commands/Stack/DeleteStackCommand.cs index 7ab085ef..fc33897e 100644 --- a/src/Stack/Commands/Stack/DeleteStackCommand.cs +++ b/src/Stack/Commands/Stack/DeleteStackCommand.cs @@ -1,10 +1,10 @@ -using Stack.Config; +using System.CommandLine; +using Microsoft.Extensions.Logging; +using Stack.Commands.Helpers; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; -using Stack.Commands.Helpers; -using System.CommandLine; -using Microsoft.Extensions.Logging; +using Stack.Persistence; namespace Stack.Commands; diff --git a/src/Stack/Commands/Stack/ListStacksCommand.cs b/src/Stack/Commands/Stack/ListStacksCommand.cs index 54aec7fa..059374e1 100644 --- a/src/Stack/Commands/Stack/ListStacksCommand.cs +++ b/src/Stack/Commands/Stack/ListStacksCommand.cs @@ -4,10 +4,9 @@ using Microsoft.Extensions.Logging; using Spectre.Console; using Stack.Commands.Helpers; -using Stack.Config; -using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; +using Stack.Persistence; namespace Stack.Commands; diff --git a/src/Stack/Commands/Stack/NewStackCommand.cs b/src/Stack/Commands/Stack/NewStackCommand.cs index fdff04df..73222134 100644 --- a/src/Stack/Commands/Stack/NewStackCommand.cs +++ b/src/Stack/Commands/Stack/NewStackCommand.cs @@ -4,10 +4,11 @@ using Microsoft.Extensions.Logging; using Spectre.Console; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; +using Stack.Model; +using Stack.Persistence; namespace Stack.Commands; @@ -93,7 +94,7 @@ public override async Task Handle(NewStackCommandInputs inputs, CancellationToke var sourceBranch = await inputProvider.Select(logger, Questions.SelectSourceBranch, inputs.SourceBranch, branches, cancellationToken); var remoteUri = gitClient.GetRemoteUri(); - var stack = new Config.Stack(name, remoteUri, sourceBranch, []); + var stack = new Model.Stack(name, remoteUri, sourceBranch, []); string? branchName = null; BranchAction? branchAction = null; diff --git a/src/Stack/Commands/Stack/RenameStackCommand.cs b/src/Stack/Commands/Stack/RenameStackCommand.cs index 2d2879bf..ce954fba 100644 --- a/src/Stack/Commands/Stack/RenameStackCommand.cs +++ b/src/Stack/Commands/Stack/RenameStackCommand.cs @@ -1,10 +1,10 @@ using System.CommandLine; using Microsoft.Extensions.Logging; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; +using Stack.Persistence; namespace Stack.Commands; diff --git a/src/Stack/Commands/Stack/StackStatusCommand.cs b/src/Stack/Commands/Stack/StackStatusCommand.cs index eed91f2f..24f07b41 100644 --- a/src/Stack/Commands/Stack/StackStatusCommand.cs +++ b/src/Stack/Commands/Stack/StackStatusCommand.cs @@ -5,10 +5,10 @@ using MoreLinq.Extensions; using Spectre.Console; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; +using Stack.Persistence; namespace Stack.Commands; @@ -220,7 +220,7 @@ public override async Task Handle(StackStatusCommand var currentBranch = gitClient.GetCurrentBranch(); - var stacksToCheckStatusFor = new List(); + var stacksToCheckStatusFor = new List(); if (inputs.All) { diff --git a/src/Stack/Commands/Stack/StackSwitchCommand.cs b/src/Stack/Commands/Stack/StackSwitchCommand.cs index ab2d3128..a85f0768 100644 --- a/src/Stack/Commands/Stack/StackSwitchCommand.cs +++ b/src/Stack/Commands/Stack/StackSwitchCommand.cs @@ -2,10 +2,11 @@ using Microsoft.Extensions.Logging; using Spectre.Console; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; +using Stack.Model; +using Stack.Persistence; namespace Stack.Commands; diff --git a/src/Stack/Commands/Stack/UpdateStackCommand.cs b/src/Stack/Commands/Stack/UpdateStackCommand.cs index 8e5b4d56..299d2036 100644 --- a/src/Stack/Commands/Stack/UpdateStackCommand.cs +++ b/src/Stack/Commands/Stack/UpdateStackCommand.cs @@ -1,10 +1,10 @@ using System.CommandLine; using Microsoft.Extensions.Logging; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; +using Stack.Persistence; namespace Stack.Commands; diff --git a/src/Stack/Git/GitClient.cs b/src/Stack/Git/GitClient.cs index 8954fdb8..66c7ad54 100644 --- a/src/Stack/Git/GitClient.cs +++ b/src/Stack/Git/GitClient.cs @@ -1,8 +1,5 @@ -using System.Diagnostics; using Microsoft.Extensions.Logging; using Spectre.Console; -using Stack.Infrastructure; -using Stack.Infrastructure.Settings; namespace Stack.Git; diff --git a/src/Stack/Git/GitHubClient.cs b/src/Stack/Git/GitHubClient.cs index c1b25ba9..410bd3d2 100644 --- a/src/Stack/Git/GitHubClient.cs +++ b/src/Stack/Git/GitHubClient.cs @@ -1,9 +1,7 @@ -using System.Text; using System.Text.Json; using System.Text.Json.Serialization; using Microsoft.Extensions.Logging; using Spectre.Console; -using Stack.Infrastructure; using Stack.Infrastructure.Settings; namespace Stack.Git; diff --git a/src/Stack/Git/ProcessHelpers.cs b/src/Stack/Git/ProcessHelpers.cs index 95d9fb53..f1ceb1e3 100644 --- a/src/Stack/Git/ProcessHelpers.cs +++ b/src/Stack/Git/ProcessHelpers.cs @@ -2,7 +2,6 @@ using System.Text; using Microsoft.Extensions.Logging; using Spectre.Console; -using Stack.Infrastructure; namespace Stack.Git; diff --git a/src/Stack/Git/SafeGitHubClient.cs b/src/Stack/Git/SafeGitHubClient.cs index 6ee87c19..3d41b885 100644 --- a/src/Stack/Git/SafeGitHubClient.cs +++ b/src/Stack/Git/SafeGitHubClient.cs @@ -1,4 +1,3 @@ -using System.Threading; using Microsoft.Extensions.Logging; namespace Stack.Git; diff --git a/src/Stack/Infrastructure/Commands/CommandWithOutput.cs b/src/Stack/Infrastructure/Commands/CommandWithOutput.cs index 0bd80c0a..3e134a38 100644 --- a/src/Stack/Infrastructure/Commands/CommandWithOutput.cs +++ b/src/Stack/Infrastructure/Commands/CommandWithOutput.cs @@ -1,5 +1,4 @@ using System.CommandLine; -using System.Text.Json; using Microsoft.Extensions.Logging; using Stack.Infrastructure; using Stack.Infrastructure.Settings; diff --git a/src/Stack/Infrastructure/HostApplicationBuilderExtensions.cs b/src/Stack/Infrastructure/HostApplicationBuilderExtensions.cs index bf07b09b..741c5e94 100644 --- a/src/Stack/Infrastructure/HostApplicationBuilderExtensions.cs +++ b/src/Stack/Infrastructure/HostApplicationBuilderExtensions.cs @@ -1,16 +1,14 @@ using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Console; using Spectre.Console; +using Stack.Commands; using Stack.Commands.Helpers; -using Stack.Config; using Stack.Git; -using Stack.Infrastructure; using Stack.Infrastructure.Settings; -using Stack.Commands; -using Microsoft.Extensions.Logging; -using System.Security.Cryptography.X509Certificates; -using Microsoft.Extensions.Logging.Console; +using Stack.Persistence; namespace Stack.Infrastructure; diff --git a/src/Stack/Config/Stack.cs b/src/Stack/Model/Stack.cs similarity index 97% rename from src/Stack/Config/Stack.cs rename to src/Stack/Model/Stack.cs index 8fd6d877..17183c46 100644 --- a/src/Stack/Config/Stack.cs +++ b/src/Stack/Model/Stack.cs @@ -1,7 +1,7 @@ +using System.ComponentModel; using Stack.Commands; -using System.Text.RegularExpressions; -namespace Stack.Config; +namespace Stack.Model; public record Stack(string Name, string RemoteUri, string SourceBranch, List Branches) { @@ -308,4 +308,13 @@ public List> GetAllPaths() } return result; } +} + +public enum RemoveBranchChildAction +{ + [Description("Move children branches to parent branch")] + MoveChildrenToParent, + + [Description("Remove children branches")] + RemoveChildren } \ No newline at end of file diff --git a/src/Stack/Config/StackExtensionMethods.cs b/src/Stack/Model/StackExtensionMethods.cs similarity index 94% rename from src/Stack/Config/StackExtensionMethods.cs rename to src/Stack/Model/StackExtensionMethods.cs index 77896598..9051fd53 100644 --- a/src/Stack/Config/StackExtensionMethods.cs +++ b/src/Stack/Model/StackExtensionMethods.cs @@ -1,10 +1,10 @@ -namespace Stack.Config; +namespace Stack.Model; public static class StackExtensionMethods { public static bool IsCurrentStack(this Stack stack, string currentBranch) { - return stack.SourceBranch.Equals(currentBranch, StringComparison.OrdinalIgnoreCase) || + return stack.SourceBranch.Equals(currentBranch, StringComparison.OrdinalIgnoreCase) || stack.AllBranchNames.Contains(currentBranch); } diff --git a/src/Stack/Config/StackConfig.cs b/src/Stack/Persistence/StackConfig.cs similarity index 82% rename from src/Stack/Config/StackConfig.cs rename to src/Stack/Persistence/StackConfig.cs index 3795479f..36f5a4f2 100644 --- a/src/Stack/Config/StackConfig.cs +++ b/src/Stack/Persistence/StackConfig.cs @@ -1,9 +1,10 @@ using System.Text.Json; using System.Text.Json.Serialization; +using Stack.Model; -namespace Stack.Config; +namespace Stack.Persistence; -public record StackData(List Stacks); +public record StackData(List Stacks); public interface IStackConfig { @@ -100,7 +101,7 @@ private bool IsStackConfigInV2Format(string jsonString) } } - private List LoadStacksFromV2Format(string jsonString) + private List LoadStacksFromV2Format(string jsonString) { var stacksV2 = JsonSerializer.Deserialize(jsonString, StackConfigJsonSerializerContext.Default.StackConfigV2); @@ -111,7 +112,7 @@ private List LoadStacksFromV2Format(string jsonString) return [.. stacksV2.Stacks.Select(MapFromV2Format)]; } - private static StackV2 MapToV2Format(Stack stack) + private static StackV2 MapToV2Format(Model.Stack stack) { var branchesV2 = stack.Branches.Select(MapToV2Format).ToList(); return new StackV2(stack.Name, stack.RemoteUri, stack.SourceBranch, branchesV2); @@ -122,7 +123,7 @@ private static StackV2Branch MapToV2Format(Branch branch) return new StackV2Branch(branch.Name, [.. branch.Children.Select(MapToV2Format)]); } - private List LoadStacksFromV1Format(string jsonString) + private List LoadStacksFromV1Format(string jsonString) { var stacksV1 = JsonSerializer.Deserialize(jsonString, StackConfigJsonSerializerContext.Default.ListStackV1); if (stacksV1 == null) @@ -133,31 +134,31 @@ private List LoadStacksFromV1Format(string jsonString) return [.. stacksV1.Select(MapFromV1Format)]; } - private static Stack MapFromV2Format(StackV2 stackV2) + private static Model.Stack MapFromV2Format(StackV2 stackV2) { - var branches = stackV2.Branches.Select(b => new Branch(b.Name, [.. b.Children.Select(MapFromV2Format)])).ToList(); - return new Stack(stackV2.Name, stackV2.RemoteUri, stackV2.SourceBranch, branches); + var branches = stackV2.Branches.Select(b => new Model.Branch(b.Name, [.. b.Children.Select(MapFromV2Format)])).ToList(); + return new Model.Stack(stackV2.Name, stackV2.RemoteUri, stackV2.SourceBranch, branches); } - private static Branch MapFromV2Format(StackV2Branch branchV2) + private static Model.Branch MapFromV2Format(StackV2Branch branchV2) { - return new Branch(branchV2.Name, [.. branchV2.Children.Select(MapFromV2Format)]); + return new Model.Branch(branchV2.Name, [.. branchV2.Children.Select(MapFromV2Format)]); } - private static StackV1 MapToV1Format(Stack stack) + private static StackV1 MapToV1Format(Model.Stack stack) { return new StackV1(stack.Name, stack.RemoteUri, stack.SourceBranch, stack.AllBranchNames); } - private static Stack MapFromV1Format(StackV1 stackV1) + private static Model.Stack MapFromV1Format(StackV1 stackV1) { // In v1, the branches are a flat list, but this actually represents a tree structure // where each branch is the child of the previous one. - var childBranches = new List(); - Branch? currentParent = null; + var childBranches = new List(); + Model.Branch? currentParent = null; foreach (var branch in stackV1.Branches) { - var newBranch = new Branch(branch, []); + var newBranch = new Model.Branch(branch, []); if (currentParent == null) { childBranches.Add(newBranch); @@ -169,7 +170,7 @@ private static Stack MapFromV1Format(StackV1 stackV1) currentParent = newBranch; } - return new Stack(stackV1.Name, stackV1.RemoteUri, stackV1.SourceBranch, childBranches); + return new Model.Stack(stackV1.Name, stackV1.RemoteUri, stackV1.SourceBranch, childBranches); } } diff --git a/src/Stack/Config/StackConstants.cs b/src/Stack/Persistence/StackConstants.cs similarity index 95% rename from src/Stack/Config/StackConstants.cs rename to src/Stack/Persistence/StackConstants.cs index 47096067..a4300730 100644 --- a/src/Stack/Config/StackConstants.cs +++ b/src/Stack/Persistence/StackConstants.cs @@ -1,4 +1,4 @@ -namespace Stack.Config; +namespace Stack.Persistence; public static class StackConstants { diff --git a/src/Stack/Config/StackRepository.cs b/src/Stack/Persistence/StackRepository.cs similarity index 81% rename from src/Stack/Config/StackRepository.cs rename to src/Stack/Persistence/StackRepository.cs index 077ecf1e..cbd3d7d6 100644 --- a/src/Stack/Config/StackRepository.cs +++ b/src/Stack/Persistence/StackRepository.cs @@ -1,15 +1,15 @@ using Stack.Git; using Stack.Infrastructure.Settings; -namespace Stack.Config; +namespace Stack.Persistence; public interface IStackRepository { - List GetStacks(); + List GetStacks(); - void AddStack(Stack stack); + void AddStack(Model.Stack stack); - void RemoveStack(Stack stack); + void RemoveStack(Model.Stack stack); void SaveChanges(); } @@ -32,19 +32,19 @@ public StackRepository( this.stackData = new Lazy(() => stackConfig.Load()); } - public List GetStacks() + public List GetStacks() { var remoteUri = gitClientFactory.Create(executionContext.WorkingDirectory).GetRemoteUri(); return [.. stackData.Value.Stacks.Where(s => s.RemoteUri.Equals(remoteUri, StringComparison.OrdinalIgnoreCase))]; } - public void AddStack(Stack stack) + public void AddStack(Model.Stack stack) { stackData.Value.Stacks.Add(stack); } - public void RemoveStack(Stack stack) + public void RemoveStack(Model.Stack stack) { stackData.Value.Stacks.Remove(stack); } From 5dd4b7f576b66824eeb757ce0f7756cf5654a9f1 Mon Sep 17 00:00:00 2001 From: Geoff Lamrock Date: Wed, 15 Oct 2025 08:35:55 +1100 Subject: [PATCH 2/3] Fix build --- .../Commands/Branch/RemoveBranchCommandHandlerTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Stack.Tests/Commands/Branch/RemoveBranchCommandHandlerTests.cs b/src/Stack.Tests/Commands/Branch/RemoveBranchCommandHandlerTests.cs index 297606d8..48afe34e 100644 --- a/src/Stack.Tests/Commands/Branch/RemoveBranchCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/Branch/RemoveBranchCommandHandlerTests.cs @@ -6,6 +6,7 @@ using Stack.Git; using Stack.Infrastructure; using Stack.Infrastructure.Settings; +using Stack.Model; using Stack.Tests.Helpers; using Xunit.Abstractions; From e63b3651e82998c148ec021522c8ca2ba9c5bca1 Mon Sep 17 00:00:00 2001 From: Geoff Lamrock Date: Wed, 15 Oct 2025 08:39:51 +1100 Subject: [PATCH 3/3] Cleanup --- .../Remote/PullStackCommandHandlerTests.cs | 9 ++++--- .../Stack/CleanupStackCommandHandlerTests.cs | 27 ++++++++++++------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/Stack.Tests/Commands/Remote/PullStackCommandHandlerTests.cs b/src/Stack.Tests/Commands/Remote/PullStackCommandHandlerTests.cs index 75b70988..5b2791ca 100644 --- a/src/Stack.Tests/Commands/Remote/PullStackCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/Remote/PullStackCommandHandlerTests.cs @@ -39,7 +39,8 @@ public async Task WhenNoStackNameIsProvided_AsksForStack_PullsChangesForTheCorre var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new PullStackCommandHandler(inputProvider, logger, displayProvider, gitClientFactory, executionContext, stackRepository, stackActions); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(branch1); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); + gitClient.GetCurrentBranch().Returns(branch1); inputProvider.Select(Questions.SelectStack, Arg.Any(), Arg.Any()).Returns("Stack1"); @@ -79,7 +80,8 @@ public async Task WhenNameIsProvided_DoesNotAskForName_PullsChangesForTheCorrect var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new PullStackCommandHandler(inputProvider, logger, displayProvider, gitClientFactory, executionContext, stackRepository, stackActions); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(branch1); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); + gitClient.GetCurrentBranch().Returns(branch1); // Act await handler.Handle(new PullStackCommandInputs("Stack1"), CancellationToken.None); @@ -118,7 +120,8 @@ public async Task WhenNameIsProvided_ButStackDoesNotExist_Throws() var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new PullStackCommandHandler(inputProvider, logger, displayProvider, gitClientFactory, executionContext, stackRepository, stackActions); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(branch1); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); + gitClient.GetCurrentBranch().Returns(branch1); // Act and assert var invalidStackName = Some.Name(); diff --git a/src/Stack.Tests/Commands/Stack/CleanupStackCommandHandlerTests.cs b/src/Stack.Tests/Commands/Stack/CleanupStackCommandHandlerTests.cs index bf0bd4fe..39166064 100644 --- a/src/Stack.Tests/Commands/Stack/CleanupStackCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/Stack/CleanupStackCommandHandlerTests.cs @@ -39,7 +39,8 @@ public async Task WhenBranchExistsLocally_ButHasNotBeenPushedToTheRemote_BranchI var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new CleanupStackCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); + gitClient.GetCurrentBranch().Returns(sourceBranch); // Setup branch statuses - branch without remote tracking should not be cleaned up var branchStatuses = new Dictionary @@ -86,7 +87,8 @@ public async Task WhenBranchExistsLocally_AndHasBeenDeletedFromTheRemote_BranchI var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new CleanupStackCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); + gitClient.GetCurrentBranch().Returns(sourceBranch); // Setup branch statuses - branchToCleanup has been deleted from remote var branchStatuses = new Dictionary @@ -133,7 +135,8 @@ public async Task WhenBranchExistsLocally_AndInRemote_BranchIsNotDeletedLocally( var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new CleanupStackCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); + gitClient.GetCurrentBranch().Returns(sourceBranch); // Setup branch statuses - all branches exist in remote var branchStatuses = new Dictionary @@ -181,7 +184,8 @@ public async Task WhenConfirmationIsFalse_DoesNotDeleteAnyBranches() var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new CleanupStackCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); + gitClient.GetCurrentBranch().Returns(sourceBranch); // Setup branch statuses - branchToCleanup has remote tracking but remote branch was deleted var branchStatuses = new Dictionary @@ -228,7 +232,8 @@ public async Task WhenStackNameIsProvided_ItIsNotAskedFor() var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new CleanupStackCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); + gitClient.GetCurrentBranch().Returns(sourceBranch); // Setup branch statuses - branchToCleanup has remote tracking but remote branch was deleted var branchStatuses = new Dictionary @@ -274,7 +279,8 @@ public async Task WhenStackNameIsProvided_ButStackDoesNotExist_Throws() var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new CleanupStackCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); + gitClient.GetCurrentBranch().Returns(sourceBranch); inputProvider.Confirm(Questions.ConfirmDeleteBranches, Arg.Any()).Returns(true); @@ -309,7 +315,8 @@ public async Task WhenOnlyASingleStackExists_StackIsSelectedAutomatically() var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new CleanupStackCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); + gitClient.GetCurrentBranch().Returns(sourceBranch); // Setup branch statuses - branchToCleanup has remote tracking but remote branch was deleted var branchStatuses = new Dictionary @@ -355,7 +362,8 @@ public async Task WhenConfirmIsProvided_DoesNotAskForConfirmation_DeletesBranche var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new CleanupStackCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); + gitClient.GetCurrentBranch().Returns(sourceBranch); // Setup branch statuses - branchToCleanup has been deleted from remote var branchStatuses = new Dictionary @@ -403,7 +411,8 @@ public async Task WhenChildBranchExistsLocally_AndHasBeenDeletedFromTheRemote_Br var executionContext = new CliExecutionContext { WorkingDirectory = "/some/path" }; var handler = new CleanupStackCommandHandler(inputProvider, logger, gitClientFactory, executionContext, gitHubClient, stackRepository); - gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); gitClient.GetCurrentBranch().Returns(sourceBranch); + gitClientFactory.Create(executionContext.WorkingDirectory).Returns(gitClient); + gitClient.GetCurrentBranch().Returns(sourceBranch); // Setup branch statuses - branchToCleanup has been deleted from remote var branchStatuses = new Dictionary