public long CreateLibrary(CreateLibraryDto library, string guid = null)
        {
            if (guid == null)
            {
                guid = UniqueIdUtil.GenerateUniqueId();
            }

            using (var db = DataAccessUtil.CreateSqlConnection()) {
                db.Open();
                long createdLibraryId = -1;

                using (var txn = db.BeginTransaction()) {
                    var command = new SqliteCommand();
                    command.Connection  = db;
                    command.CommandText = "INSERT INTO library VALUES(NULL, @Name, @BackgroundId, false, @UniqueId)";
                    command.Parameters.AddWithValue("@Name", library.Name);
                    command.Parameters.AddWithValue("@BackgroundId", QueryUtil.GetNullableIdForStorage(library.BackgroundImageId));
                    command.Parameters.AddWithValue("@UniqueId", guid);
                    command.Transaction = txn;
                    command.ExecuteNonQuery();
                    createdLibraryId = QueryUtil.GetLastInsertedPrimaryKey(db, txn);

                    foreach (var setting in LibrarySettings.DEFAULT_SETTINGS)
                    {
                        var createSettingsCommand = new SqliteCommand($"INSERT INTO library_setting VALUES({createdLibraryId}, '{setting.Key}', '{setting.Value}')", db, txn);
                        createSettingsCommand.ExecuteNonQuery();
                    }

                    txn.Commit();
                }

                return(createdLibraryId);
            }
        }
Beispiel #2
0
        public void ImportLibrary_SeriesSequence_ShouldReference_FileSeries()
        {
            var files = new List <MediaFile> {
                new MediaFile(-1, "https://google.ca", MediaFileType.IMAGE_TYPE, "f1", DateTime.Now, UniqueIdUtil.GenerateUniqueId()),
                new MediaFile(-1, "https://google.com", MediaFileType.IMAGE_TYPE, "f2", DateTime.Now, UniqueIdUtil.GenerateUniqueId())
            };
            var publishers = new List <ExportedPublisherSimpleDto> {
            };
            var calendars  = new List <Calendar> {
            };
            var series     = new List <ExportedSeriesSimpleDto> {
                new ExportedSeriesSimpleDto(
                    new Series(-1, "s1", "", -1, "", -1, -1, -1, false, UniqueIdUtil.GenerateUniqueId()),
                    null, null, null
                    )
            };
            var sequences = new List <ExportedSeriesSequenceSimpleDto> {
                new ExportedSeriesSequenceSimpleDto(
                    new SeriesSequence(-1, "s1", "", -1, false, false, 0, -1, UniqueIdUtil.GenerateUniqueId()),
                    files[0].UniqueId, series[0].Details.UniqueId
                    ),
                new ExportedSeriesSequenceSimpleDto(
                    new SeriesSequence(-1, "s1", "", -1, false, false, 0, -1, UniqueIdUtil.GenerateUniqueId()),
                    null, series[0].Details.UniqueId
                    )
            };

            var dto = new ExportedLibraryDto(
                "lib", UniqueIdUtil.GenerateUniqueId(), null,
                new List <ExportedVideoSimpleDto>(), new List <ExportedCharacterSimpleDto>(), new List <ExportedCharacterSimpleDto>(),
                series, publishers, new List <ExportedLocationSimpleDto>(),
                calendars, new List <ExportedPlaylistSimpleDto>(),
                new List <Ingvilt.Dto.Tags.Tag>(), new List <Ingvilt.Dto.Tags.Tag>(), files,
                sequences, new List <Ingvilt.Dto.Export.SeriesTagExportDto>(),
                new List <Ingvilt.Dto.Export.VideoTagExportDto>(), new List <Ingvilt.Dto.Export.FileTagExportDto>(),
                new List <Ingvilt.Dto.Export.CharacterTagExportDto>(), new List <Ingvilt.Dto.Export.VideoMediaFilesExportDto>(),
                new List <Ingvilt.Dto.Export.FileLocationExportDto>(), new List <Ingvilt.Dto.Export.CharacterMediaFilesExportDto>(),
                new List <Ingvilt.Dto.Export.VideosInSequencesExportDto>(), new List <Ingvilt.Dto.Export.VideosInSequencesExportDto>(),
                new List <Ingvilt.Dto.Export.VideoLocationExportDto>(), new List <Ingvilt.Dto.Export.VideoCharacterActorExportDto>(),
                new List <Ingvilt.Dto.Export.VideoCreatorExportDto>(), new LibrarySettings()
                );

            new ImportLibraryService().ImportLibrary(dto);
            var libraryId     = repository.GetLibraries(new InfinitePagination(), "").Result.Results[0].LibraryId;
            var sequencesList = new SeriesSequenceRepository().GetAllSequencesInAllSeries(new InfinitePagination(), libraryId).Result.Results;
            var retFiles      = mediaFileRepository.GetMediaFiles(new InfinitePagination(), "f1").Result.Results;
            var retSeries     = new SeriesRepository().GetSeries(new InfinitePagination()).Result.Results;

            var expectedSequences = new List <SeriesSequence> {
                sequences[0].Details,
                sequences[1].Details
            };

            expectedSequences[0].SeriesId  = retSeries[0].SeriesId;
            expectedSequences[1].SeriesId  = retSeries[0].SeriesId;
            expectedSequences[0].CoverFile = retFiles[0].MediaId;


            CollectionAssert.AreEquivalent(expectedSequences, sequencesList);
        }
Beispiel #3
0
        private long CreateTag(CreateTagDto tag, SqliteConnection db, SqliteTransaction txn)
        {
            var tagCommand = new SqliteCommand("INSERT INTO tag(type, name, deleted, unique_id) VALUES (@TagType, @TagName, false, @UniqueId)", db, txn);

            tagCommand.Parameters.AddWithValue("@TagType", tag.Type);
            tagCommand.Parameters.AddWithValue("@TagName", tag.Name);
            tagCommand.Parameters.AddWithValue("@UniqueId", UniqueIdUtil.GenerateUniqueId());
            tagCommand.ExecuteNonQuery();
            return(QueryUtil.GetLastInsertedPrimaryKey(db, txn));
        }
Beispiel #4
0
        public long CreateSeries(CreateSeriesDto dto)
        {
            using (var db = DataAccessUtil.CreateSqlConnection()) {
                db.Open();
                var command = GetCreateSeriesCommand(db, dto, UniqueIdUtil.GenerateUniqueId(), false);
                command.ExecuteNonQuery();

                return(QueryUtil.GetLastInsertedPrimaryKey(db));
            }
        }
        public CreateVideoSequenceDto(string title, string description, long coverFile, string uniqueId = null)
        {
            Title       = title;
            Description = description;
            CoverFile   = coverFile;

            if (uniqueId == null)
            {
                uniqueId = UniqueIdUtil.GenerateUniqueId();
            }
            UniqueId = uniqueId;
        }
Beispiel #6
0
        public Tag(long tagId, string name, string type, string uniqueId = null)
        {
            TagId = tagId;
            Name  = name;
            Type  = type;

            if (uniqueId == null)
            {
                uniqueId = UniqueIdUtil.GenerateUniqueId();
            }
            UniqueId = uniqueId;
        }
Beispiel #7
0
        public void ImportLibrary_Location_ShouldReferencePublisher()
        {
            var files = new List <MediaFile> {
                new MediaFile(-1, "https://google.ca", MediaFileType.IMAGE_TYPE, "f1", DateTime.Now, UniqueIdUtil.GenerateUniqueId()),
                new MediaFile(-1, "https://google.com", MediaFileType.IMAGE_TYPE, "f2", DateTime.Now, UniqueIdUtil.GenerateUniqueId())
            };
            var publishers = new List <ExportedPublisherSimpleDto> {
                new ExportedPublisherSimpleDto(
                    new Publisher(-1, "p1", "", -1, "", -1, false, UniqueIdUtil.GenerateUniqueId()),
                    null
                    )
            };
            var locations = new List <ExportedLocationSimpleDto> {
                new ExportedLocationSimpleDto(
                    new Location(-1, "l1", "d", -1, -1, -1, false, UniqueIdUtil.GenerateUniqueId()), null, publishers[0].Details.UniqueId
                    ),
                new ExportedLocationSimpleDto(
                    new Location(-1, "l2", "d", -1, -1, -1, false, UniqueIdUtil.GenerateUniqueId()), null, null
                    )
            };

            var dto = new ExportedLibraryDto(
                "lib", UniqueIdUtil.GenerateUniqueId(), null,
                new List <ExportedVideoSimpleDto>(), new List <ExportedCharacterSimpleDto>(), new List <ExportedCharacterSimpleDto>(),
                new List <ExportedSeriesSimpleDto>(), publishers, locations,
                new List <Ingvilt.Dto.Calendars.Calendar>(), new List <ExportedPlaylistSimpleDto>(),
                new List <Ingvilt.Dto.Tags.Tag>(), new List <Ingvilt.Dto.Tags.Tag>(), files,
                new List <ExportedSeriesSequenceSimpleDto>(), new List <Ingvilt.Dto.Export.SeriesTagExportDto>(),
                new List <Ingvilt.Dto.Export.VideoTagExportDto>(), new List <Ingvilt.Dto.Export.FileTagExportDto>(),
                new List <Ingvilt.Dto.Export.CharacterTagExportDto>(), new List <Ingvilt.Dto.Export.VideoMediaFilesExportDto>(),
                new List <Ingvilt.Dto.Export.FileLocationExportDto>(), new List <Ingvilt.Dto.Export.CharacterMediaFilesExportDto>(),
                new List <Ingvilt.Dto.Export.VideosInSequencesExportDto>(), new List <Ingvilt.Dto.Export.VideosInSequencesExportDto>(),
                new List <Ingvilt.Dto.Export.VideoLocationExportDto>(), new List <Ingvilt.Dto.Export.VideoCharacterActorExportDto>(),
                new List <Ingvilt.Dto.Export.VideoCreatorExportDto>(), new LibrarySettings()
                );

            new ImportLibraryService().ImportLibrary(dto);
            var locs    = new LocationRepository().GetLocations(new InfinitePagination()).Result.Results;
            var library = repository.GetLibraries(new InfinitePagination(), "").Result.Results[0];
            var retPubs = new PublisherRepository().GetPublishers(new InfinitePagination()).Result.Results;

            var expectedLocs = new List <Location> {
                locations[0].Details,
                locations[1].Details
            };

            expectedLocs[0].LibraryId   = library.LibraryId;
            expectedLocs[1].LibraryId   = library.LibraryId;
            expectedLocs[0].PublisherId = retPubs[0].PublisherId;

            CollectionAssert.AreEquivalent(expectedLocs, locs);
        }
Beispiel #8
0
        public void ImportLibrary_WithFile()
        {
            var publishers = new List <ExportedPublisherSimpleDto>();
            var files      = new List <MediaFile> {
                new MediaFile(-1, "https://google.ca", MediaFileType.IMAGE_TYPE, "", DateTime.Now, UniqueIdUtil.GenerateUniqueId()),
                new MediaFile(-1, "https://google.com", MediaFileType.IMAGE_TYPE, "", DateTime.Now, UniqueIdUtil.GenerateUniqueId())
            };
            var libraryName = "lib";
            var libraryGUID = UniqueIdUtil.GenerateUniqueId();

            var dto = new ExportedLibraryDto(
                libraryName, libraryGUID, files[0].UniqueId,
                new List <ExportedVideoSimpleDto>(), new List <ExportedCharacterSimpleDto>(), new List <ExportedCharacterSimpleDto>(),
                new List <ExportedSeriesSimpleDto>(), publishers, new List <ExportedLocationSimpleDto>(),
                new List <Ingvilt.Dto.Calendars.Calendar>(), new List <ExportedPlaylistSimpleDto>(),
                new List <Ingvilt.Dto.Tags.Tag>(), new List <Ingvilt.Dto.Tags.Tag>(), files,
                new List <ExportedSeriesSequenceSimpleDto>(), new List <Ingvilt.Dto.Export.SeriesTagExportDto>(),
                new List <Ingvilt.Dto.Export.VideoTagExportDto>(), new List <Ingvilt.Dto.Export.FileTagExportDto>(),
                new List <Ingvilt.Dto.Export.CharacterTagExportDto>(), new List <Ingvilt.Dto.Export.VideoMediaFilesExportDto>(),
                new List <Ingvilt.Dto.Export.FileLocationExportDto>(), new List <Ingvilt.Dto.Export.CharacterMediaFilesExportDto>(),
                new List <Ingvilt.Dto.Export.VideosInSequencesExportDto>(), new List <Ingvilt.Dto.Export.VideosInSequencesExportDto>(),
                new List <Ingvilt.Dto.Export.VideoLocationExportDto>(), new List <Ingvilt.Dto.Export.VideoCharacterActorExportDto>(),
                new List <Ingvilt.Dto.Export.VideoCreatorExportDto>(), new LibrarySettings()
                );

            new ImportLibraryService().ImportLibrary(dto);

            var retFiles = mediaFileRepository.GetMediaFiles(new InfinitePagination()).Result.Results;

            foreach (var file in files)
            {
                foreach (var retFile in retFiles)
                {
                    if (file.UniqueId == retFile.UniqueId)
                    {
                        file.MediaId = retFile.MediaId;
                        break;
                    }
                }
            }

            var libraries       = repository.GetLibraries(new InfinitePagination(), "").Result.Results;
            var library         = libraries[0];
            var expectedLibrary = new Library(library.LibraryId, libraryName, files[0].MediaId, false, libraryGUID);


            Assert.IsTrue(retFiles.Count == 2);
            Assert.AreEqual(1, libraries.Count);
            Assert.AreEqual(expectedLibrary, library);
            Assert.AreNotSame(DatabaseConstants.DEFAULT_ID, library.BackgroundImageId);
        }
Beispiel #9
0
        public void TestUpdateVideoSequence_ShouldNotUpdateDifferentPlaylist()
        {
            var sequenceDto = CreateDto();

            var sequenceToUpdateId = repository.CreateVideoSequence(sequenceDto);

            sequenceDto.UniqueId = UniqueIdUtil.GenerateUniqueId();
            var sequenceNotUpdatedId = repository.CreateVideoSequence(sequenceDto);

            var sequenceToUpdate = repository.GetPlaylist(sequenceToUpdateId);

            sequenceToUpdate.Description += "1";
            repository.UpdateVideoSequence(sequenceToUpdate);

            var sequenceToNotUpdate = repository.GetPlaylist(sequenceNotUpdatedId);

            Assert.AreNotEqual(sequenceToUpdate.Description, sequenceToNotUpdate.Description);
        }
Beispiel #10
0
        public int CreateMediaFiles(List <CreateMediaFileDto> dtos)
        {
            int count = 0;

            using (var db = DataAccessUtil.CreateSqlConnection()) {
                db.Open();

                using (var txn = db.BeginTransaction()) {
                    var checkUrlCommand = new SqliteCommand("SELECT media_id FROM media_file WHERE source_url = @FileUrl", db, txn);
                    checkUrlCommand.Parameters.AddWithValue("@FileUrl", "");

                    foreach (var dto in dtos)
                    {
                        checkUrlCommand.Parameters["@FileUrl"].Value = dto.SourceURL;
                        var reader = checkUrlCommand.ExecuteReader();

                        // this url already exists
                        var fileExists = reader.Read();
                        reader.Close();
                        if (fileExists)
                        {
                            continue;
                        }

                        var command = GetCreateMediaFileCommand(db, dto, UniqueIdUtil.GenerateUniqueId(), false);
                        command.Transaction = txn;
                        command.ExecuteNonQuery();

                        ++count;
                    }

                    txn.Commit();
                }

                return(count);
            }
        }
        public void UpsertCalendars_ShouldUpdateExistingItems()
        {
            var calendars = new List <Calendar>();

            for (int i = 0; i < 3; ++i)
            {
                var calendar = new Calendar(-1, "DD-MM-YYYY", "test: " + i, "test desc", testLibrary.LibraryId, false, UniqueIdUtil.GenerateUniqueId());
                calendars.Add(calendar);
            }

            repository.UpsertCalendars(calendars, new Dictionary <string, long>());
            calendars[0].Name = "new 0";
            calendars[2].Name = "new 2";
            repository.UpsertCalendars(calendars, new Dictionary <string, long>());
            var retCalendars = repository.GetCalendarsInLibrary(testLibrary.LibraryId, GetFirstPage(), "").Result.Results;

            CollectionAssert.AreEquivalent(calendars, retCalendars);
        }
Beispiel #12
0
        public void UpsertPlaylists_ShouldUpdateExistingItems()
        {
            var sequences = new List <ExportedPlaylistSimpleDto>();

            for (int i = 0; i < 3; ++i)
            {
                var s = new PlaylistDto(-1, "p" + i, "", -1, false, testLibrary.LibraryId, DateTime.Now, UniqueIdUtil.GenerateUniqueId());
                sequences.Add(new ExportedPlaylistSimpleDto(s, null));
            }

            var ids = new Dictionary <string, long>();

            repository.UpsertPlaylists(sequences, ids);
            sequences[0].Details.Title = "new 0";
            sequences[0].Details.Title = "new 2";
            repository.UpsertPlaylists(sequences, ids);

            var retSequences = repository.GetPlaylistsInLibrary(testLibrary.LibraryId, GetFirstPage(), "").Result.Results;

            var expectedSequences = sequences.Select(p => p.Details).ToList();

            CollectionAssert.AreEquivalent(expectedSequences, retSequences);
        }
        public void UpsertLocations_ShouldUpdateExistingItems()
        {
            var locations = new List <ExportedLocationSimpleDto>();

            for (int i = 0; i < 3; ++i)
            {
                var location = new Location(-1, "test " + i, "desc", testLibrary.LibraryId, -1, -1, false, UniqueIdUtil.GenerateUniqueId());
                locations.Add(new ExportedLocationSimpleDto(location, null, null));
            }

            repository.UpsertLocations(locations, new Dictionary <string, long>()).ConfigureAwait(false);
            locations[0].Details.Name = "new 0";
            locations[2].Details.Name = "new 2";
            repository.UpsertLocations(locations, new Dictionary <string, long>()).ConfigureAwait(false);

            var retLocs = repository.GetLocationsInLibrary(testLibrary.LibraryId, GetFirstPage(), "").Result.Results;

            foreach (var item in locations)
            {
                foreach (var retrieved in retLocs)
                {
                    if (item.Details.UniqueId == retrieved.UniqueId)
                    {
                        item.Details.CoverFileId = retrieved.CoverFileId;
                        break;
                    }
                }
            }

            var expectedLocs = locations.Select(p => p.Details).ToList();

            CollectionAssert.AreEquivalent(expectedLocs, retLocs);
        }
        public void UpsertVideos_ShouldUpdateExistingItems()
        {
            var videos = new List <ExportedVideoSimpleDto>();

            for (int i = 0; i < 3; ++i)
            {
                var v = new Video(-1, "t" + i, 0, null, null, 0, 0, "", "", "", "", -1, VideoWatchStatus.NEED_TO_WATCH, null, -1, testLibrary.LibraryId, null, null, -1, false, UniqueIdUtil.GenerateUniqueId());
                videos.Add(new ExportedVideoSimpleDto(v, null, null, null));
            }

            var ids = new Dictionary <string, long>();

            repository.UpsertVideos(videos, ids).ConfigureAwait(false);
            videos[0].Details.Title = "new 0";
            videos[2].Details.Title = "new 2";
            repository.UpsertVideos(videos, ids).ConfigureAwait(false);

            var retVideos = repository.GetVideosInLibrary(testLibrary.LibraryId, GetFirstPage(), "").Result.Results;

            var expectedVideos = videos.Select(p => p.Details).ToList();

            CollectionAssert.AreEquivalent(expectedVideos, retVideos);
        }
        public void UpsertSeries_ShouldInsertNewItems()
        {
            var series = new List <ExportedSeriesSimpleDto>();

            for (int i = 0; i < 3; ++i)
            {
                var s = new Series(-1, "test " + i, "", -1, "", -1, testLibrary.LibraryId, -1, false, UniqueIdUtil.GenerateUniqueId());
                series.Add(new ExportedSeriesSimpleDto(s, null, null, null));
            }

            var ids = new Dictionary <string, long>();

            repository.UpsertSeries(series, ids).ConfigureAwait(false);

            var retSeries   = repository.GetSeriesInLibrary(testLibrary.LibraryId, GetFirstPage(), "").Result.Results;
            var expectedIds = new Dictionary <string, long>();

            foreach (var s in retSeries)
            {
                expectedIds[s.UniqueId] = s.SeriesId;
            }

            var expectedSeries = series.Select(p => p.Details).ToList();

            CollectionAssert.AreEquivalent(expectedSeries, retSeries);
            CollectionAssert.AreEquivalent(expectedIds, ids);
        }
Beispiel #16
0
        private void ImportLibrary_Character_ShouldReference_FileCalendar(bool creator)
        {
            var files = new List <MediaFile> {
                new MediaFile(-1, "https://google.ca", MediaFileType.IMAGE_TYPE, "f1", DateTime.Now, UniqueIdUtil.GenerateUniqueId()),
                new MediaFile(-1, "https://google.com", MediaFileType.IMAGE_TYPE, "f2", DateTime.Now, UniqueIdUtil.GenerateUniqueId())
            };
            var publishers = new List <ExportedPublisherSimpleDto> {
            };
            var series     = new List <ExportedSeriesSimpleDto> {
            };
            var videos     = new List <ExportedVideoSimpleDto> {
            };
            var calendars  = new List <Calendar> {
                new Calendar(-1, "", "", "", -1, false, UniqueIdUtil.GenerateUniqueId())
            };
            var characters = new List <ExportedCharacterSimpleDto> {
                new ExportedCharacterSimpleDto(
                    new Character(-1, "c1", "", null, null, null, 0, -1, -1, -1, false, creator, UniqueIdUtil.GenerateUniqueId()),
                    files[0].UniqueId, calendars[0].UniqueId
                    ),
                new ExportedCharacterSimpleDto(
                    new Character(-1, "c1", "", null, null, null, 0, -1, -1, -1, false, creator, UniqueIdUtil.GenerateUniqueId()),
                    null, null
                    )
            };

            var emptyCharacters = new List <ExportedCharacterSimpleDto>();

            var dto = new ExportedLibraryDto(
                "lib", UniqueIdUtil.GenerateUniqueId(), null,
                videos, creator ? emptyCharacters : characters, creator ? characters : emptyCharacters,
                series, publishers, new List <ExportedLocationSimpleDto>(),
                calendars, new List <ExportedPlaylistSimpleDto>(),
                new List <Ingvilt.Dto.Tags.Tag>(), new List <Ingvilt.Dto.Tags.Tag>(), files,
                new List <ExportedSeriesSequenceSimpleDto>(), new List <Ingvilt.Dto.Export.SeriesTagExportDto>(),
                new List <Ingvilt.Dto.Export.VideoTagExportDto>(), new List <Ingvilt.Dto.Export.FileTagExportDto>(),
                new List <Ingvilt.Dto.Export.CharacterTagExportDto>(), new List <Ingvilt.Dto.Export.VideoMediaFilesExportDto>(),
                new List <Ingvilt.Dto.Export.FileLocationExportDto>(), new List <Ingvilt.Dto.Export.CharacterMediaFilesExportDto>(),
                new List <Ingvilt.Dto.Export.VideosInSequencesExportDto>(), new List <Ingvilt.Dto.Export.VideosInSequencesExportDto>(),
                new List <Ingvilt.Dto.Export.VideoLocationExportDto>(), new List <Ingvilt.Dto.Export.VideoCharacterActorExportDto>(),
                new List <Ingvilt.Dto.Export.VideoCreatorExportDto>(), new LibrarySettings()
                );

            new ImportLibraryService().ImportLibrary(dto);
            var charactersList = new CharacterRepository().GetCharacters(new InfinitePagination(), creator).Result.Results;
            var library        = repository.GetLibraries(new InfinitePagination(), "").Result.Results[0];
            var retFiles       = mediaFileRepository.GetMediaFiles(new InfinitePagination(), "f1").Result.Results;
            var retCalendars   = new CalendarRepository().GetCalendars(new InfinitePagination()).Result.Results;

            var expectedChars = new List <Character> {
                characters[0].Details,
                characters[1].Details
            };

            expectedChars[0].LibraryId    = library.LibraryId;
            expectedChars[1].LibraryId    = library.LibraryId;
            expectedChars[0].CoverMediaId = retFiles[0].MediaId;
            expectedChars[0].CalendarId   = retCalendars[0].CalendarId;

            CollectionAssert.AreEquivalent(expectedChars, charactersList);
        }
        public void UpsertSeries_ShouldUpdateExistingItems()
        {
            var series = new List <ExportedSeriesSimpleDto>();

            for (int i = 0; i < 3; ++i)
            {
                var s = new Series(-1, "test " + i, "", -1, "", -1, testLibrary.LibraryId, -1, false, UniqueIdUtil.GenerateUniqueId());
                series.Add(new ExportedSeriesSimpleDto(s, null, null, null));
            }

            repository.UpsertSeries(series, new Dictionary <string, long>()).ConfigureAwait(false);
            series[0].Details.Name = "new 0";
            series[2].Details.Name = "new 2";
            repository.UpsertSeries(series, new Dictionary <string, long>()).ConfigureAwait(false);

            var retSeries = repository.GetSeriesInLibrary(testLibrary.LibraryId, GetFirstPage(), "").Result.Results;

            var expectedSeries = series.Select(p => p.Details).ToList();

            CollectionAssert.AreEquivalent(expectedSeries, retSeries);
        }
        public void UpsertCalendars_ShouldInsertNewItems()
        {
            var calendars = new List <Calendar>();

            for (int i = 0; i < 3; ++i)
            {
                var calendar = new Calendar(-1, "DD-MM-YYYY", "test: " + i, "test desc", testLibrary.LibraryId, false, UniqueIdUtil.GenerateUniqueId());
                calendars.Add(calendar);
            }

            var ids = new Dictionary <string, long>();

            repository.UpsertCalendars(calendars, ids);
            var retCalendars = repository.GetCalendarsInLibrary(testLibrary.LibraryId, GetFirstPage(), "").Result.Results;
            var expectedIds  = new Dictionary <string, long>();

            foreach (var calendar in retCalendars)
            {
                expectedIds[calendar.UniqueId] = calendar.CalendarId;
            }

            CollectionAssert.AreEquivalent(calendars, retCalendars);
            CollectionAssert.AreEquivalent(expectedIds, ids);
        }
        public void UpsertSeriesSequences_ShouldUpdateExistingItems()
        {
            var sequences = new List <ExportedSeriesSequenceSimpleDto>();

            for (int i = 0; i < 3; ++i)
            {
                var s = new SeriesSequence(-1, "t" + i, "", -1, false, false, 0, testSeries.SeriesId, UniqueIdUtil.GenerateUniqueId());
                sequences.Add(new ExportedSeriesSequenceSimpleDto(s, null, testSeries.UniqueId));
            }

            var ids = new Dictionary <string, long>();

            repository.UpsertSeriesSequences(sequences, ids);
            sequences[0].Details.Title = "new 0";
            sequences[2].Details.Title = "new 2";
            repository.UpsertSeriesSequences(sequences, ids);

            var retSequences = repository.GetVideoSequencesInSeries(testSeries.SeriesId, GetFirstPage()).Result.Results;

            var expectedSequences = sequences.Select(p => p.Details).ToList();

            CollectionAssert.AreEquivalent(expectedSequences, retSequences);
        }
Beispiel #20
0
        public void UpsertMediaFiles_ShouldUpdateExistingFiles()
        {
            var files = new List <MediaFile>();

            for (int i = 0; i < 3; ++i)
            {
                var newFile = new MediaFile(-1, "https://google.ca", MediaFileType.VIDEO_TYPE, $"file {i}", DateTime.Now, UniqueIdUtil.GenerateUniqueId());
                files.Add(newFile);
            }

            repository.UpsertMediaFiles(files, new Dictionary <string, long>()).ConfigureAwait(false);
            files[0].Name = "new 1";
            files[2].Name = "new 2";
            repository.UpsertMediaFiles(files, new Dictionary <string, long>()).ConfigureAwait(false);

            var retrievedFiles = repository.GetMediaFiles(GetFirstPage()).Result.Results;

            foreach (var file in files)
            {
                foreach (var retrieved in retrievedFiles)
                {
                    if (file.UniqueId == retrieved.UniqueId)
                    {
                        file.MediaId = retrieved.MediaId;
                        break;
                    }
                }
            }

            CollectionAssert.AreEquivalent(files, retrievedFiles);
        }
Beispiel #21
0
        public void UpsertPublishers_ShouldUpdateExistingPublishers()
        {
            var publishers = new List <ExportedPublisherSimpleDto>();

            for (int i = 0; i < 3; ++i)
            {
                var publisher = new Publisher(-1, "test " + i, "https://google.ca", -1, "desc", testLibrary.LibraryId, false, UniqueIdUtil.GenerateUniqueId());
                publishers.Add(new ExportedPublisherSimpleDto(publisher, null));
            }

            repository.UpsertPublishers(publishers, new Dictionary <string, long>()).ConfigureAwait(false);
            publishers[0].Details.Name = "new 0";
            publishers[2].Details.Name = "new 2";
            repository.UpsertPublishers(publishers, new Dictionary <string, long>()).ConfigureAwait(false);

            var retrievedPublishers = repository.GetPublishersInLibrary(testLibrary.LibraryId, GetFirstPage(), "").Result.Results;

            foreach (var publisher in publishers)
            {
                foreach (var retrieved in retrievedPublishers)
                {
                    if (publisher.Details.UniqueId == retrieved.UniqueId)
                    {
                        publisher.Details.LogoFileId = retrieved.LogoFileId;
                        break;
                    }
                }
            }

            var expectedPublishers = publishers.Select(p => p.Details).ToList();

            CollectionAssert.AreEquivalent(expectedPublishers, retrievedPublishers);
        }