• 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

76.92
/src/EntityFrameworkCore.Generator.Core/OptionMapper.cs
1
using EntityFrameworkCore.Generator.Options;
2
using EntityFrameworkCore.Generator.Serialization;
3

4
namespace EntityFrameworkCore.Generator;
5

6
public static class OptionMapper
7
{
8
    public static GeneratorOptions Map(GeneratorModel generator)
9
    {
10
        var options = new GeneratorOptions();
5✔
11
        options.Variables.ShouldEvaluate = false;
5✔
12

13
        MapProject(options.Project, generator.Project);
5✔
14
        MapDatabase(options.Database, generator.Database);
5✔
15
        MapData(options.Data, generator.Data);
5✔
16
        MapModel(options.Model, generator.Model);
5✔
17
        MapScript(options.Script, generator.Script);
5✔
18

19
        options.Variables.ShouldEvaluate = true;
5✔
20

21
        return options;
5✔
22
    }
23

24
    private static void MapScript(ScriptOptions option, ScriptModel? script)
25
    {
26
        if (script == null)
5!
27
            return;
5✔
28

29
        MapList(option.Context, script.Context, (template) =>
×
30
        {
×
31
            var prefix = OptionsBase.AppendPrefix(option.Prefix, $"Context{option.Context.Count:0000}");
×
32
            return MapTemplate(option.Variables, template, prefix);
×
33
        });
×
34

35
        MapList(option.Entity, script.Entity, (template) =>
×
36
        {
×
37
            var prefix = OptionsBase.AppendPrefix(option.Prefix, $"Entity{option.Entity.Count:0000}");
×
38
            return MapTemplate(option.Variables, template, prefix);
×
39
        });
×
40

41
        MapList(option.Model, script.Model, (template) =>
×
42
        {
×
43
            var prefix = OptionsBase.AppendPrefix(option.Prefix, $"Model{option.Entity.Count:0000}");
×
44
            return MapTemplate(option.Variables, template, prefix);
×
45
        });
×
46
    }
×
47

48
    private static void MapModel(ModelOptions option, ViewModel model)
49
    {
50
        MapShared(option.Shared, model.Shared);
5✔
51
        MapRead(option.Read, model.Read);
5✔
52
        MapCreate(option.Create, model.Create);
5✔
53
        MapUpdate(option.Update, model.Update);
5✔
54
        MapMapper(option.Mapper, model.Mapper);
5✔
55
        MapValidator(option.Validator, model.Validator);
5✔
56
    }
5✔
57

58
    private static void MapClassBase(ClassOptionsBase option, ClassBase classBase)
59
    {
60
        option.Namespace = classBase.Namespace;
45✔
61
        option.Directory = classBase.Directory;
45✔
62
        option.Document = classBase.Document;
45✔
63
        option.Name = classBase.Name;
45✔
64
        option.BaseClass = classBase.BaseClass;
45✔
65
        option.Attributes = classBase.Attributes;
45✔
66
        option.Header = classBase.Header;
45✔
67
    }
45✔
68

69
    private static void MapModelBase(ModelOptionsBase option, ModelBase modelBase)
70
    {
71
        MapClassBase(option, modelBase);
15✔
72

73
        option.Generate = modelBase.Generate;
15✔
74

75
        MapSelection(option.Include, modelBase.Include);
15✔
76
        MapSelection(option.Exclude, modelBase.Exclude);
15✔
77

78
    }
15✔
79

80
    private static void MapValidator(ValidatorClassOptions option, ValidatorClass validator)
81
    {
82
        MapClassBase(option, validator);
5✔
83

84
        option.Generate = validator.Generate;
5✔
85
    }
5✔
86

87
    private static void MapMapper(MapperClassOptions option, MapperClass mapper)
88
    {
89
        MapClassBase(option, mapper);
5✔
90

91
        option.Generate = mapper.Generate;
5✔
92
    }
5✔
93

94
    private static void MapUpdate(UpdateModelOptions option, UpdateModel update)
95
    {
96
        MapModelBase(option, update);
5✔
97
    }
5✔
98

99
    private static void MapCreate(CreateModelOptions option, CreateModel create)
100
    {
101
        MapModelBase(option, create);
5✔
102
    }
5✔
103

104
    private static void MapRead(ReadModelOptions option, ReadModel read)
105
    {
106
        MapModelBase(option, read);
5✔
107
    }
5✔
108

109
    private static void MapShared(SharedModelOptions option, SharedModel shared)
110
    {
111
        option.Namespace = shared.Namespace;
5✔
112
        option.Directory = shared.Directory;
5✔
113
        option.Header = shared.Header;
5✔
114

115
        MapSelection(option.Include, shared.Include);
5✔
116
        MapSelection(option.Exclude, shared.Exclude);
5✔
117
    }
5✔
118

119
    private static void MapData(DataOptions option, DataModel data)
120
    {
121
        MapContext(option.Context, data.Context);
5✔
122
        MapEntity(option.Entity, data.Entity);
5✔
123
        MapMapping(option.Mapping, data.Mapping);
5✔
124
        MapQuery(option.Query, data.Query);
5✔
125
    }
5✔
126

127
    private static void MapQuery(QueryExtensionOptions option, QueryExtension query)
128
    {
129
        MapClassBase(option, query);
5✔
130

131
        option.Generate = query.Generate;
5✔
132
        option.IndexPrefix = query.IndexPrefix;
5✔
133
        option.UniquePrefix = query.UniquePrefix;
5✔
134
    }
5✔
135

136
    private static void MapMapping(MappingClassOptions option, MappingClass mapping)
137
    {
138
        MapClassBase(option, mapping);
5✔
139

140
        option.Temporal = mapping.Temporal;
5✔
141
        option.RowVersion = mapping.RowVersion;
5✔
142
    }
5✔
143

144
    private static void MapEntity(EntityClassOptions option, EntityClass entity)
145
    {
146
        MapClassBase(option, entity);
5✔
147

148
        option.EntityNaming = entity.EntityNaming;
5✔
149
        option.RelationshipNaming = entity.RelationshipNaming;
5✔
150
        option.PrefixWithSchemaName = entity.PrefixWithSchemaName;
5✔
151
        option.MappingAttributes = entity.MappingAttributes;
5✔
152

153
        MapSelection(option.Renaming, entity.Renaming);
5✔
154

155
        MapList(option.TypeMapping, entity.TypeMapping, MapTypeMapping);
5✔
156
    }
5✔
157

158
    private static TypeMappingOptions MapTypeMapping(Serialization.TypeMapping typeMapping)
159
    {
160
        return new TypeMappingOptions
11✔
161
        {
11✔
162
            NativeType = typeMapping.NativeType,
11✔
163
            SystemType = typeMapping.SystemType
11✔
164
        };
11✔
165
    }
166

167
    private static void MapSelection(SelectionOptions option, SelectionModel? selection)
168
    {
169
        if (selection == null)
45✔
170
            return;
33✔
171

172
        MapList(option.Entities, selection.Entities, (match) =>
12✔
173
        {
12✔
174
            var prefix = OptionsBase.AppendPrefix(option.Prefix, $"Entity{option.Entities.Count:0000}");
12✔
175
            return MapMatch(option.Variables, match, prefix);
12✔
176
        });
12✔
177

178
        MapList(option.Properties, selection.Properties, (match) =>
12✔
179
        {
12✔
180
            var prefix = OptionsBase.AppendPrefix(option.Prefix, $"Property{option.Properties.Count:0000}");
12✔
181
            return MapMatch(option.Variables, match, prefix);
12✔
182
        });
12✔
183
    }
12✔
184

185
    private static void MapContext(ContextClassOptions option, ContextClass context)
186
    {
187
        MapClassBase(option, context);
5✔
188

189
        option.PropertyNaming = context.PropertyNaming;
5✔
190
    }
5✔
191

192
    private static void MapDatabase(DatabaseOptions option, DatabaseModel database)
193
    {
194
        option.Provider = database.Provider;
5✔
195
        option.ConnectionString = database.ConnectionString;
5✔
196
        option.ConnectionName = database.ConnectionName;
5✔
197
        option.UserSecretsId = database.UserSecretsId;
5✔
198
        option.TableNaming = database.TableNaming;
5✔
199

200
        MapList(option.Tables, database.Tables);
5✔
201
        MapList(option.Schemas, database.Schemas);
5✔
202

203
        MapDatabaseMatch(option.Exclude, database.Exclude);
5✔
204
    }
5✔
205

206
    private static void MapProject(ProjectOptions option, ProjectModel project)
207
    {
208
        option.Namespace = project.Namespace;
5✔
209
        option.Directory = project.Directory;
5✔
210
        option.Nullable = project.Nullable;
5✔
211
        option.FileScopedNamespace = project.FileScopedNamespace;
5✔
212
    }
5✔
213

214
    private static void MapDatabaseMatch(DatabaseMatchOptions option, DatabaseMatchModel? match)
215
    {
216
        if (match == null)
5✔
217
            return;
4✔
218

219
        MapList(option.Tables, match.Tables, (match) =>
1✔
220
        {
1✔
221
            var prefix = OptionsBase.AppendPrefix(option.Prefix, $"Table{option.Tables?.Count:0000}");
1✔
222
            return MapMatch(option.Variables, match, prefix);
1✔
223
        });
1✔
224

225
        MapList(option.Columns, match.Columns, (match) =>
1✔
226
        {
1✔
227
            var prefix = OptionsBase.AppendPrefix(option.Prefix, $"Column{option.Columns?.Count:0000}");
1✔
228
            return MapMatch(option.Variables, match, prefix);
1✔
229
        });
1✔
230

231
        MapList(option.Relationships, match.Relationships, (match) =>
1✔
232
        {
1✔
233
            var prefix = OptionsBase.AppendPrefix(option.Prefix, $"Relationship{option.Relationships?.Count:0000}");
1✔
234
            return MapMatch(option.Variables, match, prefix);
1✔
235
        });
1✔
236
    }
1✔
237

238
    private static void MapList<T>(IList<T> targetList, IList<T>? sourceList)
239
    {
240
        if (sourceList == null || sourceList.Count == 0)
10!
241
            return;
10✔
242

243
        foreach (var source in sourceList)
×
244
            targetList.Add(source);
×
UNCOV
245
    }
×
246

247
    private static void MapList<TTarget, TSource>(IList<TTarget> targetList, IList<TSource>? sourceList, Func<TSource, TTarget> factory)
248
    {
249
        if (sourceList == null || sourceList.Count == 0)
32✔
250
            return;
14✔
251

252
        foreach (var source in sourceList)
100✔
253
        {
254
            var target = factory(source);
32✔
255
            targetList.Add(target);
32✔
256
        }
257
    }
18✔
258

259
    private static MatchOptions MapMatch(VariableDictionary variables, MatchModel match, string? prefix)
260
    {
261
        return new MatchOptions(variables, prefix)
21✔
262
        {
21✔
263
            Exact = match.Exact,
21✔
264
            Expression = match.Expression
21✔
265
        };
21✔
266
    }
267

268
    private static TemplateOptions MapTemplate(VariableDictionary variables, TemplateModel template, string? prefix)
269
    {
270
        var option = new TemplateOptions(variables, prefix)
×
271
        {
×
UNCOV
272
            TemplatePath = template.TemplatePath,
×
273
            FileName = template.FileName,
×
274
            Namespace = template.Namespace,
×
UNCOV
275
            BaseClass = template.BaseClass,
×
276
            Directory = template.Directory,
×
UNCOV
277
            Overwrite = template.Overwrite,
×
UNCOV
278
            Merge = template.Merge,
×
UNCOV
279
        };
×
280

UNCOV
281
        if (template.Parameters == null || template.Parameters.Count == 0)
×
UNCOV
282
            return option;
×
283

UNCOV
284
        foreach (var paremeter in template.Parameters)
×
UNCOV
285
            option.Parameters[paremeter.Key] = paremeter.Value;
×
286

UNCOV
287
        return option;
×
288
    }
289
}
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