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

loresoft / EntityFrameworkCore.Generator / 15460811637

05 Jun 2025 07:12AM CUT coverage: 54.917%. Remained the same
15460811637

Pull #669

github

web-flow
Merge 7e40b6960 into b2ad58745
Pull Request #669: Bump the azure group with 3 updates

643 of 1333 branches covered (48.24%)

Branch coverage included in aggregate %.

1881 of 3263 relevant lines covered (57.65%)

61.27 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
        option.Header = classBase.Header;
×
67
    }
×
68

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

73
        option.Generate = modelBase.Generate;
×
74

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

78
    }
×
79

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

153
        MapSelection(option.Renaming, entity.Renaming);
×
154
    }
×
155

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

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

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

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

178
        option.PropertyNaming = context.PropertyNaming;
×
179
    }
×
180

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

189
        MapList(option.Tables, database.Tables);
×
190
        MapList(option.Schemas, database.Schemas);
×
191

192
        MapDatabaseMatch(option.Exclude, database.Exclude);
×
193
    }
×
194

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

203
    private static void MapDatabaseMatch(DatabaseMatchOptions option, DatabaseMatchModel? match)
204
    {
205
        if (match == null)
×
206
            return;
×
207

208
        MapList(option.Tables, match.Tables, (match) =>
×
209
        {
×
210
            var prefix = OptionsBase.AppendPrefix(option.Prefix, $"Table{option.Tables?.Count:0000}");
×
211
            return MapMatch(option.Variables, match, prefix);
×
212
        });
×
213

214
        MapList(option.Columns, match.Columns, (match) =>
×
215
        {
×
216
            var prefix = OptionsBase.AppendPrefix(option.Prefix, $"Column{option.Columns?.Count:0000}");
×
217
            return MapMatch(option.Variables, match, prefix);
×
218
        });
×
219
    }
×
220

221
    private static void MapList<T>(IList<T> targetList, IList<T>? sourceList)
222
    {
223
        if (sourceList == null || sourceList.Count == 0)
×
224
            return;
×
225

226
        foreach (var source in sourceList)
×
227
            targetList.Add(source);
×
228
    }
×
229

230
    private static void MapList<TTarget, TSource>(IList<TTarget> targetList, IList<TSource>? sourceList, Func<TSource, TTarget> factory)
231
    {
232
        if (sourceList == null || sourceList.Count == 0)
×
233
            return;
×
234

235
        foreach (var source in sourceList)
×
236
        {
237
            var target = factory(source);
×
238
            targetList.Add(target);
×
239
        }
240
    }
×
241

242
    private static MatchOptions MapMatch(VariableDictionary variables, MatchModel match, string? prefix)
243
    {
244
        return new MatchOptions(variables, prefix)
×
245
        {
×
246
            Exact = match.Exact,
×
247
            Expression = match.Expression
×
248
        };
×
249
    }
250

251
    private static TemplateOptions MapTemplate(VariableDictionary variables, TemplateModel template, string? prefix)
252
    {
253
        var option = new TemplateOptions(variables, prefix)
×
254
        {
×
255
            TemplatePath = template.TemplatePath,
×
256
            FileName = template.FileName,
×
257
            Namespace = template.Namespace,
×
258
            BaseClass = template.BaseClass,
×
259
            Directory = template.Directory,
×
260
            Overwrite = template.Overwrite,
×
261
            Merge = template.Merge,
×
262
        };
×
263

264
        if (template.Parameters == null || template.Parameters.Count == 0)
×
265
            return option;
×
266

267
        foreach (var paremeter in template.Parameters)
×
268
            option.Parameters[paremeter.Key] = paremeter.Value;
×
269

270
        return option;
×
271
    }
272
}
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