• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

loresoft / EntityFrameworkCore.Generator / 27730465225

18 Jun 2026 01:21AM UTC coverage: 74.693% (+19.8%) from 54.885%
27730465225

push

github

pwelter34
update tests

922 of 1609 branches covered (57.3%)

Branch coverage included in aggregate %.

7 of 7 new or added lines in 2 files covered. (100.0%)

230 existing lines in 23 files now uncovered.

4007 of 4990 relevant lines covered (80.3%)

1258.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.0
/src/EntityFrameworkCore.Generator.Core/ConfigurationSerializer.cs
1
using EntityFrameworkCore.Generator.Serialization;
2

3
using Microsoft.Extensions.Logging;
4

5
using YamlDotNet.Serialization;
6
using YamlDotNet.Serialization.NamingConventions;
7

8
namespace EntityFrameworkCore.Generator;
9

10
/// <summary>
11
/// Serialization and Deserialization for the <see cref="Generator"/> class
12
/// </summary>
13
public class ConfigurationSerializer : IConfigurationSerializer
14
{
15
    private readonly ILogger<ConfigurationSerializer> _logger;
16

17
    /// <summary>
18
    /// Initializes a new instance of the <see cref="ConfigurationSerializer"/> class.
19
    /// </summary>
20
    /// <param name="logger">The logger.</param>
21
    public ConfigurationSerializer(ILogger<ConfigurationSerializer> logger)
6✔
22
    {
23
        _logger = logger;
6✔
24
    }
6✔
25

26
    /// <summary>
27
    /// The options file name. Default 'generation.yml'
28
    /// </summary>
29
    public const string OptionsFileName = "generation.yml";
30

31
    /// <summary>
32
    /// Loads the options file using the specified <paramref name="directory"/> and <paramref name="file"/>.
33
    /// </summary>
34
    /// <param name="directory">The directory where the file is located.</param>
35
    /// <param name="file">The name of the options file.</param>
36
    /// <returns>An instance of <see cref="Generator"/> if the file exists; otherwise <c>null</c>.</returns>
37
    public GeneratorModel? Load(string? directory = null, string file = OptionsFileName)
38
    {
39
        var path = GetPath(directory, file);
4✔
40
        if (!File.Exists(path))
4!
41
        {
42
            _logger.LogWarning("Option file not found: {file}", file);
×
43
            return null;
×
44
        }
45

46
        _logger.LogInformation("Loading options file: {file}", file);
4✔
47
        using var reader = File.OpenText(path);
4✔
48

49
        return Load(reader);
4✔
50
    }
4✔
51

52
    /// <summary>
53
    /// Loads the options using the specified <paramref name="reader" />
54
    /// </summary>
55
    /// <param name="reader">The reader.</param>
56
    /// <returns>
57
    /// An instance of <see cref="Generator" />.
58
    /// </returns>
59
    public GeneratorModel? Load(TextReader reader)
60
    {
61
        if (reader == null)
6!
UNCOV
62
            return null;
×
63

64
        var deserializer = new DeserializerBuilder()
6✔
65
            .WithNamingConvention(CamelCaseNamingConvention.Instance)
6✔
66
            .Build();
6✔
67

68
        // use Serialization model for better yaml support
69
        return deserializer.Deserialize<GeneratorModel>(reader);
6✔
70
    }
71

72
    /// <summary>
73
    /// Saves the generator options to the specified <paramref name="directory"/> and <paramref name="file"/>.
74
    /// </summary>
75
    /// <param name="generatorOptions">The generator options to save.</param>
76
    /// <param name="directory">The directory where the file is located.</param>
77
    /// <param name="file">The name of the options file.</param>
78
    /// <returns>The full path of the options file.</returns>
79
    public string Save(GeneratorModel generatorOptions, string? directory = null, string file = OptionsFileName)
80
    {
UNCOV
81
        if (string.IsNullOrWhiteSpace(directory))
×
UNCOV
82
            directory = Environment.CurrentDirectory;
×
83

84
        if (string.IsNullOrWhiteSpace(file))
×
85
            file = OptionsFileName;
×
86

87
        if (!Directory.Exists(directory))
×
88
        {
UNCOV
89
            _logger.LogTrace($"Creating Directory: {directory}");
×
90
            Directory.CreateDirectory(directory);
×
91
        }
92

93
        _logger.LogInformation($"Saving options file: {file}");
×
94

UNCOV
95
        var path = Path.Combine(directory, file);
×
96

UNCOV
97
        var serializer = new SerializerBuilder()
×
98
            .ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitDefaults)
×
UNCOV
99
            .WithNamingConvention(CamelCaseNamingConvention.Instance)
×
100
            .Build();
×
101

102
        using (var streamWriter = File.CreateText(path))
×
103
            serializer.Serialize(streamWriter, generatorOptions);
×
104

105
        return path;
×
106
    }
107

108
    /// <summary>
109
    /// Determines if the specified options file exists.
110
    /// </summary>
111
    /// <param name="directory">The directory where the file is located.</param>
112
    /// <param name="file">The name of the options file.</param>
113
    /// <returns><c>true</c> if options file exits; otherwise <c>false</c>.</returns>
114
    public bool Exists(string? directory = null, string file = OptionsFileName)
115
    {
UNCOV
116
        var path = GetPath(directory, file);
×
UNCOV
117
        return File.Exists(path);
×
118
    }
119

120

121
    private static string GetPath(string? directory, string? file)
122
    {
123
        if (string.IsNullOrWhiteSpace(directory))
4!
UNCOV
124
            directory = Environment.CurrentDirectory;
×
125

126
        if (string.IsNullOrWhiteSpace(file))
4!
127
            file = OptionsFileName;
×
128

129
        var path = Path.Combine(directory, file);
4✔
130
        return path;
4✔
131
    }
132
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc