コード例 #1
0
        private async Task LoadPackagesAsync()
        {
            IReadOnlyList <ILibraryGroup> groups = await _catalog.SearchAsync(string.Empty, 50, CancellationToken.None).ConfigureAwait(false);

            AvailablePackages = groups;
        }
コード例 #2
0
        public async Task InstallAsync_FullEndToEnd()
        {
            ILibraryCatalog catalog = _provider.GetCatalog();

            // Search for libraries to display in search result
            IReadOnlyList <ILibraryGroup> groups = await catalog.SearchAsync("jquery", 4, CancellationToken.None);

            Assert.IsTrue(groups.Count > 0);

            // Show details for selected library
            ILibraryGroup group = groups.FirstOrDefault();

            Assert.AreEqual("jquery", group.DisplayName);

            // Get all libraries in group to display version list
            IEnumerable <string> libraryVersions = await group.GetLibraryVersions(CancellationToken.None);

            Assert.IsTrue(libraryVersions.Count() >= 0);

            // Get the library to install
            ILibrary library = await catalog.GetLibraryAsync("jquery", libraryVersions.First(), CancellationToken.None);

            Assert.AreEqual(group.DisplayName, library.Name);

            var desiredState = new LibraryInstallationState
            {
                Name            = "jquery",
                Version         = "3.3.1",
                ProviderId      = "jsdelivr",
                DestinationPath = "lib",
                Files           = new[] { "dist/jquery.js", "dist/jquery.min.js" }
            };

            // Install library
            ILibraryOperationResult result = await _provider.InstallAsync(desiredState, CancellationToken.None).ConfigureAwait(false);

            foreach (string file in desiredState.Files)
            {
                string absolute = Path.Combine(_projectFolder, desiredState.DestinationPath, file);
                Assert.IsTrue(File.Exists(absolute));
            }


            //GitHub library test
            Assert.IsTrue(result.Success);
            Assert.IsFalse(result.Cancelled);
            Assert.AreEqual(0, result.Errors.Count);

            var desiredStateGH = new LibraryInstallationState
            {
                Name            = "jquery/jquery",
                Version         = "3.3.1",
                ProviderId      = "jsdelivr",
                DestinationPath = "lib",
                Files           = new[] { "dist/jquery.js", "dist/jquery.min.js" }
            };

            // Install library
            ILibraryOperationResult resultGH = await _provider.InstallAsync(desiredStateGH, CancellationToken.None).ConfigureAwait(false);

            foreach (string file in desiredStateGH.Files)
            {
                string absolute = Path.Combine(_projectFolder, desiredStateGH.DestinationPath, file);
                Assert.IsTrue(File.Exists(absolute));
            }

            Assert.IsTrue(resultGH.Success);
            Assert.IsFalse(resultGH.Cancelled);
            Assert.AreEqual(0, resultGH.Errors.Count);
        }