public Article Create(IArticleCreateDto model) { var builder = new ArticleBuilder() .WithName(model.Name) ; return(builder.Build()); }
public async Task ShouldAutoFillCreateTime() { var article = Mapper.Map <Article>(ArticleBuilder.Build(a => { a.CreateTime = DateTime.Now.AddYears(-10); })); await _repository.InsertAsync(article); article.CreateTime.Date.Should().Be(DateTime.Now.Date); }
public async Task ShouldUpdateFailedWhenEntityNotExists() { var exception = await Assert.ThrowsAsync <KeyNotFoundException>(async() => { await _repository.UpdateAsync(Mapper.Map <Article>(ArticleBuilder.Build())); }); Assert.NotNull(exception.Message); }
public async Task ShouldInsertSuccess() { var article = Mapper.Map <Article>(ArticleBuilder.Build()); await _repository.InsertAsync(article); var insertedArticle = await _repository.GetByIdAsync(article.Id); insertedArticle.Should().NotBeNull(); }
public async Task ShouldGetArticleSuccess() { var article = Mapper.Map <Article>(ArticleBuilder.Build()); await _articleRepository.InsertAsync(article); var searchedArticle = await _articleRepository.GetByIdAsync(article.Id); searchedArticle.Should().NotBeNull(); }
public async Task ShouldAutoFilterDeletedArticle() { var article = Mapper.Map <Article>(ArticleBuilder.Build()); article.IsDelete = true; await _articleRepository.InsertAsync(article); var findArticles = await _articleRepository.FindAllAsync(x => true); findArticles.Should().NotContain(x => x.Id == article.Id); }
public async Task ShouldDeleteSuccess() { var article = Mapper.Map <Article>(ArticleBuilder.Build()); await _repository.InsertAsync(article); await _repository.DeleteAsync(article.Id); var deletedArticle = await _repository.GetByIdAsync(article.Id); deletedArticle.Should().BeNull(); }
public async Task ShouldUpdateSuccess() { var article = Mapper.Map <Article>(ArticleBuilder.Build()); await _repository.InsertAsync(article); article.Title = Guid.NewGuid().ToString(); await _repository.UpdateAsync(article); var updatedArticle = await _repository.GetByIdAsync(article.Id); updatedArticle.Title.Should().Be(article.Title); }
public async Task ShouldDeleteSuccessWhenPartOfIdNotExist() { var entity = Mapper.Map <Article>(ArticleBuilder.Build()); await _repository.InsertAsync(entity); var ids = new List <ObjectId> { entity.Id, ObjectId.GenerateNewId() }; await _repository.DeleteMultipleAsync(ids); var deletedEntity = await _repository.GetByIdAsync(entity.Id); deletedEntity.Should().BeNull(); }
public async Task ShouldDeleteSuccess() { var entity1 = Mapper.Map <Article>(ArticleBuilder.Build()); var entity2 = Mapper.Map <Article>(ArticleBuilder.Build()); await _repository.InsertAsync(entity1); await _repository.InsertAsync(entity2); var ids = new List <ObjectId> { entity1.Id, entity2.Id }; await _repository.DeleteMultipleAsync(ids); var deletedEntity1 = await _repository.GetByIdAsync(entity1.Id); var deletedEntity2 = await _repository.GetByIdAsync(entity2.Id); deletedEntity1.Should().BeNull(); deletedEntity2.Should().BeNull(); }