public async Task TestDirectoryDeleteAsync() { await using var tmpDir = _baseFixture.WithDisposableTempDirectory(_snapFilesystem); var rootDirectory = _snapFilesystem.PathCombine(tmpDir.WorkingDirectory, "rootDirectory"); _snapFilesystem.DirectoryCreate(rootDirectory); var subDirectory = _snapFilesystem.PathCombine(rootDirectory, "subDirectory"); _snapFilesystem.DirectoryCreate(subDirectory); var testFile = _snapFilesystem.PathCombine(subDirectory, "mytEstFile.txt"); await _snapFilesystem.FileWriteUtf8StringAsync("yolo", testFile, default); await _snapFilesystem.DirectoryDeleteAsync(rootDirectory); Assert.False(_snapFilesystem.DirectoryExists(rootDirectory)); }
public async Task TestRestoreAsync_Checksums_Genesis() { var snapAppsReleases = new SnapAppsReleases(); var genesisSnapApp = _baseFixturePackaging.BuildSnapApp(); var snapAppChannel = genesisSnapApp.GetDefaultChannelOrThrow(); using var rootDirectory = new DisposableDirectory(_baseFixturePackaging.WorkingDirectory, _snapFilesystem); using var restoreDirectory = new DisposableDirectory(_baseFixturePackaging.WorkingDirectory, _snapFilesystem); using var nugetPackageSourcesDirectory = _snapFilesystem.WithDisposableTempDirectory(_baseFixturePackaging.WorkingDirectory); using var genesisReleaseBuilder = _baseFixturePackaging.WithSnapReleaseBuilder(rootDirectory, snapAppsReleases, genesisSnapApp, _releaseBuilderContext); var packagesDirectory = _snapFilesystem.PathCombine(restoreDirectory.WorkingDirectory, "packages"); _snapFilesystem.DirectoryCreate(packagesDirectory); var nugetPackageSources = genesisSnapApp.BuildNugetSources(nugetPackageSourcesDirectory.WorkingDirectory); var packageSource = nugetPackageSources.Items.Single(); genesisReleaseBuilder .AddNuspecItem(_baseFixturePackaging.BuildSnapExecutable(genesisSnapApp)) .AddSnapDll(); using var genesisPackageContext = await _baseFixturePackaging.BuildPackageAsync(genesisReleaseBuilder); var snapAppChannelReleases = snapAppsReleases.GetReleases(genesisSnapApp, snapAppChannel); var progressSourceMock = new Mock <ISnapPackageManagerProgressSource>(); progressSourceMock.Setup(x => x.RaiseChecksumProgress( It.IsAny <int>(), It.IsAny <long>(), It.IsAny <long>(), It.IsAny <long>())); var genesisPackageAbsolutePath = _snapFilesystem.PathCombine(packagesDirectory, genesisPackageContext.FullPackageSnapRelease.Filename); await _snapFilesystem.FileCopyAsync(genesisPackageContext.FullPackageAbsolutePath, genesisPackageAbsolutePath, default); var restoreSummary = await _snapPackageManager.RestoreAsync(packagesDirectory, snapAppChannelReleases, packageSource, SnapPackageManagerRestoreType.Default, progressSourceMock.Object); progressSourceMock.Verify(x => x.RaiseChecksumProgress( It.Is <int>(v => v == 0), It.Is <long>(v => v == 0), It.Is <long>(v => v == 0), It.Is <long>(v => v == 1)), Times.Once); progressSourceMock.Verify(x => x.RaiseChecksumProgress( It.Is <int>(v => v == 100), It.Is <long>(v => v == 1), It.Is <long>(v => v == 1), It.Is <long>(v => v == 1)), Times.Once); Assert.Equal(SnapPackageManagerRestoreType.Default, restoreSummary.RestoreType); Assert.Single(restoreSummary.ChecksumSummary); Assert.True(restoreSummary.ChecksumSummary[0].Ok); Assert.Equal(genesisPackageContext.FullPackageSnapRelease.Filename, restoreSummary.ChecksumSummary[0].SnapRelease.Filename); Assert.Empty(restoreSummary.DownloadSummary); Assert.Empty(restoreSummary.ReassembleSummary); Assert.True(restoreSummary.Success); using var packageArchiveReader = new PackageArchiveReader(genesisPackageAbsolutePath); Assert.Equal(genesisPackageContext.FullPackageSnapRelease.BuildPackageIdentity(), packageArchiveReader.GetIdentity()); Assert.Equal(genesisPackageContext.FullPackageSnapRelease.FullSha256Checksum, _snapCryptoProvider.Sha256(genesisPackageContext.FullPackageSnapRelease, packageArchiveReader, _snapPack)); }