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_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); } }
public void Should_NotAllowNullValues_When_CreateWuStateDownloading() { IUpdateDownloader downloader = new UpdateDownloaderFake(); IUpdateCollection updates = new UpdateCollectionFake(); try { new WuStateDownloading(null, updates, _defaultCompleted, _defaultTimeout, null, 100); Assert.Fail("exception expected"); } catch (ArgumentNullException) { } try { new WuStateDownloading(downloader, null, _defaultCompleted, _defaultTimeout, null, 100); Assert.Fail("exception expected"); } catch (ArgumentNullException) { } try { new WuStateDownloading(downloader, updates, null, _defaultTimeout, null, 100); Assert.Fail("exception expected"); } catch (ArgumentNullException) { } try { new WuStateDownloading(downloader, updates, _defaultCompleted, null, null, 100); Assert.Fail("exception expected"); } catch (ArgumentNullException) { } }
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_ContainSpecifiedValues_When_CreateWuStateCompleted() { IUpdateCollection collection = new UpdateCollectionFake(); int hresult = 2; var sc = new WuStateSearchCompleted(collection, hresult); var dc = new WuStateDownloadCompleted(collection, hresult); var ic = new WuStateInstallCompleted(collection, hresult); Assert.AreSame(collection, sc.Updates); Assert.AreEqual(hresult, sc.HResult); Assert.AreSame(collection, dc.Updates); Assert.AreEqual(hresult, dc.HResult); Assert.AreSame(collection, ic.Updates); Assert.AreEqual(hresult, ic.HResult); }
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_CallCompletedCallback_When_SearchingCompletes() { ManualResetEvent callbackSignal = new ManualResetEvent(false); ISearchResult result = null; WuStateSearching.SearchCompletedCallback callback = (x) => { result = x; callbackSignal.Set(); }; IUpdateCollection updates = new UpdateCollectionFake(); UpdateSearcherFake searcher = new UpdateSearcherFake(); searcher.FakeSearchResult = CommonMocks.GetSearchResult(updates); var state = new WuStateSearching(searcher, callback, (x, y) => { }, 100); state.EnterState(new WuStateReady()); if (!callbackSignal.WaitOne(1000)) { Assert.Fail($"callback was not called"); } Assert.AreSame(searcher.FakeSearchResult, 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) { } }