public void CreatePlaylist_PlaylistDoesntExist_PlaylistCreated()
        {
            PlaylistDto playlistDto = Helpers.CreatePlaylistDto();

            JsonDataContractActionResult result = (JsonDataContractActionResult)PlaylistController.Create(playlistDto);

            PlaylistDto createdPlaylistDto = (PlaylistDto)result.Data;

            //  Make sure we actually get a Playlist DTO back from the Controller.
            Assert.NotNull(createdPlaylistDto);

            NHibernateSessionManager.Instance.Clear();

            Folder folder = FolderDao.Get(createdPlaylistDto.FolderId);

            //  Make sure that the created playlist was cascade added to the Folder
            Assert.That(folder.Playlists.Count(p => p.Id == createdPlaylistDto.Id) == 1);
        }
        public void GetSharedPlaylist_PlaylistShareCodeExists_CopyOfPlaylistCreated()
        {
            Folder folder = UserManager.CreateUser().Folders.First();

            ShareCode shareCode = ShareCodeManager.GetShareCode(ShareableEntityType.Playlist, folder.Playlists.First().Id);

            JsonDataContractActionResult result = (JsonDataContractActionResult)PlaylistController.CreateCopyByShareCode(shareCode.ShortId, shareCode.UrlFriendlyEntityTitle, folder.Id);
            PlaylistDto playlistDto             = (PlaylistDto)result.Data;

            //  Make sure we actually get a Playlist DTO back from the Controller.
            Assert.NotNull(playlistDto);

            NHibernateSessionManager.Instance.Clear();

            Folder folderFromDatabase = FolderDao.Get(playlistDto.FolderId);

            //  Make sure that the created playlist was cascade added to the Folder
            Assert.That(folderFromDatabase.Playlists.Count(p => p.Id == playlistDto.Id) == 1);
        }
        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);
        }