private IEnumerable <ILibraryInstallationState> ValidateParametersAndGetLibrariesToUninstall(
            Manifest manifest)
        {
            var errors = new List <string>();

            if (string.IsNullOrWhiteSpace(LibraryId.Value))
            {
                errors.Add(Resources.Text.LibraryIdRequiredForUnInstall);
            }

            IProvider provider = null;

            if (Provider.HasValue())
            {
                provider = ManifestDependencies.GetProvider(Provider.Value());
                if (provider == null)
                {
                    errors.Add(string.Format(Resources.Text.ProviderNotInstalled, Provider.Value()));
                }
            }

            if (errors.Any())
            {
                throw new InvalidOperationException(string.Join(Environment.NewLine, errors));
            }

            return(LibraryResolver.Resolve(LibraryId.Value,
                                           manifest,
                                           provider));
        }
        public async Task TestResolveLibraryAsync()
        {
            string libmanjsonPath = Path.Combine(WorkingDir, "libman.json");

            File.WriteAllText(libmanjsonPath, _manifestContents);

            Manifest manifest = await Manifest.FromFileAsync(
                libmanjsonPath,
                _dependencies,
                CancellationToken.None);

            // Matches jquery for all providers.
            IReadOnlyList <ILibraryInstallationState> result = LibraryResolver.Resolve(
                "jquery",
                manifest,
                null);

            Assert.AreEqual(3, result.Count);

            Assert.AreEqual("jquery", result[0].Name);
            Assert.AreEqual("", result[0].Version);
            Assert.AreEqual("jquery", result[1].Name);
            Assert.AreEqual("3.3.1", result[1].Version);
            Assert.AreEqual("jquery", result[2].Name);
            Assert.AreEqual("2.2.0", result[2].Version);

            // Matches jquery for cdnjs provider
            result = LibraryResolver.Resolve(
                "jquery",
                manifest,
                _dependencies.GetProvider("cdnjs"));

            Assert.AreEqual(2, result.Count);

            Assert.AreEqual("jquery", result[0].Name);
            Assert.AreEqual("3.3.1", result[0].Version);
            Assert.AreEqual("jquery", result[1].Name);
            Assert.AreEqual("2.2.0", result[1].Version);

            // Matches only one result.
            result = LibraryResolver.Resolve(
                "[email protected]",
                manifest,
                null);

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("jquery", result[0].Name);
            Assert.AreEqual("3.3.1", result[0].Version);

            // Does not match library for a different provider.
            result = LibraryResolver.Resolve(
                "[email protected]",
                manifest,
                _dependencies.GetProvider("filesystem"));

            Assert.AreEqual(0, result.Count);

            // Does not return partial matches.
            result = LibraryResolver.Resolve(
                "[email protected]",
                manifest,
                null);

            Assert.AreEqual(0, result.Count);

            result = LibraryResolver.Resolve(
                "jquer",
                manifest,
                null);

            Assert.AreEqual(0, result.Count);
        }