Ejemplo n.º 1
0
        public void writeresponse_should_set_200_status_and_mimetype_and_write_bytes()
        {
            // Arrange
            AttachmentFileHandler handler = new AttachmentFileHandler(_applicationSettings, _fileService);

            string fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Unit", "Attachments", "afile.jpg");

            File.WriteAllText(fullPath, "fake content");
            byte[] expectedBytes    = File.ReadAllBytes(fullPath);
            string expectedMimeType = "image/jpeg";

            string localPath       = "/wiki/Attachments/afile.jpg";
            string applicationPath = "/wiki";
            string modifiedSince   = "";

            ResponseWrapperMock wrapper = new ResponseWrapperMock();

            // Act
            handler.WriteResponse(localPath, applicationPath, modifiedSince, wrapper, null);

            // Assert
            Assert.That(wrapper.StatusCode, Is.EqualTo(200));
            Assert.That(wrapper.ContentType, Is.EqualTo(expectedMimeType));
            Assert.That(wrapper.Buffer, Is.EqualTo(expectedBytes));
        }
Ejemplo n.º 2
0
        public void writeresponse_should_throw_404_exception_for_bad_application_path()
        {
            // Arrange
            AttachmentFileHandler handler = new AttachmentFileHandler(_applicationSettings, _fileService);

            string fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Unit", "Attachments", "afile.jpg");

            File.WriteAllText(fullPath, "fake content");

            string localPath       = "/wiki/Attachments/afile.jpg";
            string applicationPath = "/wookie";
            string modifiedSince   = "";

            ResponseWrapperMock wrapper = new ResponseWrapperMock();

            try
            {
                // Act + Assert
                handler.WriteResponse(localPath, applicationPath, modifiedSince, wrapper, null);

                Assert.Fail("No 500 HttpException thrown");
            }
            catch (HttpException e)
            {
                Assert.That(e.GetHttpCode(), Is.EqualTo(404));
            }
        }
Ejemplo n.º 3
0
        private static string[] _filesToExclude = new string[] { "emptyfile.txt", "_installtest.txt" };         // installer/publish files

        /// <summary>
        /// Constructor for the file manager.
        /// </summary>
        /// <remarks>This action requires editor rights.</remarks>
        public FileManagerController(ApplicationSettings settings, UserServiceBase userManager, IUserContext context,
                                     SettingsService settingsService, AttachmentFileHandler attachment)
            : base(settings, userManager, context, settingsService)
        {
            _attachmentHandler  = attachment;
            _attachmentPathUtil = new AttachmentPathUtil(settings);
        }
Ejemplo n.º 4
0
        public void TranslateLocalPathToFilePath(string localPath, string appPath, string expectedPath)
        {
            // Arrange
            _applicationSettings.AttachmentsFolder = @"C:\Attachments\";
            AttachmentFileHandler handler = new AttachmentFileHandler(_applicationSettings, _fileService);

            // Act
            string actualPath = handler.TranslateUrlPathToFilePath(localPath, appPath);

            // Assert
            Assert.That(actualPath, Is.EqualTo(expectedPath), "Failed with {0} {1} {2}", localPath, appPath, expectedPath);
        }
Ejemplo n.º 5
0
        public void translatelocalpathtofilepath_should_be_case_sensitive()
        {
            // Arrange
            _applicationSettings.AttachmentsFolder = @"C:\attachments\";
            AttachmentFileHandler handler = new AttachmentFileHandler(_applicationSettings, _fileService);

            // Act
            string actualPath = handler.TranslateUrlPathToFilePath("/Attachments/a.jpg", "/");

            // Assert
            Assert.That(actualPath, Is.Not.EqualTo(@"c:\Attachments\a.jpg"), "TranslateLocalPathToFilePath does a case sensitive url" +
                        " replacement (this is for Apache compatibility");
        }
        public void Setup()
        {
            _container = new MocksAndStubsContainer();

            _applicationSettings   = _container.ApplicationSettings;
            _context               = _container.UserContext;
            _repository            = _container.Repository;
            _pluginFactory         = _container.PluginFactory;
            _settingsService       = _container.SettingsService;
            _userService           = _container.UserService;
            _historyService        = _container.HistoryService;
            _pageService           = _container.PageService;
            _attachmentFileHandler = new AttachmentFileHandler(_applicationSettings, _container.FileService);
            _fileService           = _container.FileService as FileServiceMock;

            try
            {
                // Delete any existing attachments folder
                DirectoryInfo directoryInfo = new DirectoryInfo(_applicationSettings.AttachmentsFolder);
                if (directoryInfo.Exists)
                {
                    directoryInfo.Attributes = FileAttributes.Normal;
                    directoryInfo.Delete(true);
                }

                Directory.CreateDirectory(_applicationSettings.AttachmentsFolder);
            }
            catch (IOException e)
            {
                Assert.Fail("Unable to delete the attachments folder " + _applicationSettings.AttachmentsFolder + ", does it have a lock/explorer window open, or Mercurial open?" + e.ToString());
            }
            catch (ArgumentException e)
            {
                Assert.Fail("Unable to delete the attachments folder " + _applicationSettings.AttachmentsFolder + ", is EasyMercurial open?" + e.ToString());
            }

            _filesController  = new FileManagerController(_applicationSettings, _userService, _context, _settingsService, _attachmentFileHandler, _fileService);
            _mvcMockContainer = _filesController.SetFakeControllerContext();
        }
Ejemplo n.º 7
0
        public void writeresponse_should_throw_404_exception_for_missing_file()
        {
            // Arrange
            AttachmentFileHandler handler = new AttachmentFileHandler(_applicationSettings, _fileService);

            string localPath       = "/wiki/Attachments/doesntexist404.jpg";
            string applicationPath = "/wiki";
            string modifiedSince   = "";

            ResponseWrapperMock wrapper = new ResponseWrapperMock();

            try
            {
                // Act + Assert
                handler.WriteResponse(localPath, applicationPath, modifiedSince, wrapper, null);

                Assert.Fail("No 404 HttpException thrown");
            }
            catch (HttpException e)
            {
                Assert.That(e.GetHttpCode(), Is.EqualTo(404));
            }
        }