Exemplo n.º 1
0
        public async Task ValidateStatusAndDescription(MangaInfo mangaInfo)
        {
            IManga manga;

            using (var context = Repository.GetEntityContext("Description"))
            {
                var mangaUri    = new Uri(mangaInfo.Uri);
                var existsManga = await context.Get <IManga>().FirstOrDefaultAsync(m => m.Uri == mangaUri).ConfigureAwait(false);

                if (existsManga != null)
                {
                    await context.Delete(existsManga).ConfigureAwait(false);
                }
                manga = await Mangas.CreateFromWeb(mangaUri).ConfigureAwait(false);
            }

            Assert.AreEqual(mangaInfo.Description, manga.Description);
            if (Equals(mangaInfo.Status, manga.Status))
            {
                Assert.Pass();
            }
            else
            {
                var storedWords = GetWords(mangaInfo.Status);
                var downloaded  = GetWords(manga.Status);
                var changes     = storedWords.Except(downloaded).Count() + downloaded.Except(storedWords).Count();
                // Status can contain regular changed info, try to compare
                Assert.LessOrEqual(changes, 2);
            }
        }
Exemplo n.º 2
0
        public async Task ValidateStatusAndDescription(MangaInfo mangaInfo)
        {
            IManga manga;

            using (var context = Repository.GetEntityContext("Description"))
            {
                if (mangaInfo.Uri == MangaInfos.Mangachan.EveScramble.Uri)
                {
                    var login = await context.Get <MangachanLogin>().SingleAsync().ConfigureAwait(false);

                    login.PasswordHash = "e84fce6c43aacd7f8452409a63083c18";
                    login.UserId       = "282433";
                    login.IsLogined    = true;
                    await context.Save(login).ConfigureAwait(false);
                }

                var mangaUri    = new Uri(mangaInfo.Uri);
                var existsManga = await context.Get <IManga>().FirstOrDefaultAsync(m => m.Uri == mangaUri).ConfigureAwait(false);

                if (existsManga != null)
                {
                    await context.Delete(existsManga).ConfigureAwait(false);
                }
                manga = await Mangas.CreateFromWeb(mangaUri).ConfigureAwait(false);
            }

            Assert.AreEqual(mangaInfo.Description, manga.Description);
            if (Equals(mangaInfo.Status, manga.Status))
            {
                Assert.Pass();
            }
            else
            {
                var storedWords = GetWords(mangaInfo.Status);
                var downloaded  = GetWords(manga.Status);
                var changes     = storedWords.Except(downloaded).Count() + downloaded.Except(storedWords).Count();
                // Status can contain regular changed info, try to compare
                Assert.LessOrEqual(changes, 2);
            }
        }
Exemplo n.º 3
0
        public async Task Download(MangaInfo mangaInfo)
        {
            IManga manga;
            var    sw = new Stopwatch();

            using (var context = Repository.GetEntityContext($"Test to download {mangaInfo.Uri}"))
            {
                foreach (var toDelete in context.Get <IManga>().Where(m => m.Uri.ToString() == mangaInfo.Uri))
                {
                    await context.Delete(toDelete).ConfigureAwait(false);

                    DirectoryHelpers.DeleteDirectory(toDelete.GetAbsoluteFolderPath());
                }

                manga = await Mangas.CreateFromWeb(new Uri(mangaInfo.Uri)).ConfigureAwait(false);

                DirectoryHelpers.DeleteDirectory(manga.GetAbsoluteFolderPath());
                sw.Start();
                await manga.Download().ConfigureAwait(false);
            }

            sw.Stop();
            Log.Add($"manga loaded {sw.Elapsed.TotalSeconds}, iscompleted = {manga.IsDownloaded}, downloaded = {manga.Downloaded}%");
            Assert.IsTrue(Directory.Exists(manga.GetAbsoluteFolderPath()));
            var files = Directory.GetFiles(manga.GetAbsoluteFolderPath(), "*", SearchOption.AllDirectories);

            Assert.AreEqual(mangaInfo.FilesInFolder, files.Length);
            var fileInfos = files.Select(f => new FileInfo(f)).ToList();

            Assert.AreEqual(mangaInfo.FolderSize, fileInfos.Sum(f => f.Length), mangaInfo.FolderSize / 100.0);
            if (mangaInfo.AllFilesUnique)
            {
                Assert.AreEqual(1, fileInfos.GroupBy(f => f.Length).Max(g => g.Count()));
            }
            Assert.IsTrue(manga.IsDownloaded);
            Assert.AreEqual(100, manga.Downloaded);
        }