From b5ea3c7caaab0403f20990058712a7b51b990c59 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Mon, 4 Mar 2024 10:18:02 +0000 Subject: [PATCH] update and run csharpier --- .config/dotnet-tools.json | 4 +- src/Conduit/Domain/ArticleFavorite.cs | 2 +- src/Conduit/Domain/ArticleTag.cs | 2 +- src/Conduit/Domain/Comment.cs | 2 +- src/Conduit/Domain/FollowedPeople.cs | 2 +- src/Conduit/Domain/Tag.cs | 2 +- .../Features/Articles/ArticleEnvelope.cs | 2 +- .../Features/Articles/ArticlesController.cs | 22 ++++---- .../Features/Articles/ArticlesEnvelope.cs | 2 +- src/Conduit/Features/Articles/Create.cs | 3 +- src/Conduit/Features/Articles/Details.cs | 4 +- src/Conduit/Features/Articles/Edit.cs | 18 +++---- src/Conduit/Features/Articles/List.cs | 19 +++---- .../Features/Comments/CommentEnvelope.cs | 2 +- .../Features/Comments/CommentsController.cs | 9 ++-- .../Features/Comments/CommentsEnvelope.cs | 2 +- src/Conduit/Features/Comments/Create.cs | 4 +- src/Conduit/Features/Comments/Delete.cs | 4 +- src/Conduit/Features/Comments/List.cs | 4 +- src/Conduit/Features/Favorites/Add.cs | 12 ++--- src/Conduit/Features/Favorites/Delete.cs | 10 ++-- .../Features/Favorites/FavoritesController.cs | 8 ++- src/Conduit/Features/Followers/Add.cs | 4 +- src/Conduit/Features/Followers/Delete.cs | 4 +- .../Features/Followers/FollowersController.cs | 6 ++- src/Conduit/Features/Profiles/Details.cs | 6 ++- .../Features/Profiles/IProfileReader.cs | 2 +- .../Features/Profiles/MappingProfile.cs | 2 +- src/Conduit/Features/Profiles/Profile.cs | 2 +- .../Features/Profiles/ProfileEnvelope.cs | 2 +- .../Features/Profiles/ProfileReader.cs | 22 +++----- .../Features/Profiles/ProfilesController.cs | 3 +- src/Conduit/Features/Tags/List.cs | 9 ++-- src/Conduit/Features/Tags/TagsController.cs | 3 +- src/Conduit/Features/Tags/TagsEnvelope.cs | 2 +- src/Conduit/Features/Users/Create.cs | 17 +++--- src/Conduit/Features/Users/Details.cs | 13 ++--- src/Conduit/Features/Users/Edit.cs | 13 ++--- src/Conduit/Features/Users/Login.cs | 13 ++--- src/Conduit/Features/Users/MappingProfile.cs | 2 +- src/Conduit/Features/Users/User.cs | 2 +- src/Conduit/Features/Users/UserController.cs | 3 +- .../Infrastructure/CurrentUserAccessor.cs | 4 +- .../Infrastructure/Errors/Constants.cs | 2 +- .../Errors/ErrorHandlingMiddleware.cs | 3 +- .../GroupByApiRootConvention.cs | 6 +-- .../Infrastructure/ICurrentUserAccessor.cs | 2 +- .../Security/IJwtTokenGenerator.cs | 2 +- .../Security/IPasswordHasher.cs | 2 +- .../Security/JwtIssuerOptions.cs | 2 +- .../Infrastructure/Security/PasswordHasher.cs | 2 +- src/Conduit/Infrastructure/Slug.cs | 2 +- .../ValidationPipelineBehavior.cs | 5 +- src/Conduit/Program.cs | 52 +++++++++---------- src/Conduit/Startup.cs | 49 ++++++++--------- src/Conduit/StartupExtensions.cs | 13 ++--- .../Features/Articles/ArticleHelpers.cs | 10 ++-- .../Features/Articles/DeleteTests.cs | 35 ++++++------- .../Features/Articles/EditTests.cs | 11 ++-- .../Features/Comments/CommentHelpers.cs | 22 ++++---- .../Features/Users/CreateTests.cs | 8 ++- .../Features/Users/LoginTests.cs | 2 +- .../Features/Users/UserHelpers.cs | 4 +- 63 files changed, 227 insertions(+), 280 deletions(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 50bf6c3d..a4713c52 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,10 +3,10 @@ "isRoot": true, "tools": { "csharpier": { - "version": "0.25.0", + "version": "0.27.3", "commands": [ "dotnet-csharpier" ] } } -} +} \ No newline at end of file diff --git a/src/Conduit/Domain/ArticleFavorite.cs b/src/Conduit/Domain/ArticleFavorite.cs index 8531e616..992d21ad 100644 --- a/src/Conduit/Domain/ArticleFavorite.cs +++ b/src/Conduit/Domain/ArticleFavorite.cs @@ -7,4 +7,4 @@ public class ArticleFavorite public int PersonId { get; init; } public Person? Person { get; init; } -} \ No newline at end of file +} diff --git a/src/Conduit/Domain/ArticleTag.cs b/src/Conduit/Domain/ArticleTag.cs index a3e31698..0d34e477 100644 --- a/src/Conduit/Domain/ArticleTag.cs +++ b/src/Conduit/Domain/ArticleTag.cs @@ -7,4 +7,4 @@ public class ArticleTag public string? TagId { get; init; } public Tag? Tag { get; init; } -} \ No newline at end of file +} diff --git a/src/Conduit/Domain/Comment.cs b/src/Conduit/Domain/Comment.cs index ea876a27..7a1710e7 100644 --- a/src/Conduit/Domain/Comment.cs +++ b/src/Conduit/Domain/Comment.cs @@ -24,4 +24,4 @@ public class Comment public DateTime CreatedAt { get; init; } public DateTime UpdatedAt { get; init; } -} \ No newline at end of file +} diff --git a/src/Conduit/Domain/FollowedPeople.cs b/src/Conduit/Domain/FollowedPeople.cs index 8e3fcbe5..bab1d764 100644 --- a/src/Conduit/Domain/FollowedPeople.cs +++ b/src/Conduit/Domain/FollowedPeople.cs @@ -7,4 +7,4 @@ public class FollowedPeople public int TargetId { get; init; } public Person? Target { get; init; } -} \ No newline at end of file +} diff --git a/src/Conduit/Domain/Tag.cs b/src/Conduit/Domain/Tag.cs index 4100e34e..ea78ed30 100644 --- a/src/Conduit/Domain/Tag.cs +++ b/src/Conduit/Domain/Tag.cs @@ -7,4 +7,4 @@ public class Tag public string? TagId { get; init; } public List ArticleTags { get; init; } = new(); -} \ No newline at end of file +} diff --git a/src/Conduit/Features/Articles/ArticleEnvelope.cs b/src/Conduit/Features/Articles/ArticleEnvelope.cs index bbb86f5c..95394233 100644 --- a/src/Conduit/Features/Articles/ArticleEnvelope.cs +++ b/src/Conduit/Features/Articles/ArticleEnvelope.cs @@ -2,4 +2,4 @@ namespace Conduit.Features.Articles; -public record ArticleEnvelope(Article Article); \ No newline at end of file +public record ArticleEnvelope(Article Article); diff --git a/src/Conduit/Features/Articles/ArticlesController.cs b/src/Conduit/Features/Articles/ArticlesController.cs index 964370cd..9b458e4d 100644 --- a/src/Conduit/Features/Articles/ArticlesController.cs +++ b/src/Conduit/Features/Articles/ArticlesController.cs @@ -18,11 +18,7 @@ public Task Get( [FromQuery] int? limit, [FromQuery] int? offset, CancellationToken cancellationToken - ) => - mediator.Send( - new List.Query(tag, author, favorited, limit, offset), - cancellationToken - ); + ) => mediator.Send(new List.Query(tag, author, favorited, limit, offset), cancellationToken); [HttpGet("feed")] public Task GetFeed( @@ -34,18 +30,20 @@ public Task GetFeed( CancellationToken cancellationToken ) => mediator.Send( - new List.Query(tag, author, favorited, limit, offset) { IsFeed = true }, cancellationToken); + new List.Query(tag, author, favorited, limit, offset) { IsFeed = true }, + cancellationToken + ); [HttpGet("{slug}")] - public Task Get(string slug, CancellationToken cancellationToken) => mediator.Send(new Details.Query(slug), cancellationToken); + public Task Get(string slug, CancellationToken cancellationToken) => + mediator.Send(new Details.Query(slug), cancellationToken); [HttpPost] [Authorize(AuthenticationSchemes = JwtIssuerOptions.Schemes)] public Task Create( [FromBody] Create.Command command, CancellationToken cancellationToken - ) => - mediator.Send(command, cancellationToken); + ) => mediator.Send(command, cancellationToken); [HttpPut("{slug}")] [Authorize(AuthenticationSchemes = JwtIssuerOptions.Schemes)] @@ -53,10 +51,10 @@ public Task Edit( string slug, [FromBody] Edit.Model model, CancellationToken cancellationToken - ) => - mediator.Send(new Edit.Command(model, slug), cancellationToken); + ) => mediator.Send(new Edit.Command(model, slug), cancellationToken); [HttpDelete("{slug}")] [Authorize(AuthenticationSchemes = JwtIssuerOptions.Schemes)] - public Task Delete(string slug, CancellationToken cancellationToken) => mediator.Send(new Delete.Command(slug), cancellationToken); + public Task Delete(string slug, CancellationToken cancellationToken) => + mediator.Send(new Delete.Command(slug), cancellationToken); } diff --git a/src/Conduit/Features/Articles/ArticlesEnvelope.cs b/src/Conduit/Features/Articles/ArticlesEnvelope.cs index b7dde6fb..347ce78c 100644 --- a/src/Conduit/Features/Articles/ArticlesEnvelope.cs +++ b/src/Conduit/Features/Articles/ArticlesEnvelope.cs @@ -8,4 +8,4 @@ public class ArticlesEnvelope public List
Articles { get; set; } = new(); public int ArticlesCount { get; set; } -} \ No newline at end of file +} diff --git a/src/Conduit/Features/Articles/Create.cs b/src/Conduit/Features/Articles/Create.cs index 815e4b68..5d66d49b 100644 --- a/src/Conduit/Features/Articles/Create.cs +++ b/src/Conduit/Features/Articles/Create.cs @@ -38,7 +38,8 @@ public record Command(ArticleData Article) : IRequest; public class CommandValidator : AbstractValidator { - public CommandValidator() => RuleFor(x => x.Article).NotNull().SetValidator(new ArticleDataValidator()); + public CommandValidator() => + RuleFor(x => x.Article).NotNull().SetValidator(new ArticleDataValidator()); } public class Handler(ConduitContext context, ICurrentUserAccessor currentUserAccessor) diff --git a/src/Conduit/Features/Articles/Details.cs b/src/Conduit/Features/Articles/Details.cs index 86655c0e..05a77473 100644 --- a/src/Conduit/Features/Articles/Details.cs +++ b/src/Conduit/Features/Articles/Details.cs @@ -25,8 +25,8 @@ public async Task Handle( CancellationToken cancellationToken ) { - var article = await context.Articles - .GetAllData() + var article = await context + .Articles.GetAllData() .FirstOrDefaultAsync(x => x.Slug == message.Slug, cancellationToken); if (article == null) diff --git a/src/Conduit/Features/Articles/Edit.cs b/src/Conduit/Features/Articles/Edit.cs index 9b54eb25..25b16786 100644 --- a/src/Conduit/Features/Articles/Edit.cs +++ b/src/Conduit/Features/Articles/Edit.cs @@ -33,8 +33,8 @@ public async Task Handle( CancellationToken cancellationToken ) { - var article = await context.Articles - .Include(x => x.ArticleTags) // include also the article tags since they also need to be updated + var article = await context + .Articles.Include(x => x.ArticleTags) // include also the article tags since they also need to be updated .Where(x => x.Slug == message.Slug) .FirstOrDefaultAsync(cancellationToken); @@ -59,7 +59,7 @@ CancellationToken cancellationToken if ( context.ChangeTracker.Entries().First(x => x.Entity == article).State - == EntityState.Modified + == EntityState.Modified || articleTagsToCreate.Count != 0 || articleTagsToDelete.Count != 0 ) @@ -80,14 +80,10 @@ CancellationToken cancellationToken await context.SaveChangesAsync(cancellationToken); - article = - await context.Articles - .GetAllData() - .Where(x => x.Slug == article.Slug) - .FirstOrDefaultAsync( - x => x.ArticleId == article.ArticleId, - cancellationToken - ); + article = await context + .Articles.GetAllData() + .Where(x => x.Slug == article.Slug) + .FirstOrDefaultAsync(x => x.ArticleId == article.ArticleId, cancellationToken); if (article is null) { throw new RestException( diff --git a/src/Conduit/Features/Articles/List.cs b/src/Conduit/Features/Articles/List.cs index 71937cd1..d0ed2e8b 100644 --- a/src/Conduit/Features/Articles/List.cs +++ b/src/Conduit/Features/Articles/List.cs @@ -33,8 +33,8 @@ CancellationToken cancellationToken if (message.IsFeed && currentUserAccessor.GetCurrentUsername() != null) { - var currentUser = await context.Persons - .Include(x => x.Following) + var currentUser = await context + .Persons.Include(x => x.Following) .FirstOrDefaultAsync( x => x.Username == currentUserAccessor.GetCurrentUsername(), cancellationToken @@ -47,11 +47,8 @@ CancellationToken cancellationToken new { User = Constants.NOT_FOUND } ); } - queryable = queryable.Where( - x => - currentUser.Following - .Select(y => y.TargetId) - .Contains(x.Author!.PersonId) + queryable = queryable.Where(x => + currentUser.Following.Select(y => y.TargetId).Contains(x.Author!.PersonId) ); } @@ -63,8 +60,8 @@ CancellationToken cancellationToken ); if (tag != null) { - queryable = queryable.Where( - x => x.ArticleTags.Select(y => y.TagId).Contains(tag.TagId) + queryable = queryable.Where(x => + x.ArticleTags.Select(y => y.TagId).Contains(tag.TagId) ); } else @@ -97,8 +94,8 @@ CancellationToken cancellationToken ); if (author != null) { - queryable = queryable.Where( - x => x.ArticleFavorites.Any(y => y.PersonId == author.PersonId) + queryable = queryable.Where(x => + x.ArticleFavorites.Any(y => y.PersonId == author.PersonId) ); } else diff --git a/src/Conduit/Features/Comments/CommentEnvelope.cs b/src/Conduit/Features/Comments/CommentEnvelope.cs index 9b784580..23662e4d 100644 --- a/src/Conduit/Features/Comments/CommentEnvelope.cs +++ b/src/Conduit/Features/Comments/CommentEnvelope.cs @@ -2,4 +2,4 @@ namespace Conduit.Features.Comments; -public record CommentEnvelope(Comment Comment); \ No newline at end of file +public record CommentEnvelope(Comment Comment); diff --git a/src/Conduit/Features/Comments/CommentsController.cs b/src/Conduit/Features/Comments/CommentsController.cs index 4ff3ad67..c45e91a2 100644 --- a/src/Conduit/Features/Comments/CommentsController.cs +++ b/src/Conduit/Features/Comments/CommentsController.cs @@ -16,13 +16,14 @@ public Task Create( string slug, [FromBody] Create.Model model, CancellationToken cancellationToken - ) => - mediator.Send(new Create.Command(model, slug), cancellationToken); + ) => mediator.Send(new Create.Command(model, slug), cancellationToken); [HttpGet("{slug}/comments")] - public Task Get(string slug, CancellationToken cancellationToken) => mediator.Send(new List.Query(slug), cancellationToken); + public Task Get(string slug, CancellationToken cancellationToken) => + mediator.Send(new List.Query(slug), cancellationToken); [HttpDelete("{slug}/comments/{id}")] [Authorize(AuthenticationSchemes = JwtIssuerOptions.Schemes)] - public Task Delete(string slug, int id, CancellationToken cancellationToken) => mediator.Send(new Delete.Command(slug, id), cancellationToken); + public Task Delete(string slug, int id, CancellationToken cancellationToken) => + mediator.Send(new Delete.Command(slug, id), cancellationToken); } diff --git a/src/Conduit/Features/Comments/CommentsEnvelope.cs b/src/Conduit/Features/Comments/CommentsEnvelope.cs index 869987ec..5bb1d657 100644 --- a/src/Conduit/Features/Comments/CommentsEnvelope.cs +++ b/src/Conduit/Features/Comments/CommentsEnvelope.cs @@ -3,4 +3,4 @@ namespace Conduit.Features.Comments; -public record CommentsEnvelope(List Comments); \ No newline at end of file +public record CommentsEnvelope(List Comments); diff --git a/src/Conduit/Features/Comments/Create.cs b/src/Conduit/Features/Comments/Create.cs index 9c0a742c..b32d90bd 100644 --- a/src/Conduit/Features/Comments/Create.cs +++ b/src/Conduit/Features/Comments/Create.cs @@ -32,8 +32,8 @@ public async Task Handle( CancellationToken cancellationToken ) { - var article = await context.Articles - .Include(x => x.Comments) + var article = await context + .Articles.Include(x => x.Comments) .FirstOrDefaultAsync(x => x.Slug == message.Slug, cancellationToken); if (article == null) diff --git a/src/Conduit/Features/Comments/Delete.cs b/src/Conduit/Features/Comments/Delete.cs index 9806f0bb..08b0144a 100644 --- a/src/Conduit/Features/Comments/Delete.cs +++ b/src/Conduit/Features/Comments/Delete.cs @@ -24,8 +24,8 @@ public class QueryHandler(ConduitContext context) : IRequestHandler public async Task Handle(Command message, CancellationToken cancellationToken) { var article = - await context.Articles - .Include(x => x.Comments) + await context + .Articles.Include(x => x.Comments) .FirstOrDefaultAsync(x => x.Slug == message.Slug, cancellationToken) ?? throw new RestException( HttpStatusCode.NotFound, diff --git a/src/Conduit/Features/Comments/List.cs b/src/Conduit/Features/Comments/List.cs index c8e4bf31..ffd70e13 100644 --- a/src/Conduit/Features/Comments/List.cs +++ b/src/Conduit/Features/Comments/List.cs @@ -19,8 +19,8 @@ public async Task Handle( CancellationToken cancellationToken ) { - var article = await context.Articles - .Include(x => x.Comments) + var article = await context + .Articles.Include(x => x.Comments) .ThenInclude(x => x.Author) .FirstOrDefaultAsync(x => x.Slug == message.Slug, cancellationToken); diff --git a/src/Conduit/Features/Favorites/Add.cs b/src/Conduit/Features/Favorites/Add.cs index 9f5a0ce0..e8ddae04 100644 --- a/src/Conduit/Features/Favorites/Add.cs +++ b/src/Conduit/Features/Favorites/Add.cs @@ -72,15 +72,9 @@ CancellationToken cancellationToken await context.SaveChangesAsync(cancellationToken); } - - - article = - await context.Articles - .GetAllData() - .FirstOrDefaultAsync( - x => x.ArticleId == article.ArticleId, - cancellationToken - ); + article = await context + .Articles.GetAllData() + .FirstOrDefaultAsync(x => x.ArticleId == article.ArticleId, cancellationToken); if (article is null) { throw new RestException( diff --git a/src/Conduit/Features/Favorites/Delete.cs b/src/Conduit/Features/Favorites/Delete.cs index 84d5f06f..5a25c787 100644 --- a/src/Conduit/Features/Favorites/Delete.cs +++ b/src/Conduit/Features/Favorites/Delete.cs @@ -60,13 +60,9 @@ await context.Articles.FirstOrDefaultAsync( await context.SaveChangesAsync(cancellationToken); } - article = - await context.Articles - .GetAllData() - .FirstOrDefaultAsync( - x => x.ArticleId == article.ArticleId, - cancellationToken - ); + article = await context + .Articles.GetAllData() + .FirstOrDefaultAsync(x => x.ArticleId == article.ArticleId, cancellationToken); if (article is null) { throw new RestException( diff --git a/src/Conduit/Features/Favorites/FavoritesController.cs b/src/Conduit/Features/Favorites/FavoritesController.cs index ba2c677a..eac28723 100644 --- a/src/Conduit/Features/Favorites/FavoritesController.cs +++ b/src/Conduit/Features/Favorites/FavoritesController.cs @@ -13,13 +13,11 @@ public class FavoritesController(IMediator mediator) : Controller { [HttpPost("{slug}/favorite")] [Authorize(AuthenticationSchemes = JwtIssuerOptions.Schemes)] - public Task FavoriteAdd(string slug, CancellationToken cancellationToken) => mediator.Send(new Add.Command(slug), cancellationToken); + public Task FavoriteAdd(string slug, CancellationToken cancellationToken) => + mediator.Send(new Add.Command(slug), cancellationToken); [HttpDelete("{slug}/favorite")] [Authorize(AuthenticationSchemes = JwtIssuerOptions.Schemes)] - public Task FavoriteDelete( - string slug, - CancellationToken cancellationToken - ) => + public Task FavoriteDelete(string slug, CancellationToken cancellationToken) => mediator.Send(new Delete.Command(slug), cancellationToken); } diff --git a/src/Conduit/Features/Followers/Add.cs b/src/Conduit/Features/Followers/Add.cs index 234b851e..cb07dfa8 100644 --- a/src/Conduit/Features/Followers/Add.cs +++ b/src/Conduit/Features/Followers/Add.cs @@ -23,8 +23,8 @@ public class CommandValidator : AbstractValidator public class QueryHandler( ConduitContext context, ICurrentUserAccessor currentUserAccessor, - IProfileReader profileReader) - : IRequestHandler + IProfileReader profileReader + ) : IRequestHandler { public async Task Handle( Command message, diff --git a/src/Conduit/Features/Followers/Delete.cs b/src/Conduit/Features/Followers/Delete.cs index 2d7a719a..f9fd7ee6 100644 --- a/src/Conduit/Features/Followers/Delete.cs +++ b/src/Conduit/Features/Followers/Delete.cs @@ -22,8 +22,8 @@ public class CommandValidator : AbstractValidator public class QueryHandler( ConduitContext context, ICurrentUserAccessor currentUserAccessor, - IProfileReader profileReader) - : IRequestHandler + IProfileReader profileReader + ) : IRequestHandler { public async Task Handle( Command message, diff --git a/src/Conduit/Features/Followers/FollowersController.cs b/src/Conduit/Features/Followers/FollowersController.cs index 8e8bd47e..a0fca6ec 100644 --- a/src/Conduit/Features/Followers/FollowersController.cs +++ b/src/Conduit/Features/Followers/FollowersController.cs @@ -13,9 +13,11 @@ public class FollowersController(IMediator mediator) : Controller { [HttpPost("{username}/follow")] [Authorize(AuthenticationSchemes = JwtIssuerOptions.Schemes)] - public Task Follow(string username, CancellationToken cancellationToken) => mediator.Send(new Add.Command(username), cancellationToken); + public Task Follow(string username, CancellationToken cancellationToken) => + mediator.Send(new Add.Command(username), cancellationToken); [HttpDelete("{username}/follow")] [Authorize(AuthenticationSchemes = JwtIssuerOptions.Schemes)] - public Task Unfollow(string username, CancellationToken cancellationToken) => mediator.Send(new Delete.Command(username), cancellationToken); + public Task Unfollow(string username, CancellationToken cancellationToken) => + mediator.Send(new Delete.Command(username), cancellationToken); } diff --git a/src/Conduit/Features/Profiles/Details.cs b/src/Conduit/Features/Profiles/Details.cs index fc759ef3..4f76e0e0 100644 --- a/src/Conduit/Features/Profiles/Details.cs +++ b/src/Conduit/Features/Profiles/Details.cs @@ -14,8 +14,10 @@ public class QueryValidator : AbstractValidator public QueryValidator() => RuleFor(x => x.Username).NotEmpty(); } - public class QueryHandler(IProfileReader profileReader) : IRequestHandler + public class QueryHandler(IProfileReader profileReader) + : IRequestHandler { - public Task Handle(Query message, CancellationToken cancellationToken) => profileReader.ReadProfile(message.Username, cancellationToken); + public Task Handle(Query message, CancellationToken cancellationToken) => + profileReader.ReadProfile(message.Username, cancellationToken); } } diff --git a/src/Conduit/Features/Profiles/IProfileReader.cs b/src/Conduit/Features/Profiles/IProfileReader.cs index 87eb7ae5..0c2c4468 100644 --- a/src/Conduit/Features/Profiles/IProfileReader.cs +++ b/src/Conduit/Features/Profiles/IProfileReader.cs @@ -6,4 +6,4 @@ namespace Conduit.Features.Profiles; public interface IProfileReader { Task ReadProfile(string username, CancellationToken cancellationToken); -} \ No newline at end of file +} diff --git a/src/Conduit/Features/Profiles/MappingProfile.cs b/src/Conduit/Features/Profiles/MappingProfile.cs index 24c9627d..4c7e2d16 100644 --- a/src/Conduit/Features/Profiles/MappingProfile.cs +++ b/src/Conduit/Features/Profiles/MappingProfile.cs @@ -5,4 +5,4 @@ namespace Conduit.Features.Profiles; public class MappingProfile : AutoMapper.Profile { public MappingProfile() => CreateMap(MemberList.None); -} \ No newline at end of file +} diff --git a/src/Conduit/Features/Profiles/Profile.cs b/src/Conduit/Features/Profiles/Profile.cs index c42f9137..091f3aec 100644 --- a/src/Conduit/Features/Profiles/Profile.cs +++ b/src/Conduit/Features/Profiles/Profile.cs @@ -12,4 +12,4 @@ public class Profile [JsonPropertyName("following")] public bool IsFollowed { get; set; } -} \ No newline at end of file +} diff --git a/src/Conduit/Features/Profiles/ProfileEnvelope.cs b/src/Conduit/Features/Profiles/ProfileEnvelope.cs index ce1c42b7..e483b315 100644 --- a/src/Conduit/Features/Profiles/ProfileEnvelope.cs +++ b/src/Conduit/Features/Profiles/ProfileEnvelope.cs @@ -1,3 +1,3 @@ namespace Conduit.Features.Profiles; -public record ProfileEnvelope(Profile Profile); \ No newline at end of file +public record ProfileEnvelope(Profile Profile); diff --git a/src/Conduit/Features/Profiles/ProfileReader.cs b/src/Conduit/Features/Profiles/ProfileReader.cs index eb1d80ae..cce9a952 100644 --- a/src/Conduit/Features/Profiles/ProfileReader.cs +++ b/src/Conduit/Features/Profiles/ProfileReader.cs @@ -12,8 +12,8 @@ namespace Conduit.Features.Profiles; public class ProfileReader( ConduitContext context, ICurrentUserAccessor currentUserAccessor, - IMapper mapper) - : IProfileReader + IMapper mapper +) : IProfileReader { public async Task ReadProfile( string username, @@ -22,30 +22,24 @@ CancellationToken cancellationToken { var currentUserName = currentUserAccessor.GetCurrentUsername(); - var person = await context.Persons - .AsNoTracking() + var person = await context + .Persons.AsNoTracking() .FirstOrDefaultAsync(x => x.Username == username, cancellationToken); if (person is null) { - throw new RestException( - HttpStatusCode.NotFound, - new { User = Constants.NOT_FOUND } - ); + throw new RestException(HttpStatusCode.NotFound, new { User = Constants.NOT_FOUND }); } if (person == null) { - throw new RestException( - HttpStatusCode.NotFound, - new { User = Constants.NOT_FOUND } - ); + throw new RestException(HttpStatusCode.NotFound, new { User = Constants.NOT_FOUND }); } var profile = mapper.Map(person); if (currentUserName != null) { - var currentPerson = await context.Persons - .Include(x => x.Following) + var currentPerson = await context + .Persons.Include(x => x.Following) .Include(x => x.Followers) .FirstOrDefaultAsync(x => x.Username == currentUserName, cancellationToken); diff --git a/src/Conduit/Features/Profiles/ProfilesController.cs b/src/Conduit/Features/Profiles/ProfilesController.cs index 15a5d33e..d3af98fc 100644 --- a/src/Conduit/Features/Profiles/ProfilesController.cs +++ b/src/Conduit/Features/Profiles/ProfilesController.cs @@ -9,5 +9,6 @@ namespace Conduit.Features.Profiles; public class ProfilesController(IMediator mediator) : Controller { [HttpGet("{username}")] - public Task Get(string username, CancellationToken cancellationToken) => mediator.Send(new Details.Query(username), cancellationToken); + public Task Get(string username, CancellationToken cancellationToken) => + mediator.Send(new Details.Query(username), cancellationToken); } diff --git a/src/Conduit/Features/Tags/List.cs b/src/Conduit/Features/Tags/List.cs index 06e78a65..cd4d6be3 100644 --- a/src/Conduit/Features/Tags/List.cs +++ b/src/Conduit/Features/Tags/List.cs @@ -14,13 +14,10 @@ public record Query : IRequest; public class QueryHandler(ConduitContext context) : IRequestHandler { - public async Task Handle( - Query message, - CancellationToken cancellationToken - ) + public async Task Handle(Query message, CancellationToken cancellationToken) { - var tags = await context.Tags - .OrderBy(x => x.TagId) + var tags = await context + .Tags.OrderBy(x => x.TagId) .AsNoTracking() .ToListAsync(cancellationToken); return new TagsEnvelope() diff --git a/src/Conduit/Features/Tags/TagsController.cs b/src/Conduit/Features/Tags/TagsController.cs index fce38d05..c063bea4 100644 --- a/src/Conduit/Features/Tags/TagsController.cs +++ b/src/Conduit/Features/Tags/TagsController.cs @@ -9,5 +9,6 @@ namespace Conduit.Features.Tags; public class TagsController(IMediator mediator) : Controller { [HttpGet] - public Task Get(CancellationToken cancellationToken) => mediator.Send(new List.Query(), cancellationToken); + public Task Get(CancellationToken cancellationToken) => + mediator.Send(new List.Query(), cancellationToken); } diff --git a/src/Conduit/Features/Tags/TagsEnvelope.cs b/src/Conduit/Features/Tags/TagsEnvelope.cs index 1f4da691..aca8dfbd 100644 --- a/src/Conduit/Features/Tags/TagsEnvelope.cs +++ b/src/Conduit/Features/Tags/TagsEnvelope.cs @@ -5,4 +5,4 @@ namespace Conduit.Features.Tags; public class TagsEnvelope { public List Tags { get; set; } = new(); -} \ No newline at end of file +} diff --git a/src/Conduit/Features/Users/Create.cs b/src/Conduit/Features/Users/Create.cs index abe2c54c..f63ebb7b 100644 --- a/src/Conduit/Features/Users/Create.cs +++ b/src/Conduit/Features/Users/Create.cs @@ -34,17 +34,14 @@ public class Handler( ConduitContext context, IPasswordHasher passwordHasher, IJwtTokenGenerator jwtTokenGenerator, - IMapper mapper) - : IRequestHandler + IMapper mapper + ) : IRequestHandler { - public async Task Handle( - Command message, - CancellationToken cancellationToken - ) + public async Task Handle(Command message, CancellationToken cancellationToken) { if ( - await context.Persons - .Where(x => x.Username == message.User.Username) + await context + .Persons.Where(x => x.Username == message.User.Username) .AnyAsync(cancellationToken) ) { @@ -55,8 +52,8 @@ await context.Persons } if ( - await context.Persons - .Where(x => x.Email == message.User.Email) + await context + .Persons.Where(x => x.Email == message.User.Email) .AnyAsync(cancellationToken) ) { diff --git a/src/Conduit/Features/Users/Details.cs b/src/Conduit/Features/Users/Details.cs index 427701cf..9fe133c8 100644 --- a/src/Conduit/Features/Users/Details.cs +++ b/src/Conduit/Features/Users/Details.cs @@ -24,16 +24,13 @@ public class QueryValidator : AbstractValidator public class QueryHandler( ConduitContext context, IJwtTokenGenerator jwtTokenGenerator, - IMapper mapper) - : IRequestHandler + IMapper mapper + ) : IRequestHandler { - public async Task Handle( - Query message, - CancellationToken cancellationToken - ) + public async Task Handle(Query message, CancellationToken cancellationToken) { - var person = await context.Persons - .AsNoTracking() + var person = await context + .Persons.AsNoTracking() .FirstOrDefaultAsync(x => x.Username == message.Username, cancellationToken); if (person == null) diff --git a/src/Conduit/Features/Users/Edit.cs b/src/Conduit/Features/Users/Edit.cs index e78fea28..45a661e3 100644 --- a/src/Conduit/Features/Users/Edit.cs +++ b/src/Conduit/Features/Users/Edit.cs @@ -39,17 +39,14 @@ public class Handler( ConduitContext context, IPasswordHasher passwordHasher, ICurrentUserAccessor currentUserAccessor, - IMapper mapper) - : IRequestHandler + IMapper mapper + ) : IRequestHandler { - public async Task Handle( - Command message, - CancellationToken cancellationToken - ) + public async Task Handle(Command message, CancellationToken cancellationToken) { var currentUsername = currentUserAccessor.GetCurrentUsername(); - var person = await context.Persons - .Where(x => x.Username == currentUsername) + var person = await context + .Persons.Where(x => x.Username == currentUsername) .FirstOrDefaultAsync(cancellationToken); if (person is null) { diff --git a/src/Conduit/Features/Users/Login.cs b/src/Conduit/Features/Users/Login.cs index 43dab254..db28a97c 100644 --- a/src/Conduit/Features/Users/Login.cs +++ b/src/Conduit/Features/Users/Login.cs @@ -38,16 +38,13 @@ public class Handler( ConduitContext context, IPasswordHasher passwordHasher, IJwtTokenGenerator jwtTokenGenerator, - IMapper mapper) - : IRequestHandler + IMapper mapper + ) : IRequestHandler { - public async Task Handle( - Command message, - CancellationToken cancellationToken - ) + public async Task Handle(Command message, CancellationToken cancellationToken) { - var person = await context.Persons - .Where(x => x.Email == message.User.Email) + var person = await context + .Persons.Where(x => x.Email == message.User.Email) .SingleOrDefaultAsync(cancellationToken); if (person == null) { diff --git a/src/Conduit/Features/Users/MappingProfile.cs b/src/Conduit/Features/Users/MappingProfile.cs index 46e8116a..3f289e42 100644 --- a/src/Conduit/Features/Users/MappingProfile.cs +++ b/src/Conduit/Features/Users/MappingProfile.cs @@ -5,4 +5,4 @@ namespace Conduit.Features.Users; public class MappingProfile : Profile { public MappingProfile() => CreateMap(MemberList.None); -} \ No newline at end of file +} diff --git a/src/Conduit/Features/Users/User.cs b/src/Conduit/Features/Users/User.cs index 19e8944c..e8b7b72e 100644 --- a/src/Conduit/Features/Users/User.cs +++ b/src/Conduit/Features/Users/User.cs @@ -13,4 +13,4 @@ public class User public string? Token { get; set; } } -public record UserEnvelope(User User); \ No newline at end of file +public record UserEnvelope(User User); diff --git a/src/Conduit/Features/Users/UserController.cs b/src/Conduit/Features/Users/UserController.cs index 81308ba6..65674fcd 100644 --- a/src/Conduit/Features/Users/UserController.cs +++ b/src/Conduit/Features/Users/UserController.cs @@ -23,6 +23,5 @@ public Task GetCurrent(CancellationToken cancellationToken) => public Task UpdateUser( [FromBody] Edit.Command command, CancellationToken cancellationToken - ) => - mediator.Send(command, cancellationToken); + ) => mediator.Send(command, cancellationToken); } diff --git a/src/Conduit/Infrastructure/CurrentUserAccessor.cs b/src/Conduit/Infrastructure/CurrentUserAccessor.cs index e520004f..a413c61c 100644 --- a/src/Conduit/Infrastructure/CurrentUserAccessor.cs +++ b/src/Conduit/Infrastructure/CurrentUserAccessor.cs @@ -7,7 +7,7 @@ namespace Conduit.Infrastructure; public class CurrentUserAccessor(IHttpContextAccessor httpContextAccessor) : ICurrentUserAccessor { public string? GetCurrentUsername() => - httpContextAccessor.HttpContext - ?.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier) + httpContextAccessor + .HttpContext?.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier) ?.Value; } diff --git a/src/Conduit/Infrastructure/Errors/Constants.cs b/src/Conduit/Infrastructure/Errors/Constants.cs index d5bda2bf..697b360b 100644 --- a/src/Conduit/Infrastructure/Errors/Constants.cs +++ b/src/Conduit/Infrastructure/Errors/Constants.cs @@ -5,4 +5,4 @@ public static class Constants public const string NOT_FOUND = "not found"; public const string IN_USE = "in use"; public const string InternalServerError = nameof(InternalServerError); -} \ No newline at end of file +} diff --git a/src/Conduit/Infrastructure/Errors/ErrorHandlingMiddleware.cs b/src/Conduit/Infrastructure/Errors/ErrorHandlingMiddleware.cs index ddbb1742..625112cf 100644 --- a/src/Conduit/Infrastructure/Errors/ErrorHandlingMiddleware.cs +++ b/src/Conduit/Infrastructure/Errors/ErrorHandlingMiddleware.cs @@ -11,7 +11,8 @@ namespace Conduit.Infrastructure.Errors; public class ErrorHandlingMiddleware( RequestDelegate next, IStringLocalizer localizer, - ILogger logger) + ILogger logger +) { private static readonly Action LOGGER_MESSAGE = LoggerMessage.Define( diff --git a/src/Conduit/Infrastructure/GroupByApiRootConvention.cs b/src/Conduit/Infrastructure/GroupByApiRootConvention.cs index 338c2a76..440c3397 100644 --- a/src/Conduit/Infrastructure/GroupByApiRootConvention.cs +++ b/src/Conduit/Infrastructure/GroupByApiRootConvention.cs @@ -8,12 +8,10 @@ public class GroupByApiRootConvention : IControllerModelConvention { public void Apply(ControllerModel controller) { - var controllerNamespace = controller.Attributes - .OfType() - .FirstOrDefault(); + var controllerNamespace = controller.Attributes.OfType().FirstOrDefault(); var apiVersion = controllerNamespace?.Template?.Split('/').First().ToLowerInvariant() ?? "default"; controller.ApiExplorer.GroupName = apiVersion; } -} \ No newline at end of file +} diff --git a/src/Conduit/Infrastructure/ICurrentUserAccessor.cs b/src/Conduit/Infrastructure/ICurrentUserAccessor.cs index 10c5d002..9fcb3991 100644 --- a/src/Conduit/Infrastructure/ICurrentUserAccessor.cs +++ b/src/Conduit/Infrastructure/ICurrentUserAccessor.cs @@ -3,4 +3,4 @@ namespace Conduit.Infrastructure; public interface ICurrentUserAccessor { string? GetCurrentUsername(); -} \ No newline at end of file +} diff --git a/src/Conduit/Infrastructure/Security/IJwtTokenGenerator.cs b/src/Conduit/Infrastructure/Security/IJwtTokenGenerator.cs index 55a2b139..a032d208 100644 --- a/src/Conduit/Infrastructure/Security/IJwtTokenGenerator.cs +++ b/src/Conduit/Infrastructure/Security/IJwtTokenGenerator.cs @@ -3,4 +3,4 @@ namespace Conduit.Infrastructure.Security; public interface IJwtTokenGenerator { string CreateToken(string username); -} \ No newline at end of file +} diff --git a/src/Conduit/Infrastructure/Security/IPasswordHasher.cs b/src/Conduit/Infrastructure/Security/IPasswordHasher.cs index 5ebef64d..12620039 100644 --- a/src/Conduit/Infrastructure/Security/IPasswordHasher.cs +++ b/src/Conduit/Infrastructure/Security/IPasswordHasher.cs @@ -6,4 +6,4 @@ namespace Conduit.Infrastructure.Security; public interface IPasswordHasher : IDisposable { Task Hash(string password, byte[] salt); -} \ No newline at end of file +} diff --git a/src/Conduit/Infrastructure/Security/JwtIssuerOptions.cs b/src/Conduit/Infrastructure/Security/JwtIssuerOptions.cs index 8ef6ea6c..0010c724 100644 --- a/src/Conduit/Infrastructure/Security/JwtIssuerOptions.cs +++ b/src/Conduit/Infrastructure/Security/JwtIssuerOptions.cs @@ -100,4 +100,4 @@ public class JwtIssuerOptions /// The signing key to use when generating tokens. /// public SigningCredentials? SigningCredentials { get; set; } -} \ No newline at end of file +} diff --git a/src/Conduit/Infrastructure/Security/PasswordHasher.cs b/src/Conduit/Infrastructure/Security/PasswordHasher.cs index 43a5bade..563d88e9 100644 --- a/src/Conduit/Infrastructure/Security/PasswordHasher.cs +++ b/src/Conduit/Infrastructure/Security/PasswordHasher.cs @@ -22,4 +22,4 @@ public Task Hash(string password, byte[] salt) } public void Dispose() => x.Dispose(); -} \ No newline at end of file +} diff --git a/src/Conduit/Infrastructure/Slug.cs b/src/Conduit/Infrastructure/Slug.cs index 1d291dd6..a707bf45 100644 --- a/src/Conduit/Infrastructure/Slug.cs +++ b/src/Conduit/Infrastructure/Slug.cs @@ -30,4 +30,4 @@ public static partial class Slug [GeneratedRegex("\\s")] private static partial Regex TrimRegex(); -} \ No newline at end of file +} diff --git a/src/Conduit/Infrastructure/ValidationPipelineBehavior.cs b/src/Conduit/Infrastructure/ValidationPipelineBehavior.cs index dd25956c..59eaf52d 100644 --- a/src/Conduit/Infrastructure/ValidationPipelineBehavior.cs +++ b/src/Conduit/Infrastructure/ValidationPipelineBehavior.cs @@ -7,8 +7,9 @@ namespace Conduit.Infrastructure; -public class ValidationPipelineBehavior(IEnumerable> validators) - : IPipelineBehavior +public class ValidationPipelineBehavior( + IEnumerable> validators +) : IPipelineBehavior where TRequest : notnull { private readonly List> _validators = validators.ToList(); diff --git a/src/Conduit/Program.cs b/src/Conduit/Program.cs index 0e9fe37e..878242da 100644 --- a/src/Conduit/Program.cs +++ b/src/Conduit/Program.cs @@ -1,21 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Reflection; using Conduit; using Conduit.Features.Profiles; -using Conduit.Infrastructure.Security; using Conduit.Infrastructure; +using Conduit.Infrastructure.Errors; +using Conduit.Infrastructure.Security; +using FluentValidation; +using FluentValidation.AspNetCore; using MediatR; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using System.Reflection; -using Microsoft.EntityFrameworkCore; -using System; -using Microsoft.OpenApi.Models; -using System.Collections.Generic; -using FluentValidation.AspNetCore; -using FluentValidation; -using Conduit.Infrastructure.Errors; using Microsoft.Extensions.Logging; +using Microsoft.OpenApi.Models; // read database configuration (database provider + database connection) from environment variables //Environment.GetEnvironmentVariable(DEFAULT_DATABASE_PROVIDER) @@ -25,8 +25,8 @@ var builder = WebApplication.CreateBuilder(args); -builder.Services.AddMediatR( - cfg => cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()) +builder.Services.AddMediatR(cfg => + cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()) ); builder.Services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationPipelineBehavior<,>)); builder.Services.AddScoped( @@ -99,28 +99,28 @@ x.SwaggerDoc("v1", new OpenApiInfo { Title = "RealWorld API", Version = "v1" }); x.CustomSchemaIds(y => y.FullName); x.DocInclusionPredicate((version, apiDescription) => true); - x.TagActionsBy( - y => new List() { y.GroupName ?? throw new InvalidOperationException() } - ); + x.TagActionsBy(y => new List() + { + y.GroupName ?? throw new InvalidOperationException() + }); x.CustomSchemaIds(s => s.FullName?.Replace("+", ".")); }); builder.Services.AddCors(); -builder.Services - .AddMvc(opt => +builder + .Services.AddMvc(opt => { opt.Conventions.Add(new GroupByApiRootConvention()); opt.Filters.Add(typeof(ValidatorActionFilter)); opt.EnableEndpointRouting = false; }) - .AddJsonOptions( - opt => - opt.JsonSerializerOptions.DefaultIgnoreCondition = System - .Text - .Json - .Serialization - .JsonIgnoreCondition - .WhenWritingNull + .AddJsonOptions(opt => + opt.JsonSerializerOptions.DefaultIgnoreCondition = System + .Text + .Json + .Serialization + .JsonIgnoreCondition + .WhenWritingNull ); builder.Services.AddFluentValidationAutoValidation(); @@ -156,8 +156,8 @@ using (var scope = app.Services.CreateScope()) { - var dbContext = scope.ServiceProvider - .GetRequiredService() + var dbContext = scope + .ServiceProvider.GetRequiredService() .Database.EnsureCreated(); // use context } diff --git a/src/Conduit/Startup.cs b/src/Conduit/Startup.cs index e17b0571..24ce0f4f 100644 --- a/src/Conduit/Startup.cs +++ b/src/Conduit/Startup.cs @@ -32,13 +32,10 @@ public class Startup // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { - services.AddMediatR( - cfg => cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()) - ); - services.AddTransient( - typeof(IPipelineBehavior<,>), - typeof(ValidationPipelineBehavior<,>) + services.AddMediatR(cfg => + cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()) ); + services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationPipelineBehavior<,>)); services.AddScoped( typeof(IPipelineBehavior<,>), typeof(DBContextTransactionPipelineBehavior<,>) @@ -57,18 +54,18 @@ public void ConfigureServices(IServiceCollection services) { if ( databaseProvider - .ToLowerInvariant() - .Trim() - .Equals("sqlite", StringComparison.Ordinal) + .ToLowerInvariant() + .Trim() + .Equals("sqlite", StringComparison.Ordinal) ) { options.UseSqlite(connectionString); } else if ( databaseProvider - .ToLowerInvariant() - .Trim() - .Equals("sqlserver", StringComparison.Ordinal) + .ToLowerInvariant() + .Trim() + .Equals("sqlserver", StringComparison.Ordinal) ) { // only works in windows container @@ -120,9 +117,10 @@ public void ConfigureServices(IServiceCollection services) x.SwaggerDoc("v1", new OpenApiInfo { Title = "RealWorld API", Version = "v1" }); x.CustomSchemaIds(y => y.FullName); x.DocInclusionPredicate((version, apiDescription) => true); - x.TagActionsBy( - y => new List() { y.GroupName ?? throw new InvalidOperationException() } - ); + x.TagActionsBy(y => new List() + { + y.GroupName ?? throw new InvalidOperationException() + }); }); services.AddCors(); @@ -133,14 +131,13 @@ public void ConfigureServices(IServiceCollection services) opt.Filters.Add(typeof(ValidatorActionFilter)); opt.EnableEndpointRouting = false; }) - .AddJsonOptions( - opt => - opt.JsonSerializerOptions.DefaultIgnoreCondition = System - .Text - .Json - .Serialization - .JsonIgnoreCondition - .WhenWritingNull + .AddJsonOptions(opt => + opt.JsonSerializerOptions.DefaultIgnoreCondition = System + .Text + .Json + .Serialization + .JsonIgnoreCondition + .WhenWritingNull ); services.AddFluentValidationAutoValidation(); @@ -174,10 +171,8 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) app.UseSwagger(c => c.RouteTemplate = "swagger/{documentName}/swagger.json"); // Enable middleware to serve swagger-ui assets(HTML, JS, CSS etc.) - app.UseSwaggerUI( - x => x.SwaggerEndpoint("/swagger/v1/swagger.json", "RealWorld API V1") - ); + app.UseSwaggerUI(x => x.SwaggerEndpoint("/swagger/v1/swagger.json", "RealWorld API V1")); app.ApplicationServices.GetRequiredService().Database.EnsureCreated(); } -} \ No newline at end of file +} diff --git a/src/Conduit/StartupExtensions.cs b/src/Conduit/StartupExtensions.cs index 13690184..c74a391b 100644 --- a/src/Conduit/StartupExtensions.cs +++ b/src/Conduit/StartupExtensions.cs @@ -20,10 +20,7 @@ public static void AddJwt(this IServiceCollection services) var signingKey = new SymmetricSecurityKey( Encoding.ASCII.GetBytes("somethinglongerforthisdumbalgorithmisrequired") ); - var signingCredentials = new SigningCredentials( - signingKey, - SecurityAlgorithms.HmacSha256 - ); + var signingCredentials = new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256); var issuer = "issuer"; var audience = "audience"; @@ -61,9 +58,7 @@ public static void AddJwt(this IServiceCollection services) OnMessageReceived = (context) => { var token = context.HttpContext.Request.Headers.Authorization.ToString(); - if ( - token.StartsWith("Token ", StringComparison.OrdinalIgnoreCase) - ) + if (token.StartsWith("Token ", StringComparison.OrdinalIgnoreCase)) { context.Token = token["Token ".Length..].Trim(); } @@ -77,8 +72,8 @@ public static void AddJwt(this IServiceCollection services) public static void AddSerilogLogging(this ILoggerFactory loggerFactory) { // Attach the sink to the logger configuration - var log = new LoggerConfiguration().MinimumLevel - .Verbose() + var log = new LoggerConfiguration() + .MinimumLevel.Verbose() .Enrich.FromLogContext() //just for local debug .WriteTo.Console( diff --git a/tests/Conduit.IntegrationTests/Features/Articles/ArticleHelpers.cs b/tests/Conduit.IntegrationTests/Features/Articles/ArticleHelpers.cs index ab7c5149..52c90e92 100644 --- a/tests/Conduit.IntegrationTests/Features/Articles/ArticleHelpers.cs +++ b/tests/Conduit.IntegrationTests/Features/Articles/ArticleHelpers.cs @@ -37,16 +37,12 @@ Create.Command command new System.Threading.CancellationToken() ); - var dbArticle = await fixture.ExecuteDbContextAsync( - db => - db.Articles - .Where(a => a.ArticleId == created.Article.ArticleId) - .SingleOrDefaultAsync() + var dbArticle = await fixture.ExecuteDbContextAsync(db => + db.Articles.Where(a => a.ArticleId == created.Article.ArticleId).SingleOrDefaultAsync() ); if (dbArticle is null) { - throw new RestException(HttpStatusCode.NotFound, new {Article = Constants.NOT_FOUND}); - + throw new RestException(HttpStatusCode.NotFound, new { Article = Constants.NOT_FOUND }); } return dbArticle; diff --git a/tests/Conduit.IntegrationTests/Features/Articles/DeleteTests.cs b/tests/Conduit.IntegrationTests/Features/Articles/DeleteTests.cs index eed88add..97c6a5fc 100644 --- a/tests/Conduit.IntegrationTests/Features/Articles/DeleteTests.cs +++ b/tests/Conduit.IntegrationTests/Features/Articles/DeleteTests.cs @@ -33,8 +33,8 @@ public async Task Expect_Delete_Article() var articleDeleteHandler = new Delete.QueryHandler(dbContext); await articleDeleteHandler.Handle(deleteCmd, new System.Threading.CancellationToken()); - var dbArticle = await ExecuteDbContextAsync( - db => db.Articles.Where(d => d.Slug == deleteCmd.Slug).SingleOrDefaultAsync() + var dbArticle = await ExecuteDbContextAsync(db => + db.Articles.Where(d => d.Slug == deleteCmd.Slug).SingleOrDefaultAsync() ); Assert.Null(dbArticle); @@ -54,23 +54,21 @@ public async Task Expect_Delete_Article_With_Tags() ); var article = await ArticleHelpers.CreateArticle(this, createCmd); - var dbArticleWithTags = await ExecuteDbContextAsync( - db => - db.Articles - .Include(a => a.ArticleTags) - .Where(d => d.Slug == article.Slug) - .SingleOrDefaultAsync() + var dbArticleWithTags = await ExecuteDbContextAsync(db => + db.Articles.Include(a => a.ArticleTags) + .Where(d => d.Slug == article.Slug) + .SingleOrDefaultAsync() ); - var deleteCmd = new Delete.Command(article.Slug?? throw new InvalidOperationException()); + var deleteCmd = new Delete.Command(article.Slug ?? throw new InvalidOperationException()); var dbContext = GetDbContext(); var articleDeleteHandler = new Delete.QueryHandler(dbContext); await articleDeleteHandler.Handle(deleteCmd, new System.Threading.CancellationToken()); - var dbArticle = await ExecuteDbContextAsync( - db => db.Articles.Where(d => d.Slug == deleteCmd.Slug).SingleOrDefaultAsync() + var dbArticle = await ExecuteDbContextAsync(db => + db.Articles.Where(d => d.Slug == deleteCmd.Slug).SingleOrDefaultAsync() ); Assert.Null(dbArticle); } @@ -88,13 +86,12 @@ public async Task Expect_Delete_Article_With_Comments() ); var article = await ArticleHelpers.CreateArticle(this, createArticleCmd); - var dbArticle = await ExecuteDbContextAsync( - db => - db.Articles - .Include(a => a.ArticleTags) + var dbArticle = + await ExecuteDbContextAsync(db => + db.Articles.Include(a => a.ArticleTags) .Where(d => d.Slug == article.Slug) .SingleOrDefaultAsync() - ) ?? throw new InvalidOperationException(); + ) ?? throw new InvalidOperationException(); var articleId = dbArticle.ArticleId; var slug = dbArticle.Slug; @@ -102,7 +99,7 @@ public async Task Expect_Delete_Article_With_Comments() // create article comment var createCommentCmd = new Conduit.Features.Comments.Create.Command( new(new Conduit.Features.Comments.Create.CommentData("article comment")), - slug?? throw new InvalidOperationException() + slug ?? throw new InvalidOperationException() ); var comment = await CommentHelpers.CreateComment( @@ -119,8 +116,8 @@ public async Task Expect_Delete_Article_With_Comments() var articleDeleteHandler = new Delete.QueryHandler(dbContext); await articleDeleteHandler.Handle(deleteCmd, new System.Threading.CancellationToken()); - var deleted = await ExecuteDbContextAsync( - db => db.Articles.Where(d => d.Slug == deleteCmd.Slug).SingleOrDefaultAsync() + var deleted = await ExecuteDbContextAsync(db => + db.Articles.Where(d => d.Slug == deleteCmd.Slug).SingleOrDefaultAsync() ); Assert.Null(deleted); } diff --git a/tests/Conduit.IntegrationTests/Features/Articles/EditTests.cs b/tests/Conduit.IntegrationTests/Features/Articles/EditTests.cs index 46ef80e2..1ac62b68 100644 --- a/tests/Conduit.IntegrationTests/Features/Articles/EditTests.cs +++ b/tests/Conduit.IntegrationTests/Features/Articles/EditTests.cs @@ -25,8 +25,13 @@ public async Task Expect_Edit_Article() var command = new Edit.Command( new( - new Edit.ArticleData("Updated " + createdArticle.Title, "Updated " + createdArticle.Description, "Updated " + createdArticle.Body, - [createdArticle.TagList[1], "tag3"])), + new Edit.ArticleData( + "Updated " + createdArticle.Title, + "Updated " + createdArticle.Description, + "Updated " + createdArticle.Body, + [createdArticle.TagList[1], "tag3"] + ) + ), createdArticle.Slug ?? throw new InvalidOperationException() ); @@ -43,6 +48,6 @@ public async Task Expect_Edit_Article() Assert.Equal(edited.Article.TagList.Count, command.Model.Article.TagList?.Count() ?? 0); // use assert Contains because we do not know the order in which the tags are saved/retrieved Assert.Contains(edited.Article.TagList[0], command.Model.Article.TagList ?? []); - Assert.Contains(edited.Article.TagList[1], command.Model.Article.TagList?? []); + Assert.Contains(edited.Article.TagList[1], command.Model.Article.TagList ?? []); } } diff --git a/tests/Conduit.IntegrationTests/Features/Comments/CommentHelpers.cs b/tests/Conduit.IntegrationTests/Features/Comments/CommentHelpers.cs index 4b2fd8ec..5364a88f 100644 --- a/tests/Conduit.IntegrationTests/Features/Comments/CommentHelpers.cs +++ b/tests/Conduit.IntegrationTests/Features/Comments/CommentHelpers.cs @@ -46,28 +46,26 @@ string userName new System.Threading.CancellationToken() ); - var dbArticleWithComments = await fixture.ExecuteDbContextAsync( - db => - db.Articles - .Include(a => a.Comments) - .Include(a => a.Author) - .Where(a => a.Slug == command.Slug) - .SingleOrDefaultAsync() + var dbArticleWithComments = await fixture.ExecuteDbContextAsync(db => + db.Articles.Include(a => a.Comments) + .Include(a => a.Author) + .Where(a => a.Slug == command.Slug) + .SingleOrDefaultAsync() ); if (dbArticleWithComments is null) { - throw new RestException(HttpStatusCode.NotFound, new {Article = Constants.NOT_FOUND}); + throw new RestException(HttpStatusCode.NotFound, new { Article = Constants.NOT_FOUND }); } var dbComment = dbArticleWithComments.Comments.FirstOrDefault(c => - c.ArticleId == dbArticleWithComments.ArticleId - && c.Author == dbArticleWithComments.Author -); + c.ArticleId == dbArticleWithComments.ArticleId + && c.Author == dbArticleWithComments.Author + ); if (dbComment is null) { - throw new RestException(HttpStatusCode.NotFound, new {Article = Constants.NOT_FOUND}); + throw new RestException(HttpStatusCode.NotFound, new { Article = Constants.NOT_FOUND }); } return dbComment; diff --git a/tests/Conduit.IntegrationTests/Features/Users/CreateTests.cs b/tests/Conduit.IntegrationTests/Features/Users/CreateTests.cs index 9bec2334..d7a574e3 100644 --- a/tests/Conduit.IntegrationTests/Features/Users/CreateTests.cs +++ b/tests/Conduit.IntegrationTests/Features/Users/CreateTests.cs @@ -12,14 +12,12 @@ public class CreateTests : SliceFixture [Fact] public async Task Expect_Create_User() { - var command = new Create.Command( - new Create.UserData("username", "email", "password") - ); + var command = new Create.Command(new Create.UserData("username", "email", "password")); await SendAsync(command); - var created = await ExecuteDbContextAsync( - db => db.Persons.Where(d => d.Email == command.User.Email).SingleOrDefaultAsync() + var created = await ExecuteDbContextAsync(db => + db.Persons.Where(d => d.Email == command.User.Email).SingleOrDefaultAsync() ); Assert.NotNull(created); diff --git a/tests/Conduit.IntegrationTests/Features/Users/LoginTests.cs b/tests/Conduit.IntegrationTests/Features/Users/LoginTests.cs index 2783ed70..d0925448 100644 --- a/tests/Conduit.IntegrationTests/Features/Users/LoginTests.cs +++ b/tests/Conduit.IntegrationTests/Features/Users/LoginTests.cs @@ -33,4 +33,4 @@ public async Task Expect_Login() Assert.Equal("username", user.User.Username); Assert.NotNull(user.User.Token); } -} \ No newline at end of file +} diff --git a/tests/Conduit.IntegrationTests/Features/Users/UserHelpers.cs b/tests/Conduit.IntegrationTests/Features/Users/UserHelpers.cs index f445294e..edf10383 100644 --- a/tests/Conduit.IntegrationTests/Features/Users/UserHelpers.cs +++ b/tests/Conduit.IntegrationTests/Features/Users/UserHelpers.cs @@ -14,9 +14,7 @@ public static class UserHelpers /// public static async Task CreateDefaultUser(SliceFixture fixture) { - var command = new Create.Command( - new Create.UserData(DefaultUserName, "email", "password") - ); + var command = new Create.Command(new Create.UserData(DefaultUserName, "email", "password")); var commandResult = await fixture.SendAsync(command); return commandResult.User;