public void Should_CallCompletedCallback_When_DownloadCompletes()
        {
            ManualResetEvent callbackSignal = new ManualResetEvent(false);
            IDownloadResult  result         = null;

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

            Dictionary <OperationResultCode, UpdateDownloaderFake> downloaders = new Dictionary <OperationResultCode, UpdateDownloaderFake>();

            downloaders.Add(OperationResultCode.orcAborted, GetDownloaderWithResultCode(OperationResultCode.orcAborted));
            downloaders.Add(OperationResultCode.orcFailed, GetDownloaderWithResultCode(OperationResultCode.orcFailed));
            downloaders.Add(OperationResultCode.orcSucceeded, GetDownloaderWithResultCode(OperationResultCode.orcSucceeded));
            downloaders.Add(OperationResultCode.orcSucceededWithErrors, GetDownloaderWithResultCode(OperationResultCode.orcSucceededWithErrors));

            foreach (var downloader in downloaders)
            {
                callbackSignal.Reset();
                result = null;
                var downloading = new WuStateDownloading(downloader.Value, updates, callback, _defaultTimeout, null, 100);
                downloading.EnterState(new WuStateReady());

                if (!callbackSignal.WaitOne(1000))
                {
                    Assert.Fail($"callback was not called");
                }
                Assert.AreEqual(result.ResultCode, downloader.Key);
            }
        }
Exemple #2
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 downloading the updates found with <see cref="BeginSearchUpdates(int)"/>.
 /// Throws an expection if no updates are available, check it with <see cref="GetAvailableUpdates"/>
 /// </summary>
 /// <exception cref="InvalidStateTransitionException" />
 /// <exception cref="PreConditionNotFulfilledException" />
 /// <exception cref="System.Runtime.InteropServices.COMException" />
 public WuStateId BeginDownloadUpdates(int timeoutSec = (int)DefaultAsyncOperationTimeout.DownloadTimeout)
 {
     Log.Debug("Start async download of updates.");
     using (ll.Lock(StateLock))
     {
         AcceptEulas();
         ThrowIfInvalidStateTransition(typeof(WuStateDownloading));
         WuStateDownloading downloading;
         IUpdateCollection  updatesToDownload;
         using (ll.Lock(UpdateHolderLock))
         {
             updatesToDownload = ToUpdateCollection(UpdateHolder.GetSelectedUpdates((u) => u.EulaAccepted && !u.IsInstalled && !u.IsDownloaded));
         }
         downloading = new WuStateDownloading(UpdateDownloader, updatesToDownload, EndDownloadUpdates, TimeoutDownloadUpdates, ProgressChangedCallback, timeoutSec);
         EnterState(downloading);
         return(_currentState.StateId);
     }
 }