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

loresoft / EntityFrameworkCore.Generator / 15098211199

18 May 2025 05:11PM UTC coverage: 54.862% (-0.07%) from 54.934%
15098211199

push

github

pwelter34
fix tests

620 of 1291 branches covered (48.02%)

Branch coverage included in aggregate %.

1840 of 3193 relevant lines covered (57.63%)

61.91 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

190
        MapDatabaseMatch(option.Exclude, database.Exclude);
×
191
    }
×
192

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

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

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

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

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

224
        foreach (var source in sourceList)
×
225
            targetList.Add(source);
×
226
    }
×
227

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

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

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

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

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

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

268
        return option;
×
269
    }
270
}
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