Example #1
0
        public void DeletedOwnerTests()
        {
            // To ensure validity of this test we need to delete orphaned records from other tests
            ClearDeletedTestRecords();

            IEnhancedVideoDbRepository _enhancedRepo
                = new EnhancedVideoDbRepository(
                      new VideoDbRepository(VideoDbContextFactory.Create(connectionString),
                                            new Microsoft.Extensions.Caching.Memory.MemoryCache(
                                                new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions())),
                      EnhancedVideoDbContextFactory.Create(connectionString),
                      _options);

            var video = new DatabaseModel.videodb_videodata();

            video.title    = "TestVideoDeleted";
            video.plot     = "TestPlot";
            video.owner_id = _options.DeletedOwnerId;

            IVideoDbRepository _videoDbRepository
                = new VideoDbRepository(VideoDbContextFactory.Create(connectionString));

            var id = _videoDbRepository.InsertOrUpdateVideo(video);

            var actual = _enhancedRepo.GetMovieByTitle("TestVideoDeleted");

            Assert.True(actual.Count() == 0, $"Assert 1: {actual.Count()}");

            var deleted = _enhancedRepo.GetVideoData(id);

            Assert.Equal("Video has been marked as deleted (no owner).", deleted.Owner);
            Assert.Equal(_options.DeletedOwnerId, deleted.OwnerId);

            _videoDbRepository.DeleteVideo(id);
        }
Example #2
0
        public void FilterDeletedRecordsTest()
        {
            // To ensure validity of this test we need to delete orphaned records from other tests
            ClearDeletedTestRecords();

            IEnhancedVideoDbRepository _enhancedRepo
                = new EnhancedVideoDbRepository(
                      new VideoDbRepository(VideoDbContextFactory.Create(connectionString),
                                            new Microsoft.Extensions.Caching.Memory.MemoryCache(
                                                new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions())),
                      EnhancedVideoDbContextFactory.Create(connectionString),
                      _options);

            var video = new DatabaseModel.videodb_videodata();

            video.title    = "TestVideoDeleted";
            video.plot     = "TestPlot";
            video.owner_id = _options.DeletedOwnerId;

            IVideoDbRepository _videoDbRepository
                = new VideoDbRepository(VideoDbContextFactory.Create(connectionString));

            var id = _videoDbRepository.InsertOrUpdateVideo(video);

            _options.FilterDeletedRecords = false;
            var actual = _enhancedRepo.GetMovieByTitle("TestVideoDeleted");

            Assert.True(actual.Count() == 1, "Assert 1");

            _options.FilterDeletedRecords = true;
            actual = _enhancedRepo.GetMovieByTitle("TestVideoDeleted");
            Assert.True(actual.Count() == 0, "Assert 2");

            _videoDbRepository.DeleteVideo(id);
        }
Example #3
0
        /// <summary>
        /// This method clears records with title "TestVideoDeleted" which maybe orphaned records from
        /// former tests.
        /// </summary>
        private void ClearDeletedTestRecords()
        {
            IVideoDbRepository _videoDbRepository
                = new VideoDbRepository(VideoDbContextFactory.Create(connectionString));

            var orphanedRecords = _videoDbRepository.GetVideoDataByTitle("TestVideoDeleted").ToList();

            foreach (var record in orphanedRecords)
            {
                _videoDbRepository.DeleteVideo(record.id);
            }
        }
        public void InsertOrUpdateVideoDataTest()
        {
            var video = new videodb_videodata();

            video.title = "TestVideo";

            // plot was cut after 256 items, see https://github.com/viper3400/VideoDb/issues/1
            var plotBuilder = new StringBuilder();

            plotBuilder.Append("Lorem ipsum dolor sit amet, causae honestatis his eu. Justo quaeque gubergren at per, probo brute nihil vis no.");
            plotBuilder.Append("His id salutandi consectetuer. In qualisque incorrupte vis, iudico aliquip mei et, ei adolescens voluptaria duo. ");
            plotBuilder.Append("Atqui populo singulis cum at. In causae labores vivendo sea. In brute oporteat appellantur sed.");
            plotBuilder.Append("Cu odio error laboramus his, percipit iracundia argumentum eam te, ea tamquam utroque constituto mei. ");
            plotBuilder.Append("Odio albucius elaboraret ei est. Iudico possim nam ne, cu iusto efficiantur vix. ");
            plotBuilder.Append("Te eum simul albucius conclusionemque, et cum nulla eruditi intellegam. Impetus singulis no mel.");
            plotBuilder.Append("Usu quidam accumsan concludaturque an, pri dico inimicus.");
            video.plot     = plotBuilder.ToString();;
            video.owner_id = 3;

            IVideoDbRepository _videoDbRepository
                = new VideoDbRepository(VideoDbContextFactory.Create(connectionString));

            var id = _videoDbRepository.InsertOrUpdateVideo(video);

            Assert.True(id != 0);

            var actual = _videoDbRepository.GetVideoDataById(id);

            Assert.Equal("TestVideo", actual.title);
            Assert.Equal(plotBuilder.ToString(), actual.plot);
            Assert.Equal(3, actual.owner_id);

            video.title = "TestVideo (Updated)";
            var updatedId = _videoDbRepository.InsertOrUpdateVideo(video);

            Assert.Equal(id, updatedId);

            Assert.Equal("TestVideo (Updated)", actual.title);
            Assert.Equal(plotBuilder.ToString(), actual.plot);
            Assert.Equal(3, actual.owner_id);

            var deleted = _videoDbRepository.DeleteVideo(updatedId);

            Assert.True(deleted);

            var deletedVideo = _videoDbRepository.GetVideoDataById(updatedId);

            Assert.Null(deletedVideo);
        }