コード例 #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);
                }
            }
コード例 #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);
                }
            }