Exemplo n.º 1
0
        public async Task UninstallAsync_Success()
        {
            var manifest            = new Manifest(_dependencies);
            CancellationToken token = CancellationToken.None;

            IProvider provider     = _dependencies.GetProvider("cdnjs");
            var       desiredState = new LibraryInstallationState
            {
                LibraryId       = "[email protected]",
                ProviderId      = "cdnjs",
                DestinationPath = "lib",
                Files           = new[] { "jquery.js", "jquery.min.js" }
            };

            manifest.AddVersion("1.0");
            manifest.AddLibrary(desiredState);
            IEnumerable <ILibraryOperationResult> results = await manifest.RestoreAsync(token);

            string file1 = Path.Combine(_projectFolder, "lib", "jquery.js");
            string file2 = Path.Combine(_projectFolder, "lib", "jquery.min.js");

            Assert.IsTrue(File.Exists(file1));
            Assert.IsTrue(File.Exists(file2));
            Assert.IsTrue(results.Count() == 1);
            Assert.IsTrue(results.First().Success);

            ILibraryOperationResult uninstallResult = await manifest.UninstallAsync(desiredState.LibraryId, (file) => _hostInteraction.DeleteFilesAsync(file, token), token);

            Assert.IsFalse(File.Exists(file1));
            Assert.IsFalse(File.Exists(file2));
            Assert.IsTrue(results.Count() == 1);
            Assert.IsTrue(results.First().Success);
        }
Exemplo n.º 2
0
        public async Task SaveAsync_Success()
        {
            var manifest = new Manifest(_dependencies);

            IProvider provider     = _dependencies.GetProvider("cdnjs");
            var       desiredState = new LibraryInstallationState
            {
                LibraryId       = "[email protected]",
                ProviderId      = "cdnjs",
                DestinationPath = "lib",
                Files           = new[] { "jquery.min.js" }
            };

            ILibraryOperationResult result = await provider.InstallAsync(desiredState, CancellationToken.None).ConfigureAwait(false);

            Assert.IsTrue(result.Success);

            manifest.AddVersion("1.0");
            manifest.AddLibrary(desiredState);
            await manifest.SaveAsync(_filePath, CancellationToken.None).ConfigureAwait(false);

            Manifest newManifest = await Manifest.FromFileAsync(_filePath, _dependencies, CancellationToken.None).ConfigureAwait(false);

            Assert.IsTrue(File.Exists(_filePath));
            Assert.AreEqual(manifest.Libraries.Count(), newManifest.Libraries.Count());
            Assert.AreEqual(manifest.Version, newManifest.Version);
        }
Exemplo n.º 3
0
        protected async Task <Manifest> CreateManifestAsync(string defaultProvider,
                                                            string defaultDestination,
                                                            EnvironmentSettings settings,
                                                            CancellationToken cancellationToken)
        {
            if (File.Exists(Settings.ManifestFileName))
            {
                throw new InvalidOperationException(Resources.Text.InitFailedLibmanJsonFileExists);
            }

            Manifest manifest = await Manifest.FromFileAsync(Settings.ManifestFileName, ManifestDependencies, cancellationToken);

            manifest.AddVersion(Manifest.SupportedVersions.Last().ToString());
            manifest.DefaultDestination = string.IsNullOrEmpty(defaultDestination) ? null : defaultDestination;

            defaultProvider = string.IsNullOrEmpty(defaultProvider)
                ? HostEnvironment.InputReader.GetUserInputWithDefault(nameof(settings.DefaultProvider), settings.DefaultProvider)
                : defaultProvider;

            if (ManifestDependencies.GetProvider(defaultProvider) == null)
            {
                IError unknownProviderError = PredefinedErrors.ProviderUnknown(defaultProvider);
                string message = string.Format(Resources.Text.InitFailedUnknownProvider, unknownProviderError.Code, unknownProviderError.Message);
                throw new InvalidOperationException(message);
            }

            manifest.DefaultProvider = defaultProvider;

            await manifest.SaveAsync(Settings.ManifestFileName, cancellationToken);

            return(manifest);
        }
Exemplo n.º 4
0
        public async Task CleanAsync_Success()
        {
            var manifest            = new Manifest(_dependencies);
            CancellationToken token = CancellationToken.None;

            IProvider provider = _dependencies.GetProvider("cdnjs");
            var       state1   = new LibraryInstallationState
            {
                Name            = "jquery",
                Version         = "3.1.1",
                ProviderId      = "cdnjs",
                DestinationPath = "lib",
                Files           = new[] { "jquery.js", "jquery.min.js" }
            };

            var state2 = new LibraryInstallationState
            {
                Name            = "knockout",
                Version         = "3.4.2",
                ProviderId      = "cdnjs",
                DestinationPath = "lib",
                Files           = new[] { "knockout-min.js" }
            };

            manifest.AddVersion("1.0");
            manifest.AddLibrary(state1);
            manifest.AddLibrary(state2);
            await manifest.RestoreAsync(token);

            string file1 = Path.Combine(_projectFolder, "lib", "jquery.js");
            string file2 = Path.Combine(_projectFolder, "lib", "jquery.min.js");
            string file3 = Path.Combine(_projectFolder, "lib", "knockout-min.js");

            Assert.IsTrue(File.Exists(file1));
            Assert.IsTrue(File.Exists(file2));
            Assert.IsTrue(File.Exists(file3));

            IEnumerable <ILibraryOperationResult> results = await manifest.CleanAsync((file) => _hostInteraction.DeleteFilesAsync(file, token), token);

            Assert.IsFalse(File.Exists(file1));
            Assert.IsFalse(File.Exists(file2));
            Assert.IsFalse(File.Exists(file3));
            Assert.IsTrue(results.Count() == 2);
            Assert.IsTrue(results.All(r => r.Success));
        }
Exemplo n.º 5
0
        public async Task CleanAsync_Success()
        {
            var manifest            = new Manifest(_dependencies);
            CancellationToken token = CancellationToken.None;

            IProvider provider = _dependencies.GetProvider("cdnjs");
            var       state1   = new LibraryInstallationState
            {
                LibraryId       = "[email protected]",
                ProviderId      = "cdnjs",
                DestinationPath = "lib",
                Files           = new[] { "jquery.js", "jquery.min.js" }
            };

            var state2 = new LibraryInstallationState
            {
                LibraryId       = "[email protected]",
                ProviderId      = "cdnjs",
                DestinationPath = "lib",
                Files           = new[] { "knockout-min.js" }
            };

            manifest.AddVersion("1.0");
            manifest.AddLibrary(state1);
            manifest.AddLibrary(state2);
            await manifest.RestoreAsync(token);

            string file1 = Path.Combine(_projectFolder, "lib", "jquery.js");
            string file2 = Path.Combine(_projectFolder, "lib", "jquery.min.js");
            string file3 = Path.Combine(_projectFolder, "lib", "knockout-min.js");

            Assert.IsTrue(File.Exists(file1));
            Assert.IsTrue(File.Exists(file2));
            Assert.IsTrue(File.Exists(file3));

            manifest.Clean((file) => { _hostInteraction.DeleteFile(file); });

            Assert.IsFalse(File.Exists(file1));
            Assert.IsFalse(File.Exists(file2));
            Assert.IsFalse(File.Exists(file3));
        }