Skip to content

Commit

Permalink
code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Dec 11, 2023
1 parent 3dbf7ce commit b5d92a4
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 100 deletions.
1 change: 1 addition & 0 deletions starsky/starskytest/Controllers/HomeControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ public void Trash_ReturnsPhysicalFile_WhenRequestedUrlIsNotCaseSensitive()
{
// Arrange
int p = 0;
// difference is trash vs import
_controller.Request.Path = "/trash";

// Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ public async Task Import_Thumbnail_WrongInputName()
var services = new ServiceCollection();
services.AddSingleton<IStorage, FakeIStorage>();
services.AddSingleton<ISelectorStorage, FakeSelectorStorage>();
var serviceProvider = services.BuildServiceProvider();
var storageProvider = serviceProvider.GetRequiredService<IStorage>();

var importController = new ImportThumbnailController(_appSettings,
new FakeSelectorStorage(),new FakeIWebLogger(),
Expand Down Expand Up @@ -180,7 +178,7 @@ public async Task WriteThumbnailsTest_ShouldMoveFile()
var storage = new FakeIStorage(new List<string>(), new List<string>{ "/upload/123.jpg" });
var service = new ImportThumbnailController(_appSettings,
new FakeSelectorStorage(storage), logger, new FakeIThumbnailQuery());
var result = await service.WriteThumbnails(new List<string>{ "/upload/123.jpg" }, new List<string>{ "123" });
await service.WriteThumbnails(new List<string>{ "/upload/123.jpg" }, new List<string>{ "123" });

Assert.IsFalse(storage.ExistFile("/upload/123.jpg"));
Assert.IsTrue(storage.ExistFile("123"));
Expand Down Expand Up @@ -210,7 +208,7 @@ public void MapToTransferObject1_2000()
public void MapToTransferObject1_NonValidType()
{
var inputList = new List<string> { "1234567890123456" };
var result = ImportThumbnailController.MapToTransferObject(inputList);
ImportThumbnailController.MapToTransferObject(inputList);
}
}
}
2 changes: 0 additions & 2 deletions starsky/starskytest/Controllers/MetaInfoControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ namespace starskytest.Controllers
public sealed class MetaInfoControllerTest
{
private readonly IMetaInfo _metaInfo;
private readonly FakeIStorage _iStorage;

public MetaInfoControllerTest()
{
_iStorage = new FakeIStorage();
_metaInfo = new MetaInfo(new FakeIQuery(
new List<FileIndexItem>{new FileIndexItem("/test.jpg"), new FileIndexItem("/readonly/image.jpg"),
new FileIndexItem("/source_missing.jpg")}),
Expand Down
4 changes: 0 additions & 4 deletions starsky/starskytest/Controllers/MetaReplaceControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ namespace starskytest.Controllers
public sealed class MetaReplaceControllerTest
{
private readonly IQuery _query;
private readonly IExifTool _exifTool;
private readonly AppSettings _appSettings;
private readonly CreateAnImage _createAnImage;
private readonly IUpdateBackgroundTaskQueue _bgTaskQueue;
Expand Down Expand Up @@ -99,9 +98,6 @@ public MetaReplaceControllerTest()
_bgTaskQueue = serviceProvider.GetRequiredService<IUpdateBackgroundTaskQueue>();

_iStorage = new StorageSubPathFilesystem(_appSettings, new FakeIWebLogger());

// inject fake exifTool
_exifTool = new FakeExifTool(_iStorage,_appSettings);
}

private async Task InsertSearchData(bool delete = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public void ParseDate1()
{
var (parsed, parsedDateTime) = NotificationController.ParseDate("2020-04-11T17:55:35.922319Z");
Assert.IsTrue(parsed);
var expected = new DateTime(2020, 4, 11, 17, 55, 35, 922).ToString(CultureInfo.InvariantCulture);
var expected = new DateTime(2020, 4, 11, 17,
55, 35, 922, kind: DateTimeKind.Local).ToString(CultureInfo.InvariantCulture);
Assert.AreEqual(expected,parsedDateTime.ToString(CultureInfo.InvariantCulture));
}

Expand Down
6 changes: 2 additions & 4 deletions starsky/starskytest/Helpers/HttpClientHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public async Task Download_HttpClientHelperBadDomainDownload()
services.AddSingleton<IStorage, FakeIStorage>();
services.AddSingleton<ISelectorStorage, FakeSelectorStorage>();
var serviceProvider = services.BuildServiceProvider();
var storageProvider = serviceProvider.GetRequiredService<IStorage>();
var scopeFactory = serviceProvider.GetRequiredService<IServiceScopeFactory>();

var httpClientHelper = new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger());
Expand Down Expand Up @@ -145,7 +144,6 @@ public async Task ReadString_HttpClientHelper_ReadString()
services.AddSingleton<ISelectorStorage, FakeSelectorStorage>();
var serviceProvider = services.BuildServiceProvider();
var scopeFactory = serviceProvider.GetRequiredService<IServiceScopeFactory>();
var storageProvider = serviceProvider.GetRequiredService<IStorage>();

var httpClientHelper = new HttpClientHelper(httpProvider, scopeFactory, new FakeIWebLogger());

Expand Down Expand Up @@ -253,8 +251,8 @@ public async Task PostString_HttpClientHelper_VerboseFalse()
await httpClientHelper
.PostString("https://qdraw.nl/test", new StringContent(string.Empty),false);

Assert.IsFalse(fakeLogger.TrackedInformation.Any(p => p.Item2.Contains("PostString")));
Assert.IsFalse(fakeLogger.TrackedInformation.Any(p => p.Item2.Contains("HttpClientHelper")));
Assert.IsFalse(fakeLogger.TrackedInformation.Exists(p => p.Item2.Contains("PostString")));
Assert.IsFalse(fakeLogger.TrackedInformation.Exists(p => p.Item2.Contains("HttpClientHelper")));
}

[TestMethod]
Expand Down
85 changes: 36 additions & 49 deletions starsky/starskytest/Middleware/MiddlewareExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ namespace starskytest.Middleware
[TestClass]
public sealed class MiddlewareExtensionsTest
{
private readonly IUserManager _userManager;


public MiddlewareExtensionsTest()
{
var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
builder.UseInMemoryDatabase("test");
var options = builder.Options;
var context = new ApplicationDbContext(options);
_userManager = new UserManager(context,new AppSettings(), new FakeIWebLogger());
}



[TestMethod]
public async Task MiddlewareExtensionsBasicAuthenticationMiddlewareNotSignedIn()
Expand All @@ -43,46 +30,46 @@ public async Task MiddlewareExtensionsBasicAuthenticationMiddlewareNotSignedIn()
}


// [TestMethod]
// public async Task MiddlewareExtensionsBasicAuthenticationMiddlewareSignedIn()
// {
//// // Arrange
//// var httpContext = new DefaultHttpContext();
//// var authMiddleware = new BasicAuthenticationMiddleware(next: (innerHttpContext) => Task.FromResult(0));
// [TestMethod]
// public async Task MiddlewareExtensionsBasicAuthenticationMiddlewareSignedIn()
// {
// // // Arrange
// // var httpContext = new DefaultHttpContext();
// // var authMiddleware = new BasicAuthenticationMiddleware(next: (innerHttpContext) => Task.FromResult(0));
//
// var httpContext = new DefaultHttpContext();
// var httpContext = new DefaultHttpContext();
//
// var services = new ServiceCollection()
//// .AddDbContext<ApplicationDbContext>(options => options.UseInMemoryDatabase("starsky"))
// .AddIdentity<ApplicationUser, IdentityRole>(options =>
// {
// // Password settings
// options.Password.RequireDigit = false;
// options.Password.RequiredLength = 10;
// options.Password.RequiredUniqueChars = 0;
// options.Password.RequireLowercase = false;
// options.Password.RequireNonAlphanumeric = false;
// options.Password.RequireUppercase = false;
// })
// .AddEntityFrameworkStores<ApplicationDbContext>()
// .AddDefaultTokenProviders();
//
// var serviceProvider = services..BuildServiceProvider();
//
// serviceProvider.Services.
//// var userManager = httpContext.RequestServices.GetRequiredService<UserManager<ApplicationUser>>();
// var services = new ServiceCollection()
// // .AddDbContext<ApplicationDbContext>(options => options.UseInMemoryDatabase("starsky"))
// .AddIdentity<ApplicationUser, IdentityRole>(options =>
// {
// // Password settings
// options.Password.RequireDigit = false;
// options.Password.RequiredLength = 10;
// options.Password.RequiredUniqueChars = 0;
// options.Password.RequireLowercase = false;
// options.Password.RequireNonAlphanumeric = false;
// options.Password.RequireUppercase = false;
// })
// .AddEntityFrameworkStores<ApplicationDbContext>()
// .AddDefaultTokenProviders();
//
// var serviceProvider = services..BuildServiceProvider();
//
// serviceProvider.Services.
// // var userManager = httpContext.RequestServices.GetRequiredService<UserManager<ApplicationUser>>();
//
// var user = new ApplicationUser { UserName = "test", Email = "test" };
// var result = await userManager.CreateAsync(user, "model.Password");
//
//
// var t = await userManager.FindByNameAsync("test");
// var user = new ApplicationUser { UserName = "test", Email = "test" };
// var result = await userManager.CreateAsync(user, "model.Password");
//
//
// var t = await userManager.FindByNameAsync("test");
//
//
// Console.WriteLine();
// // Act
//// await authMiddleware.Invoke(httpContext);
// }
//
// Console.WriteLine();
// // Act
// // await authMiddleware.Invoke(httpContext);
// }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private void Setup()
};


// create a temp folder;
// create a temp folder
if ( !new StorageHostFullPathFilesystem().ExistFolder(_appSettings.DependenciesFolder) )
{
new StorageHostFullPathFilesystem().CreateDirectory(_appSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ namespace starskytest.starsky.feature.import.Services
[TestClass]
public sealed class ImportCliTest
{
private readonly HttpClientHelper _httpClientHelper;

public ImportCliTest()
{
_httpClientHelper = new HttpClientHelper(new FakeIHttpProvider(), null, new FakeIWebLogger());
}

[TestMethod]
public async Task ImporterCli_CheckIfExifToolIsCalled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,9 @@ public async Task Preflight_DirectoryRecursive()
Assert.AreEqual(ImportStatus.Ok, importIndexItems[2].Status);

// "/layer0.jpg","/test/layer1.jpg", "/test/test/layer2.jpg" (order is random)
Assert.IsTrue(importIndexItems.Any(p => p.SourceFullFilePath == "/layer0.jpg"));
Assert.IsTrue(importIndexItems.Any(p => p.SourceFullFilePath == "/test/layer1.jpg"));
Assert.IsTrue(importIndexItems.Any(p => p.SourceFullFilePath == "/test/test/layer2.jpg"));
Assert.IsTrue(importIndexItems.Exists(p => p.SourceFullFilePath == "/layer0.jpg"));
Assert.IsTrue(importIndexItems.Exists(p => p.SourceFullFilePath == "/test/layer1.jpg"));
Assert.IsTrue(importIndexItems.Exists(p => p.SourceFullFilePath == "/test/test/layer2.jpg"));
}

[TestMethod]
Expand Down Expand Up @@ -1152,7 +1152,7 @@ public void CheckForReadOnlyFileSystems_2()
Assert.AreEqual(2,readOnlyFileSystems.Count);

Assert.AreEqual(DefaultPath(),readOnlyFileSystems[0].Item1);
var testItem = importIndexItems.FirstOrDefault(p =>
var testItem = importIndexItems.Find(p =>
p.SourceFullFilePath == "/test.jpg");
Assert.AreEqual(ImportStatus.ReadOnlyFileSystem,testItem?.Status);

Expand Down Expand Up @@ -1186,7 +1186,7 @@ public void CheckForReadOnlyFileSystems_2a_same_folder()

Assert.AreEqual(1,readOnlyFileSystems.Count);
Assert.AreEqual(DefaultPath()+ Path.Combine("test","test"),readOnlyFileSystems[0].Item1);
var testItem = importIndexItems.FirstOrDefault(p =>
var testItem = importIndexItems.Find(p =>
p.SourceFullFilePath == "/test/test/test.jpg");
Assert.AreEqual(ImportStatus.ReadOnlyFileSystem,testItem?.Status);

Expand Down Expand Up @@ -1218,7 +1218,7 @@ public void CheckForReadOnlyFileSystems_3()
Assert.AreEqual(1,readOnlyFileSystems.Count);

Assert.AreEqual(DefaultPath(),readOnlyFileSystems[0].Item1);
var testItem = importIndexItems.FirstOrDefault(p =>
var testItem = importIndexItems.Find(p =>
p.SourceFullFilePath == "/not-found.jpg");
Assert.AreEqual(ImportStatus.Default,testItem?.Status);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public async Task Importer_HappyFlow_ItShouldAddTo_ImportDb()
_console, new FakeIMetaExifThumbnailService(),
new FakeIWebLogger(),new FakeIThumbnailQuery());

var result = await importService.Importer(new List<string> {"/test.jpg"},
await importService.Importer(new List<string> {"/test.jpg"},
new ImportSettingsModel{
Structure = "/yyyy/MM/yyyy_MM_dd*/_yyyyMMdd_HHmmss.ext"
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,13 @@ public async Task RotationThumbnailExecute2()
Assert.AreEqual(ThumbnailNameHelper.AllThumbnailSizes.Length,
thumbnailService.InputsRotate.Count);

Assert.IsTrue(thumbnailService.InputsRotate.Any(p => p.Item3 ==
Assert.IsTrue(thumbnailService.InputsRotate.Exists(p => p.Item3 ==
ThumbnailNameHelper.GetSize(ThumbnailSize.Small)));
Assert.IsTrue(thumbnailService.InputsRotate.Any(p => p.Item3 ==
Assert.IsTrue(thumbnailService.InputsRotate.Exists(p => p.Item3 ==
ThumbnailNameHelper.GetSize(ThumbnailSize.TinyMeta)));
Assert.IsTrue(thumbnailService.InputsRotate.Any(p => p.Item3 ==
Assert.IsTrue(thumbnailService.InputsRotate.Exists(p => p.Item3 ==
ThumbnailNameHelper.GetSize(ThumbnailSize.Large)));
Assert.IsTrue(thumbnailService.InputsRotate.Any(p => p.Item3 ==
Assert.IsTrue(thumbnailService.InputsRotate.Exists(p => p.Item3 ==
ThumbnailNameHelper.GetSize(ThumbnailSize.ExtraLarge)));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task OnStartupSyncBackgroundService_DoesStoreAfterWards()
Assert.IsNotNull(setting);
Assert.AreEqual(DateTime.UtcNow.Day, setting.ToUniversalTime().Day);
Assert.AreEqual(DateTime.UtcNow.Hour, setting.ToUniversalTime().Hour);
Assert.IsTrue((synchronize as FakeISynchronize)!.Inputs.Any(p => p.Item1 == "/"));
Assert.IsTrue((synchronize as FakeISynchronize)!.Inputs.Exists(p => p.Item1 == "/"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public async Task OpenConnection_MySqlConnector_MySqlException()
DatabaseType = AppSettings.DatabaseTypeList.Mysql
},logger).OpenConnection();

Assert.IsTrue(logger.TrackedExceptions.Any(x=>x.Item2.Contains("MySqlException")));
Assert.IsTrue(logger.TrackedExceptions.Exists(x=>x.Item2.Contains("MySqlException")));
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,12 @@ namespace starskytest.starsky.foundation.database.Import
[TestClass]
public sealed class ImportQueryTest
{
private readonly IMemoryCache _memoryCache;
private readonly ImportQuery _importQuery;
private readonly ApplicationDbContext _dbContext;
private readonly IServiceScopeFactory _serviceScope;

public ImportQueryTest()
{
var provider = new ServiceCollection()
.AddMemoryCache()
.BuildServiceProvider();
_memoryCache = provider.GetService<IMemoryCache>();

_serviceScope = CreateNewScope();
var scope = _serviceScope.CreateScope();
_dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
Expand Down Expand Up @@ -130,7 +124,7 @@ public async Task History()

if ( !historyResult.Any() ) throw new ArgumentNullException("should not be 0");

Assert.IsTrue(historyResult.Any(p => p.FileHash == "TEST8"));
Assert.IsTrue(historyResult.Exists(p => p.FileHash == "TEST8"));
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public async Task OnHomePageNotLoginShouldAutoLogin()
await middleware.Invoke(httpContext);

var userManager = serviceProvider.GetService<IUserManager>() as FakeUserManagerActiveUsers;
Assert.IsTrue(userManager.Users.Any(p => p.Credentials.Any(p => p.Identifier == NoAccountMiddleware.Identifier)));
Assert.IsTrue(userManager?.Users.Exists(p => p.Credentials!.Any(p => p.Identifier == NoAccountMiddleware.Identifier)));

Assert.IsTrue(invoked);
}
Expand Down Expand Up @@ -125,7 +125,7 @@ public async Task OnHomePageNotLoginShouldAutoLogin_DemoModeOn()
await middleware.Invoke(httpContext);

var userManager = serviceProvider.GetService<IUserManager>() as FakeUserManagerActiveUsers;
Assert.IsTrue(userManager.Users.Any(p => p.Credentials.Any(p => p.Identifier == NoAccountMiddleware.Identifier)));
Assert.IsTrue(userManager?.Users.Any(p => p.Credentials.Any(p => p.Identifier == NoAccountMiddleware.Identifier)));

Assert.IsTrue(invoked);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public async Task StartAsync()
Assert.IsTrue(connectionService.FakeSendToAllAsync.LastOrDefault()?.Contains("dateTime"));

source.Cancel();
source.Dispose();
}

[TestMethod]
Expand All @@ -39,6 +40,7 @@ public async Task StartAsync_CancelBeforeStart()
await service.StartAsync(token);

Assert.AreEqual(0,connectionService.FakeSendToAllAsync.Count);
source.Dispose();
}

[TestMethod]
Expand All @@ -54,6 +56,8 @@ public async Task StartAsyncStop()
await service.StopAsync(token);

Assert.IsTrue(connectionService.FakeSendToAllAsync.LastOrDefault()?.Contains("dateTime"));
source.Dispose();

}
}
}
Loading

0 comments on commit b5d92a4

Please sign in to comment.