Beispiel #1
0
        public void ExportAsWikiFiles_Should_Save_Zip_File_To_Export_Directory()
        {
            // Arrange
            string filename    = string.Format("export-{0}.zip", DateTime.Now.Ticks);
            string zipFullPath = Path.Combine(_wikiExporter.ExportFolder, filename);

            _repository.AddNewPage(new Page()
            {
                Id = 1
            }, "text", "admin", DateTime.UtcNow);
            _repository.AddNewPage(new Page()
            {
                Id = 2
            }, "text", "admin", DateTime.UtcNow);

            // Act
            _wikiExporter.ExportAsWikiFiles(filename);

            // Assert
            Assert.That(File.Exists(zipFullPath), Is.True);

            FileInfo file = new FileInfo(zipFullPath);

            Assert.That(file.Length, Is.GreaterThan(1));
        }
        /// <summary>
        /// Exports the pages of the site as .wiki files, in ZIP format.
        /// </summary>
        /// <returns>A <see cref="FileStreamResult"/> called 'export-{date}.zip'. This file is saved in the App_Data folder first.
        /// If an error occurs, the action adds the error message to the TempData 'ErrorMessage' item.</returns>
        public ActionResult ExportAsWikiFiles()
        {
            try
            {
                string zipFilename = string.Format("export-{0}.zip", DateTime.UtcNow.ToString("yyyy-MM-dd-HHmm"));
                _wikiExporter.ExportAsWikiFiles(zipFilename);

                string zipFullPath = Path.Combine(_wikiExporter.ExportFolder, zipFilename);
                return(File(zipFullPath, "application/zip", zipFilename));
            }
            catch (IOException e)
            {
                Log.Warn(e, "Unable to export wiki content");
                TempData["ErrorMessage"] = string.Format(SiteStrings.SiteSettings_Tools_ExportContent_Error, e.Message);

                return(RedirectToAction("Index"));
            }
        }