< Summary

Information
Class: Application.Service.ProductService
Assembly: Application
File(s): /home/runner/work/Northwind-Api/Northwind-Api/src/Application/Service/ProductService.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 33
Coverable lines: 33
Total lines: 56
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
Create()100%210%
Update()0%620%
DeleteAsync()0%620%

File(s)

/home/runner/work/Northwind-Api/Northwind-Api/src/Application/Service/ProductService.cs

#LineLine coverage
 1using System.Reflection;
 2using Infrastructure.Entity;
 3using Infrastructure.Repository;
 4using Microsoft.EntityFrameworkCore;
 5using Microsoft.Extensions.Logging;
 6
 7namespace Application.Service;
 8public class ProductService {
 9
 10  private readonly ILogger<ProductService> _logger;
 11  private readonly NorthwindRepository _repository;
 12
 013  public ProductService(ILogger<ProductService> logger, NorthwindRepository repository) {
 014    _logger = logger;
 015    _repository = repository;
 016  }
 17
 018  public async Task<product> Create(product product, CancellationToken ct) {
 019    await _repository.Add(product, ct);
 020    await _repository.SaveChangesAsync(ct);
 021    _logger.LogInformation("Product created: {ProductId}", product.product_id);
 022    return product;
 023  }
 24
 025  public async Task<product?> Update(int id, product product, CancellationToken ct) {
 026    var existing = await _repository.GetById<product>(id, ct);
 027    if (existing == null) {
 028      _logger.LogWarning("Product not found for update: {ProductId}", id);
 029      return null;
 30    }
 31
 032    existing.product_name = product.product_name;
 033    existing.unit_price = product.unit_price;
 034    existing.units_in_stock = product.units_in_stock;
 035    existing.category_id = product.category_id;
 36
 37    //TODO other properties and mapping
 38
 039    await _repository.Update(existing, ct);
 040    await _repository.SaveChangesAsync(ct);
 041    return existing;
 042  }
 43
 044  public async Task<bool> DeleteAsync(int id, CancellationToken ct) {
 045    var product = await _repository.GetById<product>(id, ct);
 046    if (product == null) {
 047      _logger.LogWarning("Product not found for delete: {ProductId}", id);
 048      return false;
 49    }
 50
 051    await _repository.Delete(product, ct);
 052    await _repository.SaveChangesAsync(ct);
 053    _logger.LogInformation("Product deleted: {ProductId}", id);
 054    return true;
 055  }
 56}