< Summary

Information
Class: DatabaseService
Assembly: TreeGrouping.Application
File(s): /home/runner/work/Studio2Prod/Studio2Prod/TreeGrouping.Application/DbService/DatabaseService.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 24
Coverable lines: 24
Total lines: 54
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
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(...)0%620%
ExecuteStoredProcedureAsync()100%210%
ExecuteStoredProcedure(...)100%210%
GetAllCategoryLinksAsync()100%210%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/TreeGrouping.Application/DbService/DatabaseService.cs

#LineLine coverage
 1using System.Data;
 2using System.Data.SqlClient;
 3using ConsoleApp1;
 4using Dapper;
 5using Microsoft.Data.SqlClient;
 6using Microsoft.Extensions.Configuration;
 7using TreeGrouping.Application.DbService;
 8using TreeGrouping.Application.DbService.Models;
 9
 10public class DatabaseService:IDatabaseService
 11{
 12    private readonly string _connectionString;
 13
 014    public DatabaseService(IConfiguration configuration)
 15    {
 016        _connectionString = configuration.GetConnectionString("DefaultTreeConnection")
 017                            ?? throw new InvalidOperationException("Connection string not found");
 018    }
 19
 20    public async Task<IEnumerable<CategoryModel>> ExecuteStoredProcedureAsync(StoredProcedureType type, object parameter
 21    {
 022        using var connection = new SqlConnection(_connectionString);
 23
 024        var procedureName = type.GetProcedureName();
 025        var paramDict = type.GetParameter(parameters);
 26
 027        return await connection.QueryAsync<CategoryModel>(
 028            procedureName, paramDict, commandType: CommandType.StoredProcedure
 029        );
 030    }
 31
 32    public IEnumerable<CategoryModel> ExecuteStoredProcedure(StoredProcedureType type, object? parameters = null)
 33    {
 034        using var connection = new SqlConnection(_connectionString);
 35
 036        var procedureName = type.GetProcedureName();
 037        var paramDict = type.GetParameter(parameters);
 38
 039        return connection.Query<CategoryModel>(
 040            procedureName, paramDict, commandType: CommandType.StoredProcedure
 041        );
 042    }
 43
 44
 45    public async Task<IEnumerable<CategoryLinkModel>> GetAllCategoryLinksAsync()
 46    {
 047        using var connection = new SqlConnection(_connectionString);
 48
 049        return await connection.QueryAsync<CategoryLinkModel>(
 050            "GetAllCategoryLinks",
 051            commandType: CommandType.StoredProcedure
 052        );
 053    }
 54}