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);

            NHibernateSessionManager.Instance.OpenSessionAndBeginTransaction();
            PlaylistManager.Save(playlist);
            NHibernateSessionManager.Instance.CommitTransactionAndCloseSession();

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

            NHibernateSessionManager.Instance.OpenSessionAndBeginTransaction();
            Playlist deletedPlaylist = PlaylistDao.Get(playlist.Id);

            bool objectNotFoundExceptionEncountered = false;
            try
            {
                //  Evaluating a lazyily-loaded entity which isn't in the database will throw an ONF exception.
                Assert.IsNull(deletedPlaylist);
            }
            catch (ObjectNotFoundException)
            {
                objectNotFoundExceptionEncountered = true;
            }

            Assert.IsTrue(objectNotFoundExceptionEncountered);
            NHibernateSessionManager.Instance.CommitTransactionAndCloseSession();
        }
Exemplo n.º 2
0
        public void ShouldMap()
        {
            var sessionFactory = new NHibernateConfiguration().Configure().BuildSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var createdUser = new User {GooglePlusId = "some id?", Name = "user name"};
                    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.Name, Is.EqualTo(createdUser.Name));
                    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.º 3
0
        public JsonResult CreateCopyByShareCode(string shareCodeShortId, string urlFriendlyEntityTitle, Guid userId)
        {
            PlaylistDto playlistDto;

            using (ITransaction transaction = Session.BeginTransaction())
            {
                ShareCode shareCode = ShareCodeManager.GetByShortIdAndEntityTitle(shareCodeShortId, 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(userId);

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

                PlaylistManager.Save(playlistCopy);

                playlistDto = PlaylistDto.Create(playlistCopy);

                transaction.Commit();
            }

            return Json(playlistDto);
        }
Exemplo n.º 4
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);
        }
        public void ShouldMap()
        {
            var sessionFactory = new NHibernateConfiguration().Configure().BuildSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var createdUser = new User {GooglePlusId = "some id?", Name = "user name"};
                    session.Save(createdUser);

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

                    var video = new Video
                        {
                            Id = "some id",
                            Author = "video author",
                            Duration = 90,
                            HighDefinition = true,
                            Title = "my video",
                        };
                    session.Save(video);
                    var playlistItem = new PlaylistItem
                        {
                            Cid = "cid",
                            Playlist = playlist2,
                            Video = video,
                            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));

                    Assert.That(savedPlaylistItem.Video, Is.EqualTo(playlistItem.Video));

                    transaction.Rollback();
                }
            }
        }
Exemplo n.º 6
0
        public void SetupContext()
        {
            Folder folder = User.Folders.First();

            //  Make a new Playlist object each time to ensure no side-effects from previous test case.
            Playlist = folder.CreateAndAddPlaylist();
            PlaylistManager.Save(Playlist);

            //  Ensure that the Playlist is still lazily-loaded in all instances.
            NHibernateSessionManager.Instance.Evict(Playlist);
        }
Exemplo n.º 7
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 static PlaylistItem CreateItemInPlaylist(Playlist playlist)
        {
            Video videoNotInDatabase = CreateUnsavedVideoWithId();

            //  Create a new PlaylistItem and write it to the database.
            string title = videoNotInDatabase.Title;
            var playlistItem = new PlaylistItem(title, videoNotInDatabase);

            playlist.AddItem(playlistItem);
            PlaylistItemManager.Save(playlistItem);

            return playlistItem;
        }
Exemplo n.º 8
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 static PlaylistItem CreateItemInPlaylist(Playlist playlist)
        {
            Video videoNotInDatabase = CreateUnsavedVideoWithId();

            //  Create a new PlaylistItem and write it to the database.
            string title = videoNotInDatabase.Title;
            var playlistItem = new PlaylistItem(title, videoNotInDatabase);

            playlist.AddItem(playlistItem);

            NHibernateSessionManager.Instance.OpenSessionAndBeginTransaction();
            PlaylistItemManager.Save(playlistItem);
            NHibernateSessionManager.Instance.CommitTransactionAndCloseSession();

            return playlistItem;
        }
Exemplo n.º 9
0
        public virtual void Copy(Playlist playlist)
        {
            Title = playlist.Title;

            foreach (PlaylistItem playlistItem in playlist.Items)
            {
                PlaylistItem shareableItemCopy = new PlaylistItem(playlistItem);
                AddItem(shareableItemCopy);

                //  If the old playlist's firstItemId was the currently old item we're iterating over,
                //  set the current new item as the first item.
                if (playlistItem == playlist.FirstItem)
                {
                    FirstItem = shareableItemCopy;
                }
            }
        }
Exemplo n.º 10
0
        public void ShouldMap()
        {
            var sessionFactory = new NHibernateConfiguration().Configure().BuildSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var createdUser = new User {GooglePlusId = "some id?", Name = "user name"};

                    session.Save(createdUser);

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

                    var playlistItem = new PlaylistItem
                        {
                            Cid = "cid",
                            Playlist = playlist2,
                            Video = new Video(),
                            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.º 11
0
        public static Playlist Create(PlaylistDto playlistDto, IUserManager userManager, IPlaylistManager playlistManager)
        {
            Playlist playlist = new Playlist
                {
                    Id = playlistDto.Id,
                    Items = PlaylistItem.Create(playlistDto.Items, playlistManager),
                    Sequence = playlistDto.Sequence,
                    Title = playlistDto.Title,
                    User = userManager.Get(playlistDto.UserId)
                };

            //  TODO: This seems unnecessary...
            //  TODO: I could probably leverage backbone's CID property to have the items know of their playlist. Or maybe I should just enforce adding client-side before saving?
            //  If an unsaved playlist comes from the client with items already in it, the items will not know their playlist's ID.
            //  So, re-map to the playlist as appropriate.
            List<PlaylistItem> improperlyAddedItems = playlist.Items.Where(i => i.Playlist == null).ToList();
            improperlyAddedItems.ForEach(i => playlist.Items.Remove(i));
            playlist.AddItems(improperlyAddedItems);

            return playlist;
        }
Exemplo n.º 12
0
 public static PlaylistDto Create(Playlist playlist)
 {
     PlaylistDto playlistDto = Mapper.Map<Playlist, PlaylistDto>(playlist);
     return playlistDto;
 }
Exemplo n.º 13
0
        public void DeletePlaylist()
        {
            //  Create a new Playlist and write it to the database.
            string title = string.Format("New Playlist {0:D4}", Folder.Playlists.Count);
            var playlist = new Playlist(title);

            Folder.AddPlaylist(playlist);
            PlaylistManager.Save(playlist);

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

            //  Remove entity from NHibernate cache to force DB query to ensure actually created.
            NHibernateSessionManager.Instance.Clear();

            Playlist deletedPlaylist = PlaylistDao.Get(playlist.Id);

            bool objectNotFoundExceptionEncountered = false;
            try
            {
                //  Evaluating a lazyily-loaded entity which isn't in the database will throw an ONF exception.
                Assert.IsNull(deletedPlaylist);
            }
            catch (ObjectNotFoundException)
            {
                objectNotFoundExceptionEncountered = true;
            }

            Assert.IsTrue(objectNotFoundExceptionEncountered);

        }
Exemplo n.º 14
0
 public Playlist(Playlist playlist)
     : this()
 {
     Copy(playlist);
 }
Exemplo n.º 15
0
 public Playlist(Playlist playlist)
     : this()
 {
     Copy(playlist);
 }
Exemplo n.º 16
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.º 17
0
        public JsonResult CreateCopyByShareCode(string shareCodeShortId, string urlFriendlyEntityTitle, Guid folderId)
        {
            ShareCode shareCode = ShareCodeDao.GetByShortIdAndEntityTitle(shareCodeShortId, urlFriendlyEntityTitle);

            if (shareCode == null)
            {
                throw new ApplicationException("Unable to locate shareCode in database.");
            }

            if (shareCode.EntityType != ShareableEntityType.Playlist)
            {
                throw new ApplicationException("Expected shareCode to have entityType of Playlist");
            }

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

            Folder folder = FolderDao.Get(folderId);

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

            PlaylistManager.Save(playlistCopy);

            PlaylistDto playlistDto = PlaylistDto.Create(playlistCopy);
            return new JsonDataContractActionResult(playlistDto);
        }