public void Delete_ReturnsFalseOnExcepiton()
        {
            // Arrange
            var articlesService = new ArticlesService(null);

            // Act
            var result = articlesService.Delete(3);

            //Assert
            Assert.False(result);
        }
Exemplo n.º 2
0
        //[Authorize(Roles="Author")]
        public async Task <IActionResult> DeleteArticle(string id)
        {
            // Authorization

            var article = await _articlesService.GetArticleById(id);

            if (article == null)
            {
                return(NotFound());
            }

            await _articlesService.Delete(article.Slug);

            return(RedirectToAction(nameof(Index)));
        }
        public void Delete_ReturnsFalseIfItemNotFound()
        {
            // Arrange
            var context  = this.ServiceProvider.GetRequiredService <WmipDbContext>();
            var article1 = new Article {
                Id = 1, Title = "s1"
            };
            var article2 = new Article {
                Id = 2, Title = "s2"
            };

            context.Articles.AddRange(article1, article2);
            context.SaveChanges();
            var articlesService = new ArticlesService(context);

            // Act
            var result = articlesService.Delete(3);

            //Assert
            Assert.False(result);
        }
Exemplo n.º 4
0
        public async Task DeleteArticle_Test()
        {
            // Arrange
            var articlesService = new ArticlesService(this.dbContext);
            var articles        = this.dbContext.Articles;

            articles.Add(new Article {
                Title = "ArticleToDelete", Content = "DeleteContent"
            });
            await this.dbContext.SaveChangesAsync();

            var articleToDelete = this.dbContext
                                  .Articles
                                  .FirstOrDefault(a => a.Title == "ArticleToDelete");

            // Act
            await articlesService.Delete(articleToDelete);

            // Assert
            Assert.AreEqual(false, articles.Any(a => a.Title == "ArticleToDelete"));
        }
Exemplo n.º 5
0
        public async Task DeleteArticleShouldBeSuccessfull()
        {
            var options = new DbContextOptionsBuilder <SportsNewsContext>()
                          .UseInMemoryDatabase(databaseName: "Find_User_Database3")
                          .Options;

            var dbContext       = new SportsNewsContext(options);
            var repository      = new DbRepository <Article>(dbContext);
            var articlesService = new ArticlesService(repository, null);

            await articlesService.Create(1, "sdsda", "dasasd");

            await articlesService.Create(1, "sdsda", "dasasd");

            await articlesService.Create(1, "sdsda", "dasasd");

            var id = repository.All().FirstOrDefault().Id;
            await articlesService.Delete(id);

            var count = repository.All().Count();

            Assert.Equal(2, count);
        }
        public void Delete_RemovesCorrectAlbum()
        {
            // Arrange
            var context  = this.ServiceProvider.GetRequiredService <WmipDbContext>();
            var article1 = new Article {
                Id = 1, Title = "s1"
            };
            var article2 = new Article {
                Id = 2, Title = "s2"
            };

            context.Articles.AddRange(article1, article2);
            context.SaveChanges();
            var articlesService = new ArticlesService(context);

            // Act
            var result = articlesService.Delete(1);

            //Assert
            Assert.True(result);
            Assert.Single(context.Articles);
            Assert.Equal(article2.Title, context.Articles.First().Title);
        }
Exemplo n.º 7
0
 public ActionResult Delete(ArticleViewModel articleViewModel)
 {
     articlesService.Delete(articleViewModel);
     return(Json(new[] { articleViewModel }));
 }