Skip to content

Commit

Permalink
Merge pull request #26 from unoplatform/dev/jela/fix-version-property
Browse files Browse the repository at this point in the history
fix: Fix version property update lookup
  • Loading branch information
jeromelaban authored Nov 9, 2024
2 parents 0350fd1 + 4708b9e commit 88c64fe
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/NvGet.Tests/NvGet.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<None Remove="Scenarios\Given_VersionPropertyUpdate\Directory.Packages.props" />
</ItemGroup>

<ItemGroup>
<Content Include="Scenarios\Given_VersionPropertyUpdate\Directory.Packages.props">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<None Include="..\..\.editorconfig" Link=".editorconfig" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<UnoUIVersion>0.9</UnoUIVersion>
</PropertyGroup>
</Project>
44 changes: 43 additions & 1 deletion src/NvGet.Tests/Tools/Updater/NuGetUpdaterTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand All @@ -15,7 +17,7 @@ namespace NvGet.Tests.Tools
[TestClass]
public class NuGetUpdaterTests
{
private static readonly Dictionary<string, string[]> TestPackages = new Dictionary<string, string[]>
private static readonly Dictionary<string, string[]> TestPackages = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase)
{
{"Uno.UI", new[] { "1.0", "1.1-dev.1" } },
{"Uno.Core", new[] { "1.0", "1.0-beta.1" } },
Expand Down Expand Up @@ -43,5 +45,45 @@ public async Task GivenUnspecifiedTarget_NoUpdateIsMade()

Assert.IsTrue(logger.GetUpdates().None());
}

[TestMethod]
[DataRow("stable", "uno.ui", "1.0")]
[DataRow("dev", "uno.ui", "1.1-dev.1")]
public async Task Given_VersionPropertyUpdate(string targetVersion, string package, string version)
{
var testTempPath = CreateTempWorkspace(".\\Scenarios\\Given_VersionPropertyUpdate");

var parameters = new UpdaterParameters
{
SolutionRoot = testTempPath,
UpdateTarget = FileType.All,
TargetVersions = { targetVersion },
Feeds = { TestFeed },
};

var logger = new UpdaterLogger(Console.Out);

var updater = new NuGetUpdater(parameters, logger);

await updater.UpdatePackages(CancellationToken.None);

var updates = logger.GetUpdates();
Assert.AreEqual(1, updates.Count());
Assert.AreEqual(package, updates.First().PackageId.ToLowerInvariant());
Assert.AreEqual(version, updates.First().UpdatedVersion.OriginalVersion);
}

private static string CreateTempWorkspace(string sourceFolder)
{
var tempFolder = Path.GetTempPath();
var testTempPath = Path.Combine(tempFolder, Guid.NewGuid().ToString());
Directory.CreateDirectory(testTempPath);
foreach(var files in Directory.GetFiles(sourceFolder, "*", SearchOption.AllDirectories))
{
File.Copy(files, Path.Combine(testTempPath, Path.GetFileName(files)));
}

return testTempPath;
}
}
}
9 changes: 8 additions & 1 deletion src/NvGet/Tools/Updater/Extensions/XmlDocumentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using NvGet.Extensions;
using NvGet.Tools.Updater.Log;
using Uno.Extensions;
using Uno.Extensions.Specialized;


#if WINDOWS_UWP
using XmlDocument = Windows.Data.Xml.Dom.XmlDocument;
Expand Down Expand Up @@ -98,7 +100,10 @@ UpdateOperation operation

var propertyGroupVersionReferences = document
.SelectElements("PropertyGroup")
.SelectMany(pg => pg.SelectNodes(packageId.Replace(".", "") + "Version").OfType<XmlElement>());
.SelectMany(pg => pg
.SelectNodes("*")
.OfType<XmlElement>()
.Where(n => string.Equals(n.Name, packageId.Replace(".", string.Empty) + "Version", StringComparison.OrdinalIgnoreCase)));

foreach(var versionProperty in propertyGroupVersionReferences)
{
Expand All @@ -110,6 +115,8 @@ UpdateOperation operation
{
versionProperty.InnerText = currentOperation.UpdatedVersion.ToString();
}

operations.Add(currentOperation);
}
}

Expand Down

0 comments on commit 88c64fe

Please sign in to comment.