コード例 #1
0
        public virtual TDto FromEntityToDto(TEntity entity, TDto?existingDto)
        {
            if (_entityTypeAndDtoTypeAreEqual == true)
            {
                return((entity as TDto) !);
            }

            return(existingDto == null?Mapper.Map <TEntity, TDto>(entity) : Mapper.Map(entity, existingDto));
        }
コード例 #2
0
        public async Task <ActionResult <TDto> > Get(int id)
        {
            TDto?entity = await Service.FetchByIdAsync(id);

            if (entity is null)
            {
                return(NotFound());
            }

            return(Ok(entity));
        }
コード例 #3
0
        public async Task UpdateAsync_WithNoItem_ItReturnsNull()
        {
            // Arrange
            using var dbContext = new ApplicationDbContext(Options);
            IEntityService <TDto, TInputDto> service = GetService(dbContext, Mapper);

            TInputDto newEntity = CreateInputDto();

            // Act
            TDto?updated = await service.UpdateAsync(1, newEntity);

            // Assert
            Assert.IsNull(updated);
        }
コード例 #4
0
        public async Task <ActionResult <TDto> > Get(int id)
        {
            try
            {
                TDto?entity = await Service.FetchByIdAsync(id);

                if (entity is null)
                {
                    return(NotFound());
                }

                return(Ok(entity));
            }
            catch (UserPermissionException)
            {
                return(Unauthorized());
            }
        }
コード例 #5
0
        public async Task UpdateAsync_WithExistingItem_UpdatesItem()
        {
            // Arrange
            using var setupContext = new ApplicationDbContext(Options);
            TEntity entity = CreateEntity();

            setupContext.Set <TEntity>().Add(entity);
            await setupContext.SaveChangesAsync();

            using var dbContext = new ApplicationDbContext(Options);
            IEntityService <TDto, TInputDto> service = GetService(dbContext, Mapper);

            TInputDto newEntity = CreateInputDto();

            // Act
            TDto?updated = await service.UpdateAsync(entity.Id, newEntity);

            // Assert
            Assert.IsNotNull(updated);
        }
コード例 #6
0
    protected override TEntity?PerformGet(TId?id)
    {
        Sql <ISqlContext> sql = GetBaseQuery(false);

        sql.Where(GetBaseWhereClause(), GetBaseWhereClauseArguments(id));

        TDto?dto = PerformFetch(sql).FirstOrDefault();

        if (dto == null)
        {
            return(null);
        }

        TEntity entity = ConvertToEntity(dto);

        if (entity is EntityBase dirtyEntity)
        {
            // reset dirty initial properties (U4-1946)
            dirtyEntity.ResetDirtyProperties(false);
        }

        return(entity);
    }
コード例 #7
0
 public TBuilder Where_TryGetOneAsync_returns(TDto?dto, TId id)
 {
     Mock.Setup(x => x.TryGetOneAsync(id)).ReturnsAsync(dto);
     return((TBuilder)this);
 }
コード例 #8
0
 public TBuilder Where_TryGetOneAsync_returns(TDto?dto)
 {
     Mock.Setup(x => x.TryGetOneAsync(It.IsAny <TId>())).ReturnsAsync(dto);
     return((TBuilder)this);
 }