Esempio n. 1
0
        public void DeleteArticle_DeletingFailed_ThrowDatabaseException()
        {
            database.Setup(d => d.ArticleRepository.DeleteByColumn(new(Id, It.IsNotNull <string>())))
            .ReturnsAsync(false);

            Assert.That(() => articleService.DeleteArticle(It.IsNotNull <string>()),
                        Throws.Exception.TypeOf <DatabaseException>());
        }
Esempio n. 2
0
        public async void DeleteArticles()
        {
            foreach (Article article in SelectedItems)
            {
                await ArticleService.DeleteArticle(article.Id);
            }

            NavigationManager.NavigateTo($"/article_view/{Id}", true);
        }
Esempio n. 3
0
        public async void DeleteArticles()
        {
            foreach (Article article in SelectedItems)
            {
                await ArticleService.DeleteArticle(article.Id);
            }

            NavigationManager.NavigateTo("/overview_purchaser", true);
        }
Esempio n. 4
0
        public void DeleteArticle(int?Id)
        {
            var mockBlogRepository = new Mock <IBlogRepository>();

            mockBlogRepository.Setup(m => m.Articles.Get(-1)).Returns((Article)null);

            var _articleService = new ArticleService(mockBlogRepository.Object);

            Assert.Throws <ValidationException>(() => _articleService.DeleteArticle(Id));
        }
Esempio n. 5
0
 public ActionResult Delete(ArticleGetViewModel journalView)
 {
     if (journalView == null)
     {
         return(HttpNotFound());
     }
     if (journalView.Article.Id != 0)
     {
         _articleService.DeleteArticle(journalView);
     }
     return(RedirectToAction("Index"));
 }
Esempio n. 6
0
        public JsonResult <object> DeleteArticle(DeleteArticleRequest request)
        {
            var baseInfo = GetBaseInfo();

            if (request == null)
            {
                return(JsonError("请求数据错误"));
            }

            _articleService.DeleteArticle(request.ArticleID);

            return(JsonNet("删除文章成功"));
        }
Esempio n. 7
0
        public void ThrowArgumentNullException_WhenArticleIdIsNull()
        {
            // Arrange
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var mockedRepository = new Mock <IEfGenericRepository <Article> >();
            var articleService   = new ArticleService(mockedRepository.Object, mockedUnitOfWork.Object);

            // Act
            var exception = Assert.Throws <ArgumentNullException>(() => articleService.DeleteArticle(null));

            // Assert
            StringAssert.IsMatch("articleId", exception.ParamName);
        }
        public void ThrowInvalidOperationException_WhenPassedArticleIsNull()
        {
            // Arrange
            var contextMock        = new Mock <ITravelGuideContext>();
            var factoryMock        = new Mock <IArticleFactory>();
            var commentFactoryMock = new Mock <IArticleCommentFactory>();

            var service = new ArticleService(contextMock.Object, factoryMock.Object, commentFactoryMock.Object);

            // Act & Assert
            var ex = Assert.Throws <InvalidOperationException>(() => service.DeleteArticle(null));

            StringAssert.Contains("null", ex.Message);
        }
Esempio n. 9
0
        public ActionResult DelArt(int?id)
        {
            string error;
            int    result = service.DeleteArticle(id ?? 0, out error);

            if (result > 0)
            {
                return(Json(new { state = 1 }));
            }
            else
            {
                return(Json(new { state = -1, error = error }));
            }
        }
        public async Task <IActionResult> Delete([FromRoute] string slug)
        {
            try
            {
                var tokenHeader = Request.Headers["Authorization"];
                var token       = tokenHeader.Count > 0
                    ? tokenHeader.First().Split(' ')[1]
                    : null;

                User currentUser = null;

                if (!string.IsNullOrWhiteSpace(token))
                {
                    currentUser = UserService.GetCurrentUser(token);
                }

                if (currentUser == null)
                {
                    return(Unauthorized());
                }

                var article = await ArticleService.DeleteArticle(slug, token);

                return(article != null
                    ? Ok(new SingleArticleResponse
                {
                    Article = new ArticleModel(
                        article.Slug,
                        article.Title,
                        article.Description,
                        article.Body,
                        article.ArticleTags.Select(t => t.Tag.TagName).ToList(),
                        article.CreatedAt,
                        article.UpdatedAt,
                        article.GetFavorited(currentUser),
                        article.FavoritesCount,
                        article.Author.Profile
                        )
                })
                    : (IActionResult)BadRequest("Not updated."));
            }
            catch (Exception ex)
            {
                var genericErrorModel = new GenericErrorModel(new GenericErrorModelErrors(new[] { ex.ToString() }));
                return(BadRequest(genericErrorModel));
            }
        }
        public void DeleteArticleShouldDeleteAnArticleFromDatabase()
        {
            var options   = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase("Database_For_Tests").Options;
            var dbContext = new ApplicationDbContext(options);
            var service   = new ArticleService(dbContext);

            dbContext.Articles.Add(new Article());
            dbContext.Articles.Add(new Article());
            dbContext.Articles.Add(new Article());
            dbContext.SaveChanges();

            var article = dbContext.Articles.First();

            service.DeleteArticle(article);

            Assert.Equal(2, dbContext.Articles.Count());
        }
Esempio n. 12
0
 public ResultModel Delete([FromBody] BaseRequest request)
 {
   if (request.Id > 0)
   {
     try
     {
       ResultModel result = ArticleService.DeleteArticle(request);
       return result;
     }
     catch (Exception ex)
     {
       return new ResultModel { Data = null, Status = ResultStatus.ServerInternalError, Message = "Hata oluştu" };
     }
   }
   else
     return new ResultModel { Data = null, Status = ResultStatus.BadRequest, Message = "Geçersiz değer" };
 }
        public void ThrowInvalidOperationException_WhenNoSuchArticleIsFound()
        {
            // Arrange
            var contextMock        = new Mock <ITravelGuideContext>();
            var factoryMock        = new Mock <IArticleFactory>();
            var commentFactoryMock = new Mock <IArticleCommentFactory>();
            var article            = new Article();

            var service = new ArticleService(contextMock.Object, factoryMock.Object, commentFactoryMock.Object);

            contextMock.Setup(x => x.Articles.Find(It.IsAny <Guid>())).Returns((Article)null);

            // Act & Assert
            var ex = Assert.Throws <InvalidOperationException>(() => service.DeleteArticle(article));

            StringAssert.Contains("database", ex.Message);
        }
Esempio n. 14
0
        public void DeleteArticle_Test()
        {
            var dbArticles = new List <Article>();

            CreateArticleDTO article = FakeArticles.CreateArticleWithTwoTagsDto();

            _fakeArticleUnitOfWork.Setup(setup => setup.Commit()).Returns(1).Verifiable();

            _fakeArticleRepository.Setup(setup => setup.GetById(2)).Returns(FakeArticles.CreateArticle());

            _fakeArticleRepository.Setup(setup => setup.Delete(It.IsAny <Article>())).Callback((Article a) =>
                                                                                               { dbArticles.Remove(a); });

            _sut.AddArticle(article);

            _sut.DeleteArticle(article.Id);

            Assert.IsTrue(!dbArticles.Any());
        }
Esempio n. 15
0
        public void CallUnitOfWorkMethodCommitOnce()
        {
            // Arrange
            var  mockedUnitOfWork = new Mock <IUnitOfWork>();
            var  mockedRepository = new Mock <IEfGenericRepository <Article> >();
            Guid articleId        = Guid.NewGuid();
            var  article          = new Article()
            {
                Id = articleId
            };

            mockedRepository.Setup(x => x.GetById(articleId)).Returns(article);
            var articleService = new ArticleService(mockedRepository.Object, mockedUnitOfWork.Object);

            // Act
            articleService.DeleteArticle(articleId.ToString());

            // Assert
            mockedUnitOfWork.Verify(x => x.Commit(), Times.Once);
        }
        public void CallSaveChanges_WhenParamsAreValid()
        {
            // Arrange
            var contextMock        = new Mock <ITravelGuideContext>();
            var factoryMock        = new Mock <IArticleFactory>();
            var commentFactoryMock = new Mock <IArticleCommentFactory>();
            var article            = new Article();

            article.IsDeleted = false;
            var initialValue = article.IsDeleted;
            var service      = new ArticleService(contextMock.Object, factoryMock.Object, commentFactoryMock.Object);

            contextMock.Setup(x => x.Articles.Find(It.IsAny <Guid>())).Returns(article);

            // Act
            service.DeleteArticle(article);

            // Assert
            contextMock.Verify(x => x.SaveChanges(), Times.Once);
        }
        public void CorrectlySetDeletedPropery_WhenParamsAreValid()
        {
            // Arrange
            var contextMock        = new Mock <ITravelGuideContext>();
            var factoryMock        = new Mock <IArticleFactory>();
            var commentFactoryMock = new Mock <IArticleCommentFactory>();
            var article            = new Article();

            article.IsDeleted = false;
            var initialValue = article.IsDeleted;
            var service      = new ArticleService(contextMock.Object, factoryMock.Object, commentFactoryMock.Object);

            contextMock.Setup(x => x.Articles.Find(It.IsAny <Guid>())).Returns(article);

            // Act
            service.DeleteArticle(article);

            // Assert
            Assert.AreEqual(initialValue, false);
            Assert.AreEqual(article.IsDeleted, true);
        }
Esempio n. 18
0
        public void TestDeleteArticle()
        {
            var articleService = new ArticleService(_articleRepository.Object);

            var article = new ArticleOld(ArticleType.Full, new FullArticleValidator(), new ArticlePublishingRules())
            {
                Id = Guid.NewGuid(), Title = "my new article to be deleted"
            };
            int articleCount = articleService.GetArticles().Count;

            articleService.SaveArticle(article);
            Assert.AreEqual(articleCount + 1, articleService.GetArticles().Count);

            var testArticle = articleService.GetArticle(article.Id);

            Assert.IsNotNull(testArticle);

            articleService.DeleteArticle(article);
            Assert.AreEqual(articleCount, articleService.GetArticles().Count);
            Assert.IsNull(articleService.GetArticle(article.Id));
        }
        public async Task <IActionResult> DeleteArticle(string id)
        {
            await _articleService.DeleteArticle(id);

            return(NoContent());
        }
        private void DeleteArticle(string articleId)
        {
            ArticleService service = new ArticleService();

            service.DeleteArticle(articleId);
        }
Esempio n. 21
0
        public async Task UpdateArticleUpdateTheGivenArticle()
        {
            // arrange
            ArticleService   articleService   = new ArticleService(_client);
            PurchaserService purchaserService = new PurchaserService(_client);
            CountryService   countryService   = new CountryService(_client);
            SupplierService  supplierService  = new SupplierService(_client);

            Article article = new Article()
            {
                Id                                  = 0,
                PurchaserId                         = 1,
                CountryId                           = 1,
                SupplierId                          = 1,
                ArticleInformationId                = 0,
                InternalArticleInformationId        = 0,
                VailedForCustomer                   = "Customer",
                DateCreated                         = DateTime.Now,
                ArticleInformationCompleted         = 0,
                InternalArticalInformationCompleted = 0,
                ArticleState                        = 0,
                ErrorReported                       = 0,
                ErrorField                          = "Field",
                ErrorMessage                        = "Message",
                ErrorOwner                          = "Owner",
                ArticleInformation                  = new ArticleInformation(),
                InternalArticleInformation          = new InternalArticleInformation()
            };

            Country country = new Country()
            {
                Id          = 0,
                ProfileId   = 0,
                CountryName = "Name",
                CountryCode = "Code",
                Profile     = new Profile()
                {
                    Id       = 0,
                    Username = "******",
                    Password = "******",
                    Usertype = 0
                }
            };

            Purchaser purchaser = new Purchaser()
            {
                Id        = 0,
                ProfileId = 0,
                CountryId = 1,
                Profile   = new Profile()
                {
                    Id       = 0,
                    Username = "******",
                    Password = "******",
                    Usertype = 2
                }
            };

            Supplier supplier = new Supplier()
            {
                Id                    = 0,
                ProfileId             = 0,
                CompanyName           = "Name",
                CompanyLocation       = "Location",
                FreightResponsibility = "EXW",
                PalletExchange        = 1,
                Profile               = new Profile()
                {
                    Id       = 0,
                    Username = "******",
                    Password = "******",
                    Usertype = 2
                }
            };

            Country countryToDelete = await countryService.CreateCountry(country);

            purchaser.CountryId = countryToDelete.Id;
            Purchaser purchaserToDelete = await purchaserService.CreatePurchaser(purchaser);

            Supplier supplierToDelete = await supplierService.CreateSupplier(supplier);

            article.CountryId   = countryToDelete.Id;
            article.SupplierId  = supplierToDelete.Id;
            article.PurchaserId = purchaserToDelete.Id;
            Article expected = await articleService.CreateArticle(article);

            expected.ArticleState = 3;

            // act
            await articleService.UpdateArticle(expected.Id, expected);

            Article actual = await articleService.GetArticle(expected.Id);

            // assert
            Assert.IsTrue(expected.ArticleState == actual.ArticleState);
            List <Country> now = await countryService.GetCountries();

            await articleService.DeleteArticle(expected.Id);

            await purchaserService.DeletePurchaserForProfile(purchaserToDelete.ProfileId);

            await supplierService.DeleteSupplier(supplierToDelete.Id);

            await countryService.DeleteCountry(countryToDelete.Id);

            await _context.DisposeAsync();

            List <Country> late = await countryService.GetCountries();
        }
Esempio n. 22
0
        private async Task OnDeleteButtonClick(Article article)
        {
            await ArticleService.DeleteArticle(article);

            NavigationManager.NavigateTo("articles", forceLoad: true);
        }
 public ActionResult Delete(int id)
 {
     _articleService.DeleteArticle(id);
     return(RedirectToAction("Index"));
 }
Esempio n. 24
0
 public IActionResult Delete(int Id)
 {
     ArticleService.DeleteArticle(Id);
     return(NoContent());
 }
Esempio n. 25
0
 public ActionResult DeleteConfirmed(string id)
 {
     articleService.DeleteArticle(id);
     return(RedirectToAction("Index"));
 }
        public void TestDeleteArticle()
        {
            var articleService = new ArticleService(_articleRepository.Object);

            var article = new ArticleOld(ArticleType.Full, new FullArticleValidator(), new ArticlePublishingRules()) { Id = Guid.NewGuid(), Title = "my new article to be deleted" };
            int articleCount = articleService.GetArticles().Count;

            articleService.SaveArticle(article);
            Assert.AreEqual(articleCount + 1, articleService.GetArticles().Count);

            var testArticle = articleService.GetArticle(article.Id);
            Assert.IsNotNull(testArticle);

            articleService.DeleteArticle(article);
            Assert.AreEqual(articleCount, articleService.GetArticles().Count);
            Assert.IsNull(articleService.GetArticle(article.Id));
        }