Skip to content

Commit

Permalink
code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Dec 9, 2023
1 parent c3d8f54 commit 20fb12f
Show file tree
Hide file tree
Showing 27 changed files with 52 additions and 49 deletions.
3 changes: 3 additions & 0 deletions starsky/build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
using Nuke.Common.CI;
using Nuke.Common.ProjectModel;

// ReSharper disable once CheckNamespace
namespace build;

[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage",
"S3887:Use an immutable collection or reduce the " +
"accessibility of the non-private readonly field",
Expand Down
3 changes: 3 additions & 0 deletions starsky/build/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using System.Diagnostics.CodeAnalysis;
using Nuke.Common.Tooling;

// ReSharper disable once CheckNamespace
namespace build;

[TypeConverter(typeof(TypeConverter<Configuration>))]
[SuppressMessage("Usage", "CA2211:Non-constant fields should not be visible")]
[SuppressMessage("Usage", "S1104:Make this field 'private' and encapsulate it in a 'public' property")]
Expand Down
2 changes: 1 addition & 1 deletion starsky/build/helpers/ClientHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.IO;
using static SimpleExec.Command;
using static Build;
using static build.Build;

namespace helpers
{
Expand Down
3 changes: 2 additions & 1 deletion starsky/build/helpers/DotnetGenericHelper.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System.IO;
using build;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tools.DotNet;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Build;
using static build.Build;

namespace helpers
{
Expand Down
1 change: 1 addition & 0 deletions starsky/build/helpers/DotnetRuntimeSpecificHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using build;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
Expand Down
1 change: 1 addition & 0 deletions starsky/build/helpers/DotnetTestHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using build;
using Nuke.Common.IO;
using Nuke.Common.Tools.DotNet;
using static Nuke.Common.IO.FileSystemTasks;
Expand Down
2 changes: 1 addition & 1 deletion starsky/build/helpers/ProjectCheckNetCoreCommandHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.IO;
using static SimpleExec.Command;
using static Build;
using static build.Build;

namespace helpers
{
Expand Down
1 change: 1 addition & 0 deletions starsky/build/helpers/SonarQube.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using System.Text;
using build;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
Expand Down
1 change: 1 addition & 0 deletions starsky/build/helpers/ZipperHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.IO.Compression;
using System.Linq;
using build;

namespace helpers
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const FormControl: React.FunctionComponent<IFormControlProps> = ({
<div className="warning-box">{MessageFieldMaxLength}</div>
) : null}

{/* NOSONAR(S6847) */}
<div
data-test={props["data-test"] ? props["data-test"] : "form-control"}
onBlur={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const ListImage: React.FunctionComponent<IListImageProps> = memo((props) => {
data-test="list-image-img-parent-div"
>
{intersected ? (
<img
<img /* NOSONAR(S6847) */
src={src}
alt={alt}
data-test="list-image-img"
Expand Down
4 changes: 1 addition & 3 deletions starsky/starskytest/Controllers/AccountControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ public async Task AccountController_NoLogin_Login_And_newAccount_Test()
// in a normal session the State is cleared after 1 request
controller.ModelState.Clear();


// Make new account;
var newAccount = new RegisterViewModel
{
Password = "test",
Expand All @@ -170,7 +168,7 @@ public async Task AccountController_NoLogin_Login_And_newAccount_Test()
// Test login
Assert.AreEqual(true,httpContext.User.Identity?.IsAuthenticated);

// The logout is mocked so this will not actual log it out;
// The logout is mocked so this will not actual log it out
// controller.Logout() not crashing is good enough;
controller.Logout();

Expand Down
3 changes: 2 additions & 1 deletion starsky/starskytest/FakeCreateAn/CreateAnExifToolTar.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using starsky.foundation.platform.Helpers;
using starskycore.Helpers;
Expand Down Expand Up @@ -68,7 +69,7 @@ public static class CreateAnExifToolTar
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" +
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";

public static readonly byte[] Bytes = Base64Helper.TryParse(ImageExifToolTarUnix);
public static readonly ImmutableArray<byte> Bytes = Base64Helper.TryParse(ImageExifToolTarUnix).ToImmutableArray();

}
}
8 changes: 4 additions & 4 deletions starsky/starskytest/FakeCreateAn/CreateAnExifToolTarGz.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using starsky.foundation.platform.Helpers;

Expand All @@ -6,17 +7,16 @@ namespace starskytest.FakeCreateAn
public static class CreateAnExifToolTarGz
{
[SuppressMessage("ReSharper", "StringLiteralTypo")]
private static readonly string ImageExifToolTarGzUnix =
private const string ImageExifToolTarGzUnix =
"H4sIACE9w14AA+3UPU7DMBQHcIOEEJ2YGJiMOje1ncZRJRYGkDogEM3ABDKNQyvSpCJpYeIsHKF34DLMiAPg0Fa" +
"lKCoZwvf/Jz05thz7RS92q68udW3/thd4cRzWOLeazTopF2PMdRz62spJa8zaSYfbUjJpS5sJyrgUzCHUKTmPXM" +
"MkVdcmFb8XR9ZIRSMd+jpn3k1X63DJOosfRT8p29K18upvnWszkJqBUvbIq79ozOsv5Jv6S0mZYIJLQlkpu3+ga" +
"P3NtCBYss4vrT9Z21onq4Qcqg49atNTOpWNkQ0TwsSdiaw/LrbknuedTB+zN+5NbL6bsjIf3+7EfUsNBqG2QpWk" +
"w0T7vkp19bidTXzafTjL2sfn8Et+h/8m9/yXevoL3P+2s3j+ueu6jR92/v/o/V/dqV/0onrSrehON6YH6krT2d9" +
"Q+e7kAAAAAAAAAAAAAAAAAAAAoJAXspDxGwAoAAA=";

public static readonly byte[] Bytes = Base64Helper.TryParse(ImageExifToolTarGzUnix);

public static readonly string Sha1 = "b386a6849ed5f911085cc56f37d20f127162b21c";
public static readonly ImmutableArray<byte> Bytes = Base64Helper.TryParse(ImageExifToolTarGzUnix).ToImmutableArray();

public const string Sha1 = "b386a6849ed5f911085cc56f37d20f127162b21c";
}
}
7 changes: 3 additions & 4 deletions starsky/starskytest/FakeCreateAn/CreateAnImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ namespace starskytest.FakeCreateAn
public class CreateAnImage
{
private const string FileNamePrivate = "0000000000aaaaa__exifreadingtest00.jpg";

// There is an unit test for using directory thumbnails that uses the first image;
// starskytest.SyncServiceTest.SyncServiceFirstItemDirectoryTest


/// <summary>
/// The filename *.jpg
/// There is an unit test for using directory thumbnails that uses the first image;
/// starskytest.SyncServiceTest.SyncServiceFirstItemDirectoryTest
/// </summary>
[SuppressMessage("Performance", "CA1822:Mark members as static")]
[SuppressMessage("ReSharper", "MemberCanBeMadeStatic.Global")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public CreateAnImageCorrupt()

private static byte[] StreamToBytes(string path)
{
using var input = new StorageHostFullPathFilesystem(new FakeIWebLogger()).ReadStream(path);
var input = new StorageHostFullPathFilesystem(new FakeIWebLogger()).ReadStream(path);
using var ms = new MemoryStream();
input.CopyTo(ms);
input.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public CreateAnImageWithThumbnail()

private static byte[] StreamToBytes(string path)
{
using var input = new StorageHostFullPathFilesystem(new FakeIWebLogger()).ReadStream(path);
var input = new StorageHostFullPathFilesystem(new FakeIWebLogger()).ReadStream(path);
using var ms = new MemoryStream();
input.CopyTo(ms);
input.Dispose();
Expand Down
7 changes: 3 additions & 4 deletions starsky/starskytest/FakeCreateAn/CreateAnQuickTimeMp4.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using starsky.foundation.platform.Helpers;
using starskycore.Helpers;

namespace starskytest.FakeCreateAn
{
public static class CreateAnQuickTimeMp4
{
[SuppressMessage("ReSharper", "StringLiteralTypo")]
private static readonly string Base64QuickTimeMp4String =
private const string Base64QuickTimeMp4String =
"AAAAFGZ0eXBxdCAgAAAAAHF0ICAAAAAId2lkZQAAAdRtZGF0AAAAFQYFEQOH9E7NCkvcoZQ6w9SbFx8AgAAAABc" +
"luAgCBf/4gNZ988Brh5pePU0VlUZf8AAAABolbgIAgX/x8gez754DXDyWyqMd8y5gRq6/gAAAABUGBREDh/ROzQ" +
"pL3KGUOsPUmxcfAIAAAAAHIeEJET9dQAAAAAcheEJET11AAAAAFQYFEQOH9E7NCkvcoZQ6w9SbFx8AgAAAAAcBqI" +
Expand Down Expand Up @@ -39,13 +38,13 @@ public static class CreateAnQuickTimeMp4
"vb2tQcm8xNSwxAAAAMgAAAAMAAAAqZGF0YQAAAAFOTDmETWFjIE9TIFggMTAuMTQuNiAoMThHNDAzMikAAAAwAAA" +
"ABAAAAChkYXRhAAAAAU5MOYQyMDIwLTAzLTI5VDE1OjA5OjM5KzAyMDA=";

public static readonly byte[] Bytes = Base64Helper.TryParse(Base64QuickTimeMp4String);
public static readonly ImmutableArray<byte> Bytes = Base64Helper.TryParse(Base64QuickTimeMp4String).ToImmutableArray();

/// <summary>
/// @see: https://superuser.com/a/1467266 and 80 chars
/// </summary>
[SuppressMessage("ReSharper", "StringLiteralTypo")]
private static readonly string Base64QuickTimeMp4StringWithLocation =
private const string Base64QuickTimeMp4StringWithLocation =
"AAAAFGZ0eXBxdCAgAAAAAHF0ICAAAAAId2lkZQAAZhhtZGF0ANAABwD0Fy40ViowBCEhgF8ed7TC8nck" +
"xupl4ZCkNnoxcqa0tO8Q8Q+TOyJ/Vf87BP/JWf5Ogn/hCf5CZL7O/x4SH8PT7DktZ6pIfRn4/EcFyghq" +
"/I5DyBsifN+7k+w76h58nyyel4kT4VhyDpJBNshqNGQxGYIc26ETveRyfpfwnnTQE7XIyW+ukd0og5BN" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public CreateAnTagGzLongerThan100CharsFileName()

private static byte[] StreamToBytes(string path)
{
using var input = new StorageHostFullPathFilesystem(new FakeIWebLogger()).ReadStream(path);
var input = new StorageHostFullPathFilesystem(new FakeIWebLogger()).ReadStream(path);
using var ms = new MemoryStream();
input.CopyTo(ms);
input.Dispose();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using starsky.foundation.platform.Helpers;

namespace starskytest.FakeCreateAn.CreateAnZipFile12
Expand All @@ -15,7 +16,7 @@ public static class CreateAnZipFile12
+ "BOgDAABQSwECHgMKAAAAAACWiotWaAC3vhAAAAAQAAAACQAYAAAAAAABAAAApIFTAAAAZmlsZTIudHh0"
+ "VVQFAAPsljVkdXgLAAEE6AMAAAToAwAAUEsFBgAAAAACAAIAngAAAKYAAAAAAA==";

public static readonly byte[] Bytes = Base64Helper.TryParse(Base64CreateAnZipFile12String);
public static readonly ImmutableArray<byte> Bytes = Base64Helper.TryParse(Base64CreateAnZipFile12String).ToImmutableArray();

public static readonly Dictionary<string, string> Content = new Dictionary<string, string>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ namespace starskytest.Middleware
[TestClass]
public sealed class BasicAuthenticationMiddlewareTest
{
private readonly IUserManager _userManager;
private readonly IServiceProvider _serviceProvider;
private readonly Task _onNextResult = Task.FromResult(0);
private readonly RequestDelegate _onNext;
Expand Down Expand Up @@ -69,14 +68,6 @@ public BasicAuthenticationMiddlewareTest()
Interlocked.Increment(ref _requestId);
return _onNextResult;
};

// InMemory
var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
builder.UseInMemoryDatabase("123456789");
var options = builder.Options;
var context2 = new ApplicationDbContext(options);
_userManager = new UserManager(context2,new AppSettings(), new FakeIWebLogger());

}

[TestMethod]
Expand All @@ -87,7 +78,7 @@ public async Task BasicAuthenticationMiddlewareLoginTest()
var iUserManager = _serviceProvider.GetRequiredService<IUserManager>();
var httpContext = _serviceProvider.GetRequiredService<IHttpContextAccessor>().HttpContext;

var userId = "TestUserA";
const string userId = "TestUserA";
var claims = new List<Claim> { new Claim(ClaimTypes.NameIdentifier, userId) };
httpContext.User = new ClaimsPrincipal(new ClaimsIdentity(claims));

Expand Down
4 changes: 2 additions & 2 deletions starsky/starskytest/Services/ReadMeta_ExifReadTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ public void ExifRead_ReadExif_FromQuickTimeMp4InFileXMP_FileTest()

var newImage = CreateAnQuickTimeMp4.Bytes;
var fakeStorage = new FakeIStorage(new List<string> {"/"},
new List<string> {"/test.mp4"}, new List<byte[]> {newImage});
new List<string> {"/test.mp4"}, new List<byte[]> {newImage.ToArray()});

var item = new ReadMetaExif(fakeStorage, new AppSettings{VideoUseLocalTime = new List<CameraMakeModel>
{
Expand All @@ -463,7 +463,7 @@ public void ExifRead_ReadExif_FromQuickTimeMp4InFileXMP_FileTest_DutchCulture()

var newImage = CreateAnQuickTimeMp4.Bytes;
var fakeStorage = new FakeIStorage(new List<string> {"/"},
new List<string> {"/test.mp4"}, new List<byte[]> {newImage});
new List<string> {"/test.mp4"}, new List<byte[]> {newImage.ToArray()});

var item = new ReadMetaExif(fakeStorage, new AppSettings{VideoUseLocalTime = new List<CameraMakeModel>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public async Task FilterWorkThumbnailGeneration_Timeout()
);

var result = (await databaseThumbnailGenerationService.FilterAndWorkThumbnailGeneration(
new DateTime(2000,01,01),
new DateTime(2000,01,01,01,01,01, kind: DateTimeKind.Local),
new List<ThumbnailItem>
{
new ThumbnailItem("23478928939438234",null,null,null,null)
Expand Down Expand Up @@ -275,7 +275,7 @@ public async Task FilterWorkThumbnailGeneration_MatchItem()
);

var result = (await databaseThumbnailGenerationService.FilterAndWorkThumbnailGeneration(
new DateTime(3000,01,01),
new DateTime(3000,01,01,01,01,01, kind: DateTimeKind.Local),
new List<ThumbnailItem>
{
new ThumbnailItem("2437998234",null,null,null,null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -29,7 +30,7 @@ public async Task ExtractTar()
var storage = new FakeIStorage(new List<string> {"/"},
new List<string>{});

var memoryStream = new MemoryStream(CreateAnExifToolTar.Bytes);
var memoryStream = new MemoryStream(CreateAnExifToolTar.Bytes.ToArray());
await new TarBal(storage).ExtractTar(memoryStream,"/test", CancellationToken.None);
Assert.IsTrue(storage.ExistFile("/test/Image-ExifTool-11.99/exiftool"));
}
Expand All @@ -41,7 +42,7 @@ public async Task ExtractTarGz()
var storage = new FakeIStorage(new List<string> {"/"},
new List<string>{});

var memoryStream = new MemoryStream(CreateAnExifToolTarGz.Bytes);
var memoryStream = new MemoryStream(CreateAnExifToolTarGz.Bytes.ToArray());
await new TarBal(storage).ExtractTarGz(memoryStream,"/test", CancellationToken.None);
Assert.IsTrue(storage.ExistFile("/test/Image-ExifTool-11.99/exiftool"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using starsky.foundation.storage.ArchiveFormats;
Expand All @@ -26,7 +27,7 @@ public void TestExtractZip()
var zipped = CreateAnZipFile12.Bytes;

// Act
var result = Zipper.ExtractZip(zipped);
var result = Zipper.ExtractZip(zipped.ToArray());

// Assert
Assert.IsNotNull(result);
Expand Down
Loading

0 comments on commit 20fb12f

Please sign in to comment.