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

loresoft / EntityFrameworkCore.Generator / 27851701975

19 Jun 2026 10:42PM UTC coverage: 72.302% (+0.5%) from 71.825%
27851701975

push

github

pwelter34
tweak tests

997 of 1869 branches covered (53.34%)

Branch coverage included in aggregate %.

4229 of 5359 relevant lines covered (78.91%)

2018.55 hits per line

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

77.04
/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();
6✔
11
        options.Variables.ShouldEvaluate = false;
6✔
12

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

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

21
        return options;
6✔
22
    }
23

24
    private static void MapScript(ScriptOptions option, ScriptModel? script)
25
    {
26
        if (script == null)
6!
27
            return;
6✔
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);
6✔
51
        MapRead(option.Read, model.Read);
6✔
52
        MapCreate(option.Create, model.Create);
6✔
53
        MapUpdate(option.Update, model.Update);
6✔
54
        MapMapper(option.Mapper, model.Mapper);
6✔
55
        MapValidator(option.Validator, model.Validator);
6✔
56
    }
6✔
57

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

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

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

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

78
    }
18✔
79

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

148
        option.EntityNaming = entity.EntityNaming;
6✔
149
        option.RelationshipNaming = entity.RelationshipNaming;
6✔
150
        option.PrefixWithSchemaName = entity.PrefixWithSchemaName;
6✔
151
        option.MappingAttributes = entity.MappingAttributes;
6✔
152
        option.SystemTypeAnnotation = entity.SystemTypeAnnotation;
6✔
153

154
        MapSelection(option.Renaming, entity.Renaming);
6✔
155

156
        MapList(option.TypeMapping, entity.TypeMapping, MapTypeMapping);
6✔
157
    }
6✔
158

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

168
    private static void MapSelection(SelectionOptions option, SelectionModel? selection)
169
    {
170
        if (selection == null)
54✔
171
            return;
42✔
172

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

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

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

190
        option.PropertyNaming = context.PropertyNaming;
6✔
191
    }
6✔
192

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

201
        MapList(option.Tables, database.Tables);
6✔
202
        MapList(option.Schemas, database.Schemas);
6✔
203

204
        MapDatabaseMatch(option.Exclude, database.Exclude);
6✔
205
    }
6✔
206

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

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

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

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

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

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

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

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

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

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

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

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

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

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