示例#1
0
        public Article Create(IArticleCreateDto model)
        {
            var builder = new ArticleBuilder()
                          .WithName(model.Name)
            ;

            return(builder.Build());
        }
示例#2
0
        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);
        }
示例#3
0
        public async Task ShouldUpdateFailedWhenEntityNotExists()
        {
            var exception = await Assert.ThrowsAsync <KeyNotFoundException>(async() =>
            {
                await _repository.UpdateAsync(Mapper.Map <Article>(ArticleBuilder.Build()));
            });

            Assert.NotNull(exception.Message);
        }
示例#4
0
        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();
        }
示例#5
0
        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();
        }
示例#6
0
        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);
        }
示例#7
0
        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();
        }
示例#8
0
        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);
        }
示例#9
0
        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();
        }
示例#10
0
        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();
        }