• 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/SecretsStore.cs
1
using System;
2
using System.Collections.Generic;
3
using System.IO;
4
using System.Linq;
5
using System.Text.Json;
6

7
using EntityFrameworkCore.Generator.Extensions;
8

9
using Microsoft.Extensions.Configuration;
10
using Microsoft.Extensions.Configuration.UserSecrets;
11

12
namespace EntityFrameworkCore.Generator;
13

14
public class SecretsStore
15
{
16
    private readonly string _secretsFilePath;
17
    private readonly IDictionary<string, string?> _secrets;
18

19
    public SecretsStore(string userSecretsId)
×
20
    {
21
        if (string.IsNullOrEmpty(userSecretsId))
×
22
            throw new ArgumentException("Value cannot be null or empty.", nameof(userSecretsId));
×
23

24
        _secretsFilePath = PathHelper.GetSecretsPathFromSecretsId(userSecretsId);
×
25

26
        // workaround bug in configuration
27
        var secretDir = Path.GetDirectoryName(_secretsFilePath);
×
NEW
28
        if (secretDir.HasValue() && !Directory.Exists(secretDir))
×
NEW
29
            Directory.CreateDirectory(secretDir);
×
30

31
        _secrets = Load(userSecretsId);
×
32
    }
×
33

NEW
34
    public string? this[string key] => _secrets[key];
×
35

36
    public int Count => _secrets.Count;
×
37

38
    public bool ContainsKey(string key) => _secrets.ContainsKey(key);
×
39

NEW
40
    public IEnumerable<KeyValuePair<string, string?>> AsEnumerable() => _secrets;
×
41

42
    public void Clear() => _secrets.Clear();
×
43

44
    public void Set(string key, string value) => _secrets[key] = value;
×
45

46
    public void Remove(string key)
47
    {
NEW
48
        _secrets.Remove(key);
×
UNCOV
49
    }
×
50

51
    public virtual void Save()
52
    {
53
        var secretDir = Path.GetDirectoryName(_secretsFilePath);
×
NEW
54
        if (secretDir.HasValue() && !Directory.Exists(secretDir))
×
NEW
55
            Directory.CreateDirectory(secretDir);
×
56

57
        var options = new JsonWriterOptions
×
58
        {
×
59
            Indented = true
×
60
        };
×
61

62
        using var stream = File.Create(_secretsFilePath);
×
63
        using var writer = new Utf8JsonWriter(stream, options);
×
64

65
        writer.WriteStartObject();
×
66

67
        foreach (var secret in _secrets.AsEnumerable())
×
68
            writer.WriteString(secret.Key, secret.Value);
×
69

70
        writer.WriteEndObject();
×
71
        writer.Flush();
×
72
    }
×
73

74
    protected virtual IDictionary<string, string?> Load(string userSecretsId)
75
    {
76
        return new ConfigurationBuilder()
×
77
            .AddJsonFile(_secretsFilePath, optional: true)
×
78
            .Build()
×
79
            .AsEnumerable()
×
80
            .Where(i => i.Value != null)
×
81
            .ToDictionary(i => i.Key, i => i.Value, StringComparer.OrdinalIgnoreCase);
×
82
    }
83
}
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