Exemple #1
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"));
        }
Exemple #2
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);
        }