Example #1
0
        public NuGetMachineWidePackageSources([NotNull] ISnapFilesystem filesystem, [NotNull] string workingDirectory)
        {
            if (filesystem == null)
            {
                throw new ArgumentNullException(nameof(filesystem));
            }
            if (workingDirectory == null)
            {
                throw new ArgumentNullException(nameof(workingDirectory));
            }

            var nugetMachineWideSettings = new NuGetMachineWideSettings(filesystem, workingDirectory);

            var nugetConfigAbsolutePath = filesystem.DirectoryGetAllFiles(workingDirectory)
                                          .FirstOrDefault(x => x.EndsWith("nuget.config", StringComparison.OrdinalIgnoreCase));

            var packageSources = new List <PackageSource>();

            if (nugetConfigAbsolutePath != null)
            {
                var nugetConfigReader = new NuGetConfigFileReader();
                foreach (var packageSource in nugetConfigReader.ReadNugetSources(workingDirectory).Where(x => x.IsEnabled))
                {
                    if (!packageSources.Contains(packageSource))
                    {
                        packageSources.Add(packageSource);
                    }
                }
            }
            else
            {
                var packageSourceProvider = new PackageSourceProvider(nugetMachineWideSettings.Settings);
                packageSources = packageSourceProvider.LoadPackageSources().Where(x => x.IsEnabled).ToList();
            }

            Items    = packageSources;
            Settings = nugetMachineWideSettings.Settings;
        }
Example #2
0
        public async Task TestInstall_Offline_Using_Local_PackageSource()
        {
            await using var specialFoldersAnyOs = new SnapOsSpecialFoldersUnitTest(_snapFilesystem, _baseFixturePackaging.WorkingDirectory);
            await using var packagesDirectory   = new DisposableDirectory(specialFoldersAnyOs.WorkingDirectory, _snapFilesystem);
            using var cts = new CancellationTokenSource();

            SetupSnapOsMock(specialFoldersAnyOs);

            var snapInstallerIoEnvironment = new SnapInstallerIoEnvironment
            {
                WorkingDirectory        = specialFoldersAnyOs.WorkingDirectory,
                ThisExeWorkingDirectory = specialFoldersAnyOs.WorkingDirectory,
                SpecialFolders          = specialFoldersAnyOs,
            };

            var snapAppsReleases = new SnapAppsReleases();
            var genesisSnapApp   = _baseFixturePackaging.BuildSnapApp(localPackageSourceDirectory: packagesDirectory);

            Assert.True(genesisSnapApp.Channels.Count >= 2);

            using var genesisSnapReleaseBuilder = _baseFixturePackaging.WithSnapReleaseBuilder(packagesDirectory, snapAppsReleases, genesisSnapApp, _snapReleaseBuilderContext);
            var mainAssemblyDefinition = _baseFixturePackaging.BuildSnapExecutable(genesisSnapApp);

            genesisSnapReleaseBuilder
            .AddNuspecItem(mainAssemblyDefinition)
            .AddSnapDll();

            using var genesisPackageContext = await _baseFixturePackaging.BuildPackageAsync(genesisSnapReleaseBuilder, cts.Token);

            var releasesFilename   = _snapFilesystem.PathCombine(snapInstallerIoEnvironment.ThisExeWorkingDirectory, genesisPackageContext.FullPackageSnapApp.BuildNugetReleasesFilename());
            var snapAppDllFilename = _snapFilesystem.PathCombine(snapInstallerIoEnvironment.ThisExeWorkingDirectory, SnapConstants.SnapAppDllFilename);
            var setupNupkgFilename = _snapFilesystem.PathCombine(snapInstallerIoEnvironment.ThisExeWorkingDirectory, SnapConstants.SetupNupkgFilename);

            await using var releasePackageMemoryStream = _snapPack.BuildReleasesPackage(genesisSnapApp, snapAppsReleases);

            await _snapFilesystem.FileWriteAsync(genesisPackageContext.FullPackageMemoryStream, setupNupkgFilename, cts.Token);

            await _snapFilesystem.FileWriteAsync(releasePackageMemoryStream, releasesFilename, cts.Token);

            using var snapAppDllAssemblyDefinition = _snapAppWriter.BuildSnapAppAssembly(genesisSnapApp);
            snapAppDllAssemblyDefinition.Write(snapAppDllFilename);

            var(exitCode, installerType) = await Program.MainImplAsync(new[] { "--headless" }, LogLevel.Info, cts, _snapOsMock.Object, x =>
            {
                x.Register <ISnapInstallerIoEnvironment>(_ => snapInstallerIoEnvironment);
                return((ISnapInstallerEnvironment)x.GetInstance(typeof(ISnapInstallerEnvironment)));
            });

            Assert.Equal(0, exitCode);
            Assert.Equal(SnapInstallerType.Offline, installerType);

            var appInstallDirectory = _snapInstaller.GetApplicationDirectory(
                _snapFilesystem.PathCombine(specialFoldersAnyOs.LocalApplicationData, genesisSnapApp.Id), genesisSnapApp.Version);

            var files = _snapFilesystem.DirectoryGetAllFiles(appInstallDirectory).OrderBy(x => x, new OrdinalIgnoreCaseComparer()).ToList();

            Assert.Equal(3, files.Count);
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Assert.EndsWith($"{genesisSnapApp.Id}.exe", files[0]);
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                Assert.EndsWith(genesisSnapApp.Id, files[0]);
            }
            else
            {
                throw new PlatformNotSupportedException();
            }
            Assert.EndsWith(SnapConstants.SnapAppDllFilename, files[1]);
            Assert.EndsWith(SnapConstants.SnapDllFilename, files[2]);
        }