Exemplo n.º 1
0
        public void CreateItem_VideoAlreadyExists_ItemCreatedVideoNotUpdated()
        {
            Video videoNotInDatabase = Helpers.CreateUnsavedVideoWithId();

            VideoManager.Save(videoNotInDatabase);

            //  Change the title for videoInDatabase to check that cascade-update does not affect title. Videos are immutable.
            const string videoTitle      = "A video title";
            Video        videoInDatabase = Helpers.CreateUnsavedVideoWithId(titleOverride: videoTitle);

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

            Playlist.AddItem(playlistItem);

            PlaylistItemManager.Save(playlistItem);

            //  Ensure that the Video was NOT updated by comparing the new title to the old one.
            Video videoFromDatabase = VideoManager.Get(videoNotInDatabase.Id);

            Assert.AreNotEqual(videoFromDatabase.Title, videoTitle);

            //  Ensure that the PlaylistItem was created.
            PlaylistItem itemFromDatabase = PlaylistItemManager.Get(playlistItem.Id);

            Assert.NotNull(itemFromDatabase);

            //  Should have a sequence number after saving for sure.
            Assert.GreaterOrEqual(itemFromDatabase.Sequence, 0);
        }
        public JsonResult Create(PlaylistItemDto playlistItemDto)
        {
            PlaylistItemDto savedPlaylistItemDto;

            using (ITransaction transaction = Session.BeginTransaction())
            {
                PlaylistItem playlistItem = PlaylistItem.Create(playlistItemDto, PlaylistManager);

                playlistItem.Playlist.AddItem(playlistItem);

                PlaylistItemManager.Save(playlistItem);

                savedPlaylistItemDto = PlaylistItemDto.Create(playlistItem);

                transaction.Commit();
            }

            return(Json(savedPlaylistItemDto));
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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)
        {
            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.º 5
0
        public PlaylistItemDto Create(PlaylistItemDto playlistItemDto)
        {
            PlaylistItemDto savedPlaylistItemDto;

            using (ITransaction transaction = Session.BeginTransaction())
            {
                Playlist playlist = PlaylistManager.Get(playlistItemDto.PlaylistId);

                SongDto songDto = playlistItemDto.Song;

                PlaylistItem playlistItem = new PlaylistItem(playlistItemDto.Id, playlistItemDto.Title, playlistItemDto.Cid, songDto.Id, songDto.Type, songDto.Title, songDto.Duration, songDto.Author);
                playlistItemDto.SetPatchableProperties(playlistItem);

                playlist.AddItem(playlistItem);

                PlaylistItemManager.Save(playlistItem);

                savedPlaylistItemDto = PlaylistItemDto.Create(playlistItem);

                transaction.Commit();
            }

            return(savedPlaylistItemDto);
        }
Exemplo n.º 6
0
        public void CreateItem_NotAddedToPlaylistBeforeSave_ItemNotAdded()
        {
            //  Create a new PlaylistItem and write it to the database.
            var playlistItem = Helpers.CreateUnsavedPlaylistItem();

            bool validationExceptionEncountered = false;

            try
            {
                //  Try to save the item without adding to Playlist. This should fail.
                PlaylistItemManager.Save(playlistItem);
            }
            catch (ValidationException)
            {
                validationExceptionEncountered = true;
            }

            Assert.IsTrue(validationExceptionEncountered);
        }