示例#1
0
        public void SearchTracks_SqlException()
        {
            // Arrange:
            var mockMusicRepository = new Mock <IMusicRepository>();
            var exceptionOutput     = MakeSqlException();

            mockMusicRepository.Setup(x => x.SearchTracks("", "Nirvana", "Nevermind", 50)).Throws(exceptionOutput);

            // Execute & Test:
            var _musicLibraryController = new MusicLibraryController(mockMusicRepository.Object, _logger);
            var ex = Assert.Throws <SqlException>(() => _musicLibraryController.SearchTracks("", "Nirvana", "Nevermind"));

            Assert.Equal(exceptionOutput, ex); // Exception should bubble up through the controller method
        }
示例#2
0
        public void SearchTracks_OK(string title, string artist, string album)
        {
            // Arrange:
            var mockMusicRepository = new Mock <IMusicRepository>();
            var testData            = new List <TrackInfo>()
            {
                new TrackInfo()
                {
                    Title = "Hello"
                }, new TrackInfo()
                {
                    Title = "Shout"
                }
            };

            mockMusicRepository.Setup(x => x.SearchTracks(title, artist, album, 50)).Returns(testData.FindAll(x => x.Title.Contains(title)));

            // Execute:
            var _musicLibraryController = new MusicLibraryController(mockMusicRepository.Object, _logger);
            var result = _musicLibraryController.SearchTracks(title, artist, album);

            // Test:
            Assert.Equal(result, testData.FindAll(x => x.Title.Contains(title)));
        }