コード例 #1
0
        public override async Task <bool> AlbumAddAsync(Album album)
        {
            // Map album to db model
            DBModels.Album dbAlbum = autoMapper.Map <DBModels.Album>(album);

            // Add new album to database
            int recordsChanged;

            try { recordsChanged = await repository.AlbumAddAsync(dbAlbum); }
            catch { recordsChanged = 0; }
            return(recordsChanged > 0);
        }
コード例 #2
0
        public async Task AlbumAddAsync_SavesItem()
        {
            Mock <DbSet <Album> >     mockAlbums  = new Mock <DbSet <Album> >();
            Mock <MusicDemoDbContext> mockContext = new Mock <MusicDemoDbContext>();

            mockContext.Setup(m => m.Albums).Returns(mockAlbums.Object);

            MusicDemoRepository repo = new MusicDemoRepository(mockContext.Object);
            await repo.AlbumAddAsync(new Album { Name = "MxPx" });

            mockAlbums.Verify(m => m.Add(It.Is <Album>(a => a.Name == "MxPx")), Times.Once());
            mockContext.Verify(m => m.SaveChangesAsync(), Times.Once());
        }