public void TestUpdateSettings()
        {
            var builder = new AppInstallerBuilder();
            // ReSharper disable once JoinDeclarationAndInitializer
            AppInstallerConfig appInstaller;

            builder.CheckForUpdates = AppInstallerUpdateCheckingMethod.Never;
            appInstaller            = builder.Build();
            Assert.IsNull(appInstaller.UpdateSettings?.OnLaunch);
            Assert.IsNull(appInstaller.UpdateSettings?.AutomaticBackgroundTask);

            builder.CheckForUpdates = AppInstallerUpdateCheckingMethod.Launch;
            appInstaller            = builder.Build();
            Assert.IsNotNull(appInstaller.UpdateSettings?.OnLaunch);
            Assert.IsNull(appInstaller.UpdateSettings?.AutomaticBackgroundTask);

            builder.CheckForUpdates = AppInstallerUpdateCheckingMethod.LaunchAndBackground;
            appInstaller            = builder.Build();
            Assert.IsNotNull(appInstaller.UpdateSettings?.OnLaunch);
            Assert.IsNotNull(appInstaller.UpdateSettings?.AutomaticBackgroundTask);

            builder.CheckForUpdates = AppInstallerUpdateCheckingMethod.Background;
            appInstaller            = builder.Build();
            Assert.IsNull(appInstaller.UpdateSettings?.OnLaunch);
            Assert.IsNotNull(appInstaller.UpdateSettings?.AutomaticBackgroundTask);
        }
        private AppInstallerConfig GetCurrentAppInstallerConfig()
        {
            var prompt = this.PromptMode.CurrentValue;

            var builder = new AppInstallerBuilder
            {
                Version                  = this.Version.CurrentValue,
                MainPackageType          = this.TabPackage.PackageType.CurrentValue,
                MainPackageName          = this.TabPackage.Name.CurrentValue,
                MainPackageArchitecture  = this.TabPackage.Architecture.CurrentValue,
                MainPackagePublisher     = this.TabPackage.Publisher.CurrentValue,
                MainPackageVersion       = this.TabPackage.Version.CurrentValue,
                HoursBetweenUpdateChecks = int.Parse(this.Hours.CurrentValue),
                CheckForUpdates          = this.AppInstallerUpdateCheckingMethod.CurrentValue,
                ShowPrompt               = prompt != ViewModel.PromptMode.Background,
                UpdateBlocksActivation   = prompt == ViewModel.PromptMode.Force,
                AllowDowngrades          = this.AllowDowngrades.CurrentValue,
                RedirectUri              = string.IsNullOrEmpty(this.AppInstallerUri.CurrentValue) ? null : new Uri(this.AppInstallerUri.CurrentValue),
                MainPackageUri           = string.IsNullOrEmpty(this.MainPackageUri.CurrentValue) ? null : new Uri(this.MainPackageUri.CurrentValue),
            };

            var appInstaller = builder.Build();

            if (this.TabOptionalPackages.Items.Any() && appInstaller.Optional == null)
            {
                appInstaller.Optional = new List <AppInstallerBaseEntry>();
            }

            if (this.TabDependencies.Items.Any() && appInstaller.Dependencies == null)
            {
                appInstaller.Dependencies = new List <AppInstallerBaseEntry>();
            }

            if (this.TabRelatedPackages.Items.Any() && appInstaller.Related == null)
            {
                appInstaller.Related = new List <AppInstallerBaseEntry>();
            }

            foreach (var optional in this.TabOptionalPackages.Items)
            {
                var model = optional.ToModel();
                appInstaller.Optional.Add(model);
            }

            foreach (var dependency in this.TabDependencies.Items)
            {
                var model = dependency.ToModel();
                appInstaller.Dependencies.Add(model);
            }

            foreach (var related in this.TabRelatedPackages.Items)
            {
                var model = related.ToModel();
                appInstaller.Related.Add(model);
            }

            return(appInstaller);
        }
        public void TestVariousSettings()
        {
            var builder = new AppInstallerBuilder();
            // ReSharper disable once JoinDeclarationAndInitializer
            AppInstallerConfig appInstaller;

            builder.AllowDowngrades = true;
            appInstaller            = builder.Build();
            Assert.IsTrue(appInstaller.UpdateSettings?.ForceUpdateFromAnyVersion);

            builder.AllowDowngrades = false;
            appInstaller            = builder.Build();
            Assert.IsTrue(appInstaller.UpdateSettings?.ForceUpdateFromAnyVersion != true);

            builder.CheckForUpdates        = AppInstallerUpdateCheckingMethod.Launch;
            builder.UpdateBlocksActivation = true;
            appInstaller = builder.Build();
            Assert.IsTrue(appInstaller.UpdateSettings?.OnLaunch?.UpdateBlocksActivation);

            builder.CheckForUpdates        = AppInstallerUpdateCheckingMethod.Launch;
            builder.UpdateBlocksActivation = false;
            appInstaller = builder.Build();
            Assert.IsTrue(appInstaller.UpdateSettings?.OnLaunch?.UpdateBlocksActivation != true);

            builder.CheckForUpdates = AppInstallerUpdateCheckingMethod.Launch;
            builder.ShowPrompt      = true;
            appInstaller            = builder.Build();
            Assert.IsTrue(appInstaller.UpdateSettings?.OnLaunch?.ShowPrompt);

            builder.CheckForUpdates = AppInstallerUpdateCheckingMethod.Launch;
            builder.ShowPrompt      = false;
            appInstaller            = builder.Build();
            Assert.IsTrue(appInstaller.UpdateSettings?.OnLaunch?.ShowPrompt != true);

            builder.HoursBetweenUpdateChecks = 20;
            appInstaller = builder.Build();
            Assert.AreEqual(20, appInstaller.UpdateSettings?.OnLaunch?.HoursBetweenUpdateChecks);

            builder.HoursBetweenUpdateChecks = 24;
            appInstaller = builder.Build();
            Assert.AreNotEqual(24, appInstaller.UpdateSettings?.OnLaunch?.HoursBetweenUpdateChecks, "24 as a default value should be ignored.");
        }
Пример #4
0
        private AppInstallerConfig GetCurrentAppInstallerConfig()
        {
            var builder = new AppInstallerBuilder
            {
                Version                  = this.Version.CurrentValue,
                MainPackageType          = this.TabPackage.PackageType.CurrentValue,
                MainPackageName          = this.TabPackage.Name.CurrentValue,
                MainPackageArchitecture  = this.TabPackage.Architecture.CurrentValue,
                MainPackagePublisher     = this.TabPackage.Publisher.CurrentValue,
                MainPackageVersion       = this.TabPackage.Version.CurrentValue,
                HoursBetweenUpdateChecks = int.Parse(this.Hours.CurrentValue),
                CheckForUpdates          = this.AppInstallerUpdateCheckingMethod.CurrentValue,
                ShowPrompt               = this.ShowPrompt.CurrentValue,
                UpdateBlocksActivation   = this.BlockLaunching.CurrentValue,
                AllowDowngrades          = this.AllowDowngrades.CurrentValue,
                RedirectUri              = string.IsNullOrEmpty(this.AppInstallerUri.CurrentValue) ? null : new Uri(this.AppInstallerUri.CurrentValue),
                MainPackageUri           = string.IsNullOrEmpty(this.MainPackageUri.CurrentValue) ? null : new Uri(this.MainPackageUri.CurrentValue),
            };

            var appInstaller = builder.Build();

            return(appInstaller);
        }