public void WhenPhotoForValidPhoto_ThenPhotoReturned() { const int photoId = 33; MockHandlerFor( () => new Mock <GetVehiclePhoto>(null), x => x .Setup(h => h.Execute(photoId)) .Returns(new VehiclePhoto { Image = new byte[] { }, ImageMimeType = "something" })); TestableVehicleController controller = GetTestableVehicleController(); var result = (FileStreamResult)controller.Photo(photoId); Assert.NotNull(result.FileStream); }
public void WhenPhotoForInvalidPhoto_ThenDefaultPhotoReturned() { const int photoId = 33; MockHandlerFor( () => new Mock <GetVehiclePhoto>(null), x => x .Setup(h => h.Execute(photoId)) .Throws(new BusinessServicesException("BadImage"))); TestableVehicleController controller = GetTestableVehicleController(); Mock.Get(controller.HttpContext) .SetupGet(x => x.Request.ApplicationPath) .Returns("/Something"); Mock.Get(controller.HttpContext) .Setup(x => x.Response.ApplyAppPathModifier(It.IsAny <string>())) .Returns("/Something/Content/vehicle.png"); var result = (FilePathResult)controller.Photo(photoId); Assert.Contains("Something/Content/vehicle.png", result.FileName); }