Beispiel #1
0
        public Package CreatePackage(string key, Stream packageFileStream, string fileExtension, bool isInPlaceUpdate, string externalPackageUri)
        {
            string  tempPath = GenerateNewTempPath();
            Package package;

            try
            {
                package = ExtractPackage(packageFileStream, tempPath);
                if (!_packageIdValidator.IsValidPackageId(package.Id))
                {
                    throw new InvalidPackageIdException(package.Id);
                }
                _packageUriValidator.ValidatePackageUris(package);
                _packageAuthenticator.EnsureKeyCanAccessPackage(key, package.Id, package.Version);
                GenerateHash(tempPath, package);
                if (string.IsNullOrWhiteSpace(package.Summary))
                {
                    package.Summary = package.Description;
                }

                if (!isInPlaceUpdate)
                {
                    CreateNewPackage(tempPath, package, externalPackageUri, fileExtension);
                }
                else
                {
                    UpdatePackageInPlace(tempPath, package, externalPackageUri, fileExtension);
                }
            }
            finally
            {
                _fileSystem.DeleteFileIfItExists(tempPath);
            }
            return(package);
        }
Beispiel #2
0
        public void ShouldThrowWhenGivenNullPackage()
        {
            Package nullPackage = null;

            TestDelegate methodThatShouldThrow = () => _packageUriValidator.ValidatePackageUris(nullPackage);

            Assert.Throws <ArgumentNullException>(methodThatShouldThrow);
        }
Beispiel #3
0
 public void UpdateExistingPackage(Package packageToUpdate)
 {
     _packageUriValidator.ValidatePackageUris(packageToUpdate);
     _latestVersionUpdater.SetLatestVersionFlagsOfOtherVersionablesWithSameId(packageToUpdate);
     _packageRepository.Update(packageToUpdate);
 }