public void WhenGetAll_Returns_Null_IfNoData()
        {
            // Arrange
            IEnumerable<Artist> mockArtists = GetNoArtists();

            // setup
            repo.Setup(x => x.GetAllArtists()).Returns(mockArtists);

            ArtistController controller = new ArtistController(repo.Object);

            // Act
            IHttpActionResult actionResult = controller.Get();

            // Assert
            Assert.IsNotNull(actionResult, "Result is null");
            Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult), "It should return null");
        }
        public void WhenGetAll_Returns_AllArtists()
        {
            // Arrange
            IEnumerable<Artist> mockArtists = GetMockArtists();

            // setup
            repo.Setup(x => x.GetAllArtists()).Returns(mockArtists);

            ArtistController controller = new ArtistController(repo.Object);

            // Act
            IHttpActionResult actionResult = controller.Get();
            var artists = actionResult as OkNegotiatedContentResult<IEnumerable<Artist>>;

            // Assert
            Assert.IsNotNull(actionResult, "Result is null");
            Assert.IsInstanceOfType(artists.Content, typeof(IEnumerable<Artist>));
            Assert.AreEqual(2, artists.Content.Count(), "Total number of artists is 2");
        }
Esempio n. 3
0
        public void GetAllArtist_Success()
        {
            //Setup mock data
            var mockDataList = GetMockArtists();

            //Arrange
            var mockMusicRepository = new Mock<IArtistRepository>();
            mockMusicRepository.Setup(x => x.GetAllArtists()).Returns(mockDataList);

            var controller = new ArtistController(mockMusicRepository.Object);

            // Act
            IHttpActionResult result = controller.Get();

            // Assert
            Assert.IsNotNull(result);
        }
        public void WhenGet_WithCorrectId_Returns_Artist()
        {
            var artistId = 1;
            // Arrange
            IEnumerable<Artist> mockArtists = GetMockArtists();

            // setup
            repo.Setup(x => x.GetArtist(artistId)).Returns(mockArtists.FirstOrDefault(p => p.ArtistId == artistId));
            ArtistController controller = new ArtistController(repo.Object);

            // Act
            var response = controller.Get(artistId);
            var returnedArtist = response as OkNegotiatedContentResult<Artist>;

            // Assert
            Assert.IsNotNull(returnedArtist);
            Assert.AreEqual(returnedArtist.Content.Name, "Shakira", "Got correct artist");
        }