public void CanGetAlbumById() { var album = new Album().SetId(123); var daoAlbum = new DaoStub <Album>().AddEntity(album); var model = new AlbumManager(daoAlbum, new Mock <IEntityValidator>().Object); model.GetAlbumById(123).Should().Be.EqualTo(album); }
public void GetAlbumsShouldReturnOrderedAlbums() { //Arrange var daoAlbum = new DaoStub <Album>().AddEntities(new Album { Title = "za" }, new Album { Title = "aa" }); var model = new AlbumManager(daoAlbum, new Mock <IEntityValidator>().Object); //Act var result = model.GetAlbumsToBrowse(); //assert result.Should().Have.SameSequenceAs(daoAlbum.RetrieveAll().OrderBy(a => a.Title).ToArray()); }
public void WhenEntityIsInvalidThenThrowExceptionAndDontSave() { //Arrange var album = new Album(); var daoAlbum = new DaoStub <Album>().AddEntity(album); var validator = new Mock <IEntityValidator>(); validator.Setup(v => v.IsValid(album)).Returns(false); var model = new AlbumManager(daoAlbum, validator.Object); //Act model.Executing(am => am.Save(album)) .Throws <InvalidOperationException>(); //assert //assert daoAlbum.Mock.Verify(da => da.MakePersistent(album), Times.Never()); }