Add tests for Version.props

This commit is contained in:
Jordan Brown
2020-04-11 16:16:46 -04:00
parent 2a5654edb9
commit 97c7260566
2 changed files with 120 additions and 0 deletions
@@ -17,6 +17,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\Tgstation.Server.Client\Tgstation.Server.Client.csproj" />
<ProjectReference Include="..\..\src\Tgstation.Server.Host.Watchdog\Tgstation.Server.Host.Watchdog.csproj" />
<ProjectReference Include="..\..\src\Tgstation.Server.Host\Tgstation.Server.Host.csproj" />
</ItemGroup>
@@ -0,0 +1,119 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using Tgstation.Server.Api;
using Tgstation.Server.Client;
using Tgstation.Server.Host;
using Tgstation.Server.Host.Components.Watchdog;
namespace Tgstation.Server.Tests
{
[TestClass]
[TestCategory("SkipWhenLiveUnitTesting")]
public sealed class VersionsTest
{
XNamespace xmlNamespace;
XElement versionsPropertyGroup;
[TestInitialize]
public void Init()
{
var doc = XDocument.Load("../../../../../build/Version.props");
var project = doc.Root;
xmlNamespace = project.GetDefaultNamespace();
versionsPropertyGroup = project.Elements().First();
Assert.IsNotNull(versionsPropertyGroup);
}
[TestMethod]
public void TestCoreVersion()
{
var versionString = versionsPropertyGroup.Element(xmlNamespace + "TgsCoreVersion").Value + ".0";
Assert.IsNotNull(versionString);
Assert.IsTrue(Version.TryParse(versionString, out var expected));
var actual = typeof(Program).Assembly.GetName().Version;
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void TestApiVersion()
{
var versionString = versionsPropertyGroup.Element(xmlNamespace + "TgsApiVersion").Value + ".0";
Assert.IsNotNull(versionString);
Assert.IsTrue(Version.TryParse(versionString, out var expected));
var actual = typeof(ApiHeaders).Assembly.GetName().Version;
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void TestClientVersion()
{
var versionString = versionsPropertyGroup.Element(xmlNamespace + "TgsClientVersion").Value + ".0";
Assert.IsNotNull(versionString);
Assert.IsTrue(Version.TryParse(versionString, out var expected));
var actual = typeof(ServerClientFactory).Assembly.GetName().Version;
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void TestWatchdogVersion()
{
var versionString = versionsPropertyGroup.Element(xmlNamespace + "TgsHostWatchdogVersion").Value + ".0";
Assert.IsNotNull(versionString);
Assert.IsTrue(Version.TryParse(versionString, out var expected));
var actual = typeof(Host.Watchdog.WatchdogFactory).Assembly.GetName().Version;
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void TestDmapiVersion()
{
var versionString = versionsPropertyGroup.Element(xmlNamespace + "TgsDmapiVersion").Value;
Assert.IsNotNull(versionString);
Assert.IsTrue(Version.TryParse(versionString, out var expected));
var lines = File.ReadAllLines("../../../../../src/DMAPI/tgs.dm");
const string Prefix = "#define TGS_DMAPI_VERSION ";
var versionLine = lines.FirstOrDefault(l => l.StartsWith(Prefix));
Assert.IsNotNull(versionLine);
versionLine = versionLine.Substring(Prefix.Length + 1, 5);
Assert.IsTrue(Version.TryParse(versionLine, out var actual));
Assert.AreEqual(expected, actual);
Assert.AreEqual(expected, SessionController.DMApiVersion);
}
[TestMethod]
public void TestControlPanelVersion()
{
var versionString = versionsPropertyGroup.Element(xmlNamespace + "TgsControlPanelVersion").Value;
Assert.IsNotNull(versionString);
Assert.IsTrue(Version.TryParse(versionString, out var expected));
var jsonText = File.ReadAllText("../../../../../src/Tgstation.Server.Host/ClientApp/package.json");
dynamic json = JObject.Parse(jsonText);
string cpVersionString = json.dependencies["tgstation-server-control-panel"];
Assert.IsTrue(Version.TryParse(cpVersionString, out var actual));
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void TestWatchdogClientVersion()
{
var expected = typeof(Host.Watchdog.WatchdogFactory).Assembly.GetName().Version;
var actual = Program.HostWatchdogVersion;
Assert.AreEqual(expected.Major, actual.Major);
Assert.AreEqual(expected.Minor, actual.Minor);
Assert.AreEqual(expected.Build, actual.Build);
Assert.AreEqual(-1, actual.Revision);
}
}
}