Exemplo n.º 1
0
        public void ShouldMap()
        {
            using (var transaction = Session.BeginTransaction())
            {
                var createdUser = new User
                    {
                        GooglePlusId = "some id?"
                    };

                var playlist = new Playlist("boss songs")
                    {
                        User = createdUser
                    };

                createdUser.AddPlaylist(playlist);

                Session.Save(createdUser);
                Session.Flush();
                Session.Clear();

                var savedUser = Session.Get<User>(createdUser.Id);
                Assert.That(savedUser.Id, Is.Not.EqualTo(Guid.Empty));

                Assert.That(savedUser.GooglePlusId, Is.EqualTo(createdUser.GooglePlusId));
                Assert.That(savedUser.Playlists, Has.Count.EqualTo(2));

                Assert.That(Session.Query<Playlist>().Where(p => p.User == savedUser).ToList(), Has.Count.EqualTo(2));

                transaction.Rollback();
            }
        }
Exemplo n.º 2
0
        public PlaylistDto Create(PlaylistDto playlistDto)
        {
            PlaylistDto savedPlaylistDto;

            using (ITransaction transaction = Session.BeginTransaction())
            {
                User user = UserManager.Get(playlistDto.UserId);

                Playlist playlist = new Playlist(playlistDto.Id);
                playlistDto.SetPatchableProperties(playlist);

                user.AddPlaylist(playlist);

                List<PlaylistItem> playlistItems = new List<PlaylistItem>();
                foreach (PlaylistItemDto dto in playlistDto.Items)
                {
                    PlaylistItem playlistItem = new PlaylistItem(dto.Id, dto.Title, dto.Cid, dto.Song.Id, dto.Song.Type, dto.Song.Title, dto.Song.Duration, dto.Song.Author);
                    dto.SetPatchableProperties(playlistItem);
                    playlistItems.Add(playlistItem);
                }
                playlist.AddItems(playlistItems);

                PlaylistManager.Save(playlist);
                savedPlaylistDto = PlaylistDto.Create(playlist);

                transaction.Commit();
            }

            return savedPlaylistDto;
        }
Exemplo n.º 3
0
        public void DeletePlaylist()
        {
            //  Create a new Playlist and write it to the database.
            string title = string.Format("New Playlist {0:D4}", User.Playlists.Count);
            var playlist = new Playlist(title);

            User.AddPlaylist(playlist);

            PlaylistManager.Save(playlist);

            //  Now delete the created Playlist and ensure it is removed.
            PlaylistManager.Delete(playlist.Id);

            bool exceptionEncountered = false;
            try
            {
                Playlist deletedPlaylist = PlaylistManager.Get(playlist.Id);
            }
            catch (ObjectNotFoundException)
            {
                exceptionEncountered = true;
            }

            Assert.IsTrue(exceptionEncountered);
        }
Exemplo n.º 4
0
        public PlaylistDto Create(PlaylistDto playlistDto)
        {
            PlaylistDto savedPlaylistDto;

            using (ITransaction transaction = Session.BeginTransaction())
            {
                User user = UserManager.Get(playlistDto.UserId);

                Playlist playlist = new Playlist(playlistDto.Id, playlistDto.Sequence, playlistDto.Title);
                user.AddPlaylist(playlist);

                playlist.AddItems(playlistDto.Items.Select(dto => new PlaylistItem(dto.Id, dto.Sequence, dto.Title, dto.Cid, dto.Song.Id, dto.Song.Type, dto.Song.Title, dto.Song.Duration, dto.Song.Author)));

                //  Make sure the playlist has been setup properly before it is cascade-saved through the User.
                playlist.ValidateAndThrow();

                PlaylistManager.Save(playlist);

                savedPlaylistDto = PlaylistDto.Create(playlist);

                transaction.Commit();
            }

            return savedPlaylistDto;
        }
Exemplo n.º 5
0
        public void SetPatchableProperties(Playlist playlist)
        {
            if (Title != null)
                playlist.Title = Title;

            if (Sequence.HasValue)
                playlist.Sequence = (double)Sequence;
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Creates a new Video and PlaylistItem, puts item in the database and then returns
        ///     the item. Just a nice utility method to keep things DRY.
        /// </summary>
        public PlaylistItem CreateItemInPlaylist(Playlist playlist)
        {
            //  Create a new PlaylistItem and write it to the database.
            var playlistItem = CreateUnsavedPlaylistItem();

            playlist.AddItem(playlistItem);

            PlaylistItemManager.Save(playlistItem);

            return playlistItem;
        }
        public void ShouldMap()
        {
            using (var transaction = Session.BeginTransaction())
            {
                var createdUser = new User
                    {
                        GooglePlusId = "some id?"
                    };
                Session.Save(createdUser);

                var playlist2 = new Playlist("users second playlist")
                    {
                        User = createdUser,
                        Sequence = 200,
                    };

                var playlistItem = new PlaylistItem
                    {
                        Playlist = playlist2,
                        SongId = "some id",
                        Author = "author",
                        Duration = 90,
                        Sequence = 300,
                        Title = "My playlist item",
                    };

                playlist2.AddItem(playlistItem);

                Session.Save(playlist2);

                Session.Flush();
                Session.Clear();

                var savedPlaylistItem = Session.Get<PlaylistItem>(playlistItem.Id);

                Assert.That(savedPlaylistItem.Title, Is.EqualTo("My playlist item"));
                Assert.That(savedPlaylistItem.Id, Is.Not.EqualTo(Guid.Empty));
                Assert.That(savedPlaylistItem.Sequence, Is.EqualTo(300));

                transaction.Rollback();
            }
        }
Exemplo n.º 8
0
        public void ShouldMap()
        {
            using (var transaction = Session.BeginTransaction())
            {
                var createdUser = new User
                    {
                        GooglePlusId = "some id?"
                    };

                Session.Save(createdUser);

                var playlist2 = new Playlist("users second playlist")
                    {
                        User = createdUser,
                        Sequence = 200,
                    };

                var playlistItem = new PlaylistItem
                    {
                        Playlist = playlist2,
                        Sequence = 200,
                    };

                playlist2.AddItem(playlistItem);

                var playlistId = Session.Save(playlist2);

                Session.Flush();
                Session.Clear();

                var savedPlaylist = Session.Get<Playlist>(playlistId);

                Assert.That(savedPlaylist.Title, Is.EqualTo("users second playlist"));
                Assert.That(savedPlaylist.Id, Is.Not.EqualTo(Guid.Empty));
                Assert.That(savedPlaylist.Sequence, Is.EqualTo(200));

                Assert.That(savedPlaylist.Items, Has.Exactly(1).EqualTo(playlistItem));

                transaction.Rollback();
            }
        }
Exemplo n.º 9
0
        public PlaylistDto Copy(CopyPlaylistRequestDto copyPlaylistRequestDto)
        {
            PlaylistDto playlistDto;

            using (ITransaction transaction = Session.BeginTransaction())
            {
                Playlist playlistToCopy = PlaylistManager.Get(copyPlaylistRequestDto.PlaylistId);
                User user = UserManager.Get(copyPlaylistRequestDto.UserId);

                var playlistCopy = new Playlist(playlistToCopy);
                user.AddPlaylist(playlistCopy);

                PlaylistManager.Save(playlistCopy);

                playlistDto = PlaylistDto.Create(playlistCopy);

                transaction.Commit();
            }

            return playlistDto;
        }
Exemplo n.º 10
0
 public Playlist(Playlist playlist)
     : this()
 {
     Copy(playlist);
 }
Exemplo n.º 11
0
        public virtual void Copy(Playlist playlist)
        {
            Title = playlist.Title;

            foreach (PlaylistItem playlistItem in playlist.Items)
            {
                PlaylistItem shareableItemCopy = new PlaylistItem(playlistItem);
                AddItem(shareableItemCopy);
            }
        }
Exemplo n.º 12
0
        public PlaylistDto CreateCopyByShareCode(ShareCodeRequestDto shareCodeRequestDto)
        {
            PlaylistDto playlistDto;

            using (ITransaction transaction = Session.BeginTransaction())
            {
                ShareCode shareCode = ShareCodeManager.GetByShortIdAndEntityTitle(shareCodeRequestDto.ShortId, shareCodeRequestDto.UrlFriendlyEntityTitle);

                //  Never return the sharecode's playlist reference. Make a copy of it to give out so people can't modify the original.
                Playlist playlistToCopy = PlaylistManager.Get(shareCode.EntityId);

                User user = UserManager.Get(shareCodeRequestDto.UserId);

                var playlistCopy = new Playlist(playlistToCopy);
                user.AddPlaylist(playlistCopy);

                PlaylistManager.Save(playlistCopy);

                playlistDto = PlaylistDto.Create(playlistCopy);

                transaction.Commit();
            }

            return playlistDto;
        }
Exemplo n.º 13
0
 public static PlaylistDto Create(Playlist playlist)
 {
     PlaylistDto playlistDto = Mapper.Map<Playlist, PlaylistDto>(playlist);
     return playlistDto;
 }