Skip to content

Commit

Permalink
Fix upgrade command with relative path (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
lilpaf authored Aug 27, 2024
1 parent 123dace commit 3145629
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
46 changes: 37 additions & 9 deletions Sitefinity CLI.Tests/UpgradeCommandTests/UpgradeCommand_Should.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sitefinity_CLI.Commands;
using Sitefinity_CLI.PackageManagement;
using Sitefinity_CLI.VisualStudio;
using Microsoft.Extensions.Logging;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using Sitefinity_CLI;
using Microsoft.Extensions.DependencyInjection;
using SitefinityCLI.Tests.UpgradeCommandTests.Mocks;
using Sitefinity_CLI.Logging;
using Microsoft.Extensions.Logging.Console;
using System.Net.Http;

namespace SitefinityCLI.Tests.UpgradeCommandTests
Expand Down Expand Up @@ -65,15 +59,49 @@ public void Initialize()
public async Task Throw_When_SolutionPathIsNotFound()
{
var upgradeComamnd = new UpgradeCommandSut(promptService, sitefinityPackageManager, csProjectFileEditor, logger, projectConfigFileEditor, upgradeConfigGenerator, visualStudioWorker, httpClientFactory, packageSourceBuilder);
string path = "wrongSolutionpath";
try
{
upgradeComamnd.SolutionPath = "wrongSolutionpath";
upgradeComamnd.SolutionPath = path;
await upgradeComamnd.Execute();
}
catch (FileNotFoundException e)
{
Assert.AreEqual("File \"wrongSolutionpath\" not found", e.Message);
string fullPath = Path.GetFullPath(path);
Assert.AreEqual($"File \"{fullPath}\" not found", e.Message);
}
}

[TestMethod]
public async Task SolutionPathIsSetCorrect_When_SolutionPathCommandIsPassedRelatively()
{
var upgradeCommand = new UpgradeCommandSut(promptService, sitefinityPackageManager, csProjectFileEditor, logger, projectConfigFileEditor, upgradeConfigGenerator, visualStudioWorker, httpClientFactory, packageSourceBuilder);
string workingDirectory = Directory.GetCurrentDirectory();
string newWorkingDirectory = Path.Combine(workingDirectory, "UpgradeCommandTests");
string solutionPath = Path.Combine("Mocks", "fake.sln");

upgradeCommand.SolutionPath = solutionPath;
upgradeCommand.Version = "15.1.8325";
upgradeCommand.SkipPrompts = true;
Directory.SetCurrentDirectory(newWorkingDirectory);
await upgradeCommand.Execute();

Assert.AreEqual(Path.Combine(newWorkingDirectory, solutionPath), upgradeCommand.SolutionPath);
}

[TestMethod]
public async Task SolutionPathIsSetCorrect_When_SolutionPathCommandIsPassedFull()
{
var upgradeCommand = new UpgradeCommandSut(promptService, sitefinityPackageManager, csProjectFileEditor, logger, projectConfigFileEditor, upgradeConfigGenerator, visualStudioWorker, httpClientFactory, packageSourceBuilder);
string workingDirectory = Directory.GetCurrentDirectory();
string solutionPath = Path.Combine(workingDirectory, "UpgradeCommandTests", "Mocks", "fake.sln");

upgradeCommand.SolutionPath = solutionPath;
upgradeCommand.Version = "15.1.8325";
upgradeCommand.SkipPrompts = true;
await upgradeCommand.Execute();

Assert.AreEqual(solutionPath, upgradeCommand.SolutionPath);
}
}
}
5 changes: 5 additions & 0 deletions Sitefinity CLI/Commands/UpgradeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ protected async Task<int> OnExecuteAsync(CommandLineApplication app)

protected virtual async Task ExecuteUpgrade()
{
if (!Path.IsPathFullyQualified(this.SolutionPath))
{
this.SolutionPath = Path.GetFullPath(this.SolutionPath);
}

if (!File.Exists(this.SolutionPath))
{
throw new FileNotFoundException(string.Format(Constants.FileNotFoundMessage, this.SolutionPath));
Expand Down
4 changes: 2 additions & 2 deletions Sitefinity CLI/Sitefinity CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>sf</AssemblyName>
<RootNamespace>Sitefinity_CLI</RootNamespace>
<AssemblyVersion>1.1.0.48</AssemblyVersion>
<AssemblyVersion>1.1.0.49</AssemblyVersion>
<Version>1.1.0</Version>
<FileVersion>1.1.0.48</FileVersion>
<FileVersion>1.1.0.49</FileVersion>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
Expand Down

0 comments on commit 3145629

Please sign in to comment.