Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#340 Use .NET Aspire Test for integration tests instead of Testсontainers #341

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false

# Namespace declaration preferences (IDE0160 and IDE0161)
csharp_style_namespace_declarations = file_scoped
# 'var' preferences (IDE0007 and IDE0008)
csharp_style_var_for_built_in_types = true
csharp_style_var_elsewhere = true
csharp_style_var_when_type_is_apparent = true

# 'using' directive placement (IDE0065)
csharp_using_directive_placement = inside_namespace

# Use primary constructor (IDE0290)
csharp_style_prefer_primary_constructors = false

##################################################################################
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</PropertyGroup>

<PropertyGroup>
<NoWarn>$(NoWarn);NETSDK1206;xUnit1028;CS1591</NoWarn>
<NoWarn>$(NoWarn);NETSDK1206;xUnit1028;CS1591;NU1902;NU1903;NU1904</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace NKZSoft.Template.Application.Common.Behaviours;

using Exceptions;
using NKZSoft.Template.Common.Extensions;

public sealed class ValidationBehaviour<TRequest, TResponse>(IEnumerable<IValidator<TRequest>> validators)
: IPipelineBehavior<TRequest, TResponse>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace NKZSoft.Template.Application.Common.Handlers;

using Interfaces;
using NKZSoft.Template.Common.Extensions;

public abstract class HandlerBase<TQ, TM> : IRequestHandler<TQ, TM>
where TQ : IRequest<TM>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace NKZSoft.Template.Application.Common.Handlers;

using Interfaces;
using NKZSoft.Template.Common.Extensions;

public abstract class HandlerDbBase<TQ, TM> : HandlerBase<TQ, TM>
where TQ : IRequest<TM>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace NKZSoft.Template.Application.Common.Handlers;

using Interfaces;
using NKZSoft.Template.Common.Extensions;

public abstract class StreamRequestHandlerBase<TRequest, TResponse> : IStreamRequestHandler<TRequest, TResponse>
where TRequest : IStreamRequest<TResponse>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace NKZSoft.Template.Application;

using Common.Behaviours;
using NKZSoft.Template.Common.Extensions;

public static class DependencyInjectionExtensions
{
Expand Down
2 changes: 0 additions & 2 deletions src/NKZSoft.Template.Application/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.DependencyInjection.Extensions;
global using NKZSoft.Template.Application.TodoItems.Specifications;
global using NKZSoft.Template.Common;

global using NKZSoft.Template.Domain.AggregatesModel.ToDoAggregates.Entities;
global using NKZSoft.Template.Domain.Events;
global using NKZSoft.Template.Events.ToDoItem.Create;
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace NKZSoft.Template.Application.TodoItems.Commands.Create;

using Common.Repositories.PostgreSql;
using NKZSoft.Template.Common.Extensions;

public sealed class CreateToDoItemCommandHandler(IToDoItemRepository repository)
: IRequestHandler<CreateToDoItemCommand, Result<Guid>>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace NKZSoft.Template.Application.TodoItems.Commands.CreateInRedis;

using Common.Repositories.Redis;
using NKZSoft.Template.Common.Extensions;

public sealed class CreateToDoItemRedisCommandHandler(IToDoItemRedisRepository repository)
: IRequestHandler<CreateToDoItemRedisCommand, Result<Guid>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using Common.Exceptions;
using Common.Repositories.PostgreSql;
using NKZSoft.Template.Common.Extensions;

public sealed class UpdateToDoItemCommandHandler : IRequestHandler<UpdateToDoItemCommand>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Common.Interfaces;
using Common.Repositories.PostgreSql;
using NKZSoft.Template.Application.Models;
using NKZSoft.Template.Common.Extensions;

public sealed class GetTodoItemDbQueryHandler(
IToDoItemRepository repository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Common.Handlers;
using Common.Interfaces;
using Common.Repositories.Redis;
using NKZSoft.Template.Common.Extensions;

public class GetTodoItemQueryFromRedisHandler : HandlerBase<GetTodoItemQueryFromRedis, Result<ToDoItemDto>>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Common.Interfaces;
using Common.Paging;
using Common.Repositories.PostgreSql;
using NKZSoft.Template.Common.Extensions;

internal sealed class GetPageTodoDbQueryHandler(
IToDoItemRepository repository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Common.Handlers;
using Common.Interfaces;
using Common.Repositories.PostgreSql;
using NKZSoft.Template.Common.Extensions;

public class GetStreamTodoItemsQueryHandler : StreamRequestHandlerBase<GetStreamTodoItemsQuery, ToDoItemDto>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

internal sealed class ToDoItemSpecification : Specification<ToDoItem>
{
private static readonly FrozenDictionary<string, Expression<Func<ToDoItem, object>>> SortExpressions =
private static readonly FrozenDictionary<string, Expression<Func<ToDoItem, object>>> _sortExpressions =
new Dictionary<string, Expression<Func<ToDoItem, object>>>(StringComparer.OrdinalIgnoreCase)
{
{ nameof(ToDoItemFilter.Id), item => item.Id },
Expand Down Expand Up @@ -70,23 +70,16 @@ private static ISpecificationBuilder<ToDoItem> Sort(ISpecificationBuilder<ToDoIt
{
var sortDescriptors = sorts as SortDescriptor[] ?? sorts.ToArray();

if (sortDescriptors.Length != 0)
{
return sortDescriptors.Aggregate(specificationBuilder, Sort);
}

return Sort(specificationBuilder, new SortDescriptor(nameof(ToDoItemFilter.Id)));
return sortDescriptors.Length != 0 ? sortDescriptors.Aggregate(specificationBuilder, Sort) : Sort(specificationBuilder, new SortDescriptor(nameof(ToDoItemFilter.Id)));
}

private static ISpecificationBuilder<ToDoItem> Sort(ISpecificationBuilder<ToDoItem> specificationBuilder,
SortDescriptor sort)
{
if (SortExpressions.TryGetValue(sort.Field, out var se))
{
return sort.Direction == EnumSortDirection.Desc
return _sortExpressions.TryGetValue(sort.Field, out var se)
? (ISpecificationBuilder<ToDoItem>)(sort.Direction == EnumSortDirection.Desc
? specificationBuilder.OrderByDescending(se!)
: specificationBuilder.OrderBy(se!);
}
throw new BadRequestException($"Invalid field name {sort.Field}.");
: specificationBuilder.OrderBy(se!))
: throw new BadRequestException($"Invalid field name {sort.Field}.");
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace NKZSoft.Template.Common;
namespace NKZSoft.Template.Common.Extensions;

public static class GuardClausesExtensions
{
Expand Down
7 changes: 1 addition & 6 deletions src/NKZSoft.Template.Domain/Common/Enumeration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ private static T Parse<T, TK>(TK value, string description, Func<T, bool> predic

public static bool operator ==(Enumeration? left, Enumeration? right)
{
if (left is null)
{
return right is null;
}

return left.Equals(right);
return left is null ? right is null : left.Equals(right);
}

public static bool operator !=(Enumeration left, Enumeration right) => !(left == right);
Expand Down
12 changes: 1 addition & 11 deletions src/NKZSoft.Template.Domain/Common/ValueObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,7 @@ public abstract class ValueObject

public static bool operator ==(ValueObject? left, ValueObject? right)
{
if (left is null && right is null)
{
return true;
}

if (left is null || right is null)
{
return false;
}

return left.Equals(right);
return left is null && right is null || (left is not null && right is not null && left.Equals(right));
}

public static bool operator !=(ValueObject? left, ValueObject? right) => !(left == right);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace NKZSoft.Template.EFCore.Caching.Redis.Extensions;

using Common;
using Configuration;
using NKZSoft.Template.Common.Extensions;

public static class ServiceCollectionExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
namespace NKZSoft.Template.Events.ToDoItem.Create;

using Interfaces;

public sealed record ToDoItemCreatedIntegrationEvent(Guid Id, string Title, string? Note) : IIntegrationEvent;
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
namespace NKZSoft.Template.Events.ToDoItem.Update;

using Interfaces;

public sealed record ToDoItemUpdatedIntegrationEvent(Guid Id, string Name) : IIntegrationEvent;
1 change: 0 additions & 1 deletion src/NKZSoft.Template.Infrastructure.Core/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
global using System.Diagnostics.CodeAnalysis;
global using Microsoft.Extensions.DependencyInjection;
global using NKZSoft.Template.Application.Common.Interfaces;
global using NKZSoft.Template.Common;
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace NKZSoft.Template.Infrastructure.Core.Services;

using NKZSoft.Template.Common.Extensions;

public sealed class CurrentUserService(ICurrentUser currentUser) : ICurrentUserService
{
public ICurrentUser CurrentUser { get; } = currentUser.ThrowIfNull();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using NKZSoft.Template.Persistence.PostgreSQL.Common;
using NKZSoft.Template.Persistence.PostgreSQL.Extensions;

namespace NKZSoft.Template.Persistence.PostgreSQL;
namespace NKZSoft.Template.Persistence.PostgreSQL;
using NKZSoft.Template.Common.Extensions;
using Common;
using Extensions;

public class ApplicationDbContext : DbContext, IApplicationDbContext
{
private ICurrentUserService _currentUserService = null!;
private IDateTime _dateTime = null!;
private IMediator _mediator = null!;
private IDbInitializer _dbInitializer = null!;

public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
Expand All @@ -17,7 +16,7 @@ public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)

public void InitContext(ICurrentUserService currentUserService, IDbInitializer dbInitializer, IDateTime dateTime, IMediator mediator)
{
_dbInitializer = dbInitializer.ThrowIfNull();
DbInitializer = dbInitializer.ThrowIfNull();
_currentUserService = currentUserService.ThrowIfNull();
_dateTime = dateTime.ThrowIfNull();
_mediator = mediator.ThrowIfNull();
Expand All @@ -28,7 +27,7 @@ public void InitContext(ICurrentUserService currentUserService, IDbInitializer d

public DbContext AppDbContext => this;

public IDbInitializer DbInitializer => _dbInitializer;
public IDbInitializer? DbInitializer { get; private set; }

public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
{
Expand All @@ -44,7 +43,7 @@ public override async Task<int> SaveChangesAsync(CancellationToken cancellationT

public async Task MigrateAsync() => await AppDbContext.Database.MigrateAsync().ConfigureAwait(false);

public async Task SeedAsync() => await _dbInitializer.SeedAsync(this).ConfigureAwait(false);
public async Task SeedAsync() => await DbInitializer!.SeedAsync(this).ConfigureAwait(false);

private async Task DispatchDomainEventsAsync()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace NKZSoft.Template.Persistence.PostgreSQL;

using NKZSoft.Template.Common.Extensions;

public class ApplicationDbContextFactory : IDbContextFactory<ApplicationDbContext>
{
private readonly IDbContextFactory<ApplicationDbContext> _pooledFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace NKZSoft.Template.Persistence.PostgreSQL.Extensions;

using Configuration;
using NKZSoft.Template.Common.Extensions;

public static class ServiceCollectionExtension
{
Expand Down Expand Up @@ -73,7 +74,7 @@ private static IServiceCollection ConfigureDbContextFactory(this IServiceCollect
private static DbContextOptionsBuilder EnableDbLogging(this DbContextOptionsBuilder builder) => builder
.LogTo(
msg => Log.Logger.Information("{Msg}",msg),
new[] { DbLoggerCategory.Database.Name })
[DbLoggerCategory.Database.Name,])
.EnableDetailedErrors()
.EnableSensitiveDataLogging();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
global using Microsoft.Extensions.Options;
global using NKZSoft.FluentValidation.Options;
global using NKZSoft.Template.Application.Common.Interfaces;
global using NKZSoft.Template.Common;
global using NKZSoft.Template.Domain.AggregatesModel.ToDoAggregates.Entities;
global using NKZSoft.Template.Domain.Common;
global using Npgsql;
Expand Down
Loading