public void Get() { var processor = new Mock<IImageProcessor>(); processor.Setup(x => x.LoadImages()).Returns(new List<UploadImage>() { new UploadImage() { id = 1, filepath = "this/is/a/filepath", thumbnailPath = "this/is/a/thumbnail/path", fileName = "test image" }, new UploadImage() { id = 2, filepath = "this/is/a/filepath", thumbnailPath = "this/is/a/thumbnail/path", fileName = "another image" } }); var controller = new ImagesController(processor.Object); var result = controller.Get(); var contentResult = result as OkNegotiatedContentResult<IEnumerable<UploadImage>>; Assert.IsNotNull(result); Assert.IsNotNull(contentResult); Assert.AreEqual(2, contentResult.Content.Last().id); }
public void GetById_NotFound() { var processor = new Mock<IImageProcessor>(); processor.Setup(x => x.LoadImage(It.IsAny<int>())).Returns((UploadImage) null); var controller = new ImagesController(processor.Object); var result = controller.Get("2"); Assert.IsInstanceOfType(result, typeof(NotFoundResult)); }
public void GetById() { var processor = new Mock<IImageProcessor>(); processor.Setup(x => x.LoadImage(1)).Returns(new UploadImage() { id = 1, filepath = "this/is/a/filepath", thumbnailPath = "this/is/a/thumbnail/path", fileName = "test image" }); var controller = new ImagesController(processor.Object); var result = controller.Get("1"); var contentResult = result as OkNegotiatedContentResult<UploadImage>; Assert.AreEqual(1, contentResult.Content.id); }