コード例 #1
0
 public SnapEmbeddedResourcesTests(BaseFixture baseFixture)
 {
     _coreRunLibMock        = new Mock <ICoreRunLib>();
     _baseFixture           = baseFixture;
     _snapCryptoProvider    = new SnapCryptoProvider();
     _snapFilesystem        = new SnapFilesystem();
     _snapEmbeddedResources = new SnapEmbeddedResources();
 }
コード例 #2
0
ファイル: BaseFixturePackaging.cs プロジェクト: peters/snapx
 public SnapReleaseBuilderContext([NotNull] ICoreRunLib coreRunLib, [NotNull] ISnapFilesystem snapFilesystem,
                                  [NotNull] ISnapCryptoProvider snapCryptoProvider, [NotNull] ISnapEmbeddedResources snapEmbeddedResources,
                                  [NotNull] ISnapPack snapPack)
 {
     CoreRunLib            = coreRunLib ?? throw new ArgumentNullException(nameof(coreRunLib));
     SnapFilesystem        = snapFilesystem ?? throw new ArgumentNullException(nameof(snapFilesystem));
     SnapCryptoProvider    = snapCryptoProvider ?? throw new ArgumentNullException(nameof(snapCryptoProvider));
     SnapEmbeddedResources = snapEmbeddedResources ?? throw new ArgumentNullException(nameof(snapEmbeddedResources));
     SnapPack = snapPack ?? throw new ArgumentNullException(nameof(snapPack));
 }
コード例 #3
0
 public NugetServiceV3Tests(BaseFixture baseFixture)
 {
     _baseFixture           = baseFixture;
     _coreRunLibMock        = new Mock <ICoreRunLib>();
     _snapEmbeddedResources = new SnapEmbeddedResources();
     _snapCryptoProvider    = new SnapCryptoProvider();
     _snapFilesystem        = new SnapFilesystem();
     _nugetService          = new NugetService(_snapFilesystem, new NugetLogger(new LogProvider.NoOpLogger()));
     _snapPack = new SnapPack(_snapFilesystem, new SnapAppReader(), new SnapAppWriter(), _snapCryptoProvider, new SnapEmbeddedResources());
 }
コード例 #4
0
 public SnapCryptoProviderTests(BaseFixturePackaging baseFixture)
 {
     _baseFixture               = baseFixture;
     _snapCryptoProvider        = new SnapCryptoProvider();
     _snapOs                    = SnapOs.AnyOs;
     _snapAppReader             = new SnapAppReader();
     _snapAppWriter             = new SnapAppWriter();
     _snapEmbeddedResources     = new SnapEmbeddedResources();
     _snapPack                  = new SnapPack(_snapOs.Filesystem, _snapAppReader, _snapAppWriter, _snapCryptoProvider, _snapEmbeddedResources);
     _coreRunLibMock            = new Mock <ICoreRunLib>();
     _snapReleaseBuilderContext = new SnapReleaseBuilderContext(_coreRunLibMock.Object, _snapOs.Filesystem, _snapCryptoProvider, _snapEmbeddedResources, _snapPack);
 }
コード例 #5
0
 public SnapUpdateManagerTests(BaseFixture baseFixture, BaseFixturePackaging baseFixturePackaging, BaseFixtureNuget baseFixtureNuget)
 {
     _baseFixture           = baseFixture;
     _baseFixturePackaging  = baseFixturePackaging;
     _baseFixtureNuget      = baseFixtureNuget;
     _coreRunLibMock        = new Mock <ICoreRunLib>();
     _nugetServiceMock      = new Mock <INugetService>();
     _snapHttpClientMock    = new Mock <ISnapHttpClient>();
     _snapCryptoProvider    = new SnapCryptoProvider();
     _snapEmbeddedResources = new SnapEmbeddedResources();
     _snapOs                = SnapOs.AnyOs;
     _snapAppWriter         = new SnapAppWriter();
     _snapPack              = new SnapPack(_snapOs.Filesystem, new SnapAppReader(), new SnapAppWriter(), _snapCryptoProvider, _snapEmbeddedResources);
     _snapExtractor         = new SnapExtractor(_snapOs.Filesystem, _snapPack, _snapEmbeddedResources);
     _snapInstaller         = new SnapInstaller(_snapExtractor, _snapPack, _snapOs, _snapEmbeddedResources, _snapAppWriter);
     _releaseBuilderContext = new SnapReleaseBuilderContext(_coreRunLibMock.Object, _snapOs.Filesystem,
                                                            _snapCryptoProvider, _snapEmbeddedResources, _snapPack);
 }
コード例 #6
0
ファイル: SnapInstallerTests.cs プロジェクト: peters/snapx
        public SnapInstallerTests(BaseFixturePackaging baseFixture)
        {
            _baseFixture    = baseFixture;
            _snapOsMock     = new Mock <ISnapOs>();
            _coreRunLibMock = new Mock <ICoreRunLib>();

            _snapCryptoProvider    = new SnapCryptoProvider();
            _snapAppReader         = new SnapAppReader();
            _snapAppWriter         = new SnapAppWriter();
            _snapEmbeddedResources = new SnapEmbeddedResources();
            _snapFilesystem        = new SnapFilesystem();
            _snapOsProcessManager  = new SnapOsProcessManager();
            _snapPack = new SnapPack(_snapFilesystem, _snapAppReader, _snapAppWriter, _snapCryptoProvider, _snapEmbeddedResources);

            var snapExtractor = new SnapExtractor(_snapFilesystem, _snapPack, _snapEmbeddedResources);

            _snapInstaller             = new SnapInstaller(snapExtractor, _snapPack, _snapOsMock.Object, _snapEmbeddedResources, _snapAppWriter);
            _snapReleaseBuilderContext = new SnapReleaseBuilderContext(_coreRunLibMock.Object, _snapFilesystem, _snapCryptoProvider, _snapEmbeddedResources, _snapPack);
        }
コード例 #7
0
 public SnapUpdateManagerTests(BaseFixture baseFixture, BaseFixturePackaging baseFixturePackaging, BaseFixtureNuget baseFixtureNuget, ITestOutputHelper testOutputHelper)
 {
     _baseFixture           = baseFixture;
     _baseFixturePackaging  = baseFixturePackaging;
     _baseFixtureNuget      = baseFixtureNuget;
     _testOutputHelper      = testOutputHelper;
     _coreRunLibMock        = new Mock <ICoreRunLib>();
     _nugetServiceMock      = new Mock <INugetService>();
     _snapHttpClientMock    = new Mock <ISnapHttpClient>();
     _snapCryptoProvider    = new SnapCryptoProvider();
     _snapEmbeddedResources = new SnapEmbeddedResources();
     _snapFilesystem        = new SnapFilesystem();
     _snapAppWriter         = new SnapAppWriter();
     _snapPack = new SnapPack(_snapFilesystem, new SnapAppReader(),
                              new SnapAppWriter(), _snapCryptoProvider, _snapEmbeddedResources, new SnapBinaryPatcher());
     _snapOs                = new SnapOs(_snapFilesystem, new SnapOsProcessManager(), _baseFixturePackaging.WorkingDirectory, true);
     _snapExtractor         = new SnapExtractor(_snapFilesystem, _snapPack, _snapEmbeddedResources);
     _snapInstaller         = new SnapInstaller(_snapExtractor, _snapPack, _snapOs, _snapEmbeddedResources, _snapAppWriter);
     _releaseBuilderContext = new SnapReleaseBuilderContext(_coreRunLibMock.Object, _snapFilesystem,
                                                            _snapCryptoProvider, _snapEmbeddedResources, _snapPack);
 }
コード例 #8
0
        static int MainAsync([NotNull] string[] args,
                             [NotNull] CoreRunLib coreRunLib,
                             [NotNull] ISnapOs snapOs, [NotNull] ISnapExtractor snapExtractor,
                             [NotNull] ISnapFilesystem snapFilesystem,
                             [NotNull] ISnapAppReader snapAppReader,
                             [NotNull] ISnapCryptoProvider snapCryptoProvider,
                             [NotNull] ISnapPack snapPack,
                             [NotNull] ISnapAppWriter snapAppWriter,
                             [NotNull] SnapxEmbeddedResources snapXEmbeddedResources,
                             [NotNull] SnapPackageManager snapPackageManager,
                             [NotNull] ISnapNetworkTimeProvider snapNetworkTimeProvider,
                             [NotNull] INugetService nugetServiceCommandPack,
                             [NotNull] INugetService nugetServiceCommandPromote,
                             [NotNull] INugetService nugetServiceCommandDemote,
                             INugetService nugetServiceCommandRestore,
                             [NotNull] INugetService nugetServiceNoopLogger,
                             [NotNull] IDistributedMutexClient distributedMutexClient,
                             [NotNull] string toolWorkingDirectory,
                             [NotNull] string workingDirectory,
                             CancellationToken cancellationToken)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }
            if (coreRunLib == null)
            {
                throw new ArgumentNullException(nameof(coreRunLib));
            }
            if (snapOs == null)
            {
                throw new ArgumentNullException(nameof(snapOs));
            }
            if (snapExtractor == null)
            {
                throw new ArgumentNullException(nameof(snapExtractor));
            }
            if (snapFilesystem == null)
            {
                throw new ArgumentNullException(nameof(snapFilesystem));
            }
            if (snapAppReader == null)
            {
                throw new ArgumentNullException(nameof(snapAppReader));
            }
            if (snapCryptoProvider == null)
            {
                throw new ArgumentNullException(nameof(snapCryptoProvider));
            }
            if (snapPack == null)
            {
                throw new ArgumentNullException(nameof(snapPack));
            }
            if (snapAppWriter == null)
            {
                throw new ArgumentNullException(nameof(snapAppWriter));
            }
            if (snapXEmbeddedResources == null)
            {
                throw new ArgumentNullException(nameof(snapXEmbeddedResources));
            }
            if (snapPackageManager == null)
            {
                throw new ArgumentNullException(nameof(snapPackageManager));
            }
            if (snapNetworkTimeProvider == null)
            {
                throw new ArgumentNullException(nameof(snapNetworkTimeProvider));
            }
            if (nugetServiceCommandPromote == null)
            {
                throw new ArgumentNullException(nameof(nugetServiceCommandPromote));
            }
            if (nugetServiceNoopLogger == null)
            {
                throw new ArgumentNullException(nameof(nugetServiceNoopLogger));
            }
            if (distributedMutexClient == null)
            {
                throw new ArgumentNullException(nameof(distributedMutexClient));
            }
            if (toolWorkingDirectory == null)
            {
                throw new ArgumentNullException(nameof(toolWorkingDirectory));
            }
            if (workingDirectory == null)
            {
                throw new ArgumentNullException(nameof(workingDirectory));
            }

            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            return(Parser
                   .Default
                   .ParseArguments <DemoteOptions, PromoteOptions, PackOptions, Sha256Options, RcEditOptions, ListOptions, RestoreOptions, LockOptions>(args)
                   .MapResult(
                       (DemoteOptions opts) =>
            {
                var nuGetPackageSources = BuildNuGetPackageSources(snapFilesystem, SnapDemoteLogger);
                if (nuGetPackageSources == null)
                {
                    return 1;
                }
                return CommandDemoteAsync(opts, snapFilesystem, snapAppReader, snapAppWriter,
                                          nuGetPackageSources, nugetServiceCommandDemote, distributedMutexClient, snapPackageManager, snapPack,
                                          snapNetworkTimeProvider, snapExtractor, snapOs, snapXEmbeddedResources, coreRunLib,
                                          SnapDemoteLogger, workingDirectory, cancellationToken).GetAwaiter().GetResult();
            },
                       (PromoteOptions opts) =>
            {
                var nuGetPackageSources = BuildNuGetPackageSources(snapFilesystem, SnapPromoteLogger);
                if (nuGetPackageSources == null)
                {
                    return 1;
                }
                return CommandPromoteAsync(opts, snapFilesystem, snapAppReader, snapAppWriter,
                                           nuGetPackageSources, nugetServiceCommandPromote, distributedMutexClient, snapPackageManager, snapPack,
                                           snapOs.SpecialFolders,
                                           snapNetworkTimeProvider, snapExtractor, snapOs, snapXEmbeddedResources, coreRunLib,
                                           SnapPromoteLogger, workingDirectory, cancellationToken).GetAwaiter().GetResult();
            },
                       (PackOptions opts) =>
            {
                var nuGetPackageSources = BuildNuGetPackageSources(snapFilesystem, SnapPackLogger);
                if (nuGetPackageSources == null)
                {
                    return 1;
                }
                return CommandPackAsync(opts, snapFilesystem, snapAppReader, snapAppWriter,
                                        nuGetPackageSources, snapPack, nugetServiceCommandPack, snapOs, snapXEmbeddedResources,
                                        snapExtractor, snapPackageManager, coreRunLib,
                                        snapNetworkTimeProvider, SnapPackLogger, distributedMutexClient,
                                        workingDirectory, cancellationToken).GetAwaiter().GetResult();
            },
                       (Sha256Options opts) => CommandSha256(opts, snapFilesystem, snapCryptoProvider, SnapLogger),
                       (RcEditOptions opts) => CommandRcEdit(opts, coreRunLib, snapFilesystem, SnapLogger),
                       (ListOptions opts) =>
            {
                var nuGetPackageSources = BuildNuGetPackageSources(snapFilesystem, SnapListLogger);
                if (nuGetPackageSources == null)
                {
                    return 1;
                }
                return CommandListAsync(opts, snapFilesystem, snapAppReader,
                                        nuGetPackageSources, nugetServiceNoopLogger, snapExtractor, SnapListLogger,
                                        workingDirectory, cancellationToken).GetAwaiter().GetResult();
            },
                       (RestoreOptions opts) =>
            {
                var nuGetPackageSources = BuildNuGetPackageSources(snapFilesystem, SnapRestoreLogger);
                if (nuGetPackageSources == null)
                {
                    return 1;
                }
                return CommandRestoreAsync(opts, snapFilesystem, snapAppReader, snapAppWriter,
                                           nuGetPackageSources, snapPackageManager, snapOs,
                                           snapXEmbeddedResources, coreRunLib, snapPack,
                                           SnapRestoreLogger, workingDirectory, cancellationToken).GetAwaiter().GetResult();
            },
                       (LockOptions opts) => CommandLock(opts, distributedMutexClient, snapFilesystem, snapAppReader, SnapLockLogger, workingDirectory, cancellationToken).GetAwaiter().GetResult(),
                       errs =>
            {
                snapOs.EnsureConsole();
                return 0;
            }));
        }
コード例 #9
0
        static int CommandSha256([NotNull] Sha256Options sha256Options, [NotNull] ISnapFilesystem snapFilesystem, [NotNull] ISnapCryptoProvider snapCryptoProvider, [NotNull] ILog logger)
        {
            if (sha256Options == null)
            {
                throw new ArgumentNullException(nameof(sha256Options));
            }
            if (snapFilesystem == null)
            {
                throw new ArgumentNullException(nameof(snapFilesystem));
            }
            if (snapCryptoProvider == null)
            {
                throw new ArgumentNullException(nameof(snapCryptoProvider));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (sha256Options.Filename == null || !snapFilesystem.FileExists(sha256Options.Filename))
            {
                logger.Error($"File not found: {sha256Options.Filename}");
                return(1);
            }

            try
            {
                using var fileStream = new FileStream(sha256Options.Filename, FileMode.Open, FileAccess.Read);
                logger.Info(snapCryptoProvider.Sha256(fileStream));
                return(0);
            }
            catch (Exception e)
            {
                logger.ErrorException($"Error computing SHA256-checksum for filename: {sha256Options.Filename}", e);
                return(1);
            }
        }