public void CreateItem_NoVideoExists_VideoAndItemCreated() { PlaylistItem playlistItem = Helpers.CreateItemInPlaylist(Playlist); NHibernateSessionManager.Instance.OpenSessionAndBeginTransaction(); // Ensure that the Video was created. Video videoFromDatabase = VideoDao.Get(playlistItem.Video.Id); Assert.NotNull(videoFromDatabase); // Ensure that the PlaylistItem was created. PlaylistItem itemFromDatabase = PlaylistItemDao.Get(playlistItem.Id); Assert.NotNull(itemFromDatabase); // Should have a sequence number after saving for sure. Assert.GreaterOrEqual(itemFromDatabase.Sequence, 0); NHibernateSessionManager.Instance.CommitTransactionAndCloseSession(); // Pointers should be self-referential with only one item in the Playlist. //Assert.AreEqual(itemFromDatabase.NextItem, itemFromDatabase); //Assert.AreEqual(itemFromDatabase.PreviousItem, itemFromDatabase); }
public void CreateItem_VideoAlreadyExists_ItemCreatedVideoNotUpdated() { var 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"; var 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); // Remove entity from NHibernate cache to force DB query to ensure actually created. NHibernateSessionManager.Instance.Clear(); // Ensure that the Video was NOT updated by comparing the new title to the old one. Video videoFromDatabase = VideoDao.Get(videoNotInDatabase.Id); Assert.AreNotEqual(videoFromDatabase.Title, videoTitle); // Ensure that the PlaylistItem was created. PlaylistItem itemFromDatabase = PlaylistItemDao.Get(playlistItem.Id); Assert.NotNull(itemFromDatabase); // Pointers should be self-referential with only one item in the Playlist. Assert.AreEqual(itemFromDatabase.NextItem, itemFromDatabase); Assert.AreEqual(itemFromDatabase.PreviousItem, itemFromDatabase); }
public void CreateItem_NoVideoExists_VideoAndItemCreated() { PlaylistItem playlistItem = Helpers.CreateItemInPlaylist(Playlist); // Ensure that the Video was created. Video videoFromDatabase = VideoDao.Get(playlistItem.Video.Id); Assert.NotNull(videoFromDatabase); // Ensure that the PlaylistItem was created. PlaylistItem itemFromDatabase = PlaylistItemDao.Get(playlistItem.Id); Assert.NotNull(itemFromDatabase); // Pointers should be self-referential with only one item in the Playlist. Assert.AreEqual(itemFromDatabase.NextItem, itemFromDatabase); Assert.AreEqual(itemFromDatabase.PreviousItem, itemFromDatabase); }
public void CreateItem_VideoAlreadyExists_ItemCreatedVideoNotUpdated() { var videoNotInDatabase = Helpers.CreateUnsavedVideoWithId(); NHibernateSessionManager.Instance.OpenSessionAndBeginTransaction(); VideoManager.Save(videoNotInDatabase); NHibernateSessionManager.Instance.CommitTransactionAndCloseSession(); // Change the title for videoInDatabase to check that cascade-update does not affect title. Videos are immutable. const string videoTitle = "A video title"; var 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); NHibernateSessionManager.Instance.OpenSessionAndBeginTransaction(); PlaylistItemManager.Save(playlistItem); NHibernateSessionManager.Instance.CommitTransactionAndCloseSession(); NHibernateSessionManager.Instance.OpenSessionAndBeginTransaction(); // Ensure that the Video was NOT updated by comparing the new title to the old one. Video videoFromDatabase = VideoDao.Get(videoNotInDatabase.Id); Assert.AreNotEqual(videoFromDatabase.Title, videoTitle); // Ensure that the PlaylistItem was created. PlaylistItem itemFromDatabase = PlaylistItemDao.Get(playlistItem.Id); Assert.NotNull(itemFromDatabase); // Should have a sequence number after saving for sure. Assert.GreaterOrEqual(itemFromDatabase.Sequence, 0); NHibernateSessionManager.Instance.CommitTransactionAndCloseSession(); }