public void Should_NotInstallUpdate_When_EulaIsNotAccepted() { var session = new UpdateSessionFake(true); var update1 = new UpdateFake("update1", true); update1.IsDownloaded = true; var update2 = new UpdateFake("update2", true); update2.IsDownloaded = true; session.SearcherMock.FakeSearchResult = CommonMocks.GetSearchResult(ToUpdateCollection(update1, update2)); using (WuApiController wu = new WuApiController(session, UpdateCollectionFactory, SystemInfo)) { wu.AutoAcceptEulas = true; wu.BeginSearchUpdates(); WaitForStateChange(wu, WuStateId.SearchCompleted); update1.EulaAccepted = true; update2.EulaAccepted = false; wu.AutoAcceptEulas = false; wu.BeginInstallUpdates(); WaitForStateChange(wu, WuStateId.UserInputRequired); Assert.IsTrue(update1.EulaAccepted); Assert.IsFalse(update2.EulaAccepted); Assert.AreEqual(wu.GetAvailableUpdates().Count, 2); Assert.IsNotNull(wu.GetAvailableUpdates().SingleOrDefault(u => u.ID.Equals("update1") && u.IsInstalled && u.EulaAccepted)); Assert.IsNotNull(wu.GetAvailableUpdates().SingleOrDefault(u => u.ID.Equals("update2") && !u.IsInstalled && !u.EulaAccepted)); } }
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); } } }
public void Should_NotEnterInstallingState_When_NoUpdatesAvailable() { var session = new UpdateSessionFake(true); var update1 = new UpdateFake("update1", true); update1.IsInstalled = true; var update2 = new UpdateFake("update2", true); update2.IsInstalled = false; update2.IsDownloaded = false; using (WuApiController wu = new WuApiController(session, UpdateCollectionFactory, SystemInfo)) { try { wu.BeginInstallUpdates(); // nerver searched for updates, no updates should be available Assert.Fail("exception expected"); } catch (InvalidStateTransitionException) { } session.SearcherMock.FakeSearchResult = CommonMocks.GetSearchResult(ToUpdateCollection(update1)); wu.BeginSearchUpdates(); WaitForStateChange(wu, WuStateId.SearchCompleted); try { wu.BeginInstallUpdates(); // available updates are already installed Assert.Fail("exception expected"); } catch (InvalidStateTransitionException) { } session.SearcherMock.FakeSearchResult = CommonMocks.GetSearchResult(ToUpdateCollection(update2)); wu.BeginSearchUpdates(); WaitForStateChange(wu, WuStateId.SearchCompleted); try { wu.BeginInstallUpdates(); // available updates are already installed Assert.Fail("exception expected"); } catch (InvalidStateTransitionException) { } } }
public void Should_TestPreConditions_When_BeforeStateChange() { UpdateSessionFake session = new UpdateSessionFake(true); using (WuApiController wu = new WuApiController(session, UpdateCollectionFactory, SystemInfo)) { wu.BeginSearchUpdates(); WaitForStateChange(wu, WuStateId.SearchCompleted); wu.BeginInstallUpdates(); } }
public void Should_ThrowException_When_TimeoutValueIsToHigh() { UpdateSessionFake session = new UpdateSessionFake(true); session.SearcherMock.FakeSearchResult = CommonMocks.GetSearchResult(ToUpdateCollection(new UpdateFake("update1", true))); int max = int.MaxValue / 1000; int outOfRange = max + 1; using (WuApiController wu = new WuApiController(session, UpdateCollectionFactory, SystemInfo)) { wu.AutoAcceptEulas = true; try { wu.BeginSearchUpdates(outOfRange); Assert.Fail("exception expected"); } catch (ArgumentOutOfRangeException) { } wu.BeginSearchUpdates(max); WaitForStateChange(wu, WuStateId.SearchCompleted); try { wu.BeginDownloadUpdates(outOfRange); Assert.Fail("exception expected"); } catch (ArgumentOutOfRangeException) { } wu.BeginDownloadUpdates(max); WaitForStateChange(wu, WuStateId.DownloadCompleted); try { wu.BeginInstallUpdates(outOfRange); Assert.Fail("exception expected"); } catch (ArgumentOutOfRangeException) { } wu.BeginInstallUpdates(max); WaitForStateChange(wu, WuStateId.InstallCompleted); } }
public void Should_NotEnterDownloadingState_When_InstallerRequiresReboot() { var session = new UpdateSessionFake(true); session.SearcherMock.FakeSearchResult = CommonMocks.GetSearchResult(ToUpdateCollection(new UpdateFake("update1", true))); session.InstallerMock.RebootRequiredBeforeInstallation = true; using (WuApiController wu = new WuApiController(session, UpdateCollectionFactory, SystemInfo)) { wu.BeginSearchUpdates(); WaitForStateChange(wu, WuStateId.SearchCompleted); wu.BeginInstallUpdates(); } }
public void Should_NotInstallAlreadyInstalledUpdates_When_BeginInstallUpdates() { var session = new UpdateSessionFake(true); var update1 = new UpdateFake("update1", true); update1.IsInstalled = true; session.SearcherMock.FakeSearchResult = CommonMocks.GetSearchResult(ToUpdateCollection(update1)); using (WuApiController wu = new WuApiController(session, UpdateCollectionFactory, SystemInfo)) { wu.BeginSearchUpdates(); WaitForStateChange(wu, WuStateId.SearchCompleted); wu.BeginInstallUpdates(); } }
public void Should_EnterInstallCompletedState_When_InstallCompleted() { var session = new UpdateSessionFake(true); var update = new UpdateFake("update1", true); update.IsDownloaded = true; session.SearcherMock.FakeSearchResult = CommonMocks.GetSearchResult(ToUpdateCollection(update)); using (WuApiController wuau = new WuApiController(session, UpdateCollectionFactory, SystemInfo)) { wuau.AutoAcceptEulas = true; wuau.BeginSearchUpdates(); WaitForStateChange(wuau, WuStateId.SearchCompleted); wuau.BeginInstallUpdates(); WaitForStateChange(wuau, WuStateId.InstallCompleted); } }
public void Should_EnterInstallFailedState_When_AbortInstall() { var session = new UpdateSessionFake(true); var update = new UpdateFake("update1", true); update.IsDownloaded = true; session.SearcherMock.FakeSearchResult = CommonMocks.GetSearchResult(ToUpdateCollection(update)); session.InstallerMock.FakeInstallTimeMs = 10000; using (WuApiController wu = new WuApiController(session, UpdateCollectionFactory, SystemInfo)) { wu.AutoAcceptEulas = true; wu.BeginSearchUpdates(); WaitForStateChange(wu, WuStateId.SearchCompleted); wu.BeginInstallUpdates(); Assert.AreEqual(WuStateId.InstallFailed, wu.AbortInstallUpdates()); Assert.AreEqual(WuStateId.InstallFailed, wu.GetWuStatus().StateId); } }
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_AcceptEulas_When_BeginInstallingAndAutoAcceptEnabled() { var session = new UpdateSessionFake(true); var update = new UpdateFake("update1", true); update.IsDownloaded = true; session.SearcherMock.FakeSearchResult = CommonMocks.GetSearchResult(ToUpdateCollection(update)); using (WuApiController wu = new WuApiController(session, UpdateCollectionFactory, SystemInfo)) { wu.AutoAcceptEulas = true; wu.BeginSearchUpdates(); WaitForStateChange(wu, WuStateId.SearchCompleted); update.EulaAccepted = false; wu.BeginInstallUpdates(); WaitForStateChange(wu, WuStateId.InstallCompleted); Assert.AreEqual(wu.GetAvailableUpdates().Count, 1); Assert.IsTrue(wu.GetAvailableUpdates().All(u => u.IsDownloaded && u.IsInstalled && u.EulaAccepted)); } }
public void Should_EnterInstallFailedState_When_DownloadTimeRunsOut() { UpdateFake update = new UpdateFake("update1", true); update.IsDownloaded = true; var session = new UpdateSessionFake(true); session.SearcherMock.FakeSearchResult = CommonMocks.GetSearchResult(ToUpdateCollection(update)); session.InstallerMock.FakeInstallTimeMs = 10000; using (WuApiController wu = new WuApiController(session, UpdateCollectionFactory, SystemInfo)) { wu.AutoAcceptEulas = true; wu.BeginSearchUpdates(); WaitForStateChange(wu, WuStateId.SearchCompleted); wu.BeginInstallUpdates(1); WaitForStateChange(wu, WuStateId.InstallFailed, 2000); Assert.IsTrue(wu.GetWuStatus().Description.Contains("Timeout")); } }
public void Should_EnterUserInputRequiredState_When_NotInstalledUpdateCanRequestInput() { var session = new UpdateSessionFake(true); var behavMock = new Mock <IInstallationBehavior>(); behavMock.Setup(b => b.CanRequestUserInput).Returns(true); var update = new UpdateFake("update1", true); update.IsDownloaded = true; update.InstallationBehavior = behavMock.Object; session.SearcherMock.FakeSearchResult = CommonMocks.GetSearchResult(ToUpdateCollection(update)); using (WuApiController wu = new WuApiController(session, UpdateCollectionFactory, SystemInfo)) { wu.AutoAcceptEulas = true; wu.BeginSearchUpdates(); WaitForStateChange(wu, WuStateId.SearchCompleted); wu.BeginInstallUpdates(); WaitForStateChange(wu, WuStateId.UserInputRequired); } }
public void Should_FireAsyncOperationCompletedEvent_When_AsyncOperationCompleted() { var session = new UpdateSessionFake(true); session.SearcherMock.FakeSearchResult = CommonMocks.GetSearchResult(ToUpdateCollection(new UpdateFake("u", true))); using (WuApiController wu = new WuApiController(session, UpdateCollectionFactory, SystemInfo)) { wu.AutoAcceptEulas = true; ManualResetEvent eventSignal = new ManualResetEvent(false); AsyncOperation result = AsyncOperation.Installing; wu.OnAsyncOperationCompleted += (sender, args) => { result = args.Operation; eventSignal.Set(); }; eventSignal.Reset(); wu.BeginSearchUpdates(); if (!eventSignal.WaitOne(1000)) { Assert.Fail("expected event not fired"); } Assert.AreEqual(AsyncOperation.Searching, result); eventSignal.Reset(); wu.BeginDownloadUpdates(); if (!eventSignal.WaitOne(1000)) { Assert.Fail("expected event not fired"); } Assert.AreEqual(AsyncOperation.Downloading, result); eventSignal.Reset(); wu.BeginInstallUpdates(); if (!eventSignal.WaitOne(1000)) { Assert.Fail("expected event not fired"); } Assert.AreEqual(AsyncOperation.Installing, result); } }