示例#1
0
        public override async Task <bool> ArtistAddAsync(Artist artist)
        {
            // Map artist to db model
            DBModels.Artist dbArtist = autoMapper.Map <DBModels.Artist>(artist);

            // Add new artist to database
            int recordsChanged;

            try { recordsChanged = await repository.ArtistAddAsync(dbArtist); }
            catch { recordsChanged = 0; }
            return(recordsChanged > 0);
        }
示例#2
0
        public async Task ArtistAddAsync_SavesItem()
        {
            Mock <DbSet <Artist> >    mockArtists = new Mock <DbSet <Artist> >();
            Mock <MusicDemoDbContext> mockContext = new Mock <MusicDemoDbContext>();

            mockContext.Setup(m => m.Artists).Returns(mockArtists.Object);

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

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