From ee2118556de0716fd809c63bcc980f605c3c2b85 Mon Sep 17 00:00:00 2001 From: Jared Goodwin Date: Tue, 25 Feb 2020 09:11:49 -0800 Subject: [PATCH] Add Test to make sure installer is installing the correct .NET Core runtime version. --- .../Services/InstallerService.cs | 3 +- Remotely.sln | 14 ++++ .../Account/Manage/Organization.cshtml.cs | 81 ++++++++++--------- Tests/InstallerTests.cs | 19 +++++ Tests/Tests.csproj | 20 +++++ 5 files changed, 96 insertions(+), 41 deletions(-) create mode 100644 Tests/InstallerTests.cs create mode 100644 Tests/Tests.csproj diff --git a/Agent.Installer.Win/Services/InstallerService.cs b/Agent.Installer.Win/Services/InstallerService.cs index 5124ea45..d52179d7 100644 --- a/Agent.Installer.Win/Services/InstallerService.cs +++ b/Agent.Installer.Win/Services/InstallerService.cs @@ -23,6 +23,7 @@ namespace Remotely.Agent.Installer.Win.Services public event EventHandler ProgressMessageChanged; public event EventHandler ProgressValueChanged; + public static string CoreRuntimeVersion => "3.1.2"; private string InstallPath => Path.Combine(Path.GetPathRoot(Environment.SystemDirectory), "Program Files", "Remotely"); private string Platform => Environment.Is64BitOperatingSystem ? "x64" : "x86"; private JavaScriptSerializer Serializer { get; } = new JavaScriptSerializer(); @@ -304,7 +305,7 @@ namespace Remotely.Agent.Installer.Win.Services foreach (var subkeyName in GetRegistryBaseKey().OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\", false).GetSubKeyNames()) { var subkey = GetRegistryBaseKey().OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + subkeyName, false); - if (subkey?.GetValue("DisplayName")?.ToString()?.Contains("Microsoft Windows Desktop Runtime - 3.1.2") == true) + if (subkey?.GetValue("DisplayName")?.ToString()?.Contains($"Microsoft Windows Desktop Runtime - {CoreRuntimeVersion}") == true) { runtimeInstalled = true; break; diff --git a/Remotely.sln b/Remotely.sln index 88c96ab4..58206189 100644 --- a/Remotely.sln +++ b/Remotely.sln @@ -47,6 +47,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Desktop.Win", "Desktop.Win\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Agent.Installer.Win", "Agent.Installer.Win\Agent.Installer.Win.csproj", "{A3D0368C-0850-4614-B5B5-41B9D5135AA9}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{48D9D0E6-5781-44A9-84C0-56F56C2A1193}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -165,6 +167,18 @@ Global {A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Release|x64.Build.0 = Release|Any CPU {A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Release|x86.ActiveCfg = Release|Any CPU {A3D0368C-0850-4614-B5B5-41B9D5135AA9}.Release|x86.Build.0 = Release|Any CPU + {48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Debug|Any CPU.Build.0 = Debug|Any CPU + {48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Debug|x64.ActiveCfg = Debug|Any CPU + {48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Debug|x64.Build.0 = Debug|Any CPU + {48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Debug|x86.ActiveCfg = Debug|Any CPU + {48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Debug|x86.Build.0 = Debug|Any CPU + {48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Release|Any CPU.ActiveCfg = Release|Any CPU + {48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Release|Any CPU.Build.0 = Release|Any CPU + {48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Release|x64.ActiveCfg = Release|Any CPU + {48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Release|x64.Build.0 = Release|Any CPU + {48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Release|x86.ActiveCfg = Release|Any CPU + {48D9D0E6-5781-44A9-84C0-56F56C2A1193}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Server/Areas/Identity/Pages/Account/Manage/Organization.cshtml.cs b/Server/Areas/Identity/Pages/Account/Manage/Organization.cshtml.cs index bb9a0e5e..fa11f304 100644 --- a/Server/Areas/Identity/Pages/Account/Manage/Organization.cshtml.cs +++ b/Server/Areas/Identity/Pages/Account/Manage/Organization.cshtml.cs @@ -26,6 +26,9 @@ namespace Remotely.Server.Areas.Identity.Pages.Account.Manage } public List DeviceGroups { get; } = new List(); + [BindProperty] + public InputModel Input { get; set; } = new InputModel(); + [Display(Name = "Invites")] public List Invites { get; set; } @@ -33,57 +36,23 @@ namespace Remotely.Server.Areas.Identity.Pages.Account.Manage [StringLength(25)] public string OrganizationName { get; set; } - [Display(Name = "Users")] - public List Users { get; set; } - - public class InputModel - { - public bool IsAdmin { get; set; } - - [EmailAddress] - public string UserEmail { get; set; } - } - - [BindProperty] - public InputModel Input { get; set; } = new InputModel(); - [TempData] public string StatusMessage { get; set; } + [Display(Name = "Users")] + public List Users { get; set; } + private DataService DataService { get; } - private UserManager UserManager { get; } private IEmailSender EmailSender { get; } + private UserManager UserManager { get; } + public void OnGet() { PopulateViewModel(); } - private void PopulateViewModel() - { - OrganizationName = DataService.GetOrganizationName(User.Identity.Name); - - var groups = DataService.GetDeviceGroupsForUserName(User.Identity.Name); - DeviceGroups.AddRange(groups.Select(x => new SelectListItem(x.Name, x.ID))); - - Users = DataService.GetAllUsers(User.Identity.Name) - .Select(x => new OrganizationUser() - { - ID = x.Id, - IsAdmin = x.IsAdministrator, - UserName = x.UserName - }).ToList(); - - Invites = DataService.GetAllInviteLinks(User.Identity.Name).Select(x => new Invite() - { - ID = x.ID, - InvitedUser = x.InvitedUser, - IsAdmin = x.IsAdmin, - DateSent = x.DateSent - }).ToList(); - } - public async Task OnPostSendInviteAsync() { var currentUser = await UserManager.FindByEmailAsync(User.Identity.Name); @@ -122,7 +91,7 @@ namespace Remotely.Server.Areas.Identity.Pages.Account.Manage } else { - + var invite = new Invite() { InvitedUser = Input.UserEmail, @@ -147,6 +116,38 @@ namespace Remotely.Server.Areas.Identity.Pages.Account.Manage } return Page(); } + + private void PopulateViewModel() + { + OrganizationName = DataService.GetOrganizationName(User.Identity.Name); + + var groups = DataService.GetDeviceGroupsForUserName(User.Identity.Name); + DeviceGroups.AddRange(groups.Select(x => new SelectListItem(x.Name, x.ID))); + + Users = DataService.GetAllUsers(User.Identity.Name) + .Select(x => new OrganizationUser() + { + ID = x.Id, + IsAdmin = x.IsAdministrator, + UserName = x.UserName + }).ToList(); + + Invites = DataService.GetAllInviteLinks(User.Identity.Name).Select(x => new Invite() + { + ID = x.ID, + InvitedUser = x.InvitedUser, + IsAdmin = x.IsAdmin, + DateSent = x.DateSent + }).ToList(); + } + + public class InputModel + { + public bool IsAdmin { get; set; } + + [EmailAddress] + public string UserEmail { get; set; } + } } } \ No newline at end of file diff --git a/Tests/InstallerTests.cs b/Tests/InstallerTests.cs new file mode 100644 index 00000000..3b620bd2 --- /dev/null +++ b/Tests/InstallerTests.cs @@ -0,0 +1,19 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Remotely.Agent.Installer.Win.Services; +using System.Linq; +using System.Runtime.InteropServices; + +namespace Tests +{ + [TestClass] + public class InstallerTests + { + [TestMethod] + public void CoreVersionTest() + { + var description = RuntimeInformation.FrameworkDescription; + var version = description.Split().Last(); + Assert.AreEqual(InstallerService.CoreRuntimeVersion, version); + } + } +} diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj new file mode 100644 index 00000000..a8649ca3 --- /dev/null +++ b/Tests/Tests.csproj @@ -0,0 +1,20 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + + + + + +