Esempio n. 1
0
            public async Task DeletesLicenseFromPublicStorageOnDbUpdateFailure(EmbeddedLicenseFileType licenseFileType, PackageStatus originalStatus, bool expectedDelete)
            {
                Package.PackageStatusKey    = originalStatus;
                Package.EmbeddedLicenseType = licenseFileType;

                var expected = new Exception("Everything failed");

                PackageServiceMock
                .Setup(ps => ps.UpdateStatusAsync(Package, PackageStatus.Available, true))
                .Throws(expected);

                var actual = await Assert.ThrowsAsync <Exception>(
                    () => Target.SetStatusAsync(PackageValidatingEntity, ValidationSet, PackageStatus.Available));

                Assert.Same(expected, actual);

                if (expectedDelete)
                {
                    CoreLicenseFileServiceMock
                    .Verify(clfs => clfs.DeleteLicenseFileAsync(Package.Id, Package.NormalizedVersion), Times.Once);
                    CoreLicenseFileServiceMock
                    .Verify(clfs => clfs.DeleteLicenseFileAsync(It.IsAny <string>(), It.IsAny <string>()), Times.Once);
                }
                else
                {
                    CoreLicenseFileServiceMock
                    .Verify(clfs => clfs.DeleteLicenseFileAsync(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
                }
            }
Esempio n. 2
0
            public async Task SavesPackageLicenseFileWhenPresent(EmbeddedLicenseFileType licenseFileType, bool expectedSave)
            {
                var content = "Hello, world.";
                var stream  = new MemoryStream(Encoding.ASCII.GetBytes(content));

                Package.EmbeddedLicenseType = licenseFileType;
                PackageFileServiceMock
                .Setup(x => x.DownloadPackageFileToDiskAsync(ValidationSet))
                .ReturnsAsync(stream);

                await Target.SetStatusAsync(PackageValidatingEntity, ValidationSet, PackageStatus.Available);

                if (expectedSave)
                {
                    CoreLicenseFileServiceMock
                    .Verify(clfs => clfs.ExtractAndSaveLicenseFileAsync(PackageValidatingEntity.EntityRecord, stream), Times.Once);
                    CoreLicenseFileServiceMock
                    .Verify(clfs => clfs.ExtractAndSaveLicenseFileAsync(It.IsAny <Package>(), It.IsAny <Stream>()), Times.Once);
                }
                else
                {
                    CoreLicenseFileServiceMock
                    .Verify(clfs => clfs.ExtractAndSaveLicenseFileAsync(It.IsAny <Package>(), It.IsAny <Stream>()), Times.Never);
                }
            }
            public void SetsLicenseUrlToGalleryWhenPackageHasLicenseFile(EmbeddedLicenseFileType type)
            {
                var package = Data.PackageEntity;

                package.EmbeddedLicenseType = type;

                var document = _target.FullFromDb(Data.PackageId, Data.HijackDocumentChanges, package);

                Assert.Equal(Data.GalleryLicenseUrl, document.LicenseUrl);
            }
Esempio n. 4
0
            public async Task WillThrowIfPackageIsMissingPackageRegistration(EmbeddedLicenseFileType licenseFileType)
            {
                var service = CreateService();
                var package = new Package {
                    PackageRegistration = null, EmbeddedLicenseType = licenseFileType
                };

                var ex = await Assert.ThrowsAsync <ArgumentException>(() => service.SaveLicenseFileAsync(package, Stream.Null));

                Assert.StartsWith("The package is missing required data.", ex.Message);
                Assert.Equal("package", ex.ParamName);
            }
Esempio n. 5
0
            public async Task WillThrowIfPackageIsMissingNormalizedVersionAndVersion(EmbeddedLicenseFileType licenseFileType)
            {
                var service             = CreateService();
                var packageRegistration = new PackageRegistration {
                    Id = "theId"
                };
                var package = new Package {
                    PackageRegistration = packageRegistration, NormalizedVersion = null, Version = null, EmbeddedLicenseType = licenseFileType
                };

                var ex = await Assert.ThrowsAsync <ArgumentException>(
                    () => service.DownloadLicenseFileAsync(package));

                Assert.StartsWith("The package is missing required data.", ex.Message);
                Assert.Equal("package", ex.ParamName);
            }
Esempio n. 6
0
        public void ItInitializesLicenseFileTypeAndLicenseExpression(EmbeddedLicenseFileType embeddedLicenseType, string licenseExpression)
        {
            // arrange
            var package = new Package
            {
                Version             = "1.0.0",
                EmbeddedLicenseType = embeddedLicenseType,
                LicenseExpression   = licenseExpression,
            };

            // act
            var model = new DisplayLicenseViewModel(package, licenseExpressionSegments: null, licenseFileContents: null);

            // assert
            Assert.Equal(embeddedLicenseType, model.EmbeddedLicenseType);
            Assert.Equal(licenseExpression, model.LicenseExpression);
        }
Esempio n. 7
0
            public void SetsLicenseUrlToGalleryWhenPackageHasLicenseFile(EmbeddedLicenseFileType type)
            {
                var package = Data.PackageEntity;

                package.EmbeddedLicenseType = type;

                var document = _target.FullFromDb(
                    Data.PackageId,
                    Data.SearchFilters,
                    Data.Versions,
                    isLatestStable: false,
                    isLatest: true,
                    fullVersion: Data.FullVersion,
                    package: package,
                    owners: Data.Owners,
                    totalDownloadCount: Data.TotalDownloadCount,
                    isExcludedByDefault: false);

                Assert.Equal(Data.GalleryLicenseUrl, document.LicenseUrl);
            }
Esempio n. 8
0
            public async Task WillUseNormalizedRegularVersionIfNormalizedVersionMissing(EmbeddedLicenseFileType licenseFileType)
            {
                var fileStorageSvc      = new Mock <ICoreFileStorageService>();
                var service             = CreateService(fileStorageService: fileStorageSvc);
                var packageRegistration = new PackageRegistration {
                    Id = "theId"
                };
                var package = new Package {
                    PackageRegistration = packageRegistration, NormalizedVersion = null, Version = "01.01.01", EmbeddedLicenseType = licenseFileType
                };

                await service.DownloadLicenseFileAsync(package);

                fileStorageSvc
                .Verify(fss => fss.GetFileAsync(CoreConstants.Folders.PackagesContentFolderName, BuildLicenseFileName("theId", "1.1.1")),
                        Times.Once);
                fileStorageSvc
                .Verify(fss => fss.GetFileAsync(It.IsAny <string>(), It.IsAny <string>()),
                        Times.Once);
            }
Esempio n. 9
0
            public async Task WillUseNormalizedRegularVersionIfNormalizedVersionMissing(EmbeddedLicenseFileType licenseFileType, string expectedContentType)
            {
                var fileStorageSvc      = new Mock <ICoreFileStorageService>();
                var service             = CreateService(fileStorageService: fileStorageSvc);
                var packageRegistration = new PackageRegistration {
                    Id = "theId"
                };
                var package = new Package {
                    PackageRegistration = packageRegistration, NormalizedVersion = null, Version = "01.01.01", EmbeddedLicenseType = licenseFileType
                };

                fileStorageSvc.Setup(x => x.SaveFileAsync(CoreConstants.Folders.PackagesContentFolderName, BuildLicenseFileName("theId", "1.1.1"), expectedContentType, It.IsAny <Stream>(), true))
                .Completes()
                .Verifiable();

                await service.SaveLicenseFileAsync(package, Stream.Null);

                fileStorageSvc.VerifyAll();
            }