Skip to content

Commit

Permalink
refactor: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicGD committed Mar 1, 2023
1 parent ad1d8cf commit 5f5b8cb
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 32 deletions.
4 changes: 0 additions & 4 deletions apps/WASMDemo.Server/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ namespace WASMDemo.Server.Pages;
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
private readonly ILogger<ErrorModel> logger;

public ErrorModel(ILogger<ErrorModel> logger) => this.logger = logger;
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

public void OnGet() => RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}

4 changes: 2 additions & 2 deletions src/Sitko.Core.App/ApplicationModuleRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ public override (bool isSuccess, IEnumerable<Type> missingModules) CheckRequired
private TModuleOptions CreateOptions(IApplicationContext applicationContext, bool validateOptions = false)
{
TModuleOptions options;
if (optionsCache.ContainsKey(applicationContext.Id))
if (optionsCache.TryGetValue(applicationContext.Id, out var value))
{
options = optionsCache[applicationContext.Id];
options = value;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ private static void FillData(Dictionary<string, string> data, Dictionary<string,
{
foreach (var (key, value) in resourceData)
{
if (!data.ContainsKey(key))
{
data[key] = value;
}
data.TryAdd(key, value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Sitko.Core.Auth.IdentityServer.Tokens;

class UserTokenProvider : IUserTokenProvider
internal class UserTokenProvider : IUserTokenProvider
{
private readonly IUserTokenManagementService? userTokenManagementService;
private readonly IAuthenticationSchemeProvider authenticationSchemeProvider;
Expand Down
1 change: 0 additions & 1 deletion src/Sitko.Core.Db.Postgres/PostgresDatabaseModule.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Npgsql;
Expand Down
4 changes: 2 additions & 2 deletions src/Sitko.Core.Queue/QueueModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override void ConfigureServices(IApplicationContext applicationContext, I
if (startupOptions.Middlewares.Any())
{
services.Scan(selector =>
selector.AddTypes(startupOptions.Middlewares).AsSelfWithInterfaces().WithSingletonLifetime());
selector.FromTypes(startupOptions.Middlewares).AsSelfWithInterfaces().WithSingletonLifetime());
}

foreach (var options in startupOptions.Options)
Expand All @@ -40,7 +40,7 @@ public override void ConfigureServices(IApplicationContext applicationContext, I
if (startupOptions.ProcessorEntries.Any())
{
var types = startupOptions.ProcessorEntries.Select(e => e.Type).Distinct().ToArray();
services.Scan(selector => selector.AddTypes(types).AsSelfWithInterfaces().WithScopedLifetime());
services.Scan(selector => selector.FromTypes(types).AsSelfWithInterfaces().WithScopedLifetime());
var messageTypes = startupOptions.ProcessorEntries.SelectMany(e => e.MessageTypes).Distinct().ToArray();
foreach (var messageType in messageTypes)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sitko.Core.Repository/RepositoriesModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public override void ConfigureServices(IApplicationContext applicationContext, I
.Select(implementedInterface => (implementedInterface.GenericTypeArguments[0],
implementedInterface.GenericTypeArguments[1])).ToList();
services.Scan(s =>
s.AddTypes(types.Distinct()).UsingRegistrationStrategy(RegistrationStrategy.Skip).AsSelfWithInterfaces()
s.FromTypes(types.Distinct()).UsingRegistrationStrategy(RegistrationStrategy.Skip).AsSelfWithInterfaces()
.WithScopedLifetime());
foreach (var (entityType, entityPkType) in entityTypes)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sitko.Core.Search/SearchModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static IServiceCollection RegisterSearchProvider<TSearchProvider, TEntity
this IServiceCollection serviceCollection)
where TSearchProvider : class, ISearchProvider<TEntity, TEntityPk>
where TEntity : class =>
serviceCollection.Scan(a => a.AddType<TSearchProvider>().AsSelfWithInterfaces());
serviceCollection.Scan(a => a.FromType<TSearchProvider>().AsSelfWithInterfaces());
}

public abstract class SearchModuleOptions : BaseModuleOptions
Expand Down
10 changes: 5 additions & 5 deletions tests/Sitko.Core.ImgProxy.Tests/ImgProxyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Sitko.Core.ImgProxy.Tests;

public class ImgProxyTests : BaseTest<ImgProxyTestsScope>
{
private static readonly string testUrl = "https://img.test.com/img/foo.png";
private const string TestUrl = "https://img.test.com/img/foo.png";

public ImgProxyTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
{
Expand All @@ -19,7 +19,7 @@ public async Task Url()
var scope = await GetScopeAsync();
var generator = scope.GetService<IImgProxyUrlGenerator>();

var generated = generator.Url(testUrl);
var generated = generator.Url(TestUrl);
generated.Should()
.Be(
"https://imgproxy.test.com/SxQp7ZiYppbWLN0lA6-qCKCtEAafQidbWvGhObksdOg//aHR0cHM6Ly9pbWcudGVzdC5jb20vaW1nL2Zvby5wbmc");
Expand All @@ -31,7 +31,7 @@ public async Task Format()
var scope = await GetScopeAsync();
var generator = scope.GetService<IImgProxyUrlGenerator>();

var generated = generator.Format(testUrl, "jpg");
var generated = generator.Format(TestUrl, "jpg");
generated.Should()
.Be(
"https://imgproxy.test.com/UrUQdqnjooZ8VB5f2p88GAAYsxAfMRad3JDDJpIoQEI//aHR0cHM6Ly9pbWcudGVzdC5jb20vaW1nL2Zvby5wbmc.jpg");
Expand All @@ -56,7 +56,7 @@ public async Task Build()
var scope = await GetScopeAsync();
var generator = scope.GetService<IImgProxyUrlGenerator>();

var generated = generator.Build(testUrl, builder => builder.WithFormat("jpg"));
var generated = generator.Build(TestUrl, builder => builder.WithFormat("jpg"));
generated.Should()
.Be(
"https://imgproxy.test.com/UrUQdqnjooZ8VB5f2p88GAAYsxAfMRad3JDDJpIoQEI//aHR0cHM6Ly9pbWcudGVzdC5jb20vaW1nL2Zvby5wbmc.jpg");
Expand All @@ -68,7 +68,7 @@ public async Task Resize()
var scope = await GetScopeAsync();
var generator = scope.GetService<IImgProxyUrlGenerator>();

var generated = generator.Resize(testUrl, 100, 100);
var generated = generator.Resize(TestUrl, 100, 100);
generated.Should()
.Be(
"https://imgproxy.test.com/jUHPR01P3EetzCxdi8MX9cKbYJ7potdoEMO1NxZAIr4/resize:auto:100:100:0:0/aHR0cHM6Ly9pbWcudGVzdC5jb20vaW1nL2Zvby5wbmc");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System.ComponentModel.DataAnnotations.Schema;
using Sitko.Core.Repository.Tests.Data;

namespace Sitko.Core.Repository.EntityFrameworkCore.Tests.Data.TPH;

public abstract class BaseTPHClass : Entity<Guid>
{
public TPHType Type { get; set; }
public string Foo { get; set; }
public string Foo { get; set; } = "";
}

public abstract class BaseTPHClass<TConfig> : BaseTPHClass where TConfig : class, new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public class FirstTPHClass : BaseTPHClass<FirstTPHClassConfig>
{
public string Bar { get; set; }
}
public string Bar { get; set; } = "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public class SecondTPHClass : BaseTPHClass<SecondTPHClassConfig>
{
public string Baz { get; set; }
}
public string Baz { get; set; } = "";
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Sitko.Core.Repository.Tests.Data;
using Sitko.Core.Xunit;
using Sitko.Core.Xunit;

namespace Sitko.Core.Repository.EntityFrameworkCore.Tests.Data.TPH;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task Count()
var repo = scope.GetService<TestRemoteRepository>();
var result = await repo.CountAsync();

Assert.Equal(result, 6);
result.Should().Be(6);
}

[Fact]
Expand All @@ -39,8 +39,7 @@ public async Task CountWithCondition()
var scope = await GetScopeAsync();
var repo = scope.GetService<TestRemoteRepository>();
var result = await repo.CountAsync(q => q.Where(t => t.FooId == 5));

Assert.Equal(result, 2);
result.Should().Be(2);
}

[Fact]
Expand Down

0 comments on commit 5f5b8cb

Please sign in to comment.