예제 #1
0
        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);
        }
예제 #2
0
        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());
        }
예제 #3
0
        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());
        }