public void PicturesController_Details() { //Arrange var pictureRepo = new FakeRepository <Picture>(p => p.PictureID); var tagsRepo = new FakeRepository <Tag>(e => e.TagID); var postedfilesKeyCollection = new Mock <HttpFileCollectionBase>(); var fakeFileKeys = new List <string>() { "file" }; var postedfile = new Mock <HttpPostedFileBase>(); Request.Setup(req => req.Files).Returns(postedfilesKeyCollection.Object); postedfilesKeyCollection.Setup(keys => keys.GetEnumerator()).Returns(fakeFileKeys.GetEnumerator()); postedfilesKeyCollection.Setup(keys => keys["file"]).Returns(postedfile.Object); postedfile.Setup(e => e.InputStream).Returns(new MemoryStream(TEST_BMP)); postedfile.Setup(e => e.FileName).Returns("filename"); postedfile.Setup(e => e.ContentLength).Returns(TEST_BMP.Length); postedfile.Verify(f => f.SaveAs(It.IsAny <string>()), Times.AtMostOnce()); //Act var controller = new PicturesController(pictureRepo, tagsRepo); controller.ControllerContext = new ControllerContext(Context.Object, new RouteData(), controller); var result = controller.Create(postedfile.Object, "tag1, tag2, tag3", "custom name") as RedirectToRouteResult; var inserted = pictureRepo.GetAll().FirstOrDefault(); var detailsResult = controller.Details(inserted.PictureID) as ViewResult; //Assert Assert.IsNotNull(result); // Check if the view returned a valid result Assert.IsNotNull(inserted); // Check if the picture was inserted Assert.IsTrue(new string[] { "tag1", "tag2", "tag3" }.SequenceEqual(inserted.Tags.Select(t => t.TagLabel))); // Check if the tags were set correctly Assert.IsNotNull(detailsResult); }