public async Task Expect_Delete_Article_With_Tags() { var createCmd = new Create.Command(new Create.ArticleData() { Title = "Test article dsergiu77", Description = "Description of the test article", Body = "Body of the test article", TagList = new string[] { "tag1", "tag2" } }); var article = await ArticleHelpers.CreateArticle(this, createCmd); var dbArticleWithTags = await ExecuteDbContextAsync( db => db.Articles.Include(a => a.ArticleTags) .Where(d => d.Slug == article.Slug).SingleOrDefaultAsync() ); var deleteCmd = new Delete.Command(article.Slug); var dbContext = GetDbContext(); var articleDeleteHandler = new Delete.QueryHandler(dbContext); await articleDeleteHandler.Handle(deleteCmd, new System.Threading.CancellationToken()); var dbArticle = await ExecuteDbContextAsync(db => db.Articles.Where(d => d.Slug == deleteCmd.Slug).SingleOrDefaultAsync()); Assert.Null(dbArticle); }
public async Task Expect_Delete_Article() { var createCmd = new Create.Command() { Article = new Create.ArticleData() { Title = "Test article dsergiu77", Description = "Description of the test article", Body = "Body of the test article", } }; var article = await ArticleHelpers.CreateArticle(this, createCmd); var slug = article.Slug; var deleteCmd = new Delete.Command(slug); var dbContext = GetDbContext(); var articleDeleteHandler = new Delete.QueryHandler(dbContext); await articleDeleteHandler.Handle(deleteCmd, new System.Threading.CancellationToken()); var dbArticle = await ExecuteDbContextAsync(db => db.Articles.Where(d => d.Slug == deleteCmd.Slug).SingleOrDefaultAsync()); Assert.Null(dbArticle); }
public async Task DeleteTest_ValidData_ExpectSuccess() { var createCmd = new Create.Command() { Category = new Create.CategoryData() { ParentCategory = 0, Name = "TestCategory", Description = "This is a test Category" } }; var article = await CategoryHelpers.CreateCategory(this, createCmd); var CategoryId = article.CategoryId; var deleteCmd = new Delete.Command(CategoryId); var dbContext = GetDbContext(); var categoryDeleteHandler = new Delete.QueryHandler(dbContext); await categoryDeleteHandler.Handle(deleteCmd, new System.Threading.CancellationToken()); var dbArticle = await ExecuteDbContextAsync(db => db.Categories.Where(d => d.CategoryId == deleteCmd.CategoryId).SingleOrDefaultAsync()); Assert.Null(dbArticle); }
public async Task Delete_Project_Inexistent_ShouldReturn_RestException() { var mockedContext = new EletronicPartsCatalogContextMock().GetMockedContextWithData(); var sut = new Delete.QueryHandler(mockedContext); var message = new Delete.Command("slug"); await Assert.ThrowsAsync <RestException>(() => sut.Handle(message, CancellationToken.None)); }
public async Task Delete_Favorite_Inexistent_ShouldReturn_RestException() { var mockedContext = new EletronicPartsCatalogContextMock().GetMockedContextWithData(); var mockedCurrentUserAcessor = new Mock <ICurrentUserAccessor>(); mockedCurrentUserAcessor.Setup(mcua => mcua.GetCurrentUsername()).Returns("test"); var sut = new Delete.QueryHandler(mockedContext, mockedCurrentUserAcessor.Object); var message = new Delete.Command("slug"); await Assert.ThrowsAsync <RestException>(() => sut.Handle(message, CancellationToken.None)); }
public async Task Expect_Delete_Article_With_Comments() { var createArticleCmd = new Create.Command() { Article = new Create.ArticleData() { Title = "Test article dsergiu77", Description = "Description of the test article", Body = "Body of the test article", } }; var article = await ArticleHelpers.CreateArticle(this, createArticleCmd); var dbArticle = await ExecuteDbContextAsync( db => db.Articles.Include(a => a.ArticleTags) .Where(d => d.Slug == article.Slug).SingleOrDefaultAsync() ); var articleId = dbArticle.ArticleId; var slug = dbArticle.Slug; // create article comment var createCommentCmd = new Codebase.Features.Comments.Create.Command() { Comment = new Codebase.Features.Comments.Create.CommentData() { Body = "article comment" }, Slug = slug }; var comment = await CommentHelpers.CreateComment(this, createCommentCmd, UserHelpers.DefaultUserName); // delete article with comment var deleteCmd = new Delete.Command(slug); var dbContext = GetDbContext(); var articleDeleteHandler = new Delete.QueryHandler(dbContext); await articleDeleteHandler.Handle(deleteCmd, new System.Threading.CancellationToken()); var deleted = await ExecuteDbContextAsync(db => db.Articles.Where(d => d.Slug == deleteCmd.Slug).SingleOrDefaultAsync()); Assert.Null(deleted); }
public async Task DeleteTest_ValidData_ExpectSuccess() { //create a test Article var articleCmd = new Conduit.Features.Articles.Create.Command() { Article = new Conduit.Features.Articles.Create.ArticleData() { Title = "Test article dsergiu77", Description = "Description of the test article", Body = "Body of the test article", TagList = new string[] { "tag1", "tag2" } } }; //save it var article = await Articles.ArticleHelpers.CreateArticle(this, articleCmd); //create a test category var categoryCmd = new Conduit.Features.Categories.Create.Command() { Category = new Conduit.Features.Categories.Create.CategoryData() { ParentCategory = 0, Name = "TestCategory", Description = "This is a test Category" } }; //save it var createdCategory = await Categories.CategoryHelpers.CreateCategory(this, categoryCmd); //assign the article to the category var createCmd = new Create.Command() { articleCategory = new Domain.ArticleCategory() { ArticleCategoryId = 0, ArticleId = 1, CategoryId = 1, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now } }; //save the assignment var createdArticleCategory = await ArticleCategoryHelpers.CreateArticleCategory(this, createCmd); var articleCategoryId = createdArticleCategory.ArticleCategoryId; //delete created article var deleteCmd = new Delete.Command(articleCategoryId); var dbContext = GetDbContext(); var categoryDeleteHandler = new Delete.QueryHandler(dbContext); await categoryDeleteHandler.Handle(deleteCmd, new System.Threading.CancellationToken()); var dbArticle = await ExecuteDbContextAsync(db => db.ArticleCategories.Where(d => d.ArticleCategoryId == deleteCmd.ArticleCategoryId).SingleOrDefaultAsync()); Assert.Null(dbArticle); }