예제 #1
0
            public async Task ValidateSymbolsAsyncWillSucceedOnCorrectMatch()
            {
                // Arrange
                _symbolsFileService.
                Setup(sfs => sfs.DownloadNupkgFileAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>())).
                ReturnsAsync(new MemoryStream());

                _symbolsFileService.
                Setup(sfs => sfs.DownloadSnupkgFileAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).
                ReturnsAsync(new MemoryStream());

                _zipService.Setup(s => s.ValidateZipAsync(It.IsAny <Stream>(), It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);

                _zipService.Setup(s => s.ReadFilesFromZipStream(It.IsAny <Stream>(), It.IsAny <string[]>())).Returns(new List <string>()
                {
                    "foo.dll"
                });

                _zipService.Setup(s => s.ReadFilesFromZipStream(It.IsAny <Stream>(), ".pdb")).Returns(new List <string>()
                {
                    "foo.pdb"
                });

                var service = new TestSymbolsValidatorService(_symbolsFileService.Object, _zipService.Object, _telemetryService.Object, _logger.Object);

                // Act
                var result = await service.ValidateSymbolsAsync(Message, CancellationToken.None);

                // Assert
                Assert.Equal(ValidationResult.Succeeded.Status, result.Status);
                Assert.True(service.ValidateSymbolMatchingInvoked);
            }
예제 #2
0
            public async Task ValidateSymbolsAsyncWillFailIfSnupkgIsNotSafeForExtract()
            {
                // Arrange
                _symbolsFileService.
                Setup(sfs => sfs.DownloadSnupkgFileAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).
                ReturnsAsync(CreateZipSlipStream());
                var zipService = new ZipArchiveService(new Mock <ILogger <ZipArchiveService> >().Object);
                var service    = new TestSymbolsValidatorService(_symbolsFileService.Object, zipService, _telemetryService.Object, _logger.Object);

                // Act
                var result = await service.ValidateSymbolsAsync(Message, CancellationToken.None);

                // Assert
                Assert.Equal(ValidationResult.Failed.Status, result.Status);
                Assert.Equal(1, result.Issues.Count);
            }
예제 #3
0
            public async Task ValidateSymbolsAsyncWillFailIfSnupkgDoesNotHavePDBs()
            {
                // Arrange
                _symbolsFileService.
                Setup(sfs => sfs.DownloadNupkgFileAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>())).
                ReturnsAsync(new MemoryStream());

                _symbolsFileService.
                Setup(sfs => sfs.DownloadSnupkgFileAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).
                ReturnsAsync(new MemoryStream());

                _zipService.Setup(s => s.ValidateZipAsync(It.IsAny <Stream>(), It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);

                _zipService.Setup(s => s.ReadFilesFromZipStream(It.IsAny <Stream>(), It.IsAny <string[]>())).Returns(new List <string>());

                var service = new TestSymbolsValidatorService(_symbolsFileService.Object, _zipService.Object, _telemetryService.Object, _logger.Object);

                // Act
                var result = await service.ValidateSymbolsAsync(Message, CancellationToken.None);

                // Assert
                Assert.Equal(ValidationResult.Failed.Status, result.Status);
                Assert.Equal(1, result.Issues.Count);
            }