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); } }
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); }
public void Should_NotAllowNullValues_When_CreateWuStateInstalling() { IUpdateInstaller installer = new UpdateInstallerFake(); IUpdateCollection updates = new UpdateCollectionFake(); try { new WuStateInstalling(null, updates, (x, u) => { }, (x, y) => { }, null, 100); Assert.Fail("exception expected"); } catch (ArgumentNullException) { } try { new WuStateInstalling(installer, null, (x, u) => { }, (x, y) => { }, null, 100); Assert.Fail("exception expected"); } catch (ArgumentNullException) { } try { new WuStateInstalling(installer, updates, null, (x, y) => { }, null, 100); Assert.Fail("exception expected"); } catch (ArgumentNullException) { } }