public async Task IsValidAsync_NullState() { ILibraryInstallationState state = null; ILibraryOperationResult result = await state.IsValidAsync(_dependencies); Assert.IsFalse(result.Success); Assert.AreEqual(result.Errors.Count, 1); Assert.AreEqual(result.Errors.First().Code, "LIB999"); }
private async Task <IEnumerable <FileIdentifier> > GetFilesWithVersionsAsync(ILibraryInstallationState state) { IEnumerable <FileIdentifier> filesWithVersions = new List <FileIdentifier>(); ILibraryCatalog catalog = _dependencies.GetProvider(state.ProviderId)?.GetCatalog(); if (catalog == null) { return(filesWithVersions); } ILibraryOperationResult validationResult = await state.IsValidAsync(_dependencies).ConfigureAwait(false); if (validationResult.Success) { IProvider provider = _dependencies.GetProvider(state.ProviderId); if (provider != null) { ILibraryOperationResult updatedStateResult = await provider.UpdateStateAsync(state, CancellationToken.None).ConfigureAwait(false); if (updatedStateResult.Success) { ILibrary library = await catalog.GetLibraryAsync(state.Name, state.Version, CancellationToken.None).ConfigureAwait(false); if (library != null && library.Files != null) { IEnumerable <string> desiredStateFiles = updatedStateResult.InstallationState.Files; if (desiredStateFiles != null && desiredStateFiles.Any()) { filesWithVersions = desiredStateFiles.Select(f => new FileIdentifier(Path.Combine(state.DestinationPath, f), library.Version)); } } } } } else { // Assert disabled due to breaking unit test execution. See: https://github.com/Microsoft/testfx/issues/561 //Debug.Assert(validationResult.Success); } return(filesWithVersions); }
/// <summary> /// Uninstalls the specified library and removes it from the <see cref="Libraries"/> collection. /// </summary> /// <param name="libraryName">Name of the library.</param> /// <param name="version">Version of the library to uninstall.</param> /// <param name="deleteFilesFunction"></param> /// <param name="cancellationToken"></param> public async Task <ILibraryOperationResult> UninstallAsync(string libraryName, string version, Func <IEnumerable <string>, Task <bool> > deleteFilesFunction, CancellationToken cancellationToken) { ILibraryInstallationState library = Libraries.FirstOrDefault(l => l.Name == libraryName && l.Version == version); if (cancellationToken.IsCancellationRequested) { return(LibraryOperationResult.FromCancelled(library)); } if (library != null) { ILibraryOperationResult validationResult = await library.IsValidAsync(_dependencies); if (!validationResult.Success) { return(validationResult); } try { ILibraryOperationResult result = await DeleteLibraryFilesAsync(library, deleteFilesFunction, cancellationToken).ConfigureAwait(false); if (result.Success) { _libraries.Remove(library); return(result); } } catch (OperationCanceledException) { return(LibraryOperationResult.FromCancelled(library)); } } return(LibraryOperationResult.FromError(PredefinedErrors.CouldNotDeleteLibrary(libraryName))); }