Example #1
0
        public void Should_EnterInstallFailedState_When_InstallationFailed()
        {
            var session = new UpdateSessionFake(true);
            var update  = new UpdateFake("update1", true);

            update.IsDownloaded = true;
            session.SearcherMock.FakeSearchResult = CommonMocks.GetSearchResult(ToUpdateCollection(update));

            List <IInstallationResult> results = new List <IInstallationResult>();

            results.Add(CommonMocks.GetInstallationResult(OperationResultCode.orcFailed));
            results.Add(CommonMocks.GetInstallationResult(OperationResultCode.orcAborted));
            results.Add(CommonMocks.GetInstallationResult(OperationResultCode.orcNotStarted));

            foreach (var result in results)
            {
                session.InstallerMock.FakeInstallResult = result;
                using (WuApiController wu = new WuApiController(session, UpdateCollectionFactory, SystemInfo))
                {
                    wu.AutoAcceptEulas = true;
                    wu.BeginSearchUpdates();
                    WaitForStateChange(wu, WuStateId.SearchCompleted);
                    wu.BeginInstallUpdates();
                    WaitForStateChange(wu, WuStateId.InstallFailed);
                }
            }
        }
Example #2
0
        public void Should_EnterRebootRequiredState_When_UpdateInstallationRequiresReboot()
        {
            var session = new UpdateSessionFake(true);
            var update  = new UpdateFake("update1", true);

            update.IsDownloaded = true;

            session.SearcherMock.FakeSearchResult   = CommonMocks.GetSearchResult(ToUpdateCollection(update));
            session.InstallerMock.FakeInstallResult = CommonMocks.GetInstallationResult(OperationResultCode.orcSucceeded, 0, true);

            using (WuApiController wu = new WuApiController(session, UpdateCollectionFactory, SystemInfo))
            {
                wu.AutoAcceptEulas = true;
                wu.BeginSearchUpdates();
                WaitForStateChange(wu, WuStateId.SearchCompleted);
                wu.BeginInstallUpdates();
                WaitForStateChange(wu, WuStateId.RebootRequired);
            }
        }
        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);
        }