diff --git a/DNN Platform/Library/Common/Globals.cs b/DNN Platform/Library/Common/Globals.cs index e61ee6cb20a..6c432c7fa7e 100644 --- a/DNN Platform/Library/Common/Globals.cs +++ b/DNN Platform/Library/Common/Globals.cs @@ -478,6 +478,10 @@ public static TimeSpan ElapsedSinceAppStart /// public static Version NETFrameworkVersion { get; set; } + /// Gets the .Net framework version text. + /// The .Net framework version text. + public static string FormattedNetFrameworkVersion => FormatVersion(NETFrameworkVersion, "0", 3, "."); + /// Gets or sets the database engine version. /// /// The database engine version. diff --git a/DNN Platform/Tests/DotNetNuke.Tests.Core/Common/GlobalsTests.cs b/DNN Platform/Tests/DotNetNuke.Tests.Core/Common/GlobalsTests.cs new file mode 100644 index 00000000000..44996b2f878 --- /dev/null +++ b/DNN Platform/Tests/DotNetNuke.Tests.Core/Common/GlobalsTests.cs @@ -0,0 +1,57 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information + +namespace DotNetNuke.Tests.Core.Common; + +using System; + +using DotNetNuke.Common; + +using NUnit.Framework; + +[TestFixture] +public class GlobalsTests +{ + [Test] + public void FormatVersion_WhenTwoDigitVersionFormattedWithThreeParts_UsesZeroForThirdPart() + { + Assert.That(Globals.FormatVersion(new Version("4.8"), "0", 3, "."), Is.EqualTo("4.8.0")); + } + + [Test] + public void FormatVersion_WhenThreeDigitVersionFormattedWithThreeParts_DisplaysThirdPart() + { + Assert.That(Globals.FormatVersion(new Version("4.8.1"), "0", 3, "."), Is.EqualTo("4.8.1")); + } + + [Test] + public void FormatVersion_WhenFourDigitVersionFormattedWithThreeParts_DoesNotDisplayFourthPart() + { + Assert.That(Globals.FormatVersion(new Version("4.8.1.7"), "0", 3, "."), Is.EqualTo("4.8.1")); + } + + [Test] + public void FormatVersion_WhenTwoDigitVersion_DisplaysThreePartsWithLeadingZeroes_InABrokenWay() + { + Assert.That(Globals.FormatVersion(new Version("4.8")), Is.EqualTo("04.08.-01")); + } + + [Test] + public void FormatVersion_WhenThreeDigitVersion_DisplaysThirdPartWithLeadingZeroes() + { + Assert.That(Globals.FormatVersion(new Version("4.8.1")), Is.EqualTo("04.08.01")); + } + + [Test] + public void FormatVersion_WhenFourDigitVersion_DisplaysThreePartsWithLeadingZeroes() + { + Assert.That(Globals.FormatVersion(new Version("4.8.1.7")), Is.EqualTo("04.08.01")); + } + + [Test] + public void FormatVersion_WhenFourDigitVersionWithRevision_DisplaysThreePartsWithLeadingZeroes() + { + Assert.That(Globals.FormatVersion(new Version("4.8.1.7"), true), Is.EqualTo("04.08.01 (7)")); + } +} diff --git a/DNN Platform/Tests/DotNetNuke.Tests.Core/DotNetNuke.Tests.Core.csproj b/DNN Platform/Tests/DotNetNuke.Tests.Core/DotNetNuke.Tests.Core.csproj index fd3d57bce31..a8c4c6742da 100644 --- a/DNN Platform/Tests/DotNetNuke.Tests.Core/DotNetNuke.Tests.Core.csproj +++ b/DNN Platform/Tests/DotNetNuke.Tests.Core/DotNetNuke.Tests.Core.csproj @@ -162,6 +162,7 @@ + diff --git a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Components/Prompt/Models/HostModel.cs b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Components/Prompt/Models/HostModel.cs index 12b5c916d56..350ffec4889 100644 --- a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Components/Prompt/Models/HostModel.cs +++ b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Components/Prompt/Models/HostModel.cs @@ -1,20 +1,20 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information - +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information + namespace Dnn.PersonaBar.Prompt.Components.Models { using System.Web; - + using DotNetNuke.Common; using DotNetNuke.Entities.Host; using DotNetNuke.Entities.Users; - + public class HostModel { // DNN Platform for example public string Product { get; set; } - + public string Version { get; set; } public bool UpgradeAvailable { get; set; } @@ -30,23 +30,23 @@ public class HostModel // prompt.com public string Site { get; set; } - + public string Title { get; set; } - + public string Url { get; set; } - + public string Email { get; set; } - + public string Theme { get; set; } - + public string Container { get; set; } - + public string EditTheme { get; set; } - + public string EditContainer { get; set; } - + public int PortalCount { get; set; } - + public static HostModel Current() { var application = DotNetNuke.Application.DotNetNukeContext.Current.Application; @@ -63,7 +63,7 @@ public static HostModel Current() Version = "v." + Globals.FormatVersion(application.Version, true), Product = application.Description, UpgradeAvailable = upgradeIndicator != null, - Framework = isHost ? Globals.NETFrameworkVersion.ToString(3) : string.Empty, + Framework = isHost ? Globals.FormattedNetFrameworkVersion : string.Empty, IpAddress = System.Net.Dns.GetHostEntry(hostName).AddressList[0].ToString(), Permissions = DotNetNuke.Framework.SecurityPolicy.Permissions, Site = hostPortal.PortalName, diff --git a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Components/Servers/WebServer/ServerInfo.cs b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Components/Servers/WebServer/ServerInfo.cs index eefe8bd30cd..d547240daa8 100644 --- a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Components/Servers/WebServer/ServerInfo.cs +++ b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Components/Servers/WebServer/ServerInfo.cs @@ -15,7 +15,7 @@ public class ServerInfo { public string Framework => Environment.Version.ToString(); - public string NetFrameworkVersion => Globals.NETFrameworkVersion.ToString(3); + public string NetFrameworkVersion => Globals.FormattedNetFrameworkVersion; public string HostName => Dns.GetHostName(); diff --git a/Dnn.AdminExperience/Library/Dnn.PersonaBar.UI/Services/ServerSummaryController.cs b/Dnn.AdminExperience/Library/Dnn.PersonaBar.UI/Services/ServerSummaryController.cs index 699fa40760b..63f7eb789cf 100644 --- a/Dnn.AdminExperience/Library/Dnn.PersonaBar.UI/Services/ServerSummaryController.cs +++ b/Dnn.AdminExperience/Library/Dnn.PersonaBar.UI/Services/ServerSummaryController.cs @@ -51,7 +51,7 @@ public HttpResponseMessage GetServerInfo() { ProductName = DotNetNukeContext.Current.Application.Description, ProductVersion = "v. " + Globals.FormatVersion(DotNetNukeContext.Current.Application.Version, true), - FrameworkVersion = isHost ? Globals.NETFrameworkVersion.ToString(3) : string.Empty, + FrameworkVersion = isHost ? Globals.FormattedNetFrameworkVersion : string.Empty, ServerName = isHost ? Globals.ServerName : string.Empty, LicenseVisible = isHost && this.GetVisibleSetting("LicenseVisible"), DocCenterVisible = this.GetVisibleSetting("DocCenterVisible"),