public void CheckPendingRebootTest(bool isPendingReboot, int expectedLoadPendingRebootCallCount, int expectedShowPendingRebootToastNotificationCount, int expectedRemovePendingRebootToastNotificationCallCount, bool isNonCompliant, bool isDisabled) { var actualLoadPendingRebootCallCount = 0; var actualShowPendingRebootToastNotificationCount = 0; var actualRemovePendingRebootToastNotificationCount = 0; var actual = CheckPendingRebootCommand.CheckPendingRebootPure( async() => { actualLoadPendingRebootCallCount++; await Task.CompletedTask; return(new PendingRebootInfo { RebootIsPending = isPendingReboot, Sources = new List <RebootSource>() }); }, info => isNonCompliant , (info, s) => { actualShowPendingRebootToastNotificationCount++; return(Task.FromResult(new Result <ToastNotificationVisibility>(ToastNotificationVisibility.Show))); }, () => { actualRemovePendingRebootToastNotificationCount++; return(Task.FromResult(new Result <ToastNotificationVisibility>(ToastNotificationVisibility.Hide))); }, isDisabled); Assert.AreEqual(expectedLoadPendingRebootCallCount, actualLoadPendingRebootCallCount, "LoadPendingRebootResult"); Assert.AreEqual(expectedShowPendingRebootToastNotificationCount, actualShowPendingRebootToastNotificationCount, "ShowPendingRebootToastNotification"); Assert.AreEqual(expectedRemovePendingRebootToastNotificationCallCount, actualRemovePendingRebootToastNotificationCount, "RemovePendingRebootToastNotification"); }
public static async Task <Result <int> > CheckCompliance([OptionalCommandParameter( Description = "Free disk space requirement in GB", AlternativeName = "fr", ExampleValue = 40, DefaultValue = 40)] decimal requiredFreeDiskSpace, [OptionalCommandParameter( Description = "Subtract current size of Sccm cache. When set to true, disk space is compliant if: ((CurrentTotalFreeDiskSpace + CurrentSizeOfSccmCache) - requiredFreeDiskSpace) > 0. This parameter is ignored on a client without Sccm Client.", AlternativeName = "ssc", ExampleValue = true, DefaultValue = false)] bool subtractSccmCache, [OptionalCommandParameter( Description = "Maximum system uptime in hours before user gets notified about recommended reboot. Default is 168 hours (7 days).", DefaultValue = 168.0, AlternativeName = "mutd", ExampleValue = 168.0)] double maxUptimeHours, [OptionalCommandParameter(Description = "Hours to wait before notifying user about missing ms updates.", AlternativeName = "msuwait", ExampleValue = 48, DefaultValue = 48)] int hoursToWaitBeforeNotifyUserAboutMissingUpdates, [OptionalCommandParameter(Description = "Disable disk space check.", AlternativeName = "ddsc", ExampleValue = false, DefaultValue = false)] bool disableDiskSpaceCheck, [OptionalCommandParameter(Description = "Disable pending reboot check.", AlternativeName = "dprc", ExampleValue = false, DefaultValue = false)] bool disablePendingRebootCheck, [OptionalCommandParameter(Description = "Disable password expiry check.", AlternativeName = "dpec", ExampleValue = false, DefaultValue = false)] bool disablePasswordExpiryCheck, [OptionalCommandParameter(Description = "Disable system uptime check.", AlternativeName = "dsuc", ExampleValue = false, DefaultValue = false)] bool disableSystemUptimeCheck, [OptionalCommandParameter(Description = "Disable desktop data check.", AlternativeName = "dddc", ExampleValue = false, DefaultValue = false)] bool disableDesktopDataCheck, [OptionalCommandParameter(Description = "Disable missing MS updates check.", AlternativeName = "mmsuc", ExampleValue = false, DefaultValue = false)] bool disableMissingMsUpdatesCheck, [OptionalCommandParameter( Description = "Use a specific UI culture. F.example show user interface in Norwegian regardless of operating system display language.", AlternativeName = "uic", ExampleValue = "nb-NO", DefaultValue = "")] string userInterfaceCulture) { var policyUserInterfaceCulture = Profile.GetStringPolicyValue(Context.User, Option <string> .None, "UserInterfaceCulture", userInterfaceCulture); if (!string.IsNullOrEmpty(policyUserInterfaceCulture)) { CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(policyUserInterfaceCulture); } Process.GetCurrentProcess().CloseOtherProcessWithSameCommandLine(); var userProfile = await UserProfileOperations.LoadAndSetUserProfile().ConfigureAwait(false); var diskSpaceResult = new Result <ToastNotificationVisibility>(ToastNotificationVisibility.Hide); var pendingRebootResult = new Result <ToastNotificationVisibility>(ToastNotificationVisibility.Hide); var passwordExpiryResult = new Result <ToastNotificationVisibility>(ToastNotificationVisibility.Hide); var systemUptimeResult = new Result <ToastNotificationVisibility>(ToastNotificationVisibility.Hide); var desktopDataResult = new Result <ToastNotificationVisibility>(ToastNotificationVisibility.Hide); var missingMsUpdatesResult = new Result <ToastNotificationVisibility>(ToastNotificationVisibility.Hide); App.RunApplicationOnStart(async(sender, args) => { Logging.DefaultLogger.Info("Registering all toast groups"); ToastGroups.Groups.ForEach(group => Messenger.Default.Send(new RegisterToastNotificationMessage(group))); Logging.DefaultLogger.Info("Run compliance checks..."); diskSpaceResult = await CheckDiskSpaceCommand.CheckDiskSpace(userProfile, requiredFreeDiskSpace, subtractSccmCache, disableDiskSpaceCheck).ConfigureAwait(false); pendingRebootResult = await CheckPendingRebootCommand.CheckPendingReboot(userProfile, disablePendingRebootCheck).ConfigureAwait(false); passwordExpiryResult = await CheckPasswordExpiryCommand.CheckPasswordExpiry(userProfile, disablePasswordExpiryCheck).ConfigureAwait(false); systemUptimeResult = await CheckSystemUptimeCommand.CheckSystemUptime(userProfile, maxUptimeHours, disableSystemUptimeCheck).ConfigureAwait(false); desktopDataResult = await CheckDesktopDataCommand.CheckDesktopData(userProfile, disableDesktopDataCheck).ConfigureAwait(false); missingMsUpdatesResult = await CheckMissingMsUpdatesCommand.CheckMissingMsUpdates(userProfile, hoursToWaitBeforeNotifyUserAboutMissingUpdates, disableMissingMsUpdatesCheck).ConfigureAwait(false); Logging.DefaultLogger.Info("Waiting for all toast groups to be handled and unregistered..."); }); var result = new List <Result <ToastNotificationVisibility> > { diskSpaceResult, pendingRebootResult, passwordExpiryResult, systemUptimeResult, desktopDataResult, missingMsUpdatesResult } .ToResult().Match(_ => new Result <int>(0), exception => new Result <int>(exception)); return(await Task.FromResult(result).ConfigureAwait(false)); }