public void AddPackageFromStream_WhenDuplicateAndOverwriteEnabled() { // Arrange var fileSystem = new PhysicalFileSystem(tmpDir.Path); var repository = new ExpandedPackageRepository(fileSystem); var package = CreateMyPackage(); using (var packageStream = File.OpenRead(package.Path)) { var addedPackage = repository.AddPackage(packageStream, true); AssertMyPackage(fileSystem, package, addedPackage); } using (var packageStream = File.OpenRead(package.Path)) { var addedPackage = repository.AddPackage(packageStream, true); AssertMyPackage(fileSystem, package, addedPackage); } }
public async Task Remove_SupportsEnabledUnlisting() { // Arrange using (var directory = new TemporaryDirectory()) { var fileSystem = new PhysicalFileSystem(directory); var repository = new ExpandedPackageRepository(fileSystem); var logger = new Infrastructure.NullLogger(); repository.AddPackage(CreatePackage(PackageId, PackageVersion)); var target = new ServerPackageStore(fileSystem, repository, logger); // Act target.Remove(PackageId, PackageVersion, enableDelisting: true); // Assert var package = (await target.GetAllAsync(enableDelisting: true, token: Token)).SingleOrDefault(); Assert.NotNull(package); Assert.Equal(PackageId, package.Id); Assert.Equal(PackageVersion, package.Version); Assert.False(package.Listed); var fileInfo = new FileInfo(package.FullPath); Assert.True(fileInfo.Exists); Assert.Equal(FileAttributes.Hidden, fileInfo.Attributes & FileAttributes.Hidden); } }
public void AddPackageFromStream_WhenDuplicateAndOverwriteDisabled() { // Arrange var fileSystem = new PhysicalFileSystem(tmpDir.Path); var repository = new ExpandedPackageRepository(fileSystem); var package = CreateMyPackage(); using (var packageStream = File.OpenRead(package.Path)) { var addedPackage = repository.AddPackage(packageStream, false); AssertMyPackage(fileSystem, package, addedPackage); } // add again using (var packageStream = File.OpenRead(package.Path)) { Assert.Throws <PackageDuplicateException>(() => repository.AddPackage(packageStream, false)); } }
public void AddPackage_AddsExpandedPackageToThePackageDirectory() { // Arrange var fileSystem = new PhysicalFileSystem(tmpDir.Path); var repository = new ExpandedPackageRepository(fileSystem); var package = CreateMyPackage(); // Act var addedPackage = repository.AddPackage(package); AssertMyPackage(fileSystem, package, addedPackage); }
public void AddPackageFromStream_AddsExpandedPackageToThePackageDirectory(bool allowOverwrite) { // Arrange var fileSystem = new PhysicalFileSystem(tmpDir.Path); var repository = new ExpandedPackageRepository(fileSystem); var package = CreateMyPackage(); using (var packageStream = File.OpenRead(package.Path)) { // Act var addedPackage = repository.AddPackage(packageStream, allowOverwrite); AssertMyPackage(fileSystem, package, addedPackage); } }
public void AddPackage_AddsExpandedPackageToThePackageDirectory() { // Arrange var fileSystem = new MockFileSystem(); var repository = new ExpandedPackageRepository(fileSystem); var package = GetPackage(); // Act repository.AddPackage(package); // Assert var reader = Manifest.ReadFrom(fileSystem.OpenFile(@"MyPackage\1.0.0-beta2\MyPackage.nuspec"), validateSchema: true); Assert.Equal("MyPackage", reader.Metadata.Id); Assert.Equal("1.0.0-beta2", reader.Metadata.Version); Assert.True(package.GetStream().ContentEquals(fileSystem.OpenFile(@"MyPackage\1.0.0-beta2\MyPackage.1.0.0-beta2.nupkg"))); Assert.Equal(package.GetHash(new CryptoHashProvider()), fileSystem.ReadAllText(@"MyPackage\1.0.0-beta2\MyPackage.1.0.0-beta2.nupkg.sha512")); }
public async Task Remove_SupportsDisabledUnlisting() { // Arrange using (var directory = new TemporaryDirectory()) { var fileSystem = new PhysicalFileSystem(directory); var repository = new ExpandedPackageRepository(fileSystem); var logger = new Infrastructure.NullLogger(); repository.AddPackage(CreatePackage(PackageId, PackageVersion)); var target = new ServerPackageStore(fileSystem, repository, logger); // Act target.Remove(PackageId, PackageVersion, enableDelisting: false); // Assert Assert.Empty(await target.GetAllAsync(enableDelisting: false, token: Token)); Assert.Empty(repository.GetPackages()); } }
public async Task Remove_NoOpsWhenPackageDoesNotExist() { // Arrange using (var directory = new TemporaryDirectory()) { var fileSystem = new PhysicalFileSystem(directory); var repository = new ExpandedPackageRepository(fileSystem); var logger = new Infrastructure.NullLogger(); repository.AddPackage(CreatePackage(PackageId, PackageVersion)); var target = new ServerPackageStore(fileSystem, repository, logger); // Act target.Remove("Foo", PackageVersion, enableDelisting: false); // Assert var package = (await target.GetAllAsync(enableDelisting: false, token: Token)).FirstOrDefault(); Assert.NotNull(package); Assert.Equal(PackageId, package.Id); Assert.Equal(PackageVersion, package.Version); Assert.True(package.Listed); } }
private void AddPackagesFromDropFolder() { _logger.Log(LogLevel.Info, "Start adding packages from drop folder."); MonitorFileSystem(false); try { var serverPackages = new HashSet <ServerPackage>(PackageEqualityComparer.IdAndVersion); foreach (var packageFile in _fileSystem.GetFiles(_fileSystem.Root, "*.nupkg", false)) { try { // Create package var package = new OptimizedZipPackage(_fileSystem, packageFile); // Is it a symbols package? if (IgnoreSymbolsPackages && package.IsSymbolsPackage()) { var message = string.Format(Strings.Error_SymbolsPackagesIgnored, package); _logger.Log(LogLevel.Error, message); continue; } // Allow overwriting package? If not, skip this one. if (!AllowOverrideExistingPackageOnPush && _expandedPackageRepository.FindPackage(package.Id, package.Version) != null) { var message = string.Format(Strings.Error_PackageAlreadyExists, package); _logger.Log(LogLevel.Error, message); continue; } // Copy to correct filesystem location _expandedPackageRepository.AddPackage(package); _fileSystem.DeleteFile(packageFile); // Mark for addition to metadata store serverPackages.Add(CreateServerPackage(package, EnableDelisting)); } catch (UnauthorizedAccessException ex) { // The file may be in use (still being copied) - ignore the error _logger.Log(LogLevel.Error, "Error adding package file {0} from drop folder: {1}", packageFile, ex.Message); } catch (IOException ex) { // The file may be in use (still being copied) - ignore the error _logger.Log(LogLevel.Error, "Error adding package file {0} from drop folder: {1}", packageFile, ex.Message); } } // Add packages to metadata store in bulk _serverPackageStore.StoreRange(serverPackages); _serverPackageStore.PersistIfDirty(); _logger.Log(LogLevel.Info, "Finished adding packages from drop folder."); } finally { OptimizedZipPackage.PurgeCache(); MonitorFileSystem(true); } }
public ServerPackage Add(IPackage package, bool enableDelisting) { _repository.AddPackage(package); return(CreateServerPackage(package, enableDelisting)); }