public void DeletePlaylist_NextToBigPlaylist_NoStackOverflowException() { User user = Helpers.CreateUser(); Guid firstPlaylistId = user.Playlists.First().Id; PlaylistDto playlistDto = Helpers.CreatePlaylistDto(user.Id); NHibernateSessionManager.Instance.OpenSessionAndBeginTransaction(); var result = (JsonServiceStackResult)PlaylistController.Create(playlistDto); NHibernateSessionManager.Instance.CommitTransactionAndCloseSession(); var createdPlaylistDto = (PlaylistDto)result.Data; const int numItemsToCreate = 150; List <PlaylistItemDto> playlistItemDtos = Helpers.CreatePlaylistItemsDto(numItemsToCreate, createdPlaylistDto.Id); foreach (var splitPlaylistItemDtos in Split(playlistItemDtos, 50)) { NHibernateSessionManager.Instance.OpenSessionAndBeginTransaction(); PlaylistItemController.CreateMultiple(splitPlaylistItemDtos); NHibernateSessionManager.Instance.CommitTransactionAndCloseSession(); } NHibernateSessionManager.Instance.OpenSessionAndBeginTransaction(); // Now delete the first playlist. PlaylistController.Delete(firstPlaylistId); NHibernateSessionManager.Instance.CommitTransactionAndCloseSession(); }
public async void CheckToSeeIfPlaylistDeletes() { DbContextOptions <MusicDbContext> options = new DbContextOptionsBuilder <MusicDbContext>() .UseInMemoryDatabase("DeletePlaylist").Options; using (MusicDbContext context = new MusicDbContext(options)) { User user4 = new User(); user4.Name = "username"; Playlist playlist = new Playlist(); playlist.Id = 27; user4.PlaylistID = playlist.Id.Value; playlist.UserID = user4.Id; user4.GenreID = 3; await context.Users.AddAsync(user4); await context.Playlists.AddAsync(playlist); await context.SaveChangesAsync(); PlaylistController plc = new PlaylistController(context); var result = await plc.Delete(user4.Id); var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Edit", redirectToActionResult.ActionName); } }
public void CanDeletePlaylist() { DbContextOptions <MusicDbContext> options = new DbContextOptionsBuilder <MusicDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; using (MusicDbContext context = new MusicDbContext(options)) { Playlist playlist = new Playlist(); playlist.ID = 1; playlist.Name = "Test"; Playlist playlist1 = new Playlist(); playlist1.ID = 2; playlist1.Name = "Test1"; context.Playlists.AddAsync(playlist); context.SaveChangesAsync(); PlaylistController pc = new PlaylistController(context); var response = pc.Delete(1).Result; var result = (NoContentResult)response; Assert.Equal(HttpStatusCode.NoContent, (HttpStatusCode)result.StatusCode); } }
public void DeletePlaylist_NextToBigPlaylist_NoStackOverflowException() { Folder folder = UserManager.CreateUser().Folders.First(); Guid firstPlaylistId = folder.Playlists.First().Id; PlaylistDto playlistDto = Helpers.CreatePlaylistDto(folder.Id); JsonDataContractActionResult result = (JsonDataContractActionResult)PlaylistController.Create(playlistDto); PlaylistDto createdPlaylistDto = (PlaylistDto)result.Data; const int numItemsToCreate = 150; List <PlaylistItemDto> playlistItemDtos = Helpers.CreatePlaylistItemsDto(numItemsToCreate, createdPlaylistDto.Id); foreach (List <PlaylistItemDto> splitPlaylistItemDtos in Split(playlistItemDtos, 50)) { PlaylistItemController.CreateMultiple(splitPlaylistItemDtos); } NHibernateSessionManager.Instance.Clear(); // Now delete the first playlist. PlaylistController.Delete(firstPlaylistId); }
public void DeletePlaylist_PlaylistEmpty_PlaylistDeletedSuccessfully() { User user = Helpers.CreateUser(); PlaylistController.Delete(user.Playlists.First().Id); }