Exemple #1
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));
            }
        }
Exemple #2
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));
        }
Exemple #3
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));
            }
        }
		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));
			}
		}