示例#1
0
        public void MusicService_GetAllByArtistId_ValidArtistId() //when id is valid
        {
            var mockMusic = GetMusics();
            //Arrange
            //var mockUnitOfWork = new MockUnitOfWork();
            //mockUnitOfWork.Musics.MockIsValid(true)
            //                     .MockGetAllWithArtistByArtistId(mockMusic);
            var mockMusicRepo = new MockMusicRepository()
                                .MockIsValid(true)
                                .MockGetAllWithArtistByArtistId(mockMusic);

            //var mockUnitOfWork = new Mock<IUnitOfWork>();
            //mockUnitOfWork.Setup(x => x.Musics).Returns(mockMusicRepo.Object);
            var mockUnitOfWork = new MockUnitOfWork();

            mockUnitOfWork.InitializeMusicRepo(mockMusicRepo.Object);

            var musicService = new MusicService(mockUnitOfWork.Object);

            //Act
            var listOfMusic = musicService.GetAllByArtistId(1).Result;

            //Assert
            Assert.NotEmpty(listOfMusic);
            mockMusicRepo.VerifyIsValid(Times.Once());
            mockMusicRepo.VerifyGetAllWithArtistByArtistId(Times.Once());
        }