Skip to content

Commit

Permalink
code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Jan 21, 2024
1 parent b7b9998 commit 8f05918
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 58 deletions.
9 changes: 5 additions & 4 deletions starsky/starsky.feature.geolookup/Services/GeoCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand All @@ -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
Expand Down
36 changes: 17 additions & 19 deletions starsky/starsky.foundation.platform/Models/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -284,7 +283,7 @@ public enum DatabaseTypeList
}

// DatabaseType > above this one
private string _databaseConnection;
private string _databaseConnection = string.Empty;

/// <summary>
/// Connection string for the database
Expand All @@ -302,7 +301,7 @@ public string DatabaseConnection
/// <summary>
/// Internal Structure save location
/// </summary>
private string _structure;
private string? _structure;

/// <summary>
/// Auto storage structure
Expand Down Expand Up @@ -372,7 +371,7 @@ internal static TimeZoneInfo ConvertTimeZoneId(string value)
}

[JsonIgnore]
public TimeZoneInfo CameraTimeZoneInfo { get; set; }
public TimeZoneInfo? CameraTimeZoneInfo { get; set; }

/// <summary>
/// To Check if the structure is any good
Expand All @@ -396,14 +395,14 @@ public static void StructureCheck(string structure)
/// <summary>
/// Private: Location of storage of Thumbnails
/// </summary>
private string _thumbnailTempFolder;
private string? _thumbnailTempFolder;

/// <summary>
/// Location of storage of Thumbnails
/// </summary>
public string ThumbnailTempFolder
{
get => _thumbnailTempFolder;
get => _thumbnailTempFolder ??= string.Empty;
set
{
var thumbnailTempFolder = ReplaceEnvironmentVariable(value);
Expand All @@ -414,7 +413,7 @@ public string ThumbnailTempFolder
/// <summary>
/// Private: Location of temp folder
/// </summary>
private string _tempFolder;
private string? _tempFolder;

/// <summary>
/// Location of temp folder
Expand All @@ -432,7 +431,7 @@ public string TempFolder
/// <summary>
/// Private: Location of dependencies folder
/// </summary>
private string _dependenciesFolder;
private string? _dependenciesFolder;

/// <summary>
/// Location of dependencies folder
Expand All @@ -450,7 +449,7 @@ public string DependenciesFolder
/// <summary>
/// Private: Location of AppSettings Path
/// </summary>
private string _appSettingsPathPrivate;
private string? _appSettingsPathPrivate;

/// <summary>
/// To store the settings by user in the AppData folder
Expand All @@ -471,7 +470,7 @@ public string AppSettingsPath
/// <summary>
/// Private Location of ExifTool.exe
/// </summary>
private string ExifToolPathPrivate { get; set; }
private string? ExifToolPathPrivate { get; set; }

/// <summary>
/// Set in ctor on startup
Expand Down Expand Up @@ -575,7 +574,7 @@ public bool IsReadOnly(string f)
/// <summary>
/// Internal location for webFtp credentials
/// </summary>
private string _webFtp;
private string? _webFtp;

/// <summary>
/// Connection string for FTP
Expand Down Expand Up @@ -613,7 +612,7 @@ public string WebFtp
/// Publishing profiles used within the publishing module (Order by Key)
/// </summary>
[PackageTelemetry]
public Dictionary<string, List<AppSettingsPublishProfiles>> PublishProfiles {
public Dictionary<string, List<AppSettingsPublishProfiles>>? PublishProfiles {
get => PublishProfilesPrivate;
set
{
Expand Down Expand Up @@ -661,7 +660,7 @@ public Dictionary<string, List<AppSettingsPublishProfiles>> PublishProfiles {
/// <remarks>
/// { "demo@qdraw.nl": "Administrator" }
/// </remarks>
public Dictionary<string, string> AccountRolesByEmailRegisterOverwrite {
public Dictionary<string, string>? AccountRolesByEmailRegisterOverwrite {
get => AccountRolesByEmailRegisterOverwritePrivate;
init
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -891,7 +889,7 @@ private string AssemblyDirectoryReplacer(string value)
/// </summary>
public bool? ExiftoolSkipDownloadOnStartup { get; set; } = false;

public OpenTelemetrySettings OpenTelemetry { get; set; } =
public OpenTelemetrySettings? OpenTelemetry { get; set; } =
new OpenTelemetrySettings();

/// <returns>AppSettings duplicated</returns>
Expand Down
1 change: 1 addition & 0 deletions starsky/starsky.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=ILCE/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Magland/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=metaupdate/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=nosniff/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=OZHCK/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=packagetelemetry/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=QBRE/@EntryIndexedValue">True</s:Boolean>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace starskytest.FakeMocks
{
public class FakeReadMetaSubPathStorage : IReadMetaSubPathStorage
{
private readonly IReadMeta _readMeta;
private readonly FakeReadMeta _readMeta;

public FakeReadMetaSubPathStorage()
{
Expand Down
2 changes: 1 addition & 1 deletion starsky/starskytest/root/ProgramTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand All @@ -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"));
}
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<object> values)
/// <summary>
/// @see: https://github.com/drewnoakes/metadata-extractor-dotnet/blob/master/MetadataExtractor.Tests/DirectoryExtensionsTest.cs
/// </summary>
/// <param name="values">values to put in</param>
/// <returns>a mock dir</returns>
private static MockDirectory BuildDirectory(IEnumerable<object> values)
{
var directory = new MockDirectory(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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());
}
}
}
Loading

0 comments on commit 8f05918

Please sign in to comment.