public void AddTestData() { using (var session = _sessionFactory.OpenSession()) { var album = new Album() { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, Name = "Samples" }; var photo1 = new Photo() { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, Description = "Desert", Album = album, Filename = "desert.jpg", ThumbFilename = "desert_thumb.jpg" }; var photo2 = new Photo() { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, Description = "Lighthouse", Album = album, Filename = "lighthouse.jpg", ThumbFilename = "lighthouse_thumb.jpg" }; var photo3 = new Photo() { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, Description = "Penguins", Album = album, Filename = "penguins.jpg", ThumbFilename = "penguins_thumb.jpg" }; album.Photos = new List<Photo>() { photo1, photo2, photo3}; album.CoverPhoto = photo1; var tag = new Tag() { Name = "Sample" }; if (photo1.Tags == null) photo1.Tags = new List<Tag>() { tag }; if (photo2.Tags == null) photo2.Tags = new List<Tag>() { tag }; if (photo3.Tags == null) photo3.Tags = new List<Tag>() { tag }; session.SaveOrUpdate(album); session.Flush(); } }
public AlbumServiceTests() { var mockAlbumRepo = new Mock<IAlbumRepository>(); mockAlbumRepo.Setup(p => p.GetById(ValidId)).Returns(new Album() { ID = ValidId, CreatedDate = DateTime.Now.AddDays(-1), Name = "My Album with ID 1", ModifiedDate = DateTime.Now.AddMinutes(-30) }); mockAlbumRepo.Setup(p => p.GetById(InvalidId)).Returns((Album)null); mockAlbumRepo.Setup(p => p.GetById(ExceptionId)).Throws(new Exception("Repo exception")); _albums = new List<Album>(); for (int i = 1; i <= 100; i++ ) { var album = new Album() { ID = i, CreatedDate = DateTime.Now.AddDays(-i), ModifiedDate = DateTime.Now.AddSeconds(-i), Name = "Album #" + i, Photos = new List<Photo>() }; for (int j = 0; j < 51; j++) { var photo = new Photo() { Album = album, CreatedDate = DateTime.Now.AddMinutes(-i), ModifiedDate = DateTime.Now.AddMinutes(-i), Description = "Album #" + i +" Photo #" + j, Filename = "album" + i + "photo" + j + ".jpg", ID = j }; album.Photos.Add(photo); } _albums.Add(album); } mockAlbumRepo.Setup(p => p.GetAll()).Returns(_albums); _albumRepository = mockAlbumRepo.Object; }
public void Create_Should_Redirect_To_Edit_After_Add() { var mockAlbumSvc = new Mock<IAlbumService>(); var albumController = new AlbumController(mockAlbumSvc.Object, _fileStoreService); var album = new Album() { Name = "Photo Album", ID = 999 }; var result = albumController.Create(album) as RedirectToRouteResult; Assert.AreEqual("Edit", result.RouteValues["action"]); Assert.AreEqual(999, result.RouteValues["id"]); }
public ActionResult Create(Album album) { try { album.CreatedDate = DateTime.Now; album.ModifiedDate = DateTime.Now; _albumService.Add(album); _albumService.Save(); return RedirectToAction("Edit", new { id=album.ID }); } catch { return View(); } }
public void Create_Should_Add_Album_To_Repository() { var mockAlbumSvc = new Mock<IAlbumService>(); mockAlbumSvc.Setup(p => p.Add(It.IsAny<Album>())).Verifiable("Add must be called."); mockAlbumSvc.Setup(p => p.Save()).Verifiable("Save must be called."); var albumController = new AlbumController(mockAlbumSvc.Object, _fileStoreService); var album = new Album() { Name = "Photo Album", ID = 999 }; var result = albumController.Create(album); mockAlbumSvc.VerifyAll(); }
public AlbumControllerTests() { _albums = new List<Album>(); for (int i = 1; i <= 5; i++) { var album = new Album() { ID = i }; _albums.Add(album); } var mockFileStoreService = new Mock<IFileStoreService>(); _fileStoreService = mockFileStoreService.Object; }
public ActionResult Edit(int id, Album postedAlbum) { try { var album = _albumService.GetById(id); album.Name = postedAlbum.Name; int coverPhotoID = Convert.ToInt32(Request.Form["CoverPhotoID"]); var photo = album.Photos.Where(p => p.ID == coverPhotoID).Single(); album.CoverPhoto = photo; _albumService.Save(); return View(album); } catch { return View(); } }
public void Add(Album album) { _albumRespository.Add(album); }