Esempio n. 1
0
        public void Get_WhenDatabaseIsEmpty_Returns_EmptyListOfSongResponses()
        {
            var actionResult = _songsController.Get(null);

            var okObjectResult = Assert.IsType <OkObjectResult>(actionResult.Result);
            var songs          = Assert.IsAssignableFrom <IEnumerable <SongResponse> >(okObjectResult.Value);

            Assert.Empty(songs);
        }
        public void Get_ReturnsOkObjectResult_With_EnumerableSongResponse()
        {
            var firstSong = new Song
            {
                Artist     = "Artist1",
                Difficulty = "Hard",
                Id         = Guid.Parse("A08FE223-A638-48E1-9A9A-78546902C617"),
                Level      = 15,
                Name       = "Song1"
            };
            var secondSong = new Song
            {
                Artist     = "Artist2",
                Difficulty = "Easy",
                Id         = Guid.Parse("853B7DCF-3FAA-4D35-886B-0CB3C1A7A2E5"),
                Level      = 1,
                Name       = "Song2"
            };
            var songList = new List <Song> {
                firstSong, secondSong
            };

            _songService.GetAll().Returns(songList);

            var expectedSongList = songList.Select(SongResponse.FromEntity).AsEnumerable();

            var actionResult = _songsController.Get(null);

            var okObjectResult = Assert.IsType <OkObjectResult>(actionResult.Result);

            Assert.IsAssignableFrom <IEnumerable <SongResponse> >(okObjectResult.Value);
            Assert.Equal(okObjectResult.Value, expectedSongList);
        }
Esempio n. 3
0
        public void SongsGet()
        {
            var testSubject = new SongsController(_testRepo);
            var result      = testSubject.Get();

            Assert.IsTrue(result.Value.ToList().Count > 19);
        }
Esempio n. 4
0
        public void SongsFilter() //TODO figure out where this argument null exception comes from
        {
            var testSubject = new SongsController(_testRepo);
            var result      = testSubject.Get("Hans2");

            //var fact = _testRepo.GetQueryable().Where(x => x.Artist == "Hans2").ToList();
            Assert.IsTrue(result != null);
            var resultList = result.Value;
            var resultItem = resultList.FirstOrDefault();

            Assert.IsTrue(resultItem.Artist == "Hans2");
        }
Esempio n. 5
0
        public void GetRetunsString()
        {
            var options = new DbContextOptionsBuilder <MusicDbContext>()
                          .UseInMemoryDatabase(databaseName: "ReturnStringTest")
                          .Options;

            //Arrange
            using (var context = new MusicDbContext(options))
            {
                var controller = new SongsController(context);

                //Act
                var result = controller.Get(5);

                //Assert
                Assert.IsType <string>(result);
            }
        }
Esempio n. 6
0
        public void SongsGetById()
        {
            var testSubject = new SongsController(_testRepo);

            Assert.IsTrue(testSubject.Get(1).Value.Artist == "Hans1");
        }
Esempio n. 7
0
        public void SongsGetByIdNotFound()
        {
            var testSubject = new SongsController(_testRepo);

            Assert.IsTrue(testSubject.Get(300).Result.GetType() == new Microsoft.AspNetCore.Mvc.NotFoundResult().GetType());
        }
Esempio n. 8
0
        public void Get_Ok()
        {
            var result = _songsController.Get();

            Assert.IsType <OkObjectResult>(result);
        }