public void ShouldThrowWhenMimeIsNotFormData() { try { var controller = new PicturesController(); controller.Request = new HttpRequestMessage() { Content = new StreamContent(new MemoryStream()) }; controller.Post(); } catch (HttpResponseException ex) { Assert.AreEqual(ex.Response.StatusCode, HttpStatusCode.UnsupportedMediaType); } }
public void ShouldSaveAPictureWithFileName() { var id = Guid.NewGuid(); var mockPictureRepository = new Mock<IPictureRepository>(); mockPictureRepository.Setup(r => r.Save(It.IsAny<Picture>(), It.IsAny<byte[]>())).Returns<Picture, byte[]>((p, i) => { p.Id = id; p.Url = new Uri("http://foo", UriKind.Absolute); return p; }); var mockTagRepository = new Mock<ITagRepository>(); var pictureController = new PicturesController(mockPictureRepository.Object, mockTagRepository.Object); var content = new StreamContent(File.OpenRead(Path.Combine(Environment.CurrentDirectory, "multipartStreamEmpty.txt"))); content.Headers.Add("Content-Type", "multipart/form-data; boundary=---------------------------7dcfd134057c"); pictureController.Request = new HttpRequestMessage() { Content = content }; var picture = pictureController.Post(); Assert.AreEqual(picture.Id, id); Assert.AreEqual(picture.Url.ToString(), "http://foo/"); Assert.AreEqual(picture.Name, "test.txt"); Assert.IsNull(picture.Description); Assert.IsNull(picture.Tags); mockTagRepository.Verify(r => r.IncrementPictureCount(It.IsAny<string>()), Times.Never()); }