public async Task UpdateInspectionTypeAsync_UpdatedDto_ReturnsRegisteredDto()
    {
        _context.InspectionTypes.Add(new InspectionType
        {
            InspectionTypeId = 3,
            Description      = "type"
        });
        _context.SaveChanges();

        var target = new CategoryRepository(_context, _mapper);
        var dto    = new InspectionTypeDto
        {
            InspectionTypeId = 3,
            Description      = "type1"
        };
        var actualDto = await target.UpdateInspectionTypeAsync(dto);

        Assert.Equal(3, actualDto.InspectionTypeId);
        Assert.Equal("type1", actualDto.Description);

        var actualEntity = _context.InspectionTypes.First();

        Assert.Equal(3, actualEntity.InspectionTypeId);
        Assert.Equal("type1", actualEntity.Description);
    }
    public async Task <IActionResult> UpdateInspectionTypeAsync(
        [Required][FromRoute] int id,
        [Required][FromBody] InspectionTypeDto dto
        )
    {
        try
        {
            _logger.LogInformation($"try to update inspection type {dto.InspectionTypeId}");
            if (id != dto.InspectionTypeId)
            {
                return(BadRequest("Invalid ID supplied"));
            }

            if (!_repository.InspectionTypeExists(dto.InspectionTypeId))
            {
                return(NotFound($"Type with Id = {dto.InspectionTypeId} not found"));
            }

            var result = await _repository.UpdateInspectionTypeAsync(dto);

            return(CreatedAtAction(
                       nameof(GetInspectionTypeById),
                       new { id = result.InspectionTypeId }, result
                       ));
        }
        catch (Exception ex)
        {
            _logger.LogError(ex.Message);
            return(StatusCode(
                       StatusCodes.Status500InternalServerError,
                       "Internal Sever Error"
                       ));
        }
    }
    /// <inheritdoc/>
    public async Task <InspectionTypeDto> CreateInspectionTypeAsync(InspectionTypeDto dto)
    {
        var entity = _mapper.Map <InspectionType>(dto);
        await _context.InspectionTypes.AddAsync(entity);

        await _context.SaveChangesAsync();

        return(_mapper.Map <InspectionTypeDto>(entity));
    }
    /// <inheritdoc/>
    public async Task <InspectionTypeDto> UpdateInspectionTypeAsync(InspectionTypeDto dto)
    {
        var entity = await _context.InspectionTypes.FindAsync(dto.InspectionTypeId);

        if (entity is not null)
        {
            _mapper.Map(dto, entity);
            _context.InspectionTypes.Update(entity);
            await _context.SaveChangesAsync();
        }

        return(_mapper.Map <InspectionTypeDto>(entity));
    }
    public async Task CreateInspectionTypeAsync_NewDto_ReturnsRegisteredDto()
    {
        var target = new CategoryRepository(_context, _mapper);
        var dto    = new InspectionTypeDto
        {
            Description = "type"
        };
        var actualDto = await target.CreateInspectionTypeAsync(dto);

        Assert.NotEqual(0, actualDto.InspectionTypeId);
        Assert.Equal("type", actualDto.Description);

        var actualEntity = _context.InspectionTypes.First();

        Assert.NotEqual(0, actualEntity.InspectionTypeId);
        Assert.Equal("type", actualEntity.Description);
    }
    public async Task <IActionResult> CreateInspectionTypeAsync([Required][FromBody] InspectionTypeDto dto)
    {
        try
        {
            _logger.LogInformation("try to create inspection type");
            var result = await _repository.CreateInspectionTypeAsync(dto);

            return(CreatedAtAction(
                       nameof(GetInspectionTypeById),
                       new { id = result.InspectionTypeId },
                       result
                       ));
        }
        catch (Exception ex)
        {
            _logger.LogError(ex.Message);
            return(StatusCode(
                       StatusCodes.Status500InternalServerError,
                       "Internal Sever Error"
                       ));
        }
    }