Skip to content

Commit fb41411

Browse files
committed
Add Unit Tests for NuspecHandler, in the nuspec update with new style version: 3.25.7.2-build20398
1 parent c6cb0b8 commit fb41411

5 files changed

Lines changed: 99 additions & 4 deletions

File tree

src/UnturnedRedistUpdateTool/NuspecHandler.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,10 @@ public void UpdateVersion(string newVersion)
2424
versionElement.Value = newVersion;
2525
}
2626

27+
public string CreateVersion(string version, string buildId)
28+
{
29+
return $"{version}-build{buildId}";
30+
}
31+
2732
public void Save() => _doc.Save(_nuspecFilePath);
2833
}

src/UnturnedRedistUpdateTool/Program.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,22 @@ private static async Task<int> Main(string[] args)
8787
Console.WriteLine("Version element not found in nuspec file!");
8888
return 1;
8989
}
90+
var newVersionWithBuildId = nuspecHandler.CreateVersion(newVersion, buildId);
9091
Console.WriteLine($"Current nuspec version: {currentNuspecVersion}");
91-
if (newVersion == currentNuspecVersion)
92+
Console.WriteLine($"New Version & Build Id: {newVersionWithBuildId}");
93+
if (newVersionWithBuildId == currentNuspecVersion)
9294
{
9395
Console.WriteLine("Unturned Version is the same as in nuspec, it means new version is not detected, skipping...");
9496
return 1;
9597
}
96-
nuspecHandler.UpdateVersion(newVersion);
98+
nuspecHandler.UpdateVersion(newVersionWithBuildId);
9799
nuspecHandler.Save();
98100

99101
var redistUpdater = new RedistUpdater(managedDirectory, redistPath);
100102
var updatedFiles = await redistUpdater.UpdateAsync();
101103
if (updatedFiles.Count == 0)
102104
{
103-
Console.WriteLine($"No one file were updated, perhaps something went wrong.");
105+
Console.WriteLine("No one file were updated, perhaps something went wrong.");
104106
return 1;
105107
}
106108

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using Shouldly;
2+
using UnturnedRedistUpdateTool.Tests.Helpers;
3+
using Xunit;
4+
5+
namespace UnturnedRedistUpdateTool.Tests;
6+
7+
public class NuspecHandlerTests
8+
{
9+
private readonly string _testDataDir = Path.Combine(AppContext.BaseDirectory, "TestData", "Redist");
10+
private readonly string _realNuspecPath;
11+
12+
public NuspecHandlerTests()
13+
{
14+
_realNuspecPath = Path.Combine(_testDataDir, "Test.Unturned.Redist.Client.nuspec");
15+
if (!File.Exists(_realNuspecPath))
16+
throw new FileNotFoundException($"Test nuspec file not found at {_realNuspecPath}");
17+
}
18+
19+
[Fact]
20+
public void GetVersion_ShouldReturnCurrentVersion()
21+
{
22+
var handler = new NuspecHandler(_realNuspecPath);
23+
var version = handler.GetVersion();
24+
version.ShouldNotBeNullOrEmpty();
25+
version.ShouldStartWith("3.");
26+
}
27+
28+
[Fact]
29+
public void UpdateVersion_ShouldModifyVersionElement()
30+
{
31+
using var tempDir = new TempDir();
32+
var tempNuspecPath = Path.Combine(tempDir.Path, Path.GetFileName(_realNuspecPath));
33+
File.Copy(_realNuspecPath, tempNuspecPath);
34+
35+
var handler = new NuspecHandler(tempNuspecPath);
36+
37+
var newVersion = "1.0.0-test";
38+
handler.UpdateVersion(newVersion);
39+
handler.Save();
40+
41+
var reloadedHandler = new NuspecHandler(tempNuspecPath);
42+
reloadedHandler.GetVersion().ShouldBe(newVersion);
43+
}
44+
45+
[Fact]
46+
public void CreateVersion_ShouldReturnCorrectFormat()
47+
{
48+
var handler = new NuspecHandler(_realNuspecPath);
49+
var result = handler.CreateVersion("3.25.7.2", "20398");
50+
result.ShouldBe("3.25.7.2-build20398");
51+
}
52+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
3+
<metadata>
4+
<id>RocketModFix.Unturned.Redist.Client</id>
5+
<version>3.25.7.1</version>
6+
<description>
7+
Unturned 3 Client-side redistributables. Standalone and always up-to-date.
8+
</description>
9+
<authors>SmartlyDressedGames;RocketModFix</authors>
10+
<license type="file">LICENSE.txt</license>
11+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
12+
<repository type="git" url="https://github.com/RocketModFix/RocketModFix.Unturned.Redist" />
13+
<readme>README.md</readme>
14+
</metadata>
15+
<files>
16+
<!-- Common files for all frameworks -->
17+
<file src="LICENSE.txt" target="" />
18+
<file src="..\..\README.md" target="README.md" />
19+
20+
<!-- Files for .NET Framework 4.0 -->
21+
<file src="*.dll" target="lib/net40" />
22+
<file src="*.xml" target="lib/net40" />
23+
24+
<!-- Files for .NET Framework 4.8 -->
25+
<file src="*.dll" target="lib/net48" />
26+
<file src="*.xml" target="lib/net48" />
27+
28+
<!-- Files for .NET Standard 2.0 -->
29+
<file src="*.dll" target="lib/netstandard2.0" />
30+
<file src="*.xml" target="lib/netstandard2.0" />
31+
32+
<!-- Files for .NET Standard 2.1 -->
33+
<file src="*.dll" target="lib/netstandard2.1" />
34+
<file src="*.xml" target="lib/netstandard2.1" />
35+
</files>
36+
</package>

tests/UnturnedRedistUpdateTool.Tests/UnturnedRedistUpdateTool.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<ItemGroup>
1515
<None Update="TestData\**\*.*">
16-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
16+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
1717
</None>
1818
</ItemGroup>
1919

0 commit comments

Comments
 (0)