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)); }
public async Task <ActionResult <TDto> > Get(int id) { TDto?entity = await Service.FetchByIdAsync(id); if (entity is null) { return(NotFound()); } return(Ok(entity)); }
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); }
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()); } }
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); }
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); }
public TBuilder Where_TryGetOneAsync_returns(TDto?dto, TId id) { Mock.Setup(x => x.TryGetOneAsync(id)).ReturnsAsync(dto); return((TBuilder)this); }
public TBuilder Where_TryGetOneAsync_returns(TDto?dto) { Mock.Setup(x => x.TryGetOneAsync(It.IsAny <TId>())).ReturnsAsync(dto); return((TBuilder)this); }