Skip to content

Commit

Permalink
Merge pull request #82 from netcorepal/cleanup
Browse files Browse the repository at this point in the history
cleanup
  • Loading branch information
witskeeper authored Sep 16, 2024
2 parents f03c382 + 1e1a43a commit 4156f4d
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 41 deletions.
14 changes: 7 additions & 7 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@
<PackageReference Update="DotNetCore.CAP.Dashboard" Version="8.2.0" />
<PackageReference Update="Hangfire.Core" Version="1.8.0" />
<PackageReference Update="MediatR" Version="12.1.1" />
<PackageReference Update="DistributedLock.Redis" Version="1.0.2" />
<PackageReference Update="DistributedLock.Redis" Version="1.0.3" />
<PackageReference Update="System.Reactive" Version="6.0.0" />
<PackageReference Update="Microsoft.Extensions.DiagnosticAdapter" Version="3.1.32" />
<PackageReference Update="Steeltoe.Discovery.Eureka" Version="3.2.0" />
<PackageReference Update="KubernetesClient" Version="12.1.1" />
<PackageReference Update="dotnet-etcd" Version="4.1.1" />
<PackageReference Update="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageReference Update="Serilog.AspNetCore" Version="7.0.0" />
<PackageReference Update="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
<PackageReference Update="Serilog.AspNetCore" Version="8.0.2" />
<PackageReference Update="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageReference Update="Consul" Version="1.6.10.9" />
<PackageReference Update="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" PrivateAssets="all" />
Expand All @@ -87,13 +87,13 @@

<PackageReference Update="Microsoft.AspNetCore.Mvc.Testing" Version="$(FrameworkVersion)" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.6.2" />
<PackageReference Update="Moq" Version="4.18.4" />
<PackageReference Update="xunit" Version="2.4.2" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Update="Moq" Version="4.20.72" />
<PackageReference Update="xunit" Version="2.9.0" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Update="coverlet.collector" Version="6.0.0">
<PackageReference Update="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
12 changes: 6 additions & 6 deletions src/Domain.SourceGenerators/EntityIdCodeGenerators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ namespace {ns}
[TypeConverter(typeof(EntityIdTypeConverter<{className}, {sourceType}>))]
public partial record {className}({sourceType} Id) : I{sourceType}StronglyTypedId
{{
/// <summary>
/// implicit operator
/// </summary>
///// <summary>
///// implicit operator
///// </summary>
//public static implicit operator {sourceType}({className} id) => id.Id;
/// <summary>
/// implicit operator
/// </summary>
///// <summary>
///// implicit operator
///// </summary>
//public static implicit operator {className}({sourceType} id) => new {className}(id);
/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions src/Repository.EntityFrameworkCore/AppDbContextBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ protected virtual void ConfigureStronglyTypedIdValueConverter(ModelConfiguration
protected virtual void ConfigureRowVersion(ModelBuilder modelBuilder)
{
ArgumentNullException.ThrowIfNull(modelBuilder);
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
foreach (var clrType in modelBuilder.Model.GetEntityTypes().Select(p => p.ClrType))
{
var clrType = entityType.ClrType;
var properties = clrType.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p => p.PropertyType == typeof(RowVersion));

Expand Down
1 change: 0 additions & 1 deletion src/Snowflake.Consul/ConsulWorkerIdGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ public async Task Refresh(CancellationToken stoppingToken = default)

public string GetWorkerIdKey()
{
ArgumentNullException.ThrowIfNull(_workId);
return GetWorkerIdKey(_workId);
}

Expand Down
4 changes: 0 additions & 4 deletions src/Snowflake.Redis/RedisWorkerIdGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public sealed class RedisWorkerIdGenerator : BackgroundService, IWorkIdGenerator
/// </summary>
private readonly string _workerName;

private readonly IConnectionMultiplexer _connectionMultiplexer;

private readonly IDatabase _database;

public RedisWorkerIdGenerator(ILogger<RedisWorkerIdGenerator> logger,
Expand All @@ -35,7 +33,6 @@ public RedisWorkerIdGenerator(ILogger<RedisWorkerIdGenerator> logger,
_workerName = $"{Environment.MachineName}-{Guid.NewGuid()}";
_logger = logger;
_options = options.Value;
_connectionMultiplexer = connectionMultiplexer;
_database = connectionMultiplexer.GetDatabase();
_workId = GenWorkId().Result;
_logger.LogInformation("workerid got, workerId: {workerId} , identity name: {workerName}",
Expand Down Expand Up @@ -127,7 +124,6 @@ public async Task Refresh(CancellationToken stoppingToken = default)

public string GetWorkerIdKey()
{
ArgumentNullException.ThrowIfNull(_workId);
return GetWorkerIdKey(_workId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task Refresh_Throw_Exception_When_Session_Locked_By_Others_Test()
var id = consulWorkerIdGenerator.GetId();
Assert.Equal(0, id);
Assert.True(consulWorkerIdGenerator.IsHealth);
Assert.Equal(HealthStatus.Healthy, consulWorkerIdGenerator.CheckHealthAsync(healthCheckContext).Result.Status);
Assert.Equal(HealthStatus.Healthy, (await consulWorkerIdGenerator.CheckHealthAsync(healthCheckContext)).Status);

var releaseResult = await _consulClient.KV.Release(new KVPair(consulWorkerIdGenerator.GetWorkerIdKey())
{
Expand All @@ -71,7 +71,7 @@ public async Task Refresh_Throw_Exception_When_Session_Locked_By_Others_Test()
await Assert.ThrowsAsync<WorkerIdConflictException>(async () => await consulWorkerIdGenerator.Refresh());
Assert.False(consulWorkerIdGenerator.IsHealth);
Assert.Equal(HealthStatus.Unhealthy,
consulWorkerIdGenerator.CheckHealthAsync(healthCheckContext).Result.Status);
(await consulWorkerIdGenerator.CheckHealthAsync(healthCheckContext)).Status);
}


Expand All @@ -90,7 +90,7 @@ public async Task Refresh_Throw_Exception_When_Session_Locked_By_Others_And_Unhe
var id = consulWorkerIdGenerator.GetId();
Assert.Equal(0, id);
Assert.True(consulWorkerIdGenerator.IsHealth);
Assert.Equal(HealthStatus.Healthy, consulWorkerIdGenerator.CheckHealthAsync(healthCheckContext).Result.Status);
Assert.Equal(HealthStatus.Healthy, (await consulWorkerIdGenerator.CheckHealthAsync(healthCheckContext)).Status);

var releaseResult = await _consulClient.KV.Release(new KVPair(consulWorkerIdGenerator.GetWorkerIdKey())
{
Expand All @@ -116,7 +116,7 @@ public async Task Refresh_Throw_Exception_When_Session_Locked_By_Others_And_Unhe
await Assert.ThrowsAsync<WorkerIdConflictException>(async () => await consulWorkerIdGenerator.Refresh());
Assert.False(consulWorkerIdGenerator.IsHealth);
Assert.Equal(HealthStatus.Degraded,
consulWorkerIdGenerator.CheckHealthAsync(healthCheckContext).Result.Status);
(await consulWorkerIdGenerator.CheckHealthAsync(healthCheckContext)).Status);
}


Expand All @@ -134,7 +134,7 @@ public async Task Refresh_OK_When_Session_Released_And_Not_Lock_By_Others_Test()
var id = consulWorkerIdGenerator.GetId();
Assert.Equal(0, id);
Assert.True(consulWorkerIdGenerator.IsHealth);
Assert.Equal(HealthStatus.Healthy, consulWorkerIdGenerator.CheckHealthAsync(healthCheckContext).Result.Status);
Assert.Equal(HealthStatus.Healthy, (await consulWorkerIdGenerator.CheckHealthAsync(healthCheckContext)).Status);

var releaseResult = await _consulClient.KV.Release(new KVPair(consulWorkerIdGenerator.GetWorkerIdKey())
{
Expand All @@ -159,7 +159,8 @@ public async Task Refresh_OK_When_Session_Released_And_Not_Lock_By_Others_Test()
});
Assert.Equal(1, consulWorkerIdGenerator2.GetId());
Assert.True(consulWorkerIdGenerator2.IsHealth);
Assert.Equal(HealthStatus.Healthy, consulWorkerIdGenerator2.CheckHealthAsync(healthCheckContext).Result.Status);
Assert.Equal(HealthStatus.Healthy,
(await consulWorkerIdGenerator2.CheckHealthAsync(healthCheckContext)).Status);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task Refresh_Throw_Exception_When_Session_Locked_By_Others_Test()
var id = workerIdGenerator.GetId();
Assert.Equal(0, id);
Assert.True(workerIdGenerator.IsHealth);
Assert.Equal(HealthStatus.Healthy, workerIdGenerator.CheckHealthAsync(healthCheckContext).Result.Status);
Assert.Equal(HealthStatus.Healthy, (await workerIdGenerator.CheckHealthAsync(healthCheckContext)).Status);

var value = await _database.StringGetAsync(workerIdGenerator.GetWorkerIdKey());
Assert.True(value.HasValue);
Expand All @@ -65,7 +65,7 @@ public async Task Refresh_Throw_Exception_When_Session_Locked_By_Others_Test()
await Assert.ThrowsAsync<WorkerIdConflictException>(async () => await workerIdGenerator.Refresh());
Assert.False(workerIdGenerator.IsHealth);
Assert.Equal(HealthStatus.Unhealthy,
workerIdGenerator.CheckHealthAsync(healthCheckContext).Result.Status);
(await workerIdGenerator.CheckHealthAsync(healthCheckContext)).Status);
}


Expand All @@ -84,7 +84,7 @@ public async Task Refresh_Throw_Exception_When_Session_Locked_By_Others_And_Unhe
var id = workerIdGenerator.GetId();
Assert.Equal(0, id);
Assert.True(workerIdGenerator.IsHealth);
Assert.Equal(HealthStatus.Healthy, workerIdGenerator.CheckHealthAsync(healthCheckContext).Result.Status);
Assert.Equal(HealthStatus.Healthy, (await workerIdGenerator.CheckHealthAsync(healthCheckContext)).Status);

var value = await _database.StringGetAsync(workerIdGenerator.GetWorkerIdKey());
Assert.True(value.HasValue);
Expand All @@ -102,7 +102,7 @@ public async Task Refresh_Throw_Exception_When_Session_Locked_By_Others_And_Unhe
await Assert.ThrowsAsync<WorkerIdConflictException>(async () => await workerIdGenerator.Refresh());
Assert.False(workerIdGenerator.IsHealth);
Assert.Equal(HealthStatus.Degraded,
workerIdGenerator.CheckHealthAsync(healthCheckContext).Result.Status);
(await workerIdGenerator.CheckHealthAsync(healthCheckContext)).Status);
}


Expand All @@ -120,11 +120,11 @@ public async Task Refresh_OK_When_Session_Released_And_Not_Lock_By_Others_Test()
var id = consulWorkerIdGenerator.GetId();
Assert.Equal(0, id);
Assert.True(consulWorkerIdGenerator.IsHealth);
Assert.Equal(HealthStatus.Healthy, consulWorkerIdGenerator.CheckHealthAsync(healthCheckContext).Result.Status);
Assert.Equal(HealthStatus.Healthy, (await consulWorkerIdGenerator.CheckHealthAsync(healthCheckContext)).Status);

var value = await _database.StringGetAsync(consulWorkerIdGenerator.GetWorkerIdKey());
Assert.True(value.HasValue);

await _database.KeyDeleteAsync(consulWorkerIdGenerator.GetWorkerIdKey());

await consulWorkerIdGenerator.Refresh();
Expand All @@ -137,7 +137,8 @@ public async Task Refresh_OK_When_Session_Released_And_Not_Lock_By_Others_Test()
});
Assert.Equal(1, consulWorkerIdGenerator2.GetId());
Assert.True(consulWorkerIdGenerator2.IsHealth);
Assert.Equal(HealthStatus.Healthy, consulWorkerIdGenerator2.CheckHealthAsync(healthCheckContext).Result.Status);
Assert.Equal(HealthStatus.Healthy,
(await consulWorkerIdGenerator2.CheckHealthAsync(healthCheckContext)).Status);
}

[Fact]
Expand Down
6 changes: 3 additions & 3 deletions test/NetCorePal.Web.UnitTests/ProgramTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public ProgramTests(MyWebApplicationFactory factory)
JsonSerializerOptions JsonOption;

[Fact]
public void HealthCheckTest()
public async Task HealthCheckTest()
{
var client = factory.CreateClient();
var response = client.GetAsync("/health").Result;
var response = await client.GetAsync("/health");
Assert.True(response.IsSuccessStatusCode);
}

Expand Down Expand Up @@ -200,7 +200,7 @@ public async Task SetOrderItemNameTest()
Assert.Equal(14, queryResult.Count);
Assert.False(queryResult.Paid);
Assert.Equal(1, queryResult.RowVersion.VersionNumber);
Assert.Equal(1,queryResult.OrderItems.Count());
Assert.Single(queryResult.OrderItems);
Assert.Equal(1,queryResult.OrderItems.First().RowVersion.VersionNumber);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,25 @@

namespace NetCorePal.Web.Application.Commands;

/// <summary>
///
/// </summary>
/// <param name="OrderId"></param>
/// <param name="NewName"></param>
public record SetOrderItemNameCommand(OrderId OrderId,string NewName) : ICommand;

/// <summary>
///
/// </summary>
/// <param name="orderRepository"></param>
public class SetOrderItemNameCommandHandler(IOrderRepository orderRepository) : ICommandHandler<SetOrderItemNameCommand>
{
/// <summary>
///
/// </summary>
/// <param name="command"></param>
/// <param name="cancellationToken"></param>
/// <exception cref="KnownException"></exception>
public async Task Handle(SetOrderItemNameCommand command, CancellationToken cancellationToken)
{
var order = await orderRepository.GetAsync(command.OrderId, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace NetCorePal.Web.Application.IntegrationEventHandlers
///
/// </summary>
/// <param name="mediator"></param>
/// <param name="logger"></param>
public class OrderCreatedIntegrationEventHandler(
IMediator mediator,

Check warning on line 12 in test/NetCorePal.Web/Application/IntegrationEventHandlers/OrderCreatedntegrationEventHandler.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'mediator' is unread.

Check warning on line 12 in test/NetCorePal.Web/Application/IntegrationEventHandlers/OrderCreatedntegrationEventHandler.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'mediator' is unread.

Check warning on line 12 in test/NetCorePal.Web/Application/IntegrationEventHandlers/OrderCreatedntegrationEventHandler.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'mediator' is unread.

Check warning on line 12 in test/NetCorePal.Web/Application/IntegrationEventHandlers/OrderCreatedntegrationEventHandler.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'mediator' is unread.

Check warning on line 12 in test/NetCorePal.Web/Application/IntegrationEventHandlers/OrderCreatedntegrationEventHandler.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'mediator' is unread.

Check warning on line 12 in test/NetCorePal.Web/Application/IntegrationEventHandlers/OrderCreatedntegrationEventHandler.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'mediator' is unread.

Check warning on line 12 in test/NetCorePal.Web/Application/IntegrationEventHandlers/OrderCreatedntegrationEventHandler.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'mediator' is unread.
ILogger<OrderCreatedIntegrationEventHandler> logger) : IIntegrationEventHandler<OrderCreatedIntegrationEvent>
Expand All @@ -16,10 +17,11 @@ public class OrderCreatedIntegrationEventHandler(
/// </summary>
/// <param name="eventData"></param>
/// <param name="cancellationToken"></param>
public async Task HandleAsync(OrderCreatedIntegrationEvent eventData,
public Task HandleAsync(OrderCreatedIntegrationEvent eventData,
CancellationToken cancellationToken = default)
{
logger.LogInformation("OrderCreatedIntegrationEventHandler.HandleAsync");
return Task.CompletedTask;
}
}
}
18 changes: 17 additions & 1 deletion test/NetCorePal.Web/Application/Queries/OrderQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ public class OrderQuery(ApplicationDbContext applicationDbContext)
}
}

/// <summary>
///
/// </summary>
/// <param name="OrderId"></param>
/// <param name="Name"></param>
/// <param name="Count"></param>
/// <param name="Paid"></param>
/// <param name="CreateTime"></param>
/// <param name="RowVersion"></param>
/// <param name="OrderItems"></param>
public record OrderQueryResult(
OrderId OrderId,
string Name,
Expand All @@ -33,7 +43,13 @@ public record OrderQueryResult(
RowVersion RowVersion,
IEnumerable<OrderItemQueryResult> OrderItems);


/// <summary>
///
/// </summary>
/// <param name="OrderItemId"></param>
/// <param name="Name"></param>
/// <param name="Count"></param>
/// <param name="RowVersion"></param>
public record OrderItemQueryResult(
OrderItemId OrderItemId,
string Name,
Expand Down
11 changes: 11 additions & 0 deletions test/NetCorePal.Web/Controllers/OrderController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ public async Task<ResponseData> SetPaid(OrderId id)
return true.AsResponseData();
}

/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="name"></param>
/// <returns></returns>
[HttpPost]
[Route("/setorderItemName")]
public async Task<ResponseData> SetOrderItemName([FromQuery]long id, [FromQuery]string name)
Expand Down Expand Up @@ -175,6 +181,11 @@ public Task<ResponseData<long>> BadRequest(long id)
}


/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet]
[Route("/path/{id}")]
public Task<ResponseData<OrderId>> Path([FromRoute] OrderId id)
Expand Down
5 changes: 5 additions & 0 deletions test/NetCorePal.Web/Domain/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public void OrderPaid()
}


/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <exception cref="KnownException"></exception>
public void ChangeItemName(string name)
{
this.Name = name;
Expand Down
Loading

0 comments on commit 4156f4d

Please sign in to comment.