public void Should_Ensure_Unzipped_And_Sets_The_Quoted_TestAdapterPathArg()
        {
            var zipDetails = new ZipDetails {
                Path = "path", Version = "version"
            };
            var mockToolZipProvider = mocker.GetMock <IToolZipProvider>();

            mockToolZipProvider.Setup(zp => zp.ProvideZip(CoverletDataCollectorUtil.zipPrefix)).Returns(zipDetails);

            var mockToolFolder = mocker.GetMock <IToolFolder>();

            mockToolFolder.Setup(cf => cf.EnsureUnzipped("appdatafolder", CoverletDataCollectorUtil.zipDirectoryName, zipDetails)).Returns("zipdestination");

            coverletDataCollector.Initialize("appdatafolder");
            Assert.AreEqual($@"""{Path.Combine("zipdestination", "build", "netstandard1.0")}""", coverletDataCollector.TestAdapterPathArg);
        }
예제 #2
0
        public static ResponseStatus CreateZipFile(ZipDetails zipDetails)
        {
            ResponseStatus responseStatus = new ResponseStatus();

            try
            {
                if (zipDetails != null && zipDetails.DocumentDetails?.Count > 0)
                {
                    if (!Directory.Exists(Path.GetDirectoryName(zipDetails.ZipFilePath)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(zipDetails.ZipFilePath));
                    }

                    string zipFilePath = Path.Combine(zipDetails.ZipFilePath, zipDetails.ZipFileName);
                    if (File.Exists(zipFilePath))
                    {
                        File.Delete(zipFilePath);
                    }
                    using (ZipArchive archive = ZipFile.Open(zipFilePath, ZipArchiveMode.Create))
                    {
                        foreach (var fileToZip in zipDetails.DocumentDetails)
                        {
                            if (File.Exists(fileToZip.FullDocumentPath))
                            {
                                //create the entry - this is the zipped filename
                                //change slashes - now it's VALID
                                ZipArchiveEntry zipFileEntry = archive.CreateEntryFromFile(fileToZip.FullDocumentPath, fileToZip.DocumentName.Replace('\\', '/'), CompressionLevel.Fastest);
                            }
                        }
                    }

                    responseStatus.Status = "Success";
                }
                else
                {
                    responseStatus.Status       = "Failure";
                    responseStatus.ErrorMessage = "ZipDetails/DocumentDetails cannot be null.";
                }
            }
            catch (Exception ex)
            {
                responseStatus.Status       = "Failure";
                responseStatus.ErrorMessage = "CreateZipFile:- " + ex.Message;
            }
            return(responseStatus);
        }
        public void Should_Ensure_Microsoft_CodeCoverage_Is_Unzipped_To_The_Tool_Folder()
        {
            var autoMocker = new AutoMoqer();
            var msCodeCoverageRunSettingsService = autoMocker.Create <MsCodeCoverageRunSettingsService>();

            var cancellationToken = CancellationToken.None;

            var zipDetails          = new ZipDetails();
            var mockToolZipProvider = autoMocker.GetMock <IToolZipProvider>();

            mockToolZipProvider.Setup(toolZipProvider => toolZipProvider.ProvideZip("microsoft.codecoverage")).Returns(zipDetails);

            var mockToolFolder = autoMocker.GetMock <IToolFolder>();

            mockToolFolder.Setup(toolFolder =>
                                 toolFolder.EnsureUnzipped("AppDataFolder", "msCodeCoverage", zipDetails, cancellationToken)).Returns("ZipDestination");

            msCodeCoverageRunSettingsService.Initialize("AppDataFolder", null, cancellationToken);
            mockToolFolder.VerifyAll();
        }