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));
            }
        }
        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));
        }
        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));
            }
        }
		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));
			}
		}
		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));
		}
        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));
            }
        }