public async Task TestUpdateApplication() { IApplicationPool applicationPool = new ApplicationPoolStub(); IApplicationInstaller applicationInstaller = new ApplicationInstaller(_applicationsRoot, new ApplicationFactoryStub(), applicationPool); const string appId = "test.app"; AppIdentity[] existingApps = { new AppIdentity(appId, new SemVersion(1, 0, 0)), new AppIdentity(appId, new SemVersion(1, 0, 1)) }; AppIdentity[] newApps = { new AppIdentity(appId, new SemVersion(1, 0, 2)), new AppIdentity(appId, new SemVersion(2, 0, 0)) }; foreach (var existingApp in existingApps) { string appPath = Path.Combine(_applicationsRoot, existingApp.Id, existingApp.Version.ToString()); if (!Directory.Exists(appPath)) { Directory.CreateDirectory(appPath); } await applicationInstaller.Install(new AppInstallConfig(existingApp)); Assert.True(applicationPool.HasApplication(existingApp)); } await applicationInstaller.Update(existingApps, newApps.Select(appIdentity => new AppInstallConfig(appIdentity))); foreach (AppIdentity app in existingApps) { Assert.False(applicationPool.HasApplication(app)); } foreach (AppIdentity app in newApps) { Assert.True(applicationPool.HasApplication(app)); } }
private bool Install(InstallThreadParam param) { if (_context.IsValidContext() == true) { bool result = false; bool debugMode = true; if (license) { debugMode = false; } if (param.operation == XapInstallOperationType.Install) { result = _context.Install(debugMode); } else if (param.operation == XapInstallOperationType.Update) { result = _context.Update(debugMode); } else { result = _context.Uninstall(); } if (result && param.report) { while (true) { ApplicationEvent evt = _context.WaitForEvent(); if (StateChanged != null) { XapInstallEventArgs e = new XapInstallEventArgs(); e.application = _context; e.fileName = param.fileName; e.progress = evt.progress; e.state = evt.state; e.error = evt.error; Deployment.Current.Dispatcher.BeginInvoke(delegate() { StateChanged(this, e); }); } if ((evt.state == InstallationState.AppInstallCompleted && param.operation == XapInstallOperationType.Install) || (evt.state == InstallationState.AppUpdateCompleted && param.operation == XapInstallOperationType.Update) || (evt.state == InstallationState.AppRemoveCompleted && param.operation == XapInstallOperationType.Uninstall)) { break; } } } return(result); } return(false); }
public async Task TestUpdateApplication() { string updateSessionId = null; IUpdateSessionManager updateSessionManager = new StubIUpdateSessionManager() { TryStartUpdateSessionString = id => { updateSessionId = id; return(Task.FromResult(true)); }, EndUpdateSessionString = id => Task.FromResult(true) }; IApplicationPool applicationPool = new ApplicationPoolStub(); IApplicationInstaller applicationInstaller = new ApplicationInstaller(_applicationsRoot, updateSessionManager, new ApplicationFactoryStub(), applicationPool); const string appId = "test.app"; AppIdentity[] existingApps = { new AppIdentity(appId, new Version(1, 0, 0)), new AppIdentity(appId, new Version(1, 0, 1)) }; AppIdentity[] newApps = { new AppIdentity(appId, new Version(1, 0, 2)), new AppIdentity(appId, new Version(2, 0, 0)) }; foreach (var existingApp in existingApps) { string appPath = Path.Combine(_applicationsRoot, existingApp.Id, existingApp.Version.ToString()); if (!Directory.Exists(appPath)) { Directory.CreateDirectory(appPath); } await applicationInstaller.Install(existingApp); Assert.IsTrue(applicationPool.HasApplication(existingApp)); } await applicationInstaller.Update(appId, existingApps.Select(app => app.Version), newApps.Select(app => app.Version)); foreach (AppIdentity app in existingApps) { Assert.IsFalse(applicationPool.HasApplication(app)); } foreach (AppIdentity app in newApps) { Assert.IsTrue(applicationPool.HasApplication(app)); } Assert.AreEqual(appId, updateSessionId); }
public async Task TestThatUpdateReturnsIfCannotStartUpdateSession() { IUpdateSessionManager updateSessionManager = new StubIUpdateSessionManager() .TryStartUpdateSession(id => Task.FromResult(false)); IApplicationPool applicationPool = new ApplicationPoolStub(); IApplicationInstaller applicationInstaller = new ApplicationInstaller(_applicationsRoot, updateSessionManager, new ApplicationFactoryStub(), applicationPool); AppIdentity existingApp = new AppIdentity("test.app", new SemVersion(1, 0, 0)); await applicationInstaller.Install(new AppInstallConfig(existingApp)); AppIdentity newApp = new AppIdentity(existingApp.Id, new SemVersion(1, 1, 0)); await applicationInstaller.Update(new[] { existingApp }, new[] { new AppInstallConfig(newApp), }); Assert.True(applicationPool.HasApplication(existingApp)); Assert.False(applicationPool.HasApplication(newApp)); }