diff --git a/starsky/starsky.feature.geolookup/Services/GeoCli.cs b/starsky/starsky.feature.geolookup/Services/GeoCli.cs index 2d17454d8e..274ef94924 100644 --- a/starsky/starsky.feature.geolookup/Services/GeoCli.cs +++ b/starsky/starsky.feature.geolookup/Services/GeoCli.cs @@ -8,7 +8,6 @@ using starsky.foundation.platform.Helpers; using starsky.foundation.platform.Interfaces; using starsky.foundation.platform.Models; -using starsky.foundation.readmeta.Interfaces; using starsky.foundation.readmeta.Services; using starsky.foundation.storage.Interfaces; using starsky.foundation.storage.Models; @@ -87,9 +86,10 @@ public async Task CommandLineAsync(string[] args) // -s = if subPath || -p is path if ( ArgsHelper.IsSubPathOrPath(args) ) { - inputPath = _appSettings.DatabasePathToFilePath( + var path = _appSettings.DatabasePathToFilePath( ArgsHelper.GetSubPathFormArgs(args) ); + inputPath = !string.IsNullOrEmpty(path) ? path : string.Empty; } else { @@ -103,9 +103,10 @@ public async Task CommandLineAsync(string[] args) if (getSubPathRelative != null) { var dateTime = DateTime.Now.AddDays(( double ) getSubPathRelative); - inputPath = _appSettings.DatabasePathToFilePath( + var path = _appSettings.DatabasePathToFilePath( new StructureService(_iStorage, _appSettings.Structure) - .ParseSubfolders(dateTime),false); + .ParseSubfolders(dateTime), false); + inputPath = !string.IsNullOrEmpty(path) ? path : string.Empty; } // used in this session to find the files back diff --git a/starsky/starsky.foundation.platform/Models/AppSettings.cs b/starsky/starsky.foundation.platform/Models/AppSettings.cs index f43650f0a7..b4197dc60d 100644 --- a/starsky/starsky.foundation.platform/Models/AppSettings.cs +++ b/starsky/starsky.foundation.platform/Models/AppSettings.cs @@ -2,7 +2,6 @@ using System.Text.Json.Serialization; using System; using System.Collections.Generic; -using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; @@ -209,7 +208,7 @@ public bool IsVerbose() // Used in the webHtmlCli to store the log item name // used for the url - private string _name; + private string? _name; [PackageTelemetry] public string Name @@ -284,7 +283,7 @@ public enum DatabaseTypeList } // DatabaseType > above this one - private string _databaseConnection; + private string _databaseConnection = string.Empty; /// /// Connection string for the database @@ -302,7 +301,7 @@ public string DatabaseConnection /// /// Internal Structure save location /// - private string _structure; + private string? _structure; /// /// Auto storage structure @@ -372,7 +371,7 @@ internal static TimeZoneInfo ConvertTimeZoneId(string value) } [JsonIgnore] - public TimeZoneInfo CameraTimeZoneInfo { get; set; } + public TimeZoneInfo? CameraTimeZoneInfo { get; set; } /// /// To Check if the structure is any good @@ -396,14 +395,14 @@ public static void StructureCheck(string structure) /// /// Private: Location of storage of Thumbnails /// - private string _thumbnailTempFolder; + private string? _thumbnailTempFolder; /// /// Location of storage of Thumbnails /// public string ThumbnailTempFolder { - get => _thumbnailTempFolder; + get => _thumbnailTempFolder ??= string.Empty; set { var thumbnailTempFolder = ReplaceEnvironmentVariable(value); @@ -414,7 +413,7 @@ public string ThumbnailTempFolder /// /// Private: Location of temp folder /// - private string _tempFolder; + private string? _tempFolder; /// /// Location of temp folder @@ -432,7 +431,7 @@ public string TempFolder /// /// Private: Location of dependencies folder /// - private string _dependenciesFolder; + private string? _dependenciesFolder; /// /// Location of dependencies folder @@ -450,7 +449,7 @@ public string DependenciesFolder /// /// Private: Location of AppSettings Path /// - private string _appSettingsPathPrivate; + private string? _appSettingsPathPrivate; /// /// To store the settings by user in the AppData folder @@ -471,7 +470,7 @@ public string AppSettingsPath /// /// Private Location of ExifTool.exe /// - private string ExifToolPathPrivate { get; set; } + private string? ExifToolPathPrivate { get; set; } /// /// Set in ctor on startup @@ -575,7 +574,7 @@ public bool IsReadOnly(string f) /// /// Internal location for webFtp credentials /// - private string _webFtp; + private string? _webFtp; /// /// Connection string for FTP @@ -613,7 +612,7 @@ public string WebFtp /// Publishing profiles used within the publishing module (Order by Key) /// [PackageTelemetry] - public Dictionary> PublishProfiles { + public Dictionary>? PublishProfiles { get => PublishProfilesPrivate; set { @@ -661,7 +660,7 @@ public Dictionary> PublishProfiles { /// /// { "demo@qdraw.nl": "Administrator" } /// - public Dictionary AccountRolesByEmailRegisterOverwrite { + public Dictionary? AccountRolesByEmailRegisterOverwrite { get => AccountRolesByEmailRegisterOverwritePrivate; init { @@ -696,9 +695,7 @@ public string ApplicationInsightsConnectionString { var connectionString = Environment.GetEnvironmentVariable( "APPLICATIONINSIGHTS_CONNECTION_STRING"); - connectionString = connectionString ??= - string.Empty; - return connectionString; + return !string.IsNullOrEmpty(connectionString) ? connectionString : string.Empty ; } return ApplicationInsightsConnectionStringPrivate; } @@ -857,8 +854,9 @@ public bool? EnablePackageTelemetry // ------------------- Modifiers ------------------- // ------------------------------------------------- - private string AssemblyDirectoryReplacer(string value) + private string AssemblyDirectoryReplacer(string? value) { + value ??= string.Empty; return value.Replace("{AssemblyDirectory}", BaseDirectoryProject); } @@ -891,7 +889,7 @@ private string AssemblyDirectoryReplacer(string value) /// public bool? ExiftoolSkipDownloadOnStartup { get; set; } = false; - public OpenTelemetrySettings OpenTelemetry { get; set; } = + public OpenTelemetrySettings? OpenTelemetry { get; set; } = new OpenTelemetrySettings(); /// AppSettings duplicated diff --git a/starsky/starsky.sln.DotSettings b/starsky/starsky.sln.DotSettings index 391011bceb..e416a4928a 100644 --- a/starsky/starsky.sln.DotSettings +++ b/starsky/starsky.sln.DotSettings @@ -11,6 +11,7 @@ True True True + True True True True diff --git a/starsky/starskytest/FakeMocks/FakeReadMetaSubPathStorage.cs b/starsky/starskytest/FakeMocks/FakeReadMetaSubPathStorage.cs index 9bf49638ec..32369db11c 100644 --- a/starsky/starskytest/FakeMocks/FakeReadMetaSubPathStorage.cs +++ b/starsky/starskytest/FakeMocks/FakeReadMetaSubPathStorage.cs @@ -8,7 +8,7 @@ namespace starskytest.FakeMocks { public class FakeReadMetaSubPathStorage : IReadMetaSubPathStorage { - private readonly IReadMeta _readMeta; + private readonly FakeReadMeta _readMeta; public FakeReadMetaSubPathStorage() { diff --git a/starsky/starskytest/root/ProgramTest.cs b/starsky/starskytest/root/ProgramTest.cs index 3ee9bada68..cabdc0b1cb 100644 --- a/starsky/starskytest/root/ProgramTest.cs +++ b/starsky/starskytest/root/ProgramTest.cs @@ -61,7 +61,7 @@ public async Task Program_Main_NoAddress_UnixOnly() Environment.SetEnvironmentVariable("app__ExiftoolSkipDownloadOnStartup","true"); Environment.SetEnvironmentVariable("app__EnablePackageTelemetry","false"); - await Program.Main(new []{"--do-not-start"}); + await Program.Main(["--do-not-start"]); using HttpClient client = new(); await client.GetAsync("http://localhost:7514").TimeoutAfter(3000); diff --git a/starsky/starskytest/starsky.feature.webftppublish/Helpers/WebFtpCliTest.cs b/starsky/starskytest/starsky.feature.webftppublish/Helpers/WebFtpCliTest.cs index 75606904d5..9339c94672 100644 --- a/starsky/starskytest/starsky.feature.webftppublish/Helpers/WebFtpCliTest.cs +++ b/starsky/starskytest/starsky.feature.webftppublish/Helpers/WebFtpCliTest.cs @@ -53,7 +53,7 @@ public async Task Run_Default() { var console = new FakeConsoleWrapper(); await new WebFtpCli(_appSettings, new FakeSelectorStorage(), console, _webRequestFactory) - .RunAsync(new []{""}); + .RunAsync([""]); Assert.IsTrue(console.WrittenLines.FirstOrDefault()?.Contains("Please use the -p to add a path first")); } @@ -76,7 +76,7 @@ public async Task Run_NoFtpSettings() // no ftp settings await new WebFtpCli(new AppSettings(),fakeSelectorStorage , console, _webRequestFactory) - .RunAsync(new []{"-p", "/test"}); + .RunAsync(["-p", "/test"]); Assert.IsTrue(console.WrittenLines.LastOrDefault()?.Contains("WebFtp settings")); } @@ -104,7 +104,7 @@ public async Task Run_SettingsFile_successful() // instead of new byte[0] await new WebFtpCli(_appSettings, fakeSelectorStorage , console, _webRequestFactory) - .RunAsync(new []{"-p", "/test"}); + .RunAsync(["-p", "/test"]); var isSuccess = console.WrittenLines?.LastOrDefault()? .Contains("Ftp copy successful done"); diff --git a/starsky/starskytest/starsky.foundation.platform/Middleware/ContentSecurityPolicyMiddlewareTest.cs b/starsky/starskytest/starsky.foundation.platform/Middleware/ContentSecurityPolicyMiddlewareTest.cs index 9510010239..b9b94afac9 100644 --- a/starsky/starskytest/starsky.foundation.platform/Middleware/ContentSecurityPolicyMiddlewareTest.cs +++ b/starsky/starskytest/starsky.foundation.platform/Middleware/ContentSecurityPolicyMiddlewareTest.cs @@ -39,8 +39,8 @@ public async Task ContentSecurityPolicyMiddlewareTest_invoke_testContent() { Scheme = "http" } }; - var authMiddleware = new ContentSecurityPolicyMiddleware(next: (_) => Task.FromResult(0)); - + var authMiddleware = new ContentSecurityPolicyMiddleware(next: (_) => Task.CompletedTask); + // Act await authMiddleware.Invoke(httpContext); //test @@ -53,10 +53,12 @@ public async Task ContentSecurityPolicyMiddlewareTest_invoke_testContent() public async Task invoke_httpsTest_websockets() { // Arrange - var httpContext = new DefaultHttpContext(); - httpContext.Request.Scheme = "https"; - - var authMiddleware = new ContentSecurityPolicyMiddleware(next: (_) => Task.FromResult(0)); + var httpContext = new DefaultHttpContext { Request = + { + Scheme = "https" + } }; + + var authMiddleware = new ContentSecurityPolicyMiddleware(next: (_) => Task.CompletedTask); // Act await authMiddleware.Invoke(httpContext); @@ -77,7 +79,7 @@ public async Task invoke_httpsTest_websockets_localhostWithPort9000() Host = new HostString("localhost", 9000) } }; - var authMiddleware = new ContentSecurityPolicyMiddleware(next: (_) => Task.FromResult(0)); + var authMiddleware = new ContentSecurityPolicyMiddleware(next: (_) => Task.CompletedTask); // Act await authMiddleware.Invoke(httpContext); @@ -99,7 +101,7 @@ public async Task invoke_httpsTest_websockets_localhostWithNoPort() Host = new HostString("localhost") } }; - var authMiddleware = new ContentSecurityPolicyMiddleware(next: (_) => Task.FromResult(0)); + var authMiddleware = new ContentSecurityPolicyMiddleware(next: (_) => Task.CompletedTask); // Act await authMiddleware.Invoke(httpContext); @@ -119,7 +121,7 @@ public async Task ContentSecurityPolicyMiddlewareTest_invoke_otherTypes() { Scheme = "http" } }; - var authMiddleware = new ContentSecurityPolicyMiddleware((_) => Task.FromResult(0)); + var authMiddleware = new ContentSecurityPolicyMiddleware(next: (_) => Task.CompletedTask); // Act await authMiddleware.Invoke(httpContext); @@ -132,11 +134,11 @@ public async Task ContentSecurityPolicyMiddlewareTest_invoke_otherTypes() Assert.AreEqual( "DENY",frameOptions); // X-Xss-Protection - var xssProtection = httpContext.Response.Headers["X-Xss-Protection"].ToString(); + var xssProtection = httpContext.Response.Headers.XXSSProtection.ToString(); Assert.AreEqual( "1; mode=block",xssProtection); // X-Content-Type-Options - var contentTypeOptions = httpContext.Response.Headers["X-Content-Type-Options"].ToString(); + var contentTypeOptions = httpContext.Response.Headers.XContentTypeOptions.ToString(); Assert.AreEqual( "nosniff",contentTypeOptions); } @@ -151,7 +153,7 @@ public async Task Scheme = "http" } }; httpContext.Request.Headers.Append("User-Agent","Chrome"); - var authMiddleware = new ContentSecurityPolicyMiddleware((_) => Task.FromResult(0)); + var authMiddleware = new ContentSecurityPolicyMiddleware(next: (_) => Task.CompletedTask); // Act await authMiddleware.Invoke(httpContext); diff --git a/starsky/starskytest/starsky.foundation.readmeta/Services/ReadMeta_ExifReadTest.cs b/starsky/starskytest/starsky.foundation.readmeta/Services/ReadMeta_ExifReadTest.cs index fc57dfdc19..dd5b67eef0 100644 --- a/starsky/starskytest/starsky.foundation.readmeta/Services/ReadMeta_ExifReadTest.cs +++ b/starsky/starskytest/starsky.foundation.readmeta/Services/ReadMeta_ExifReadTest.cs @@ -674,8 +674,12 @@ public void ExifRead_DataParsingCorruptStreamNull() Assert.AreEqual(FileIndexItem.ExifStatus.OperationNotSupported, item.Status); } - // https://github.com/drewnoakes/metadata-extractor-dotnet/blob/master/MetadataExtractor.Tests/DirectoryExtensionsTest.cs - private static Directory BuildDirectory(IEnumerable values) + /// + /// @see: https://github.com/drewnoakes/metadata-extractor-dotnet/blob/master/MetadataExtractor.Tests/DirectoryExtensionsTest.cs + /// + /// values to put in + /// a mock dir + private static MockDirectory BuildDirectory(IEnumerable values) { var directory = new MockDirectory(null); diff --git a/starsky/starskytest/starsky.foundation.realtime/Middleware/DisabledWebSocketsMiddlewareTest.cs b/starsky/starskytest/starsky.foundation.realtime/Middleware/DisabledWebSocketsMiddlewareTest.cs index 3f911d5c81..6e1930fabf 100644 --- a/starsky/starskytest/starsky.foundation.realtime/Middleware/DisabledWebSocketsMiddlewareTest.cs +++ b/starsky/starskytest/starsky.foundation.realtime/Middleware/DisabledWebSocketsMiddlewareTest.cs @@ -15,7 +15,7 @@ public sealed class DisabledWebSocketsMiddlewareTest public async Task DisabledWebSocketsMiddleware_Invoke() { var httpContext = new DefaultHttpContext(); - var disabledWebSocketsMiddleware = new DisabledWebSocketsMiddleware(next: (_) => Task.FromResult(0)); + var disabledWebSocketsMiddleware = new DisabledWebSocketsMiddleware(next: (_) => Task.CompletedTask); await disabledWebSocketsMiddleware.Invoke(httpContext); Assert.AreEqual(400,httpContext.Response.StatusCode); } @@ -25,12 +25,12 @@ public async Task WebSocketConnection_MessageTooBig() { var httpContext = new FakeWebSocketHttpContext(false); - var disabledWebSocketsMiddleware = new DisabledWebSocketsMiddleware(next: (_) => Task.FromResult(0)); + var disabledWebSocketsMiddleware = new DisabledWebSocketsMiddleware(next: (_) => Task.CompletedTask); await disabledWebSocketsMiddleware.Invoke(httpContext); var socketManager = httpContext.WebSockets as FakeWebSocketManager; Assert.AreEqual(WebSocketCloseStatus.MessageTooBig, - (socketManager.FakeWebSocket as FakeWebSocket).FakeCloseOutputAsync.LastOrDefault()); + (socketManager?.FakeWebSocket as FakeWebSocket)?.FakeCloseOutputAsync.LastOrDefault()); } } } diff --git a/starsky/starskytest/starsky.foundation.thumbnailgeneration/Helpers/ThumbnailCliTest.cs b/starsky/starskytest/starsky.foundation.thumbnailgeneration/Helpers/ThumbnailCliTest.cs index cf561279e4..a4a075dc9b 100644 --- a/starsky/starskytest/starsky.foundation.thumbnailgeneration/Helpers/ThumbnailCliTest.cs +++ b/starsky/starskytest/starsky.foundation.thumbnailgeneration/Helpers/ThumbnailCliTest.cs @@ -38,7 +38,7 @@ public async Task Thumbnail_Enable_T_Param_AssumeHome() fakeIThumbnailService, new FakeIThumbnailCleaner(), new FakeSelectorStorage(storage)); - await thumbnailService.Thumbnail(new []{"-t", "true"}); + await thumbnailService.Thumbnail(["-t", "true"]); Assert.AreEqual("/", fakeIThumbnailService.Inputs[0].Item1); } @@ -52,7 +52,7 @@ public async Task Thumbnail_Help() new FakeIThumbnailService(), new FakeIThumbnailCleaner(), new FakeSelectorStorage(storage)); - await thumbnailService.Thumbnail(new []{"-h"}); + await thumbnailService.Thumbnail(["-h"]); Assert.IsTrue(fakeConsole.WrittenLines[0].Contains("Help")); } @@ -67,7 +67,7 @@ public async Task Thumbnail_Disable_T_Param() fakeThumbnail, new FakeIThumbnailCleaner(), new FakeSelectorStorage(storage)); - await thumbnailService.Thumbnail(new []{"-t", "false"}); + await thumbnailService.Thumbnail(["-t", "false"]); Assert.AreEqual(0, fakeThumbnail.Inputs.Count); } @@ -83,7 +83,8 @@ public async Task Thumbnail_MinusP_FullPath() fakeIThumbnailService, new FakeIThumbnailCleaner(), new FakeSelectorStorage(storage)); - await thumbnailService.Thumbnail(new []{"-v", "true", "-t","true", "-p", Path.Combine(appSettings.StorageFolder, "test")}); + await thumbnailService.Thumbnail(["-v", "true", "-t","true", "-p", Path.Combine(appSettings.StorageFolder, "test") + ]); Assert.AreEqual("/test", fakeIThumbnailService.Inputs[0].Item1); } @@ -99,7 +100,7 @@ public async Task Thumbnail_MinusS_SubPath() fakeIThumbnailService, new FakeIThumbnailCleaner(), new FakeSelectorStorage(storage)); - await thumbnailService.Thumbnail(new []{"-t","true", "-s", "/test"}); + await thumbnailService.Thumbnail(["-t","true", "-s", "/test"]); Assert.AreEqual("/test", fakeIThumbnailService.Inputs[0].Item1); } @@ -115,7 +116,7 @@ public async Task Thumbnail_MinusS_SubPath_Direct() fakeIThumbnailService, new FakeIThumbnailCleaner(), new FakeSelectorStorage(storage)); - await thumbnailService.Thumbnail(new []{"-t","true", "-s", "/test.jpg"}); + await thumbnailService.Thumbnail(["-t","true", "-s", "/test.jpg"]); Assert.AreEqual("/test.jpg", fakeIThumbnailService.Inputs[0].Item1); @@ -134,7 +135,7 @@ public async Task Thumbnail_MinusG_Relative() fakeIThumbnailService, new FakeIThumbnailCleaner(), new FakeSelectorStorage(storage)); - await thumbnailService.Thumbnail(new []{"-t","true", "-g", "0"}); + await thumbnailService.Thumbnail(["-t","true", "-g", "0"]); var subPathRelative = new StructureService(new FakeIStorage(),appSettings.Structure) .ParseSubfolders(0); @@ -152,7 +153,7 @@ public async Task Thumbnail_MinusX_CleanAllUnusedFiles() new FakeIThumbnailService(new FakeSelectorStorage(storage)), fakeIThumbnailCleaner, new FakeSelectorStorage(storage)); - await thumbnailService.Thumbnail(new []{"--clean","true"}); + await thumbnailService.Thumbnail(["--clean","true"]); Assert.IsTrue(fakeIThumbnailCleaner.Inputs[0]); } diff --git a/starsky/starskytest/starsky.foundation.writemeta/Helpers/ExifToolDownloadTest.cs b/starsky/starskytest/starsky.foundation.writemeta/Helpers/ExifToolDownloadTest.cs index 68ad5b9a7f..68d49a9863 100644 --- a/starsky/starskytest/starsky.foundation.writemeta/Helpers/ExifToolDownloadTest.cs +++ b/starsky/starskytest/starsky.foundation.writemeta/Helpers/ExifToolDownloadTest.cs @@ -23,7 +23,7 @@ public sealed class ExifToolDownloadTest { private readonly IServiceScopeFactory _serviceScopeFactory; private readonly AppSettings _appSettings; - private readonly IStorage _hostFileSystem; + private readonly StorageHostFullPathFilesystem _hostFileSystem; /// /// shasum -a 1 file.zip @@ -89,8 +89,8 @@ public async Task DownloadCheckSums_BaseChecksumDoesExist() // Happy flow var result = await new ExifToolDownload(httpClientHelper,_appSettings, new FakeIWebLogger() ) .DownloadCheckSums(); - Assert.AreEqual(ExampleCheckSum, result.Value.Value); - Assert.AreEqual(true, result.Value.Key); + Assert.AreEqual(ExampleCheckSum, result?.Value); + Assert.AreEqual(true, result?.Key); } [TestMethod] @@ -107,8 +107,8 @@ public async Task DownloadCheckSums_BaseChecksumDoesNotExist() var result = await new ExifToolDownload(httpClientHelper,_appSettings, new FakeIWebLogger() ) .DownloadCheckSums(); - Assert.AreEqual(ExampleCheckSum, result.Value.Value); - Assert.AreEqual(false, result.Value.Key); + Assert.AreEqual(ExampleCheckSum, result?.Value); + Assert.AreEqual(false, result?.Key); } [TestMethod]