| Class: | Api.Jobs.JobDTOBuilder |
|---|---|
| Assembly: | Api |
| File(s): | /home/runner/work/ProjectRead.ing/ProjectRead.ing/Api/Jobs/JobDTOBuilder.cs |
| Covered lines: | 0 |
|---|---|
| Uncovered lines: | 19 |
| Coverable lines: | 19 |
| Total lines: | 37 |
| Line coverage: | 0% |
| Covered branches: | 0 |
|---|---|
| Total branches: | 12 |
| Branch coverage: | 0% |
Feature is only available for sponsors
Upgrade to PRO version| Method | Branch coverage | Crap Score | Cyclomatic complexity | Line coverage |
|---|---|---|---|---|
| .ctor() | 0% | 42 | 6 | 0% |
| CreateFrom(...) | 0% | 6 | 2 | 0% |
| # | Line | Line coverage | ||
|---|---|---|---|---|
1 | // SPDX-FileCopyrightText: 2026 Alper Çelik <[email protected]> | |||
2 | // | |||
3 | // SPDX-License-Identifier: AGPL-3.0-or-later | |||
4 | | |||
5 | using System.Reflection; | |||
6 | using Api.Jobs.DTOs; | |||
7 | using Api.Jobs.Models; | |||
8 | | |||
9 | namespace Api.Jobs; | |||
10 | | |||
11 | public class JobDTOBuilder | |||
12 | { | |||
13 | public delegate IJob JobFactory(JobData data); | |||
14 | private readonly Dictionary<string, JobFactory> _jobFactories; | |||
15 | | |||
| 0 | 16 | JobDTOBuilder() | ||
| 0 | 17 | { | ||
| 0 | 18 | _jobFactories = Assembly | ||
| 0 | 19 | .GetExecutingAssembly() | ||
| 0 | 20 | .GetTypes() | ||
| 0 | 21 | .Where(t => | ||
| 0 | 22 | t.GetInterfaces().Any(i => i.GetType() == typeof(IJob)) && t.IsClass | ||
| 0 | 23 | ) | ||
| 0 | 24 | .ToDictionary( | ||
| 0 | 25 | t => t.Name, | ||
| 0 | 26 | t => | ||
| 0 | 27 | t.GetMethod( | ||
| 0 | 28 | nameof(IJobType.CreateFrom), | ||
| 0 | 29 | BindingFlags.Static | BindingFlags.Public | ||
| 0 | 30 | )! | ||
| 0 | 31 | .CreateDelegate<JobFactory>() | ||
| 0 | 32 | ); | ||
| 0 | 33 | } | ||
34 | | |||
35 | public IJob? CreateFrom(string jobType, JobData data) => | |||
| 0 | 36 | _jobFactories.TryGetValue(jobType, out var factory) ? factory(data) : null; | ||
37 | } |