public void Should_NotEnterState_When_InstallerIsNotReady()
        {
            UpdateInstallerFake installer = new UpdateInstallerFake();
            IUpdateCollection   updates   = new UpdateCollectionFake();

            using (var state = new WuStateInstalling(installer, updates, (x, u) => { }, (x, y) => { }, null, 100))
            {
                installer.IsBusy = true;
                try
                {
                    state.EnterState(new WuStateReady());
                    Assert.Fail("exception expected");
                }
                catch (InvalidOperationException) { }
                finally {
                    installer.IsBusy = false;
                }
                installer.RebootRequiredBeforeInstallation = true;
                try
                {
                    state.EnterState(new WuStateReady());
                    Assert.Fail("exception expected");
                }
                catch (InvalidOperationException) { }
                finally
                {
                    installer.RebootRequiredBeforeInstallation = false;
                }
            }
        }
        public void Should_UseGivenUpdateCollection_When_EnterWuStateInstalling()
        {
            IUpdateInstaller  installer = new UpdateInstallerFake();
            IUpdateCollection updates   = new UpdateCollectionFake();

            using (var state = new WuStateInstalling(installer, updates, (x, u) => { }, (x, y) => { }, null, 100))
            {
                Assert.IsNull(installer.Updates);
                state.EnterState(new WuStateReady());
                Assert.AreSame(updates, installer.Updates);
            }
        }
Ejemplo n.º 3
0
        public void Should_SetCorrectStateId_When_CreateWuProcessStateObject()
        {
            var searching   = new WuStateSearching(new UpdateSearcherFake(), (x) => { }, (x, y) => { }, 100);
            var downloading = new WuStateDownloading(new UpdateDownloaderFake(), new UpdateCollectionFake(), (x, u) => { }, (x, y) => { }, null, 100);
            var installing  = new WuStateInstalling(new UpdateInstallerFake(), new UpdateCollectionFake(), (x, u) => { }, (x, y) => { }, null, 100);

            Assert.AreEqual(WuStateId.Searching, searching.StateId);
            Assert.AreEqual(WuStateId.Downloading, downloading.StateId);
            Assert.AreEqual(WuStateId.Installing, installing.StateId);

            searching.Dispose();
            downloading.Dispose();
            installing.Dispose();

            var sfailed  = new WuStateSearchFailed(null);
            var dfailed  = new WuStateDownloadFailed(null);
            var dpfailed = new WuStateDownloadPartiallyFailed(null);
            var ifailed  = new WuStateInstallFailed(null);
            var ipfailed = new WuStateInstallPartiallyFailed(null);

            Assert.AreEqual(WuStateId.SearchFailed, sfailed.StateId);
            Assert.AreEqual(WuStateId.DownloadFailed, dfailed.StateId);
            Assert.AreEqual(WuStateId.DownloadPartiallyFailed, dpfailed.StateId);
            Assert.AreEqual(WuStateId.InstallFailed, ifailed.StateId);
            Assert.AreEqual(WuStateId.InstallPartiallyFailed, ipfailed.StateId);

            var scom = new WuStateSearchCompleted(new UpdateCollectionFake());
            var dcom = new WuStateDownloadCompleted(new UpdateCollectionFake(), 0);
            var icom = new WuStateInstallCompleted(new UpdateCollectionFake(), 0);

            Assert.AreEqual(WuStateId.SearchCompleted, scom.StateId);
            Assert.AreEqual(WuStateId.DownloadCompleted, dcom.StateId);
            Assert.AreEqual(WuStateId.InstallCompleted, icom.StateId);

            var ready     = new WuStateReady();
            var rebootreq = new WuStateRebootRequired();
            var reboot    = new WuStateRestartSentToOS();
            var userinput = new WuStateUserInputRequired(String.Empty);


            Assert.AreEqual(WuStateId.Ready, ready.StateId);
            Assert.AreEqual(WuStateId.RebootRequired, rebootreq.StateId);
            Assert.AreEqual(WuStateId.RestartSentToOS, reboot.StateId);
            Assert.AreEqual(WuStateId.UserInputRequired, userinput.StateId);
        }
        /// <summary>
        /// Starts to install downloaded updates. Throws an expection if no updates are available, check it with <see cref="GetAvailableUpdates"/>.
        /// </summary>
        /// <exception cref="InvalidStateTransitionException" />
        /// <exception cref="PreConditionNotFulfilledException" />
        /// <exception cref="ArgumentOutOfRangeException" />
        /// <exception cref="System.Runtime.InteropServices.COMException" />
        public WuStateId BeginInstallUpdates(int timeoutSec = (int)DefaultAsyncOperationTimeout.InstallTimeout)
        {
            using (ll.Lock(StateLock))
            {
                AcceptEulas();
                ThrowIfInvalidStateTransition(typeof(WuStateInstalling));
                Log.Debug("Start async installation of updates.");

                IEnumerable <IUpdate> updatesToInstall;
                using (ll.Lock(UpdateHolderLock))
                {
                    updatesToInstall = UpdateHolder.GetSelectedUpdates((u) => u.EulaAccepted && u.IsDownloaded && !u.InstallationBehavior.CanRequestUserInput && !u.IsInstalled);
                }
                Log.Debug("Selected applicable updates for installation: " + String.Join(", ", updatesToInstall.Select(u => u.Identity.UpdateID)));

                WuStateInstalling installing = new WuStateInstalling(UpdateInstaller, ToUpdateCollection(updatesToInstall), EndInstallUpdates, TimeoutInstallUpdates, ProgressChangedCallback, timeoutSec);
                EnterState(installing);
                return(_currentState.StateId);
            }
        }
        public void Should_CallCompletedCallback_When_InstallingCompletes()
        {
            ManualResetEvent    callbackSignal = new ManualResetEvent(false);
            IInstallationResult result         = null;

            WuStateInstalling.InstallCompletedCallback callback = (x, u) => { result = x; callbackSignal.Set(); };
            IUpdateCollection updates = new UpdateCollectionFake();

            UpdateInstallerFake installer = new UpdateInstallerFake();

            installer.FakeInstallResult = CommonMocks.GetInstallationResult(OperationResultCode.orcSucceeded);

            var state = new WuStateInstalling(installer, updates, callback, (x, y) => { }, null, 100);

            state.EnterState(new WuStateReady());
            if (!callbackSignal.WaitOne(1000))
            {
                Assert.Fail($"callback was not called");
            }
            Assert.AreSame(installer.FakeInstallResult, result);
        }