예제 #1
0
        public void Should_Throw_BadRequest_If_There_Is_An_Exception()
        {
            ObjectId objectId = new ObjectId();

            _mockedSongRepository.Setup(x => x.DeleteById(It.IsAny <ObjectId>())).Throws(new Exception());

            var exception = Assert.Throws <HttpResponseException>(() => _songController.Delete(objectId));

            exception.Response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
예제 #2
0
        public void Delete()
        {
            var totalSongsBefore = playlist.GetAll().Count();

            var httpStatus      = controller.Delete(1);
            var totalSongsAfter = playlist.GetAll().Count();

            FailIfNotFound(m => controller.Delete(m));
            Assert.AreEqual(HttpStatusCode.OK, httpStatus.StatusCode);
            Assert.AreEqual(totalSongsBefore - 1, totalSongsAfter);
        }
예제 #3
0
        public async Task CanDeleteSong()
        {
            DbContextOptions <MusicDbContext> options =
                new DbContextOptionsBuilder <MusicDbContext>()
                .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            using (MusicDbContext context = new MusicDbContext(options))
            {
                Song song = new Song()
                {
                    Name        = "Shake It Off",
                    Artist      = "Taylor Swift",
                    Album       = "1989",
                    Genre       = "Pop",
                    ReleaseDate = DateTime.Today,
                    PlaylistID  = 1
                };
                SongController sc = new SongController(context);
                await context.Songs.AddAsync(song);

                await context.SaveChangesAsync();

                var findSong = await context.Songs.FirstAsync(s => s.Name == song.Name);

                var response = sc.Delete(findSong.ID).Result;
                var result   = (NoContentResult)response;
                Assert.Equal(HttpStatusCode.NoContent, (HttpStatusCode)result.StatusCode);
            }
        }
예제 #4
0
        public void Delete_Removes_Song()
        {
            var SongId      = 1;
            var deletedSong = new Song(SongId, "string1", "string2");
            var SongList    = new List <Song>()
            {
                deletedSong,
                new Song(2, "string1", "string2")
            };

            songRepo.GetById(SongId).Returns(deletedSong);
            songRepo.When(d => d.Delete(deletedSong))
            .Do(d => SongList.Remove(deletedSong));
            songRepo.GetAll().Returns(SongList);

            var result = underTest.Delete(SongId);

            Assert.All(result, item => Assert.Contains("string1", item.Title));
        }
        public void Delete_Removes_A_Song()
        {
            var songId      = 1;
            var deletedSong = new Song(songId, "First Song");
            var songList    = new List <Song>()
            {
                deletedSong,
                new Song(2, "Second Song")
            };

            songRepo.GetById(songId).Returns(deletedSong);
            songRepo.When(d => d.Delete(deletedSong))
            .Do(d => songList.Remove(deletedSong));
            songRepo.GetAll().Returns(songList);

            var result = underTest.Delete(songId);

            Assert.All(result, item => Assert.Contains("Second Song", item.Title));
        }
예제 #6
0
        public void Delete_Removes_Song()
        {
            var songId      = 1;
            var deletedSong = new Songs(1, "First song", "duration", 1);
            var songList    = new List <Songs>()
            {
                deletedSong,
                new Songs(2, "Second song", "duration", 2)
            };

            songRepo.GetByID(songId).Returns(deletedSong);
            songRepo.When(d => d.Delete(deletedSong))
            .Do(d => songList.Remove(deletedSong));

            songRepo.GetAll().Returns(songList);
            var result = underTest.Delete(songId);

            Assert.DoesNotContain(deletedSong, result);
            //Assert.All(result, item => Assert.Contains("second item", item.Name));
        }
        public void Delete_Removes_Song()
        {
            var songId      = 1;
            var deletedSong = new Song(1, "Title", "Link", "Time", 1, "./css/images/genericsong.jpg");
            var songList    = new List <Song>()
            {
                deletedSong,
                new Song(1, "Title", "Link", "Time", 1, "./css/images/genericsong.jpg")
            };

            songRepo.GetById(songId).Returns(deletedSong);
            songRepo.When(d => d.Delete(deletedSong))
            .Do(d => songList.Remove(deletedSong));
            songRepo.GetAll().Returns(songList);

            var result = underTest.Delete(songId);

            Assert.DoesNotContain(deletedSong, result); /*Does not work in all cases*/
            //Assert.All(result, item => Assert.Contains("Second item", item.Title));
        }
예제 #8
0
        public async Task DeleteTest()
        {
            var actual = await controller.Create(new Song()
            {
                Name = "DeleteSong", UserId = "1"
            });

            Assert.IsType <CreatedResult>(actual);
            CreatedResult result = actual as CreatedResult;
            var           item   = result.Value as Song;

            var actual2 = await controller.Delete(Guid.Parse(item.Id));

            Assert.IsType <OkObjectResult>(actual2);

            var actual3 = await controller.GetById(Guid.Parse(item.Id));

            Assert.IsType <OkObjectResult>(actual3);
            OkObjectResult result3 = actual3 as OkObjectResult;
            var            item3   = result3.Value as Song;

            Assert.Null(item3);
        }