public void Test_Index_Return_View() { var context = new FakePhotoSharingContext(); PhotoController photoController = new PhotoController(context); var result = photoController.Index(); Assert.AreEqual("Index", ((ViewResult)result).ViewName); //Optional //var context = new FakePhotoSharingContext(); //var controller = new PhotoController(context); //var result = controller.Index() as ViewResult; //Assert.AreEqual("Index", result.ViewName); }
public void Test_GetImage_Return_Type() { //This test checks that the PhotoController GetImage action returns a FileResult var context = new FakePhotoSharingContext(); context.Photos = new[] { new Photo{ PhotoID = 1, PhotoFile = new byte[1], ImageMimeType = "image/jpeg" }, new Photo{ PhotoID = 2, PhotoFile = new byte[1], ImageMimeType = "image/jpeg" }, new Photo{ PhotoID = 3, PhotoFile = new byte[1], ImageMimeType = "image/jpeg" }, new Photo{ PhotoID = 4, PhotoFile = new byte[1], ImageMimeType = "image/jpeg" } }.AsQueryable(); var controller = new PhotoController(context); var result = controller.GetImage(1) as ActionResult; Assert.AreEqual(typeof(FileContentResult), result.GetType()); }
public void Test_PhotoGallery_Model_Type() { //This test checks that the PhotoController _PhotoGallery action passes a list of Photos to the view var context = new FakePhotoSharingContext(); context.Photos = new[] { new Photo(), new Photo(), new Photo(), new Photo() }.AsQueryable(); var controller = new PhotoController(context); var result = controller._PhotoGallery() as PartialViewResult; Assert.AreEqual(typeof(List<Photo>), result.Model.GetType()); }
public void Test_PhotoGallery_No_Parameter() { //This test checks that, when you call the _PhotoGallery action with no //parameter, all the photos in the context are returned var context = new FakePhotoSharingContext(); context.Photos = new[] { new Photo(), new Photo(), new Photo(), new Photo() }.AsQueryable(); var controller = new PhotoController(context); var result = controller._PhotoGallery() as PartialViewResult; var modelPhotos = (IEnumerable<Photo>)result.Model; Assert.AreEqual(4, modelPhotos.Count()); }