Skip to content

Commit

Permalink
Resolve nullability warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
prplecake committed Mar 3, 2023
1 parent 3aed8ee commit 708bd4c
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 33 deletions.
6 changes: 3 additions & 3 deletions BookmarkSync.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ namespace BookmarkSync.CLI;

public class Program
{
private static IConfiguration Configuration;
private static IConfiguration? _configuration;
public async static Task Main(string[] args)
{
Configuration = SetupConfiguration(args);
IConfigManager configManager = new ConfigManager(Configuration);
_configuration = SetupConfiguration(args);
IConfigManager configManager = new ConfigManager(_configuration);

using var host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
Expand Down
16 changes: 8 additions & 8 deletions BookmarkSync.Core.Tests/Configuration/ConfigManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ public void Init()

_configManager = new ConfigManager(_config);
}
private IConfigManager _configManager;
private IConfiguration _config;
private IConfigManager? _configManager;
private IConfiguration? _config;
[TestMethod]
public void ConfigManager_HasProperties()
{
// Assert
Assert.AreEqual(3, _configManager.PropertyCount());
Assert.IsTrue(_configManager.HasProperty("Configuration"));
Assert.IsTrue(_configManager.HasProperty("Instances"));
Assert.IsTrue(_configManager.HasProperty("App"));
Assert.AreEqual(3, _configManager?.PropertyCount());
Assert.IsTrue(_configManager?.HasProperty("Configuration"));
Assert.IsTrue(_configManager?.HasProperty("Instances"));
Assert.IsTrue(_configManager?.HasProperty("App"));

Assert.IsTrue(_configManager.HasMethod("GetConfigValue"));
Assert.IsTrue(_configManager?.HasMethod("GetConfigValue"));
}
[TestMethod]
public void GetConfigValue_Success()
Expand All @@ -44,7 +44,7 @@ public void GetConfigValue_Success()
var expected = "Pinboard";

// Act
string actual = _configManager.GetConfigValue("App:Bookmarking:Service");
string? actual = _configManager?.GetConfigValue("App:Bookmarking:Service");

// Assert
Assert.AreEqual(expected, actual);
Expand Down
16 changes: 7 additions & 9 deletions BookmarkSync.Core/Configuration/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace BookmarkSync.Core.Configuration;

public interface IConfigManager
{
App App { get; set; }
App? App { get; set; }
IConfiguration Configuration { get; set; }
Instance[] Instances { get; set; }
List<Instance>? Instances { get; set; }
string GetConfigValue(string key);
void SaveToFile();
}
Expand All @@ -22,19 +22,17 @@ public ConfigManager(
IConfiguration configuration)
{
Configuration = configuration;
var instance = Configuration.GetSection("Instances").Get<List<Instance>>();
var app = Configuration.GetSection("App").Get<App>();
var instances = Configuration.GetSection("Instances").Get<Instance[]>();
App = app;
App = Configuration.GetSection("App").Get<App>();
Instances = Configuration.GetSection("Instances").Get<List<Instance>>();

if (!App.IsValid())
if (App is not null && !App.IsValid())
{
throw new InvalidConfigurationException();
}
}
public IConfiguration Configuration { get; set; }
public Instance[] Instances { get; set; }
public App App { get; set; }
public List<Instance>? Instances { get; set; }
public App? App { get; set; }
public string GetConfigValue(string key)
{
string? value = Configuration[key];
Expand Down
4 changes: 2 additions & 2 deletions BookmarkSync.Core/Entities/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace BookmarkSync.Core.Entities;

public class Account
{
public string Name { get; set; }
public string? Name { get; set; }
/// <inheritdoc />
public override string ToString() => Name;
public override string ToString() => Name ?? GetType().Name;
}
10 changes: 5 additions & 5 deletions BookmarkSync.Core/Entities/Bookmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ namespace BookmarkSync.Core.Entities;

public class Bookmark
{
public Account Account { get; set; }
public string Content { get; set; }
public string Id { get; set; }
public string Uri { get; set; }
public string Visibility { get; set; }
public Account? Account { get; set; }
public string? Content { get; set; }
public string? Id { get; set; }
public string? Uri { get; set; }
public string? Visibility { get; set; }
}
2 changes: 1 addition & 1 deletion BookmarkSync.Core/Entities/Config/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace BookmarkSync.Core.Entities.Config;

public class App : ConfigurationBase
{
[ConfigRequired] public Bookmarking Bookmarking { get; set; }
[ConfigRequired] public Bookmarking? Bookmarking { get; set; }
public DateTime LastSynced { get; set; }
}
4 changes: 2 additions & 2 deletions BookmarkSync.Core/Entities/Config/Bookmarking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace BookmarkSync.Core.Entities.Config;

public class Bookmarking : ConfigurationBase
{
public string ApiToken { get; set; }
public string Service { get; set; }
public string? ApiToken { get; set; }
public string? Service { get; set; }
}
6 changes: 3 additions & 3 deletions BookmarkSync.Core/Entities/Config/Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ namespace BookmarkSync.Core.Entities.Config;

public class Instance : ConfigurationBase
{
public string AccessToken { get; set; }
public string? AccessToken { get; set; }
public bool DeleteBookmarks { get; set; }
public string Uri { get; set; }
public string? Uri { get; set; }
/// <inheritdoc />
public override string ToString() => Uri;
public override string ToString() => Uri ?? GetType().Name;
}

0 comments on commit 708bd4c

Please sign in to comment.