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

loresoft / EntityFrameworkCore.Generator / 15072048022

16 May 2025 03:31PM UTC coverage: 55.392% (-1.4%) from 56.772%
15072048022

push

github

pwelter34
enable nullable support

616 of 1271 branches covered (48.47%)

Branch coverage included in aggregate %.

233 of 397 new or added lines in 61 files covered. (58.69%)

17 existing lines in 11 files now uncovered.

1824 of 3134 relevant lines covered (58.2%)

88.56 hits per line

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

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

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

19
        options.Variables.ShouldEvaluate = true;
×
20

21
        return options;
×
22
    }
23

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

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

68
    private static void MapModelBase(ModelOptionsBase option, ModelBase modelBase)
69
    {
70
        MapClassBase(option, modelBase);
×
71

72
        option.Generate = modelBase.Generate;
×
73

74
        MapSelection(option.Include, modelBase.Include);
×
75
        MapSelection(option.Exclude, modelBase.Exclude);
×
76

77
    }
×
78

79
    private static void MapValidator(ValidatorClassOptions option, ValidatorClass validator)
80
    {
81
        MapClassBase(option, validator);
×
82

83
        option.Generate = validator.Generate;
×
84
    }
×
85

86
    private static void MapMapper(MapperClassOptions option, MapperClass mapper)
87
    {
88
        MapClassBase(option, mapper);
×
89

90
        option.Generate = mapper.Generate;
×
91
    }
×
92

93
    private static void MapUpdate(UpdateModelOptions option, UpdateModel update)
94
    {
95
        MapModelBase(option, update);
×
96
    }
×
97

98
    private static void MapCreate(CreateModelOptions option, CreateModel create)
99
    {
100
        MapModelBase(option, create);
×
101
    }
×
102

103
    private static void MapRead(ReadModelOptions option, ReadModel read)
104
    {
105
        MapModelBase(option, read);
×
106
    }
×
107

108
    private static void MapShared(SharedModelOptions option, SharedModel shared)
109
    {
110
        option.Namespace = shared.Namespace;
×
111
        option.Directory = shared.Directory;
×
112

113
        MapSelection(option.Include, shared.Include);
×
114
        MapSelection(option.Exclude, shared.Exclude);
×
115
    }
×
116

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

125
    private static void MapQuery(QueryExtensionOptions option, QueryExtension query)
126
    {
127
        MapClassBase(option, query);
×
128

129
        option.Generate = query.Generate;
×
130
        option.IndexPrefix = query.IndexPrefix;
×
131
        option.UniquePrefix = query.UniquePrefix;
×
132
    }
×
133

134
    private static void MapMapping(MappingClassOptions option, MappingClass mapping)
135
    {
136
        MapClassBase(option, mapping);
×
137

138
        option.Temporal = mapping.Temporal;
×
139
        option.RowVersion = mapping.RowVersion;
×
140
    }
×
141

142
    private static void MapEntity(EntityClassOptions option, EntityClass entity)
143
    {
144
        MapClassBase(option, entity);
×
145

146
        option.EntityNaming = entity.EntityNaming;
×
147
        option.RelationshipNaming = entity.RelationshipNaming;
×
148
        option.PrefixWithSchemaName = entity.PrefixWithSchemaName;
×
149
        option.MappingAttributes = entity.MappingAttributes;
×
150

151
        MapSelection(option.Renaming, entity.Renaming);
×
152
    }
×
153

154
    private static void MapSelection(SelectionOptions option, SelectionModel? selection)
155
    {
156
        if (selection == null)
×
157
            return;
×
158

159
        MapList(option.Entities, selection.Entities, (match) =>
×
160
        {
×
161
            var prefix = OptionsBase.AppendPrefix(option.Prefix, $"Entity{option.Entities.Count:0000}");
×
162
            return MapMatch(option.Variables, match, prefix);
×
163
        });
×
164

165
        MapList(option.Properties, selection.Properties, (match) =>
×
166
        {
×
167
            var prefix = OptionsBase.AppendPrefix(option.Prefix, $"Property{option.Properties.Count:0000}");
×
168
            return MapMatch(option.Variables, match, prefix);
×
169
        });
×
170
    }
×
171

172
    private static void MapContext(ContextClassOptions option, ContextClass context)
173
    {
174
        MapClassBase(option, context);
×
175

176
        option.PropertyNaming = context.PropertyNaming;
×
177
    }
×
178

179
    private static void MapDatabase(DatabaseOptions option, DatabaseModel database)
180
    {
181
        option.Provider = database.Provider;
×
182
        option.ConnectionString = database.ConnectionString;
×
183
        option.ConnectionName = database.ConnectionName;
×
184
        option.UserSecretsId = database.UserSecretsId;
×
185
        option.TableNaming = database.TableNaming;
×
186

187
        MapList(option.Tables, database.Tables);
×
188
        MapList(option.Schemas, database.Schemas);
×
189
        MapList(option.Exclude, database.Exclude, (match) =>
×
190
        {
×
191
            var prefix = OptionsBase.AppendPrefix(option.Prefix, $"Exclude{option.Exclude.Count:0000}");
×
192
            return MapMatch(option.Variables, match, prefix);
×
193
        });
×
194
    }
×
195

196
    private static void MapProject(ProjectOptions option, ProjectModel project)
197
    {
198
        option.Namespace = project.Namespace;
×
199
        option.Directory = project.Directory;
×
200
        option.Nullable = project.Nullable;
×
201
        option.FileScopedNamespace = project.FileScopedNamespace;
×
202
    }
×
203

204

205
    private static void MapList<T>(IList<T> targetList, IList<T>? sourceList)
206
    {
NEW
207
        if (sourceList == null || sourceList.Count == 0)
×
208
            return;
×
209

210
        foreach (var source in sourceList)
×
211
            targetList.Add(source);
×
212
    }
×
213

214
    private static void MapList<TTarget, TSource>(IList<TTarget> targetList, IList<TSource>? sourceList, Func<TSource, TTarget> factory)
215
    {
216
        if (sourceList == null || sourceList.Count == 0)
×
217
            return;
×
218

219
        foreach (var source in sourceList)
×
220
        {
221
            var target = factory(source);
×
222
            targetList.Add(target);
×
223
        }
224
    }
×
225

226
    private static MatchOptions MapMatch(VariableDictionary variables, MatchModel match, string? prefix)
227
    {
228
        return new MatchOptions(variables, prefix)
×
229
        {
×
230
            Exact = match.Exact,
×
231
            Expression = match.Expression
×
232
        };
×
233
    }
234

235
    private static TemplateOptions MapTemplate(VariableDictionary variables, TemplateModel template, string? prefix)
236
    {
237
        var option = new TemplateOptions(variables, prefix)
×
238
        {
×
239
            TemplatePath = template.TemplatePath,
×
240
            FileName = template.FileName,
×
241
            Namespace = template.Namespace,
×
242
            BaseClass = template.BaseClass,
×
243
            Directory = template.Directory,
×
244
            Overwrite = template.Overwrite,
×
245
            Merge = template.Merge,
×
246
        };
×
247

248
        if (template.Parameters == null || template.Parameters.Count == 0)
×
249
            return option;
×
250

251
        foreach (var paremeter in template.Parameters)
×
252
            option.Parameters[paremeter.Key] = paremeter.Value;
×
253

254
        return option;
×
255
    }
256
}
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

© 2025 Coveralls, Inc