public async Task DeleteEpisodeAsyncWorksCorrectly()
        {
            var episodes = new List <Episode>();
            var episode  = new Episode()
            {
                Webtoon = new Webtoon()
                {
                    AuthorId = "test"
                }
            };

            episodes.Add(episode);
            var mockEpisodesRepo = new Mock <IEpisodesRepository>();

            mockEpisodesRepo.Setup(x => x.GetEpisodeByWebtoonTitleNumberAndEpisodeNumber("smt", "smtelse")).Returns(episodes.FirstOrDefault());
            mockEpisodesRepo.Setup(x => x.Delete(It.IsAny <Episode>())).Callback((Episode episode) => episode.IsDeleted = true);
            var mockWebtoonsRepo = new Mock <IWebtoonsRepository>();
            var webtoon          = new Webtoon()
            {
                TitleNumber = "123",
                AuthorId    = "test"
            };

            mockWebtoonsRepo.Setup(x => x.GetWebtoonByTitleNumber("smt")).Returns(webtoon);

            var service = new EpisodesService(mockWebtoonsRepo.Object, mockEpisodesRepo.Object, null, null, null, null, null, null);

            await service.DeleteEpisodeAsync("smt", "smtelse", "test");

            Assert.Single(episodes);
            Assert.True(episode.IsDeleted);
        }
예제 #2
0
        public void EditWebtoonAsyncThrowsArgumentExceptionWhenGivenInvalidAuthorId()
        {
            var mockWebtoonsRepo = new Mock <IWebtoonsRepository>();
            var webtoons         = new List <Webtoon>();
            var firstWebtoon     = new Webtoon()
            {
                Id       = "7",
                AuthorId = "123",
                GenreId  = "14",
                Genre    = new Genre()
                {
                    Name = "action",
                    Id   = "14"
                },
                Author = new ApplicationUser()
                {
                    Id       = "123",
                    UserName = "******"
                },
                Title       = "Darkness",
                TitleNumber = "1",
                Episodes    = new List <Episode>(),
            };

            mockWebtoonsRepo.Setup(x => x.GetWebtoonByTitleNumber(It.IsAny <string>())).Returns((string webtoonTitleNumber) => webtoons.FirstOrDefault(x => x.TitleNumber == webtoonTitleNumber));

            var service = new WebtoonsService(mockWebtoonsRepo.Object, null, null, null, null, null, null, null, null, null);

            Assert.ThrowsAsync <ArgumentException>(() => service.EditWebtoon(null, "456", null));
        }
        public void GetUserSubscribtionsWorksCorrectly()
        {
            var webtoons = new List <Webtoon>();
            var webtoon  = new Webtoon()
            {
                Id       = "789",
                AuthorId = "test",
                Author   = new ApplicationUser()
                {
                    UserName = "******"
                },
                Genre = new Genre()
                {
                    Name = "action"
                },
                Title       = "work",
                TitleNumber = "123"
            };

            webtoon.Subscribers.Add(new WebtoonsSubscribers()
            {
                SubscriberId = "456",
                WebtoonId    = "789"
            });
            var episode = new Episode()
            {
                Id           = "012",
                WebtoonId    = "789",
                EpisodeLikes = new List <EpisodeLike>(),
            };

            episode.EpisodeLikes.Add(new EpisodeLike()
            {
                EpisodeId         = "012",
                ApplicationUserId = "ivan",
                HasLiked          = true
            });
            webtoon.Episodes.Add(episode);
            webtoons.Add(webtoon);
            var mockWebtoonsRepo = new Mock <IWebtoonsRepository>();

            mockWebtoonsRepo.Setup(x => x.All()).Returns(webtoons.AsQueryable());
            var mockEpisodesRepo = new Mock <IEpisodesRepository>();

            mockEpisodesRepo.Setup(x => x.GetEpisodesByWebtoonId("789")).Returns(webtoon.Episodes);
            var mockEpisodeLikesService = new Mock <IEpisodesLikesService>();

            mockEpisodeLikesService.Setup(x => x.GetEpisodeLikes("012")).Returns(episode.EpisodeLikes.Sum(x => x.HasLiked ? 1 : 0));

            var service = new ApplicationUsersService(mockWebtoonsRepo.Object, null, null, null, mockEpisodeLikesService.Object, mockEpisodesRepo.Object);

            var result = service.GetUserSubscribtions("456");

            Assert.Equal("pesho", result.First().Author);
            Assert.Equal(1, result.First().Episodes.Count);
            Assert.Equal("action", result.First().Genre);
            Assert.Equal("work", result.First().Title);
            Assert.Equal("123", result.First().TitleNumber);
            Assert.Equal(1, result.First().Likes);
        }
예제 #4
0
        public async Task DeleteWebtoonAsyncThrowsArgumentExceptionWhenGivenInvalidAuthorId()
        {
            var mockWebtoonsRepo = new Mock <IWebtoonsRepository>();
            var webtoons         = new List <Webtoon>();
            var firstWebtoon     = new Webtoon()
            {
                Id       = "7",
                AuthorId = "123",
                GenreId  = "14",
                Genre    = new Genre()
                {
                    Name = "action",
                    Id   = "14"
                },
                Author = new ApplicationUser()
                {
                    Id       = "123",
                    UserName = "******"
                },
                Title       = "Darkness",
                TitleNumber = "1",
                UploadDay   = MyWebtoonWebProject.Data.Models.Enums.DayOfWeek.Friday,
                Synopsis    = "old synopsis",
                CoverPhoto  = "my old friend.jpeg"
            };

            mockWebtoonsRepo.Setup(x => x.GetWebtoonByTitleNumber("1")).Returns(firstWebtoon);

            var service = new WebtoonsService(mockWebtoonsRepo.Object, null, null, null, null, null, null, null, null, null);


            await Assert.ThrowsAsync <ArgumentException>(() => service.DeleteWebtoonAsync("1", "456"));
        }
        public async Task RateWebtoonAsyncCreatesNewRatingCorrectly()
        {
            var webtoons = new List <Webtoon>();
            var webtoon  = new Webtoon()
            {
                Id          = "test",
                TitleNumber = "123"
            };

            webtoons.Add(webtoon);
            var mockWebtoonRepo = new Mock <IWebtoonsRepository>();

            mockWebtoonRepo.Setup(x => x.GetWebtoonByTitleNumber("123")).Returns(webtoon);
            var webtoonRatings         = new List <WebtoonRating>();
            var mockWebtoonRatingsRepo = new Mock <IWebtoonsRatingsRepository>();

            mockWebtoonRatingsRepo.Setup(x => x.All()).Returns(webtoonRatings.AsQueryable());
            mockWebtoonRatingsRepo.Setup(x => x.AddAsync(It.IsAny <WebtoonRating>())).Callback((WebtoonRating webtoonRating) => webtoonRatings.Add(webtoonRating));

            var service = new WebtoonsRatingsService(mockWebtoonRatingsRepo.Object, mockWebtoonRepo.Object);

            await service.RateWebtoonAsync("123", "gosho", 5);

            Assert.Single(webtoonRatings);
            Assert.Equal("test", webtoonRatings.First().WebtoonId);
            Assert.Equal("gosho", webtoonRatings.First().ApplicationUserId);
            Assert.Equal(5, webtoonRatings.First().RatingValue);
        }
        public async Task DoesWebtoonHaveARatingCorrectlyReturnsTrueWhenVotesArePresent()
        {
            var webtoons = new List <Webtoon>();
            var webtoon  = new Webtoon()
            {
                Id          = "test",
                TitleNumber = "123"
            };

            webtoons.Add(webtoon);
            var mockWebtoonRepo = new Mock <IWebtoonsRepository>();

            mockWebtoonRepo.Setup(x => x.GetWebtoonByTitleNumber("123")).Returns(webtoon);
            var webtoonRatings = new List <WebtoonRating>();

            webtoonRatings.Add(new WebtoonRating()
            {
                ApplicationUserId = "gosho",
                WebtoonId         = "test",
                RatingValue       = 1,
            });
            var mockWebtoonRatingsRepo = new Mock <IWebtoonsRatingsRepository>();

            mockWebtoonRatingsRepo.Setup(x => x.All()).Returns(webtoonRatings.AsQueryable());
            mockWebtoonRatingsRepo.Setup(x => x.AddAsync(It.IsAny <WebtoonRating>())).Callback((WebtoonRating webtoonRating) => webtoonRatings.Add(webtoonRating));

            var service = new WebtoonsRatingsService(mockWebtoonRatingsRepo.Object, mockWebtoonRepo.Object);

            await service.RateWebtoonAsync("123", "ivan", 4);

            var result = service.DoesWebtoonHaveARating("123");

            Assert.True(result);
        }
 public string BuildWebtoonFolderName(Webtoon webtoon)
 {
     return(ReplaceFolderName(string.Format(WebtoonFolderNameFormat,
                                            webtoon.ID,
                                            webtoon.Title,
                                            webtoon.Writer)));
 }
        public async Task RateWebtoonAsyncChangesRatingCorrectly()
        {
            var webtoons = new List <Webtoon>();
            var webtoon  = new Webtoon()
            {
                Id          = "test",
                TitleNumber = "123"
            };

            webtoons.Add(webtoon);
            var mockWebtoonRepo = new Mock <IWebtoonsRepository>();

            mockWebtoonRepo.Setup(x => x.GetWebtoonByTitleNumber("123")).Returns(webtoon);
            var webtoonRatings = new List <WebtoonRating>();

            webtoonRatings.Add(new WebtoonRating()
            {
                ApplicationUserId = "gosho",
                WebtoonId         = "test",
                RatingValue       = 1,
            });
            var mockWebtoonRatingsRepo = new Mock <IWebtoonsRatingsRepository>();

            mockWebtoonRatingsRepo.Setup(x => x.All()).Returns(webtoonRatings.AsQueryable());

            var service = new WebtoonsRatingsService(mockWebtoonRatingsRepo.Object, mockWebtoonRepo.Object);

            await service.RateWebtoonAsync("123", "gosho", 4);

            Assert.Single(webtoonRatings);
            Assert.Equal("test", webtoonRatings.First().WebtoonId);
            Assert.Equal("gosho", webtoonRatings.First().ApplicationUserId);
            Assert.Equal(4, webtoonRatings.First().RatingValue);
        }
        public async Task GetWebtoonAverageRatingWorksCorrectly()
        {
            var webtoons = new List <Webtoon>();
            var webtoon  = new Webtoon()
            {
                Id          = "test",
                TitleNumber = "123"
            };

            webtoons.Add(webtoon);
            var mockWebtoonRepo = new Mock <IWebtoonsRepository>();

            mockWebtoonRepo.Setup(x => x.GetWebtoonByTitleNumber("123")).Returns(webtoon);
            var webtoonRatings = new List <WebtoonRating>();

            webtoonRatings.Add(new WebtoonRating()
            {
                ApplicationUserId = "gosho",
                WebtoonId         = "test",
                RatingValue       = 1,
            });
            var mockWebtoonRatingsRepo = new Mock <IWebtoonsRatingsRepository>();

            mockWebtoonRatingsRepo.Setup(x => x.All()).Returns(webtoonRatings.AsQueryable());
            mockWebtoonRatingsRepo.Setup(x => x.AddAsync(It.IsAny <WebtoonRating>())).Callback((WebtoonRating webtoonRating) => webtoonRatings.Add(webtoonRating));

            var service = new WebtoonsRatingsService(mockWebtoonRatingsRepo.Object, mockWebtoonRepo.Object);

            await service.RateWebtoonAsync("123", "ivan", 4);

            Assert.Equal(2, webtoonRatings.Count());
            Assert.Equal(2.5, service.GetWebtoonAverageRating("123"));
        }
        public async Task DeleteEpisodeAsyncThrowsNullExceptionWhenAuthorIdIsInvalid()
        {
            var episodes = new List <Episode>();
            var episode  = new Episode()
            {
                Webtoon = new Webtoon()
                {
                    AuthorId = "test"
                }
            };

            episodes.Add(episode);
            var mockEpisodesRepo = new Mock <IEpisodesRepository>();

            mockEpisodesRepo.Setup(x => x.GetEpisodeByWebtoonTitleNumberAndEpisodeNumber("smt", "smtelse")).Returns(episodes.FirstOrDefault());
            var mockWebtoonsRepo = new Mock <IWebtoonsRepository>();
            var webtoon          = new Webtoon()
            {
                TitleNumber = "123",
                AuthorId    = "test"
            };

            mockWebtoonsRepo.Setup(x => x.GetWebtoonByTitleNumber("smt")).Returns(webtoon);

            var service = new EpisodesService(mockWebtoonsRepo.Object, mockEpisodesRepo.Object, null, null, null, null, null, null);

            await Assert.ThrowsAsync <ArgumentNullException>(() => service.DeleteEpisodeAsync("smt", "smtelse", "user"));
        }
예제 #11
0
        public void CreateWebtoonAsyncThrowsArgumentExceptionWhenAWebtoonWithTheSameTitleExists()
        {
            var webtoon          = new Webtoon();
            var webtoons         = new List <Webtoon>();
            var mockWebtoonsRepo = new Mock <IWebtoonsRepository>();

            mockWebtoonsRepo.Setup(x => x.WebtoonExists(It.IsAny <string>())).Returns(true);

            var service = new WebtoonsService(mockWebtoonsRepo.Object, null, null, null, null, null, null, null, null, null);

            Assert.ThrowsAsync <ArgumentException>(() => service.CreateWebtoonAsync(null, null));
        }
예제 #12
0
        public async Task <Webtoon> GetWebtoonAsync(int titleID)
        {
            var listPageDocument = await GetListPageDocumentAsync(titleID);

            var detailPageDocument = await GetDetailPageDocumentAsync(titleID, 1);

            Webtoon webtoon = new Webtoon()
            {
                ID     = titleID,
                Title  = listPageDocument.DocumentNode.SelectSingleNode("//*[@property=\"og:title\"]").Attributes["content"].Value,
                Writer = detailPageDocument.DocumentNode.SelectSingleNode("//*[@name=\"itemWriterId\"]").Attributes["value"].Value
            };

            return(webtoon);
        }
예제 #13
0
        public async Task EditWebtoonAsyncWorksCorrectly()
        {
            var mockWebtoonsRepo = new Mock <IWebtoonsRepository>();
            var webtoons         = new List <Webtoon>();
            var firstWebtoon     = new Webtoon()
            {
                Id       = "7",
                AuthorId = "123",
                GenreId  = "14",
                Genre    = new Genre()
                {
                    Name = "action",
                    Id   = "14"
                },
                Author = new ApplicationUser()
                {
                    Id       = "123",
                    UserName = "******"
                },
                Title       = "New Title",
                TitleNumber = "1",
                UploadDay   = MyWebtoonWebProject.Data.Models.Enums.DayOfWeek.Friday,
                Synopsis    = "old synopsis",
                CoverPhoto  = "my old friend.jpeg"
            };

            mockWebtoonsRepo.Setup(x => x.GetWebtoonByTitleNumber("1")).Returns(firstWebtoon);
            var input = new EditWebtoonInputModel()
            {
                Title              = "Darkness",
                OldTitle           = "Darkness",
                GenreId            = "16",
                UploadDay          = MyWebtoonWebProject.Data.Models.Enums.DayOfWeek.Tuesday,
                Synopsis           = "new synopsis",
                WebtoonTitleNumber = "1",
            };
            var fakePath = $@"C:\MyWebtoonWebProject\MyWebtoonWebProject\TestResults";

            var service = new WebtoonsService(mockWebtoonsRepo.Object, null, null, null, null, null, null, null, null, null);

            await service.EditWebtoon(input, "123", fakePath);

            Assert.Equal("Darkness", firstWebtoon.Title);
            Assert.Equal("16", firstWebtoon.GenreId);
            Assert.Equal("Tuesday", firstWebtoon.UploadDay.ToString());
            Assert.Equal("new synopsis", firstWebtoon.Synopsis);
        }
예제 #14
0
        public void DownloadBegin(string url)
        {
            if (UIStatusVar == UIStatus.Idle)
            {
                UIStatusVar = UIStatus.BaseInformationRequesting;

                Thread requestThread = new Thread(async( ) =>
                {
                    WebtoonBasicInformation result = await Webtoon.GetBasicInformation(url);

                    if (!string.IsNullOrEmpty(result.title) && !string.IsNullOrEmpty(result.description) && !string.IsNullOrEmpty(result.thumbnailURL))                             // 추가 필요
                    {
                        targetWebtoonBasicInformation = result;

                        if (this.InvokeRequired)
                        {
                            this.Invoke(new Action(delegate()
                            {
                                UIStatusVar = UIStatus.BaseInformationTargetLockOned;
                            }));
                        }
                        else
                        {
                            UIStatusVar = UIStatus.BaseInformationTargetLockOned;
                        }

                        return;
                    }
                    else
                    {
                        UIStatusVar = UIStatus.Idle;

                        if (!result.errorChecked)
                        {
                            NotifyBox.Show(this, "오류", "해당 웹툰의 데이터를 불러올 수 없습니다.", NotifyBoxType.OK, NotifyBoxIcon.Error);
                        }
                    }
                })
                {
                    IsBackground = true
                };

                requestThread.Start( );
            }
        }
        public async Task AddEpisodeAsyncWorksCorrectly()
        {
            var mockWebtoonsRepo = new Mock <IWebtoonsRepository>();
            var webtoon          = new Webtoon()
            {
                Title       = "test",
                Id          = "gosho",
                TitleNumber = "123",
                AuthorId    = "test",
                Episodes    = new List <Episode>()
            };

            mockWebtoonsRepo.Setup(x => x.GetWebtoonByTitleNumber("123")).Returns(webtoon);
            var episodes         = new List <Episode>();
            var mockEpisodesRepo = new Mock <IEpisodesRepository>();

            mockEpisodesRepo.Setup(x => x.GetEpisodesByWebtoonId("gosho")).Returns(episodes);
            mockEpisodesRepo.Setup(x => x.AddAsync(It.IsAny <Episode>())).Callback((Episode episode) => episodes.Add(episode));
            var pages             = new List <Page>();
            var mockPageService   = new Mock <IPagesService>();
            var episodeInputModel = new AddEpisodeInputModel()
            {
                Pages       = new List <IFormFile>(),
                TitleNumber = "123"
            };
            var pathToTestResults = $@"C:\MyWebtoonWebProject\MyWebtoonWebProject\TestResults";

            var service = new EpisodesService(mockWebtoonsRepo.Object, mockEpisodesRepo.Object, null, mockPageService.Object, null, null, null, null);

            await service.AddEpisodeAsync(episodeInputModel, pathToTestResults);

            Assert.Single(episodes);
            Assert.Equal(0, episodes.First().Comments.Count);
            Assert.Equal(0, episodes.First().EpisodeLikes.Count);
            Assert.Equal("1", episodes.First().EpisodeNumber);
            Assert.False(episodes.First().IsDeleted);
            Assert.Equal("Episode1", episodes.First().Name);
            Assert.Equal("gosho", episodes.First().WebtoonId);
        }
예제 #16
0
        private void REQUEST_BUTTON_Click(object sender, EventArgs e)
        {
            if (UIStatusVar == UIStatus.BaseInformationTargetLockOned)
            {
                DownloadOptionForm Form = new DownloadOptionForm( )
                {
                    Owner = this
                };
                Form.baseInformation       = ( WebtoonBasicInformation )targetWebtoonBasicInformation;
                Form.DownloadOptionReturn += delegate(DownloadOptionResult result, object data)
                {
                    switch (result)
                    {
                    case DownloadOptionResult.DownloadClick:
                        Form.Close( );
                        UIStatusVar = UIStatus.Working;

                        if (Webtoon.DownloadThread != null)
                        {
                            Webtoon.DownloadThread.Abort( );
                            Webtoon.DownloadThread = null;
                        }

                        Webtoon.Request(targetWebtoonBasicInformation.Value.url);

                        break;

                    case DownloadOptionResult.Cancel:
                        Form.Close( );
                        CANCEL_BUTTON_Click(null, EventArgs.Empty);

                        break;
                    }
                };
                Form.ShowDialog( );

                return;
            }
        }
예제 #17
0
        public async Task CreateWebtoonAsync(CreateWebtoonInputModel input, string webRootPath)
        {
            if (this.webtoonsRepository.WebtoonExists(input.Title))
            {
                throw new ArgumentException("Webtoon already exists!");
            }

            string topFolder     = $@"{webRootPath}\Webtoons";
            string webtoonFolder = Path.Combine(topFolder, input.Title);

            Directory.CreateDirectory(webtoonFolder);

            var extention = Path.GetExtension(input.Cover.FileName).TrimStart('.');

            string coverPhotoPath = webtoonFolder + $"/cover.{extention}";

            using (FileStream fs = new FileStream(coverPhotoPath, FileMode.Create))
            {
                await input.Cover.CopyToAsync(fs);
            }

            var webtoon = new Webtoon
            {
                Title       = input.Title,
                Synopsis    = input.Synopsis,
                CoverPhoto  = input.Title + $"/cover.{extention}",
                GenreId     = input.GenreId,
                UploadDay   = input.UploadDay,
                AuthorId    = input.AuthorId,
                CreatedOn   = DateTime.UtcNow,
                Completed   = false,
                TitleNumber = (this.webtoonsRepository.GetWebtoonsCount() + 1).ToString(),
            };

            await this.webtoonsRepository.AddAsync(webtoon);

            await this.webtoonsRepository.SaveChangesAsync();
        }
예제 #18
0
        public async Task DeleteWebtoonAsyncWorksCorrectly()
        {
            var mockWebtoonsRepo = new Mock <IWebtoonsRepository>();
            var webtoons         = new List <Webtoon>();
            var firstWebtoon     = new Webtoon()
            {
                Id       = "7",
                AuthorId = "123",
                GenreId  = "14",
                Genre    = new Genre()
                {
                    Name = "action",
                    Id   = "14"
                },
                Author = new ApplicationUser()
                {
                    Id       = "123",
                    UserName = "******"
                },
                Title       = "Darkness",
                TitleNumber = "1",
                UploadDay   = MyWebtoonWebProject.Data.Models.Enums.DayOfWeek.Friday,
                Synopsis    = "old synopsis",
                CoverPhoto  = "my old friend.jpeg"
            };

            webtoons.Add(firstWebtoon);
            mockWebtoonsRepo.Setup(x => x.GetWebtoonByTitleNumber("1")).Returns(firstWebtoon);
            mockWebtoonsRepo.Setup(x => x.Delete(It.IsAny <Webtoon>())).Callback((Webtoon webtoon) => webtoon.IsDeleted = true);

            var service = new WebtoonsService(mockWebtoonsRepo.Object, null, null, null, null, null, null, null, null, null);

            await service.DeleteWebtoonAsync("1", "123");

            Assert.Single(webtoons);
            Assert.True(firstWebtoon.IsDeleted);
        }
예제 #19
0
        public void GetWebtoonToEditWorksCorrectly()
        {
            var mockWebtoonsRepo = new Mock <IWebtoonsRepository>();
            var webtoons         = new List <Webtoon>();
            var firstWebtoon     = new Webtoon()
            {
                Id       = "7",
                AuthorId = "123",
                GenreId  = "14",
                Genre    = new Genre()
                {
                    Name = "action",
                    Id   = "14"
                },
                Author = new ApplicationUser()
                {
                    Id       = "123",
                    UserName = "******"
                },
                Title       = "Darkness",
                TitleNumber = "1",
                UploadDay   = MyWebtoonWebProject.Data.Models.Enums.DayOfWeek.Friday,
                Synopsis    = "old synopsis",
                CoverPhoto  = "my old friend.jpeg"
            };

            mockWebtoonsRepo.Setup(x => x.GetWebtoonByTitleNumber("1")).Returns(firstWebtoon);

            var service = new WebtoonsService(mockWebtoonsRepo.Object, null, null, null, null, null, null, null, null, null);

            var result = service.GetWebtoonToEdit("1", "123");

            Assert.Equal("Darkness", result.OldTitle);
            Assert.Equal("1", result.WebtoonTitleNumber);
            Assert.Equal("old synopsis", result.Synopsis);
            Assert.Equal("Friday", result.UploadDay.ToString());
        }
        public async Task DoesWebtoonHaveARatingCorrectlyReturnsFalseWhenNoRatingsArePresent()
        {
            var webtoons = new List <Webtoon>();
            var webtoon  = new Webtoon()
            {
                Id          = "test",
                TitleNumber = "123"
            };

            webtoons.Add(webtoon);
            var mockWebtoonRepo = new Mock <IWebtoonsRepository>();

            mockWebtoonRepo.Setup(x => x.GetWebtoonByTitleNumber("123")).Returns(webtoon);
            var webtoonRatings         = new List <WebtoonRating>();
            var mockWebtoonRatingsRepo = new Mock <IWebtoonsRatingsRepository>();

            mockWebtoonRatingsRepo.Setup(x => x.All()).Returns(webtoonRatings.AsQueryable());

            var service = new WebtoonsRatingsService(mockWebtoonRatingsRepo.Object, mockWebtoonRepo.Object);

            var result = service.DoesWebtoonHaveARating("123");

            Assert.False(result);
        }
        public void GetEpisodeReturnsCorrectInfo()
        {
            var mockWebtoonsRepo = new Mock <IWebtoonsRepository>();
            var webtoon          = new Webtoon()
            {
                Title       = "test",
                Id          = "gosho",
                TitleNumber = "123",
                AuthorId    = "test",
                Episodes    = new List <Episode>()
            };
            var firstEpisode = new Episode()
            {
                Webtoon = new Webtoon()
                {
                    Title       = "test",
                    TitleNumber = "123",
                    Genre       = new Genre()
                    {
                        Name = "action"
                    },
                },
                EpisodeNumber = "456",
                Name          = "works",
                CreatedOn     = new DateTime(1994, 01, 01),
            };
            var secondEpisode = new Episode()
            {
                Webtoon = new Webtoon()
                {
                    Title       = "pesho",
                    TitleNumber = "012",
                    Genre       = new Genre()
                    {
                        Name = "gosho"
                    },
                },
                EpisodeNumber = "789",
                Name          = "ivan",
                CreatedOn     = new DateTime(1998, 01, 01),
                Comments      = new List <Comment>(),
            };

            secondEpisode.Comments.Add(new Comment()
            {
                CommentAuthorId = "hello",
                CommentNumber   = "12345",
                CommentAuthor   = new ApplicationUser()
                {
                    UserName = "******"
                },
                CommentInfo  = "this should work",
                Id           = "67890",
                CreatedOn    = new DateTime(1999, 01, 01),
                Comments     = new List <Comment>(),
                CommentVotes = new List <CommentVote>(),
            });
            var episodes = new List <Episode>();

            episodes.Add(secondEpisode);
            episodes.Add(firstEpisode);
            mockWebtoonsRepo.Setup(x => x.GetWebtoonByTitleNumber("123")).Returns(webtoon);
            var mockEpisodesRepo = new Mock <IEpisodesRepository>();

            mockEpisodesRepo.Setup(x => x.GetEpisodesByWebtoonId("gosho")).Returns(episodes);
            mockEpisodesRepo.Setup(x => x.GetEpisodeByWebtoonTitleNumberAndEpisodeNumber("123", "456")).Returns(episodes.FirstOrDefault());
            var mockApplicationUsersRepo = new Mock <IApplicationUserRepository>();
            var mockPagesService         = new Mock <IPagesService>();
            var mockPagesRepo            = new Mock <IPagesRepository>();
            var mockEpisodeLikesService  = new Mock <IEpisodesLikesService>();
            var mockCommentsRepo         = new Mock <ICommentsRepository>();

            mockCommentsRepo.Setup(x => x.GetEpisodeComments(It.IsAny <string>())).Returns(secondEpisode.Comments);
            var mockCommentsVotesRepo = new Mock <ICommentsVotesRepository>();

            mockCommentsVotesRepo.Setup(x => x.GetCommentVotesByCommentId(It.IsAny <string>())).Returns(secondEpisode.Comments.First().CommentVotes);

            var service = new EpisodesService(
                mockWebtoonsRepo.Object,
                mockEpisodesRepo.Object,
                mockPagesRepo.Object, mockPagesService.Object,
                mockEpisodeLikesService.Object, mockCommentsRepo.Object,
                mockApplicationUsersRepo.Object, mockCommentsVotesRepo.Object);

            var result = service.GetEpisode("123", "456");

            Assert.Single(result.Comments);

            Assert.Equal("test", result.EpisodeAuthorId);
            Assert.Equal("hello", result.Comments.First().CommentAuthorId);
            Assert.Null(result.Comments.First().CommentAuthorUsername);
            Assert.Equal("this should work", result.Comments.First().CommentInfo);
            Assert.Equal("12345", result.Comments.First().CommentNumber);
            Assert.Empty(result.Comments.First().CommentReplies);
            Assert.Equal(new DateTime(1999, 01, 01), result.Comments.First().CreatedOn);
            Assert.Equal(0, result.Comments.First().Likes);
            Assert.Equal(0, result.Comments.First().Dislikes);
            Assert.Null(result.Comments.First().ParentId);
            Assert.Equal("67890", result.Comments.First().Id);
            Assert.Equal("789", result.EpisodeNumber);
            Assert.Equal("ivan", result.EpisodeTitle);
            Assert.False(result.HasNextEpisode);
            Assert.False(result.HasPreviousEpisode);
            Assert.Equal("457", result.NextEpisodeNumber);
            Assert.Equal(0, result.Likes);
            Assert.Null(result.PagesPaths);
            Assert.Equal("455", result.PreviousEpisodeNumber);
            Assert.Equal("test", result.WebtoonTitle);
            Assert.Equal("123", result.WebtoonTitleNumber);
        }
예제 #22
0
        public void GetAllWebtoonsWorksCorrectly()
        {
            var mockWebtoonsRepo = new Mock <IWebtoonsRepository>();
            var webtoons         = new List <Webtoon>();
            var firstWebtoon     = new Webtoon()
            {
                Id       = "7",
                AuthorId = "123",
                GenreId  = "14",
                Genre    = new Genre()
                {
                    Name = "action",
                    Id   = "14"
                },
                Author = new ApplicationUser()
                {
                    Id       = "123",
                    UserName = "******"
                },
                Title       = "Darkness",
                TitleNumber = "1",
                Episodes    = new List <Episode>(),
            };
            var secondWebtoon = new Webtoon()
            {
                Id       = "4",
                AuthorId = "456",
                GenreId  = "15",
                Genre    = new Genre()
                {
                    Name = "family-friendly",
                    Id   = "15"
                },
                Author = new ApplicationUser()
                {
                    Id       = "456",
                    UserName = "******"
                },
                Title       = "Hello",
                TitleNumber = "2",
                Episodes    = new List <Episode>(),
            };

            webtoons.Add(firstWebtoon);
            webtoons.Add(secondWebtoon);
            mockWebtoonsRepo.Setup(x => x.All()).Returns(webtoons.AsQueryable());
            var mockEpisodesRepo = new Mock <IEpisodesRepository>();

            mockEpisodesRepo.Setup(x => x.GetEpisodesByWebtoonId(It.IsAny <string>())).Returns((string webtoonId) => webtoons.FirstOrDefault(x => x.Id == webtoonId).Episodes);
            var mockGenresRepo = new Mock <IGenresRepository>();

            mockGenresRepo.Setup(x => x.GetGenreByWebtoonGenreId(It.IsAny <string>())).Returns((string genreId) => webtoons.FirstOrDefault(x => x.GenreId == genreId).Genre);
            var mockAppUserRepo = new Mock <IApplicationUserRepository>();

            mockAppUserRepo.Setup(x => x.GetWebtoonAuthorUsername(It.IsAny <string>())).Returns((string authorId) => webtoons.FirstOrDefault(x => x.AuthorId == authorId).Author.UserName);
            var mockEpisodeLikeService = new Mock <IEpisodesLikesService>();

            mockEpisodeLikeService.Setup(x => x.GetEpisodeLikes(It.IsAny <string>())).Returns(0);

            var service = new WebtoonsService(mockWebtoonsRepo.Object, mockEpisodesRepo.Object, mockGenresRepo.Object, mockAppUserRepo.Object, null, null, null, mockEpisodeLikeService.Object, null, null);

            var result = service.GetAllWebtoons();

            var firstResult  = result.ToArray()[0];
            var secondResult = result.ToArray()[1];

            Assert.Equal(2, result.Count);
            Assert.Equal("action", firstResult.GenreName);
            Assert.Equal("family-friendly", secondResult.GenreName);
            Assert.Single(firstResult.Webtoons);
            Assert.Single(secondResult.Webtoons);
            Assert.Equal("gosho", firstResult.Webtoons.First().Author);
            Assert.Equal("pesho", secondResult.Webtoons.First().Author);
            Assert.Equal("Darkness", firstResult.Webtoons.First().Title);
            Assert.Equal("Hello", secondResult.Webtoons.First().Title);
            Assert.Equal("1", firstResult.Webtoons.First().TitleNumber);
            Assert.Equal("2", secondResult.Webtoons.First().TitleNumber);
            Assert.Equal(0, firstResult.Webtoons.First().Likes);
            Assert.Equal(0, secondResult.Webtoons.First().Likes);
            Assert.Empty(firstResult.Webtoons.First().Episodes);
            Assert.Empty(secondResult.Webtoons.First().Episodes);
        }
예제 #23
0
 public async Task DownloadAsync(Webtoon webtoon,
                                 IProgress <(int Pos, int Count, Image Image)> progress,
예제 #24
0
        private void searchButton_Click(object sender, EventArgs e)
        {
            string searchText = searchTextBox.Text.Trim( );
            string searchURL  = webtoonDirectURLTextBox.Text.Trim( );

            if (searchText.Length <= 0 && searchURL.Length <= 0)
            {
                NotifyBox.Show(this, "안내", "검색할 웹툰의 이름을 입력하시거나, 해당 웹툰의 주소를 입력하세요.", NotifyBoxType.OK, NotifyBoxIcon.Warning);
                return;
            }

            if (searchURL.Length > 0)
            {
                if (Webtoon.IsValidFixURL(ref searchURL))
                {
                    (( Main )this.Owner).DownloadBegin(searchURL);
                    this.Close( );
                }
                else
                {
                    NotifyBox.Show(this, "오류", "입력한 웹툰 링크가 올바르지 않습니다, 올바른 링크를 입력하세요.", NotifyBoxType.OK, NotifyBoxIcon.Error);

                    webtoonDirectURLTextBox.Text = "";
                    webtoonDirectURLTextBox.Focus( );
                }

                return;
            }

            UIMode = true;
            StartLoadingMode(searchText);

            if (loadThread != null)
            {
                loadThread.Abort( );
                loadThread = null;
            }

            webtoonSearchResultList.Controls.Clear( );

            loadThread = new Thread(() =>
            {
                try
                {
                    int count = 0;
                    int y     = 0;

                    List <WebtoonSearchResult> searchResult = Webtoon.SearchTitle(searchText);

                    StopDotAnimation( );

                    foreach (WebtoonSearchResult info in searchResult)
                    {
                        count++;

                        WebtoonSearchListChild child = new WebtoonSearchListChild(info);
                        child.Location  = new Point(0, y);
                        child.Selected += Webtoon_Selected;

                        if (this.InvokeRequired)
                        {
                            this.Invoke(new Action(() =>
                            {
                                webtoonSearchResultList.Controls.Add(child);
                                searchStatusLabel.Text = "검색 결과를 정리하고 있습니다 ... " + ( int )((( float )count / ( float )searchResult.Count) * 100) + "%";
                            }));
                        }
                        else
                        {
                            webtoonSearchResultList.Controls.Add(child);
                            searchStatusLabel.Text = "검색 결과를 정리하고 있습니다 ... " + ( int )((( float )count / ( float )searchResult.Count) * 100) + "%";
                        }

                        y += child.Size.Height + 5;
                    }

                    Thread.Sleep(1000);

                    if (this.InvokeRequired)
                    {
                        this.Invoke(new Action(() => StopLoadingMode(searchText, searchResult.Count)));
                    }
                    else
                    {
                        StopLoadingMode(searchText, searchResult.Count);
                    }
                }
                catch (ThreadAbortException)
                {
                    GC.Collect(0, GCCollectionMode.Forced);                       // 쓰레드가 강제 종료된 후 메모리를 정리하기 위해 GC 강제 실행
                }
            })
            {
                IsBackground = true
            };

            loadThread.Start( );
        }