diff --git a/src/AuctionService/Consumers/AuctionCreatedFaultConsumer.cs b/src/AuctionService/Consumers/AuctionCreatedFaultConsumer.cs index 054ff4a..2b75eb4 100644 --- a/src/AuctionService/Consumers/AuctionCreatedFaultConsumer.cs +++ b/src/AuctionService/Consumers/AuctionCreatedFaultConsumer.cs @@ -3,7 +3,7 @@ namespace AuctionService.Consumers { - public class AuctionCreatedFaultConsumer : IConsumer> + public sealed class AuctionCreatedFaultConsumer : IConsumer> { public async Task Consume(ConsumeContext> context) { @@ -22,4 +22,4 @@ public async Task Consume(ConsumeContext> context) } } } -} \ No newline at end of file +} diff --git a/src/AuctionService/Consumers/AuctionFinishedConsumer.cs b/src/AuctionService/Consumers/AuctionFinishedConsumer.cs index 7061f3f..88a3745 100644 --- a/src/AuctionService/Consumers/AuctionFinishedConsumer.cs +++ b/src/AuctionService/Consumers/AuctionFinishedConsumer.cs @@ -5,7 +5,7 @@ namespace AuctionService.Consumers { - public class AuctionFinishedConsumer(AuctionContext dbContext) : IConsumer + public sealed class AuctionFinishedConsumer(AuctionContext dbContext) : IConsumer { public async Task Consume(ConsumeContext context) { @@ -25,4 +25,4 @@ public async Task Consume(ConsumeContext context) await dbContext.SaveChangesAsync(); } } -} \ No newline at end of file +} diff --git a/src/AuctionService/Consumers/BidPlacedConsumer.cs b/src/AuctionService/Consumers/BidPlacedConsumer.cs index 6bdfeda..1e856e1 100644 --- a/src/AuctionService/Consumers/BidPlacedConsumer.cs +++ b/src/AuctionService/Consumers/BidPlacedConsumer.cs @@ -5,7 +5,7 @@ namespace AuctionService.Consumers { - public class BidPlacedConsumer(AuctionContext dbContext) : IConsumer + public sealed class BidPlacedConsumer(AuctionContext dbContext) : IConsumer { public async Task Consume(ConsumeContext context) { @@ -22,4 +22,4 @@ public async Task Consume(ConsumeContext context) } } } -} \ No newline at end of file +} diff --git a/src/AuctionService/Contracts/AuctionCreated.cs b/src/AuctionService/Contracts/AuctionCreated.cs index 3b7789c..609b633 100644 --- a/src/AuctionService/Contracts/AuctionCreated.cs +++ b/src/AuctionService/Contracts/AuctionCreated.cs @@ -1,6 +1,6 @@ namespace Contracts { - public class AuctionCreated + public sealed class AuctionCreated { public Guid Id { get; set; } public int ReservePrice { get; set; } @@ -19,4 +19,4 @@ public class AuctionCreated public int Mileage { get; set; } public string ImageUrl { get; set; } = string.Empty; } -} \ No newline at end of file +} diff --git a/src/AuctionService/Contracts/AuctionDeleted.cs b/src/AuctionService/Contracts/AuctionDeleted.cs index 6a7166f..9d44170 100644 --- a/src/AuctionService/Contracts/AuctionDeleted.cs +++ b/src/AuctionService/Contracts/AuctionDeleted.cs @@ -1,7 +1,7 @@ namespace Contracts { - public class AuctionDeleted + public sealed class AuctionDeleted { public string? Id { get; set; } } -} \ No newline at end of file +} diff --git a/src/AuctionService/Contracts/AuctionFinished.cs b/src/AuctionService/Contracts/AuctionFinished.cs index ee5c2ea..ef96b3c 100644 --- a/src/AuctionService/Contracts/AuctionFinished.cs +++ b/src/AuctionService/Contracts/AuctionFinished.cs @@ -1,6 +1,6 @@ namespace AuctionService.Contracts { - public class AuctionFinished + public sealed class AuctionFinished { public bool ItemSold { get; set; } public string? AuctionId { get; set; } @@ -8,4 +8,4 @@ public class AuctionFinished public string? Seller { get; set; } public int? Amount { get; set; } } -} \ No newline at end of file +} diff --git a/src/AuctionService/Contracts/AuctionUpdated.cs b/src/AuctionService/Contracts/AuctionUpdated.cs index 89573dc..69a4f09 100644 --- a/src/AuctionService/Contracts/AuctionUpdated.cs +++ b/src/AuctionService/Contracts/AuctionUpdated.cs @@ -1,6 +1,6 @@ namespace Contracts { - public class AuctionUpdated + public sealed class AuctionUpdated { public string? Id { get; set; } public string? Make { get; set; } @@ -9,4 +9,4 @@ public class AuctionUpdated public string? Color { get; set; } public int Mileage { get; set; } } -} \ No newline at end of file +} diff --git a/src/AuctionService/Contracts/BidPlaced.cs b/src/AuctionService/Contracts/BidPlaced.cs index bda31ae..5310878 100644 --- a/src/AuctionService/Contracts/BidPlaced.cs +++ b/src/AuctionService/Contracts/BidPlaced.cs @@ -1,6 +1,6 @@ namespace AuctionService.Contracts { - public class BidPlaced + public sealed class BidPlaced { public string? Id { get; set; } public string? AuctionId { get; set; } @@ -9,4 +9,4 @@ public class BidPlaced public int Amount { get; set; } public string? BidStatus { get; set; } } -} \ No newline at end of file +} diff --git a/src/AuctionService/Controllers/AuctionsController.cs b/src/AuctionService/Controllers/AuctionsController.cs index 333a207..95b975b 100644 --- a/src/AuctionService/Controllers/AuctionsController.cs +++ b/src/AuctionService/Controllers/AuctionsController.cs @@ -11,7 +11,7 @@ namespace AuctionService.Controllers { [ApiController] [Route("api/[controller]")] - public class AuctionsController(IMapper mapper, IPublishEndpoint publishEndpoint, + public sealed class AuctionsController(IMapper mapper, IPublishEndpoint publishEndpoint, IAuctionRepository auctionRepository) : ControllerBase { [HttpGet] @@ -90,4 +90,4 @@ public async Task DeleteAuction(Guid id) return success ? Ok() : BadRequest("Could not update the database."); } } -} \ No newline at end of file +} diff --git a/src/AuctionService/Data/AuctionContext.cs b/src/AuctionService/Data/AuctionContext.cs index ed039e4..829a1b4 100644 --- a/src/AuctionService/Data/AuctionContext.cs +++ b/src/AuctionService/Data/AuctionContext.cs @@ -4,11 +4,11 @@ namespace AuctionService.Data { - public class AuctionContext(DbContextOptions options) : DbContext(options) + public sealed class AuctionContext(DbContextOptions options) : DbContext(options) { public DbSet Auctions { get; set; } - protected override void OnModelCreating(ModelBuilder modelBuilder) + protected sealed override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); @@ -17,4 +17,4 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.AddOutboxStateEntity(); } } -} \ No newline at end of file +} diff --git a/src/AuctionService/Data/DbInitializer.cs b/src/AuctionService/Data/DbInitializer.cs index 67166e9..7556bf9 100644 --- a/src/AuctionService/Data/DbInitializer.cs +++ b/src/AuctionService/Data/DbInitializer.cs @@ -3,7 +3,7 @@ namespace AuctionService.Data { - public class DbInitializer + public sealed class DbInitializer { public static void InitDb(WebApplication app) { @@ -210,4 +210,4 @@ public static List GetDbAuctions() => } ]; } -} \ No newline at end of file +} diff --git a/src/AuctionService/Dtos/AuctionDto.cs b/src/AuctionService/Dtos/AuctionDto.cs index 0c3f637..20b4736 100644 --- a/src/AuctionService/Dtos/AuctionDto.cs +++ b/src/AuctionService/Dtos/AuctionDto.cs @@ -1,6 +1,6 @@ namespace AuctionService.Dtos { - public class AuctionDto + public sealed class AuctionDto { public Guid Id { get; set; } public int ReservePrice { get; set; } @@ -19,4 +19,4 @@ public class AuctionDto public int Mileage { get; set; } public string ImageUrl { get; set; } = string.Empty; } -} \ No newline at end of file +} diff --git a/src/AuctionService/Dtos/CreateAuctionDto.cs b/src/AuctionService/Dtos/CreateAuctionDto.cs index 575456d..ed975dd 100644 --- a/src/AuctionService/Dtos/CreateAuctionDto.cs +++ b/src/AuctionService/Dtos/CreateAuctionDto.cs @@ -2,7 +2,7 @@ namespace AuctionService.Dtos { - public class CreateAuctionDto + public sealed class CreateAuctionDto { [Required] public string? Make { get; set; } @@ -28,4 +28,4 @@ public class CreateAuctionDto [Required] public DateTime AuctionEnd { get; set; } } -} \ No newline at end of file +} diff --git a/src/AuctionService/Dtos/UpdateAuctionDto.cs b/src/AuctionService/Dtos/UpdateAuctionDto.cs index 4d76e19..05b3475 100644 --- a/src/AuctionService/Dtos/UpdateAuctionDto.cs +++ b/src/AuctionService/Dtos/UpdateAuctionDto.cs @@ -1,6 +1,6 @@ namespace AuctionService.Dtos { - public class UpdateAuctionDto + public sealed class UpdateAuctionDto { public string? Make { get; set; } public string? Model { get; set; } @@ -8,4 +8,4 @@ public class UpdateAuctionDto public string? Color { get; set; } public int? Mileage { get; set; } } -} \ No newline at end of file +} diff --git a/src/AuctionService/Entities/Auction.cs b/src/AuctionService/Entities/Auction.cs index 0d7c6ab..24bc3be 100644 --- a/src/AuctionService/Entities/Auction.cs +++ b/src/AuctionService/Entities/Auction.cs @@ -1,6 +1,6 @@ namespace AuctionService.Entities { - public class Auction + public sealed class Auction { public Guid Id { get; set; } public int ReservePrice { get; set; } @@ -16,4 +16,4 @@ public class Auction public bool HasReservePrice() => ReservePrice > 0; } -} \ No newline at end of file +} diff --git a/src/AuctionService/Entities/Item.cs b/src/AuctionService/Entities/Item.cs index d407c25..1649223 100644 --- a/src/AuctionService/Entities/Item.cs +++ b/src/AuctionService/Entities/Item.cs @@ -3,7 +3,7 @@ namespace AuctionService.Entities { [Table("Items")] - public class Item + public sealed class Item { public Guid Id { get; set; } public string Make { get; set; } = string.Empty; @@ -17,4 +17,4 @@ public class Item public Auction? Auction { get; set; } public Guid AuctionId { get; set; } } -} \ No newline at end of file +} diff --git a/src/AuctionService/Entities/Status.cs b/src/AuctionService/Entities/Status.cs index 988fdf3..46d2302 100644 --- a/src/AuctionService/Entities/Status.cs +++ b/src/AuctionService/Entities/Status.cs @@ -6,4 +6,4 @@ public enum Status Finished, ReserveNotMet } -} \ No newline at end of file +} diff --git a/src/AuctionService/Program.cs b/src/AuctionService/Program.cs index 2f9d692..fd9452b 100644 --- a/src/AuctionService/Program.cs +++ b/src/AuctionService/Program.cs @@ -79,4 +79,4 @@ /// /// Represents the entry point for the AuctionService program. /// -public partial class Program {} +public sealed partial class Program {} diff --git a/src/AuctionService/Repositories/AuctionRepository.cs b/src/AuctionService/Repositories/AuctionRepository.cs index 1e51f1c..b72eeb3 100644 --- a/src/AuctionService/Repositories/AuctionRepository.cs +++ b/src/AuctionService/Repositories/AuctionRepository.cs @@ -7,7 +7,7 @@ namespace AuctionService.Repositories { - public class AuctionRepository(AuctionContext context, IMapper mapper) : IAuctionRepository + public sealed class AuctionRepository(AuctionContext context, IMapper mapper) : IAuctionRepository { public void AddAuction(Auction request) => context.Auctions.Add(request); @@ -36,4 +36,4 @@ public async Task> GetAuctionsAsync(string request) public async Task SaveChangesAsync() => await context.SaveChangesAsync() > 0; } -} \ No newline at end of file +} diff --git a/src/AuctionService/Repositories/IAuctionRepository.cs b/src/AuctionService/Repositories/IAuctionRepository.cs index f78492b..4eb8201 100644 --- a/src/AuctionService/Repositories/IAuctionRepository.cs +++ b/src/AuctionService/Repositories/IAuctionRepository.cs @@ -12,4 +12,4 @@ public interface IAuctionRepository void RemoveAuction(Auction request); Task SaveChangesAsync(); } -} \ No newline at end of file +} diff --git a/src/AuctionService/RequestHelpers/MappingProfiles.cs b/src/AuctionService/RequestHelpers/MappingProfiles.cs index 4da2a23..0b9d516 100644 --- a/src/AuctionService/RequestHelpers/MappingProfiles.cs +++ b/src/AuctionService/RequestHelpers/MappingProfiles.cs @@ -5,7 +5,7 @@ namespace AuctionService.RequestHelpers { - public class MappingProfiles : Profile + public sealed class MappingProfiles : Profile { public MappingProfiles() { @@ -22,4 +22,4 @@ public MappingProfiles() CreateMap(); } } -} \ No newline at end of file +} diff --git a/src/AuctionService/Services/GrpcAuctionService.cs b/src/AuctionService/Services/GrpcAuctionService.cs index 4fa4d54..4b058ba 100644 --- a/src/AuctionService/Services/GrpcAuctionService.cs +++ b/src/AuctionService/Services/GrpcAuctionService.cs @@ -3,9 +3,9 @@ namespace AuctionService.Services { - public class GrpcAuctionService(AuctionContext dbContext) : GrpcAuction.GrpcAuctionBase + public sealed class GrpcAuctionService(AuctionContext dbContext) : GrpcAuction.GrpcAuctionBase { - public override async Task GetAuction(GetAuctionRequest request, ServerCallContext context) + public sealed override async Task GetAuction(GetAuctionRequest request, ServerCallContext context) { Console.WriteLine("==> Recieved gRPC request for auction"); @@ -26,4 +26,4 @@ public override async Task GetAuction(GetAuctionRequest req return response; } } -} \ No newline at end of file +} diff --git a/src/BiddingService/Consumers/AuctionCreatedConsumer.cs b/src/BiddingService/Consumers/AuctionCreatedConsumer.cs index 83a9e37..292ff59 100644 --- a/src/BiddingService/Consumers/AuctionCreatedConsumer.cs +++ b/src/BiddingService/Consumers/AuctionCreatedConsumer.cs @@ -5,7 +5,7 @@ namespace BiddingService.Consumers { - public class AuctionCreatedConsumer : IConsumer + public sealed class AuctionCreatedConsumer : IConsumer { public async Task Consume(ConsumeContext context) { @@ -20,4 +20,4 @@ public async Task Consume(ConsumeContext context) await auction.SaveAsync(); } } -} \ No newline at end of file +} diff --git a/src/BiddingService/Contracts/AuctionCreated.cs b/src/BiddingService/Contracts/AuctionCreated.cs index 8779564..30f4690 100644 --- a/src/BiddingService/Contracts/AuctionCreated.cs +++ b/src/BiddingService/Contracts/AuctionCreated.cs @@ -1,6 +1,6 @@ namespace BiddingService.Contracts { - public class AuctionCreated + public sealed class AuctionCreated { public Guid Id { get; set; } public int ReservePrice { get; set; } @@ -19,4 +19,4 @@ public class AuctionCreated public int Mileage { get; set; } public string ImageUrl { get; set; } = string.Empty; } -} \ No newline at end of file +} diff --git a/src/BiddingService/Contracts/AuctionDeleted.cs b/src/BiddingService/Contracts/AuctionDeleted.cs index f6c1305..a835f7b 100644 --- a/src/BiddingService/Contracts/AuctionDeleted.cs +++ b/src/BiddingService/Contracts/AuctionDeleted.cs @@ -1,7 +1,7 @@ namespace BiddingService.Contracts { - public class AuctionDeleted + public sealed class AuctionDeleted { public string? Id { get; set; } } -} \ No newline at end of file +} diff --git a/src/BiddingService/Contracts/AuctionFinished.cs b/src/BiddingService/Contracts/AuctionFinished.cs index cb8bac3..cc996d7 100644 --- a/src/BiddingService/Contracts/AuctionFinished.cs +++ b/src/BiddingService/Contracts/AuctionFinished.cs @@ -1,6 +1,6 @@ namespace BiddingService.Contracts { - public class AuctionFinished + public sealed class AuctionFinished { public bool ItemSold { get; set; } public string? AuctionId { get; set; } @@ -8,4 +8,4 @@ public class AuctionFinished public string? Seller { get; set; } public int? Amount { get; set; } } -} \ No newline at end of file +} diff --git a/src/BiddingService/Contracts/AuctionUpdated.cs b/src/BiddingService/Contracts/AuctionUpdated.cs index c4a037b..1d65f55 100644 --- a/src/BiddingService/Contracts/AuctionUpdated.cs +++ b/src/BiddingService/Contracts/AuctionUpdated.cs @@ -1,6 +1,6 @@ namespace BiddingService.Contracts { - public class AuctionUpdated + public sealed class AuctionUpdated { public string? Id { get; set; } public string? Make { get; set; } @@ -9,4 +9,4 @@ public class AuctionUpdated public string? Color { get; set; } public int Mileage { get; set; } } -} \ No newline at end of file +} diff --git a/src/BiddingService/Contracts/BidPlaced.cs b/src/BiddingService/Contracts/BidPlaced.cs index 5608ace..8bd015c 100644 --- a/src/BiddingService/Contracts/BidPlaced.cs +++ b/src/BiddingService/Contracts/BidPlaced.cs @@ -1,6 +1,6 @@ namespace BiddingService.Contracts { - public class BidPlaced + public sealed class BidPlaced { public string? Id { get; set; } public string? AuctionId { get; set; } @@ -9,4 +9,4 @@ public class BidPlaced public int Amount { get; set; } public string? BidStatus { get; set; } } -} \ No newline at end of file +} diff --git a/src/BiddingService/Controllers/BidsController.cs b/src/BiddingService/Controllers/BidsController.cs index 85b4c46..7144018 100644 --- a/src/BiddingService/Controllers/BidsController.cs +++ b/src/BiddingService/Controllers/BidsController.cs @@ -12,7 +12,7 @@ namespace BiddingService.Controllers { [ApiController] [Route("api/[controller]")] - public class BidsController(IMapper mapper, IPublishEndpoint publishEndpoint, + public sealed class BidsController(IMapper mapper, IPublishEndpoint publishEndpoint, GrpcAuctionClient grpcClient) : ControllerBase { [HttpPost, Authorize] @@ -73,4 +73,4 @@ public async Task>> GetBidsForAuction(string auctionId return bids.Select(mapper.Map).ToList(); } } -} \ No newline at end of file +} diff --git a/src/BiddingService/Dtos/BidDto.cs b/src/BiddingService/Dtos/BidDto.cs index 32473e2..c863b8c 100644 --- a/src/BiddingService/Dtos/BidDto.cs +++ b/src/BiddingService/Dtos/BidDto.cs @@ -1,6 +1,6 @@ namespace BiddingService.Dtos { - public class BidDto + public sealed class BidDto { public string? Id { get; set; } public string? AuctionId { get; set; } @@ -9,4 +9,4 @@ public class BidDto public int Amount { get; set; } public string? BidStatus { get; set; } } -} \ No newline at end of file +} diff --git a/src/BiddingService/Models/Auction.cs b/src/BiddingService/Models/Auction.cs index e756fad..1120532 100644 --- a/src/BiddingService/Models/Auction.cs +++ b/src/BiddingService/Models/Auction.cs @@ -2,11 +2,11 @@ namespace BiddingService.Models { - public class Auction : Entity + public sealed class Auction : Entity { public DateTime AuctionEnd { get; set; } public string? Seller { get; set; } public int ReservePrice { get; set; } public bool Finished { get; set; } } -} \ No newline at end of file +} diff --git a/src/BiddingService/Models/Bid.cs b/src/BiddingService/Models/Bid.cs index dd38fea..6040245 100644 --- a/src/BiddingService/Models/Bid.cs +++ b/src/BiddingService/Models/Bid.cs @@ -2,7 +2,7 @@ namespace BiddingService.Models { - public class Bid : Entity + public sealed class Bid : Entity { public string? AuctionId { get; set; } public string? Bidder { get; set; } @@ -10,4 +10,4 @@ public class Bid : Entity public int Amount { get; set; } public BidStatus BidStatus { get; set; } } -} \ No newline at end of file +} diff --git a/src/BiddingService/Models/BidStatus.cs b/src/BiddingService/Models/BidStatus.cs index 7d8bf2b..397bee7 100644 --- a/src/BiddingService/Models/BidStatus.cs +++ b/src/BiddingService/Models/BidStatus.cs @@ -7,4 +7,4 @@ public enum BidStatus TooLow, Finished } -} \ No newline at end of file +} diff --git a/src/BiddingService/RequestHelpers/MappingProfiles.cs b/src/BiddingService/RequestHelpers/MappingProfiles.cs index d007703..8e956c4 100644 --- a/src/BiddingService/RequestHelpers/MappingProfiles.cs +++ b/src/BiddingService/RequestHelpers/MappingProfiles.cs @@ -5,7 +5,7 @@ namespace BiddingService.RequestHelpers { - public class MappingProfiles : Profile + public sealed class MappingProfiles : Profile { public MappingProfiles() { @@ -13,4 +13,4 @@ public MappingProfiles() CreateMap(); } } -} \ No newline at end of file +} diff --git a/src/BiddingService/Services/CheckAuctionFinished.cs b/src/BiddingService/Services/CheckAuctionFinished.cs index d10836f..1949460 100644 --- a/src/BiddingService/Services/CheckAuctionFinished.cs +++ b/src/BiddingService/Services/CheckAuctionFinished.cs @@ -5,9 +5,10 @@ namespace BiddingService.Services { - public class CheckAuctionFinished(ILogger logger, IServiceProvider services) : BackgroundService + public sealed class CheckAuctionFinished(ILogger logger, + IServiceProvider services) : BackgroundService { - protected override async Task ExecuteAsync(CancellationToken stoppingToken) + protected sealed override async Task ExecuteAsync(CancellationToken stoppingToken) { logger.LogInformation("Starting check for finished auctions"); @@ -57,4 +58,4 @@ await endpoint.Publish(new AuctionFinished } } } -} \ No newline at end of file +} diff --git a/src/BiddingService/Services/GrpcAuctionClient.cs b/src/BiddingService/Services/GrpcAuctionClient.cs index 10edf7e..3b5db22 100644 --- a/src/BiddingService/Services/GrpcAuctionClient.cs +++ b/src/BiddingService/Services/GrpcAuctionClient.cs @@ -4,7 +4,7 @@ namespace BiddingService.Services { - public class GrpcAuctionClient(ILogger logger, IConfiguration config) + public sealed class GrpcAuctionClient(ILogger logger, IConfiguration config) { public Auction GetAuction(string id) { @@ -37,4 +37,4 @@ public Auction GetAuction(string id) } } } -} \ No newline at end of file +} diff --git a/src/IdentityService/Config.cs b/src/IdentityService/Config.cs index ecfe36d..acbc4ae 100644 --- a/src/IdentityService/Config.cs +++ b/src/IdentityService/Config.cs @@ -1,47 +1,48 @@ using Duende.IdentityServer.Models; -namespace IdentityService; - -public static class Config +namespace IdentityService { - public static IEnumerable IdentityResources => - [ - new IdentityResources.OpenId(), - new IdentityResources.Profile(), - ]; + public static class Config + { + public static IEnumerable IdentityResources => + [ + new IdentityResources.OpenId(), + new IdentityResources.Profile(), + ]; - public static IEnumerable ApiScopes => - [ - new("auctionApp", "Auction app full access"), - ]; + public static IEnumerable ApiScopes => + [ + new("auctionApp", "Auction app full access"), + ]; - public static IEnumerable Clients(IConfiguration config) => - [ - // interactive client using code flow + pkce - new() - { - ClientId = "postman", - ClientName = "Postman", - AllowedScopes = { "openid", "profile", "auctionApp" }, - RedirectUris = { "https://www.getpostman.com/oauth2/callback" }, - ClientSecrets = - [ - new Secret("NotASecret".Sha256()) - ], - AllowedGrantTypes = { GrantType.ResourceOwnerPassword } - }, - new() - { - ClientId = "nextApp", - ClientName = "nextApp", - ClientSecrets = { new Secret("secret".Sha256())}, - AllowedGrantTypes = GrantTypes.CodeAndClientCredentials, - RequirePkce = false, - RedirectUris = { config["ClientApp"] + "/api/auth/callback/id-server" }, - AllowOfflineAccess = true, - AllowedScopes = { "openid", "profile", "auctionApp" }, - AccessTokenLifetime = 3600*24*30, - AlwaysIncludeUserClaimsInIdToken = true - } - ]; + public static IEnumerable Clients(IConfiguration config) => + [ + // interactive client using code flow + pkce + new() + { + ClientId = "postman", + ClientName = "Postman", + AllowedScopes = { "openid", "profile", "auctionApp" }, + RedirectUris = { "https://www.getpostman.com/oauth2/callback" }, + ClientSecrets = + [ + new Secret("NotASecret".Sha256()) + ], + AllowedGrantTypes = { GrantType.ResourceOwnerPassword } + }, + new() + { + ClientId = "nextApp", + ClientName = "nextApp", + ClientSecrets = { new Secret("secret".Sha256())}, + AllowedGrantTypes = GrantTypes.CodeAndClientCredentials, + RequirePkce = false, + RedirectUris = { config["ClientApp"] + "/api/auth/callback/id-server" }, + AllowOfflineAccess = true, + AllowedScopes = { "openid", "profile", "auctionApp" }, + AccessTokenLifetime = 3600*24*30, + AlwaysIncludeUserClaimsInIdToken = true + } + ]; + } } diff --git a/src/IdentityService/Data/ApplicationDbContext.cs b/src/IdentityService/Data/ApplicationDbContext.cs index 00824bd..3196d9b 100644 --- a/src/IdentityService/Data/ApplicationDbContext.cs +++ b/src/IdentityService/Data/ApplicationDbContext.cs @@ -2,15 +2,17 @@ using Microsoft.EntityFrameworkCore; using IdentityService.Models; -namespace IdentityService.Data; - -public class ApplicationDbContext(DbContextOptions options) : IdentityDbContext(options) +namespace IdentityService.Data { - protected override void OnModelCreating(ModelBuilder builder) + public sealed class ApplicationDbContext(DbContextOptions options) + : IdentityDbContext(options) { - base.OnModelCreating(builder); - // Customize the ASP.NET Identity model and override the defaults if needed. - // For example, you can rename the ASP.NET Identity table names and more. - // Add your customizations after calling base.OnModelCreating(builder); + protected sealed override void OnModelCreating(ModelBuilder builder) + { + base.OnModelCreating(builder); + // Customize the ASP.NET Identity model and override the defaults if needed. + // For example, you can rename the ASP.NET Identity table names and more. + // Add your customizations after calling base.OnModelCreating(builder); + } } } diff --git a/src/IdentityService/HostingExtensions.cs b/src/IdentityService/HostingExtensions.cs index e416fc3..bcde47c 100644 --- a/src/IdentityService/HostingExtensions.cs +++ b/src/IdentityService/HostingExtensions.cs @@ -5,69 +5,70 @@ using Microsoft.EntityFrameworkCore; using Serilog; -namespace IdentityService; - -internal static class HostingExtensions +namespace IdentityService { - public static WebApplication ConfigureServices(this WebApplicationBuilder builder) + internal static class HostingExtensions { - builder.Services.AddRazorPages(); + public static WebApplication ConfigureServices(this WebApplicationBuilder builder) + { + builder.Services.AddRazorPages(); - builder.Services.AddDbContext(options => - options.UseNpgsql(builder.Configuration.GetConnectionString("Default"))); + builder.Services.AddDbContext(options => + options.UseNpgsql(builder.Configuration.GetConnectionString("Default"))); - builder.Services.AddIdentity() - .AddEntityFrameworkStores() - .AddDefaultTokenProviders(); + builder.Services.AddIdentity() + .AddEntityFrameworkStores() + .AddDefaultTokenProviders(); - builder.Services - .AddIdentityServer(options => - { - options.Events.RaiseErrorEvents = true; - options.Events.RaiseInformationEvents = true; - options.Events.RaiseFailureEvents = true; - options.Events.RaiseSuccessEvents = true; - - // Sets the issuer URI to identity-svc when running in Docker. - if (builder.Environment.IsEnvironment("Docker")) - options.IssuerUri = "identity-svc"; + builder.Services + .AddIdentityServer(options => + { + options.Events.RaiseErrorEvents = true; + options.Events.RaiseInformationEvents = true; + options.Events.RaiseFailureEvents = true; + options.Events.RaiseSuccessEvents = true; + + // Sets the issuer URI to identity-svc when running in Docker. + if (builder.Environment.IsEnvironment("Docker")) + options.IssuerUri = "identity-svc"; - // see https://docs.duendesoftware.com/identityserver/v6/fundamentals/resources/ - // options.EmitStaticAudienceClaim = true; - }) - .AddInMemoryIdentityResources(Config.IdentityResources) - .AddInMemoryApiScopes(Config.ApiScopes) - .AddInMemoryClients(Config.Clients(builder.Configuration)) - .AddAspNetIdentity() - .AddProfileService(); + // see https://docs.duendesoftware.com/identityserver/v6/fundamentals/resources/ + // options.EmitStaticAudienceClaim = true; + }) + .AddInMemoryIdentityResources(Config.IdentityResources) + .AddInMemoryApiScopes(Config.ApiScopes) + .AddInMemoryClients(Config.Clients(builder.Configuration)) + .AddAspNetIdentity() + .AddProfileService(); - builder.Services.ConfigureApplicationCookie(options => - { - options.Cookie.SameSite = SameSiteMode.Lax; - }); - - builder.Services.AddAuthentication(); + builder.Services.ConfigureApplicationCookie(options => + { + options.Cookie.SameSite = SameSiteMode.Lax; + }); + + builder.Services.AddAuthentication(); - return builder.Build(); - } - - public static WebApplication ConfigurePipeline(this WebApplication app) - { - app.UseSerilogRequestLogging(); - - if (app.Environment.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); + return builder.Build(); } - - app.UseStaticFiles(); - app.UseRouting(); - app.UseIdentityServer(); - app.UseAuthorization(); - app.MapRazorPages() - .RequireAuthorization(); + public static WebApplication ConfigurePipeline(this WebApplication app) + { + app.UseSerilogRequestLogging(); + + if (app.Environment.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseStaticFiles(); + app.UseRouting(); + app.UseIdentityServer(); + app.UseAuthorization(); + + app.MapRazorPages() + .RequireAuthorization(); - return app; + return app; + } } -} \ No newline at end of file +} diff --git a/src/IdentityService/Models/ApplicationUser.cs b/src/IdentityService/Models/ApplicationUser.cs index 5156969..2ca004c 100644 --- a/src/IdentityService/Models/ApplicationUser.cs +++ b/src/IdentityService/Models/ApplicationUser.cs @@ -4,9 +4,9 @@ using Microsoft.AspNetCore.Identity; -namespace IdentityService.Models; - -// Add profile data for application users by adding properties to the ApplicationUser class -public class ApplicationUser : IdentityUser +namespace IdentityService.Models { + + // Add profile data for application users by adding properties to the ApplicationUser class + public sealed class ApplicationUser : IdentityUser { } } diff --git a/src/IdentityService/Program.cs b/src/IdentityService/Program.cs index eebdc3d..abd89bf 100644 --- a/src/IdentityService/Program.cs +++ b/src/IdentityService/Program.cs @@ -41,4 +41,4 @@ { Log.Information("Shut down complete"); Log.CloseAndFlush(); -} \ No newline at end of file +} diff --git a/src/IdentityService/SeedData.cs b/src/IdentityService/SeedData.cs index 9fb7767..d5e8696 100644 --- a/src/IdentityService/SeedData.cs +++ b/src/IdentityService/SeedData.cs @@ -5,64 +5,77 @@ using Microsoft.EntityFrameworkCore; using Serilog; -namespace IdentityService; - -public class SeedData +namespace IdentityService { - public static void EnsureSeedData(WebApplication app) + public sealed class SeedData { - using IServiceScope scope = app.Services.GetRequiredService().CreateScope(); - ApplicationDbContext context = scope.ServiceProvider.GetService(); - context.Database.Migrate(); + public static void EnsureSeedData(WebApplication app) + { + using IServiceScope scope = app.Services.GetRequiredService().CreateScope(); + ApplicationDbContext context = scope.ServiceProvider.GetService(); + context.Database.Migrate(); - UserManager userMgr = scope.ServiceProvider.GetRequiredService>(); + UserManager userMgr = scope.ServiceProvider.GetRequiredService>(); - if (userMgr.Users.Any()) return; + if (userMgr.Users.Any()) return; - ApplicationUser alice = userMgr.FindByNameAsync("alice").Result; - if (alice is null) - { - alice = new ApplicationUser + ApplicationUser alice = userMgr.FindByNameAsync("alice").Result; + if (alice is null) { - UserName = "alice", - Email = "AliceSmith@email.com", - EmailConfirmed = true, - }; - IdentityResult result = userMgr.CreateAsync(alice, "Pass123$").Result; - if (!result.Succeeded) - throw new Exception(result.Errors.First().Description); + alice = new ApplicationUser + { + UserName = "alice", + Email = "AliceSmith@email.com", + EmailConfirmed = true, + }; + IdentityResult result = userMgr.CreateAsync(alice, "Pass123$").Result; + if (!result.Succeeded) + { + throw new Exception(result.Errors.First().Description); + } - result = userMgr.AddClaimsAsync(alice, [ - new(JwtClaimTypes.Name, "Alice Smith"), - ]).Result; - if (!result.Succeeded) - throw new Exception(result.Errors.First().Description); - Log.Debug("alice created"); - } - else - Log.Debug("alice already exists"); + result = userMgr.AddClaimsAsync(alice, [ + new(JwtClaimTypes.Name, "Alice Smith"), + ]).Result; + if (!result.Succeeded) + { + throw new Exception(result.Errors.First().Description); + } + Log.Debug("alice created"); + } + else + { + Log.Debug("alice already exists"); + } - ApplicationUser bob = userMgr.FindByNameAsync("bob").Result; - if (bob is null) - { - bob = new ApplicationUser + ApplicationUser bob = userMgr.FindByNameAsync("bob").Result; + if (bob is null) { - UserName = "bob", - Email = "BobSmith@email.com", - EmailConfirmed = true - }; - IdentityResult result = userMgr.CreateAsync(bob, "Pass123$").Result; - if (!result.Succeeded) - throw new Exception(result.Errors.First().Description); + bob = new ApplicationUser + { + UserName = "bob", + Email = "BobSmith@email.com", + EmailConfirmed = true + }; + IdentityResult result = userMgr.CreateAsync(bob, "Pass123$").Result; + if (!result.Succeeded) + { + throw new Exception(result.Errors.First().Description); + } - result = userMgr.AddClaimsAsync(bob, [ - new(JwtClaimTypes.Name, "Bob Smith") - ]).Result; - if (!result.Succeeded) - throw new Exception(result.Errors.First().Description); - Log.Debug("bob created"); + result = userMgr.AddClaimsAsync(bob, [ + new(JwtClaimTypes.Name, "Bob Smith") + ]).Result; + if (!result.Succeeded) + { + throw new Exception(result.Errors.First().Description); + } + Log.Debug("bob created"); + } + else + { + Log.Debug("bob already exists"); + } } - else - Log.Debug("bob already exists"); } -} \ No newline at end of file +} diff --git a/src/IdentityService/Services/CustomProfileService.cs b/src/IdentityService/Services/CustomProfileService.cs index 1f0136b..306e416 100644 --- a/src/IdentityService/Services/CustomProfileService.cs +++ b/src/IdentityService/Services/CustomProfileService.cs @@ -7,7 +7,7 @@ namespace IdentityService.Services { - public class CustomProfileService(UserManager userManager) : IProfileService + public sealed class CustomProfileService(UserManager userManager) : IProfileService { public async Task GetProfileDataAsync(ProfileDataRequestContext context) { diff --git a/src/NotificationService/Consumers/AuctionCreatedConsumer.cs b/src/NotificationService/Consumers/AuctionCreatedConsumer.cs index d607556..cabc0ef 100644 --- a/src/NotificationService/Consumers/AuctionCreatedConsumer.cs +++ b/src/NotificationService/Consumers/AuctionCreatedConsumer.cs @@ -1,6 +1,6 @@ namespace NotificationService.Consumers { - public class AuctionCreatedConsumer(IHubContext hubContext) : IConsumer + public sealed class AuctionCreatedConsumer(IHubContext hubContext) : IConsumer { public async Task Consume(ConsumeContext context) { @@ -9,4 +9,4 @@ public async Task Consume(ConsumeContext context) await hubContext.Clients.All.SendAsync("AuctionCreated", context.Message); } } -} \ No newline at end of file +} diff --git a/src/NotificationService/Consumers/AuctionFinishedConsumer.cs b/src/NotificationService/Consumers/AuctionFinishedConsumer.cs index 6ecec3d..8ffc788 100644 --- a/src/NotificationService/Consumers/AuctionFinishedConsumer.cs +++ b/src/NotificationService/Consumers/AuctionFinishedConsumer.cs @@ -1,6 +1,6 @@ namespace NotificationService.Consumers { - public class AuctionFinishedConsumer(IHubContext hubContext) : IConsumer + public sealed class AuctionFinishedConsumer(IHubContext hubContext) : IConsumer { public async Task Consume(ConsumeContext context) { @@ -9,4 +9,4 @@ public async Task Consume(ConsumeContext context) await hubContext.Clients.All.SendAsync("AuctionFinished", context.Message); } } -} \ No newline at end of file +} diff --git a/src/NotificationService/Consumers/BidPlacedConsumer.cs b/src/NotificationService/Consumers/BidPlacedConsumer.cs index 858e5ed..1ba726b 100644 --- a/src/NotificationService/Consumers/BidPlacedConsumer.cs +++ b/src/NotificationService/Consumers/BidPlacedConsumer.cs @@ -1,6 +1,6 @@ namespace NotificationService.Consumers { - public class BidPlacedConsumer(IHubContext hubContext) : IConsumer + public sealed class BidPlacedConsumer(IHubContext hubContext) : IConsumer { public async Task Consume(ConsumeContext context) { @@ -9,4 +9,4 @@ public async Task Consume(ConsumeContext context) await hubContext.Clients.All.SendAsync("BidPlaced", context.Message); } } -} \ No newline at end of file +} diff --git a/src/NotificationService/Contracts/AuctionCreated.cs b/src/NotificationService/Contracts/AuctionCreated.cs index 3b7789c..609b633 100644 --- a/src/NotificationService/Contracts/AuctionCreated.cs +++ b/src/NotificationService/Contracts/AuctionCreated.cs @@ -1,6 +1,6 @@ namespace Contracts { - public class AuctionCreated + public sealed class AuctionCreated { public Guid Id { get; set; } public int ReservePrice { get; set; } @@ -19,4 +19,4 @@ public class AuctionCreated public int Mileage { get; set; } public string ImageUrl { get; set; } = string.Empty; } -} \ No newline at end of file +} diff --git a/src/NotificationService/Contracts/AuctionDeleted.cs b/src/NotificationService/Contracts/AuctionDeleted.cs index 6a7166f..9d44170 100644 --- a/src/NotificationService/Contracts/AuctionDeleted.cs +++ b/src/NotificationService/Contracts/AuctionDeleted.cs @@ -1,7 +1,7 @@ namespace Contracts { - public class AuctionDeleted + public sealed class AuctionDeleted { public string? Id { get; set; } } -} \ No newline at end of file +} diff --git a/src/NotificationService/Contracts/AuctionFinished.cs b/src/NotificationService/Contracts/AuctionFinished.cs index 336b932..a29e8bf 100644 --- a/src/NotificationService/Contracts/AuctionFinished.cs +++ b/src/NotificationService/Contracts/AuctionFinished.cs @@ -1,6 +1,6 @@ namespace Contracts { - public class AuctionFinished + public sealed class AuctionFinished { public bool ItemSold { get; set; } public string? AuctionId { get; set; } @@ -8,4 +8,4 @@ public class AuctionFinished public string? Seller { get; set; } public int? Amount { get; set; } } -} \ No newline at end of file +} diff --git a/src/NotificationService/Contracts/AuctionUpdated.cs b/src/NotificationService/Contracts/AuctionUpdated.cs index 89573dc..69a4f09 100644 --- a/src/NotificationService/Contracts/AuctionUpdated.cs +++ b/src/NotificationService/Contracts/AuctionUpdated.cs @@ -1,6 +1,6 @@ namespace Contracts { - public class AuctionUpdated + public sealed class AuctionUpdated { public string? Id { get; set; } public string? Make { get; set; } @@ -9,4 +9,4 @@ public class AuctionUpdated public string? Color { get; set; } public int Mileage { get; set; } } -} \ No newline at end of file +} diff --git a/src/NotificationService/Contracts/BidPlaced.cs b/src/NotificationService/Contracts/BidPlaced.cs index c2e6c15..9d37803 100644 --- a/src/NotificationService/Contracts/BidPlaced.cs +++ b/src/NotificationService/Contracts/BidPlaced.cs @@ -1,6 +1,6 @@ namespace Contracts { - public class BidPlaced + public sealed class BidPlaced { public string? Id { get; set; } public string? AuctionId { get; set; } @@ -9,4 +9,4 @@ public class BidPlaced public int Amount { get; set; } public string? BidStatus { get; set; } } -} \ No newline at end of file +} diff --git a/src/NotificationService/Hubs/NotificationHub.cs b/src/NotificationService/Hubs/NotificationHub.cs index 6b55c19..5369474 100644 --- a/src/NotificationService/Hubs/NotificationHub.cs +++ b/src/NotificationService/Hubs/NotificationHub.cs @@ -1,4 +1,4 @@ namespace NotificationService.Hubs { - public class NotificationHub : Hub { } -} \ No newline at end of file + public sealed class NotificationHub : Hub { } +} diff --git a/src/NotificationService/Program.cs b/src/NotificationService/Program.cs index 9bd751c..46f2ba4 100644 --- a/src/NotificationService/Program.cs +++ b/src/NotificationService/Program.cs @@ -30,4 +30,4 @@ app.MapHub("/notifications"); -app.Run(); \ No newline at end of file +app.Run(); diff --git a/src/SearchService/Consumers/AuctionCreatedConsumer.cs b/src/SearchService/Consumers/AuctionCreatedConsumer.cs index 9336fae..7f2786e 100644 --- a/src/SearchService/Consumers/AuctionCreatedConsumer.cs +++ b/src/SearchService/Consumers/AuctionCreatedConsumer.cs @@ -6,7 +6,7 @@ namespace SearchService.Consumers { - public class AuctionCreatedConsumer(IMapper mapper) : IConsumer + public sealed class AuctionCreatedConsumer(IMapper mapper) : IConsumer { public async Task Consume(ConsumeContext context) { @@ -19,4 +19,4 @@ public async Task Consume(ConsumeContext context) await item.SaveAsync(); } } -} \ No newline at end of file +} diff --git a/src/SearchService/Consumers/AuctionDeletedConsumer.cs b/src/SearchService/Consumers/AuctionDeletedConsumer.cs index 1e35e09..ad105c6 100644 --- a/src/SearchService/Consumers/AuctionDeletedConsumer.cs +++ b/src/SearchService/Consumers/AuctionDeletedConsumer.cs @@ -6,7 +6,7 @@ namespace SearchService.Consumers { - public class AuctionDeletedConsumer : IConsumer + public sealed class AuctionDeletedConsumer : IConsumer { public async Task Consume(ConsumeContext context) { @@ -18,4 +18,4 @@ public async Task Consume(ConsumeContext context) throw new MessageException(typeof(AuctionDeleted), "Problem deleting auction."); } } -} \ No newline at end of file +} diff --git a/src/SearchService/Consumers/AuctionFinishedConsumer.cs b/src/SearchService/Consumers/AuctionFinishedConsumer.cs index 81ec6cb..fb14492 100644 --- a/src/SearchService/Consumers/AuctionFinishedConsumer.cs +++ b/src/SearchService/Consumers/AuctionFinishedConsumer.cs @@ -5,7 +5,7 @@ namespace SearchService.Consumers { - public class AuctionFinishedConsumer : IConsumer + public sealed class AuctionFinishedConsumer : IConsumer { public async Task Consume(ConsumeContext context) { @@ -22,4 +22,4 @@ public async Task Consume(ConsumeContext context) await auction.SaveAsync(); } } -} \ No newline at end of file +} diff --git a/src/SearchService/Consumers/AuctionUpdatedConsumer.cs b/src/SearchService/Consumers/AuctionUpdatedConsumer.cs index ff5240c..fd416ab 100644 --- a/src/SearchService/Consumers/AuctionUpdatedConsumer.cs +++ b/src/SearchService/Consumers/AuctionUpdatedConsumer.cs @@ -7,7 +7,7 @@ namespace SearchService.Consumers { - public class AuctionUpdatedConsumer(IMapper mapper) : IConsumer + public sealed class AuctionUpdatedConsumer(IMapper mapper) : IConsumer { public async Task Consume(ConsumeContext context) { @@ -30,4 +30,4 @@ public async Task Consume(ConsumeContext context) throw new MessageException(typeof(AuctionUpdated), "Problem updating mongodb"); } } -} \ No newline at end of file +} diff --git a/src/SearchService/Consumers/BidPlacedConsumer.cs b/src/SearchService/Consumers/BidPlacedConsumer.cs index 4f8478a..c8ab14e 100644 --- a/src/SearchService/Consumers/BidPlacedConsumer.cs +++ b/src/SearchService/Consumers/BidPlacedConsumer.cs @@ -5,7 +5,7 @@ namespace SearchService.Consumers { - public class BidPlacedConsumer : IConsumer + public sealed class BidPlacedConsumer : IConsumer { public async Task Consume(ConsumeContext context) { @@ -21,4 +21,4 @@ public async Task Consume(ConsumeContext context) } } } -} \ No newline at end of file +} diff --git a/src/SearchService/Contracts/AuctionCreated.cs b/src/SearchService/Contracts/AuctionCreated.cs index 3b7789c..609b633 100644 --- a/src/SearchService/Contracts/AuctionCreated.cs +++ b/src/SearchService/Contracts/AuctionCreated.cs @@ -1,6 +1,6 @@ namespace Contracts { - public class AuctionCreated + public sealed class AuctionCreated { public Guid Id { get; set; } public int ReservePrice { get; set; } @@ -19,4 +19,4 @@ public class AuctionCreated public int Mileage { get; set; } public string ImageUrl { get; set; } = string.Empty; } -} \ No newline at end of file +} diff --git a/src/SearchService/Contracts/AuctionDeleted.cs b/src/SearchService/Contracts/AuctionDeleted.cs index 6a7166f..9d44170 100644 --- a/src/SearchService/Contracts/AuctionDeleted.cs +++ b/src/SearchService/Contracts/AuctionDeleted.cs @@ -1,7 +1,7 @@ namespace Contracts { - public class AuctionDeleted + public sealed class AuctionDeleted { public string? Id { get; set; } } -} \ No newline at end of file +} diff --git a/src/SearchService/Contracts/AuctionFinished.cs b/src/SearchService/Contracts/AuctionFinished.cs index efaa03c..5e5c825 100644 --- a/src/SearchService/Contracts/AuctionFinished.cs +++ b/src/SearchService/Contracts/AuctionFinished.cs @@ -1,6 +1,6 @@ namespace SearchService.Contracts { - public class AuctionFinished + public sealed class AuctionFinished { public bool ItemSold { get; set; } public string? AuctionId { get; set; } @@ -8,4 +8,4 @@ public class AuctionFinished public string? Seller { get; set; } public int? Amount { get; set; } } -} \ No newline at end of file +} diff --git a/src/SearchService/Contracts/AuctionUpdated.cs b/src/SearchService/Contracts/AuctionUpdated.cs index 89573dc..69a4f09 100644 --- a/src/SearchService/Contracts/AuctionUpdated.cs +++ b/src/SearchService/Contracts/AuctionUpdated.cs @@ -1,6 +1,6 @@ namespace Contracts { - public class AuctionUpdated + public sealed class AuctionUpdated { public string? Id { get; set; } public string? Make { get; set; } @@ -9,4 +9,4 @@ public class AuctionUpdated public string? Color { get; set; } public int Mileage { get; set; } } -} \ No newline at end of file +} diff --git a/src/SearchService/Contracts/BidPlaced.cs b/src/SearchService/Contracts/BidPlaced.cs index 3da18d5..af4890a 100644 --- a/src/SearchService/Contracts/BidPlaced.cs +++ b/src/SearchService/Contracts/BidPlaced.cs @@ -1,6 +1,6 @@ namespace SearchService.Contracts { - public class BidPlaced + public sealed class BidPlaced { public string? Id { get; set; } public string? AuctionId { get; set; } @@ -9,4 +9,4 @@ public class BidPlaced public int Amount { get; set; } public string? BidStatus { get; set; } } -} \ No newline at end of file +} diff --git a/src/SearchService/Controllers/SearchController.cs b/src/SearchService/Controllers/SearchController.cs index f3f403f..760b6e9 100644 --- a/src/SearchService/Controllers/SearchController.cs +++ b/src/SearchService/Controllers/SearchController.cs @@ -7,7 +7,7 @@ namespace SearchService.Controllers { [ApiController] [Route("api/search")] - public class SearchController : ControllerBase + public sealed class SearchController : ControllerBase { [HttpGet] public async Task>> SearchItems([FromQuery] SearchParams searchParams) @@ -54,4 +54,4 @@ public async Task>> SearchItems([FromQuery] SearchParams }); } } -} \ No newline at end of file +} diff --git a/src/SearchService/Data/DbInitializer.cs b/src/SearchService/Data/DbInitializer.cs index f4b6e2c..232fe2c 100644 --- a/src/SearchService/Data/DbInitializer.cs +++ b/src/SearchService/Data/DbInitializer.cs @@ -5,7 +5,7 @@ namespace SearchService.Data { - public class DbInitializer + public sealed class DbInitializer { public static async Task InitDb(WebApplication app) { @@ -31,4 +31,4 @@ await DB.Index() if (items.Count > 0) await DB.SaveAsync(items); } } -} \ No newline at end of file +} diff --git a/src/SearchService/Models/Item.cs b/src/SearchService/Models/Item.cs index 61fa228..4d24e36 100644 --- a/src/SearchService/Models/Item.cs +++ b/src/SearchService/Models/Item.cs @@ -2,7 +2,7 @@ namespace SearchService.Models { - public class Item : Entity + public sealed class Item : Entity { public int ReservePrice { get; set; } public string? Seller { get; set; } @@ -20,4 +20,4 @@ public class Item : Entity public int Mileage { get; set; } public string ImageUrl { get; set; } = string.Empty; } -} \ No newline at end of file +} diff --git a/src/SearchService/Program.cs b/src/SearchService/Program.cs index 42c3f52..c337eb5 100644 --- a/src/SearchService/Program.cs +++ b/src/SearchService/Program.cs @@ -63,4 +63,4 @@ static IAsyncPolicy GetPolicy() => .OrResult(msg => msg.StatusCode == HttpStatusCode.NotFound) .WaitAndRetryForeverAsync(_ => TimeSpan.FromSeconds(3)); -public partial class Program {} +public sealed partial class Program {} diff --git a/src/SearchService/RequestHelpers/MappingProfiles.cs b/src/SearchService/RequestHelpers/MappingProfiles.cs index e14b096..5940696 100644 --- a/src/SearchService/RequestHelpers/MappingProfiles.cs +++ b/src/SearchService/RequestHelpers/MappingProfiles.cs @@ -4,11 +4,11 @@ namespace SearchService.RequestHelpers { - public class MappingProfiles : Profile + public sealed class MappingProfiles : Profile { public MappingProfiles() { CreateMap(); } } -} \ No newline at end of file +} diff --git a/src/SearchService/RequestHelpers/SearchParams.cs b/src/SearchService/RequestHelpers/SearchParams.cs index 5be972c..fbe4465 100644 --- a/src/SearchService/RequestHelpers/SearchParams.cs +++ b/src/SearchService/RequestHelpers/SearchParams.cs @@ -1,6 +1,6 @@ namespace SearchService.RequestHelpers { - public class SearchParams + public sealed class SearchParams { public string? SearchTerm { get; set; } public int PageNumber { get; set; } = 1; @@ -10,4 +10,4 @@ public class SearchParams public string? OrderBy { get; set; } public string? FilterBy { get; set; } } -} \ No newline at end of file +} diff --git a/src/SearchService/Services/AuctionServiceHttpClient.cs b/src/SearchService/Services/AuctionServiceHttpClient.cs index 12bf09f..63f3370 100644 --- a/src/SearchService/Services/AuctionServiceHttpClient.cs +++ b/src/SearchService/Services/AuctionServiceHttpClient.cs @@ -3,7 +3,7 @@ namespace SearchService.Services { - public class AuctionServiceHttpClient(HttpClient httpClient, IConfiguration config) + public sealed class AuctionServiceHttpClient(HttpClient httpClient, IConfiguration config) { public async Task> GetItemsForSearchDb() { @@ -19,4 +19,4 @@ public async Task> GetItemsForSearchDb() return response!; } } -} \ No newline at end of file +} diff --git a/tests/AuctionService.IntegrationTests/AuctionBusTests.cs b/tests/AuctionService.IntegrationTests/AuctionBusTests.cs index 9c6b91e..87c92ed 100644 --- a/tests/AuctionService.IntegrationTests/AuctionBusTests.cs +++ b/tests/AuctionService.IntegrationTests/AuctionBusTests.cs @@ -1,7 +1,7 @@ namespace AuctionService.IntegrationTests { [Collection("SharedFixture")] - public class AuctionBusTests : IAsyncLifetime + public sealed class AuctionBusTests : IAsyncLifetime { private readonly CustomWebAppFactory _factory; private readonly HttpClient _httpClient; @@ -51,4 +51,4 @@ private static CreateAuctionDto GetAuctionForCreate() => Color = "Red" }; } -} \ No newline at end of file +} diff --git a/tests/AuctionService.IntegrationTests/AuctionControllerTests.cs b/tests/AuctionService.IntegrationTests/AuctionControllerTests.cs index 48b223e..c455c04 100644 --- a/tests/AuctionService.IntegrationTests/AuctionControllerTests.cs +++ b/tests/AuctionService.IntegrationTests/AuctionControllerTests.cs @@ -1,7 +1,7 @@ namespace AuctionService.IntegrationTests { [Collection("SharedFixture")] - public class AuctionControllerTests : IAsyncLifetime + public sealed class AuctionControllerTests : IAsyncLifetime { private readonly CustomWebAppFactory _factory; private readonly HttpClient _httpClient; @@ -168,4 +168,4 @@ private static CreateAuctionDto GetAuctionForCreate() => Color = "Red" }; } -} \ No newline at end of file +} diff --git a/tests/AuctionService.IntegrationTests/Fixtures/CustomWebAppFactory.cs b/tests/AuctionService.IntegrationTests/Fixtures/CustomWebAppFactory.cs index 763cbd5..699c1d2 100644 --- a/tests/AuctionService.IntegrationTests/Fixtures/CustomWebAppFactory.cs +++ b/tests/AuctionService.IntegrationTests/Fixtures/CustomWebAppFactory.cs @@ -3,7 +3,7 @@ namespace AuctionService.IntegrationTests.Fixtures /// /// Represents a custom web application factory used for integration testing. /// - public class CustomWebAppFactory : WebApplicationFactory, IAsyncLifetime + public sealed class CustomWebAppFactory : WebApplicationFactory, IAsyncLifetime { /// /// Represents a PostgreSqlContainer used for integration testing. @@ -16,7 +16,7 @@ public async Task InitializeAsync() => async Task IAsyncLifetime.DisposeAsync() => await _postgresSqlContainer.DisposeAsync().AsTask(); - protected override void ConfigureWebHost(IWebHostBuilder builder) + protected sealed override void ConfigureWebHost(IWebHostBuilder builder) { builder.ConfigureTestServices(services => { @@ -39,4 +39,4 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) }); } } -} \ No newline at end of file +} diff --git a/tests/AuctionService.IntegrationTests/Fixtures/SharedFixture.cs b/tests/AuctionService.IntegrationTests/Fixtures/SharedFixture.cs index eebf3d7..ae944c0 100644 --- a/tests/AuctionService.IntegrationTests/Fixtures/SharedFixture.cs +++ b/tests/AuctionService.IntegrationTests/Fixtures/SharedFixture.cs @@ -1,8 +1,8 @@ namespace AuctionService.IntegrationTests.Fixtures { [CollectionDefinition("SharedFixture")] - public class SharedFixture : ICollectionFixture + public sealed class SharedFixture : ICollectionFixture { } -} \ No newline at end of file +} diff --git a/tests/AuctionService.IntegrationTests/GlobalUsings.cs b/tests/AuctionService.IntegrationTests/GlobalUsings.cs index c17b231..ec804da 100644 --- a/tests/AuctionService.IntegrationTests/GlobalUsings.cs +++ b/tests/AuctionService.IntegrationTests/GlobalUsings.cs @@ -9,9 +9,11 @@ global using Testcontainers.PostgreSql; global using AuctionService.IntegrationTests.Fixtures; global using AuctionService.IntegrationTests.Utils; -global using System.Net.Http.Json; +global using AuctionService.Entities; global using AuctionService.Dtos; global using WebMotions.Fake.Authentication.JwtBearer; +global using System.Security.Claims; +global using System.Net.Http.Json; global using System.Net; global using Contracts; global using MassTransit.Testing; \ No newline at end of file diff --git a/tests/AuctionService.IntegrationTests/Utils/AuthHelper.cs b/tests/AuctionService.IntegrationTests/Utils/AuthHelper.cs index 9b69a0e..4919766 100644 --- a/tests/AuctionService.IntegrationTests/Utils/AuthHelper.cs +++ b/tests/AuctionService.IntegrationTests/Utils/AuthHelper.cs @@ -1,13 +1,11 @@ -using System.Security.Claims; - namespace AuctionService.IntegrationTests.Utils { - public class AuthHelper + public sealed class AuthHelper { public static Dictionary GetBearerForUser(string username) => new() { - {ClaimTypes.Name, username} + { ClaimTypes.Name, username } }; } -} \ No newline at end of file +} diff --git a/tests/AuctionService.IntegrationTests/Utils/DataHelper.cs b/tests/AuctionService.IntegrationTests/Utils/DataHelper.cs index de1263e..86310f7 100644 --- a/tests/AuctionService.IntegrationTests/Utils/DataHelper.cs +++ b/tests/AuctionService.IntegrationTests/Utils/DataHelper.cs @@ -1,5 +1,3 @@ -using AuctionService.Entities; - namespace AuctionService.IntegrationTests.Utils { public static class DataHelper @@ -20,4 +18,4 @@ public static void ReinitDbForTests(AuctionContext db) private static List GetAuctionsForTest() => DbInitializer.GetDbAuctions(); } -} \ No newline at end of file +} diff --git a/tests/AuctionService.IntegrationTests/Utils/ServiceCollectionExtensions.cs b/tests/AuctionService.IntegrationTests/Utils/ServiceCollectionExtensions.cs index 553fb72..cd25af5 100644 --- a/tests/AuctionService.IntegrationTests/Utils/ServiceCollectionExtensions.cs +++ b/tests/AuctionService.IntegrationTests/Utils/ServiceCollectionExtensions.cs @@ -33,4 +33,4 @@ public static void EnsureCreated(this IServiceCollection services) DataHelper.InitDbForTests(db); } } -} \ No newline at end of file +} diff --git a/tests/AuctionService.UnitTests/AuctionControllerTests.cs b/tests/AuctionService.UnitTests/AuctionControllerTests.cs index a3ec640..b90da1c 100644 --- a/tests/AuctionService.UnitTests/AuctionControllerTests.cs +++ b/tests/AuctionService.UnitTests/AuctionControllerTests.cs @@ -1,6 +1,6 @@ namespace AuctionService.UnitTests { - public class AuctionControllerTests + public sealed class AuctionControllerTests { private readonly Mock _auctionRepository; private readonly Mock _publishEndpoint; @@ -205,4 +205,4 @@ public async Task DeleteAuction_WithInvalidUser_Returns403Forbidden() Assert.IsType(result); } } -} \ No newline at end of file +} diff --git a/tests/AuctionService.UnitTests/AuctionEntityTests.cs b/tests/AuctionService.UnitTests/AuctionEntityTests.cs index 08392a2..1afce48 100644 --- a/tests/AuctionService.UnitTests/AuctionEntityTests.cs +++ b/tests/AuctionService.UnitTests/AuctionEntityTests.cs @@ -1,6 +1,6 @@ namespace AuctionService.UnitTests; -public class AuctionEntityTests +public sealed class AuctionEntityTests { [Fact] public void HasReservePrice_ReservePriceGtZero_True() @@ -35,4 +35,4 @@ public void HasReservePrice_ReservePriceIsZero_False() // Assert Assert.False(result); } -} \ No newline at end of file +} diff --git a/tests/AuctionService.UnitTests/Utils/AuthHelper.cs b/tests/AuctionService.UnitTests/Utils/AuthHelper.cs index 2b661c6..bf37bfa 100644 --- a/tests/AuctionService.UnitTests/Utils/AuthHelper.cs +++ b/tests/AuctionService.UnitTests/Utils/AuthHelper.cs @@ -2,7 +2,7 @@ namespace AuctionService.UnitTests.Utils { - public class AuthHelper + public sealed class AuthHelper { public static ClaimsPrincipal GetClaimsPrincipal() { @@ -17,4 +17,4 @@ public static ClaimsPrincipal GetClaimsPrincipal() return claimsPrincipal; } } -} \ No newline at end of file +} diff --git a/tests/SearchService.IntegrationTests/ConsumerTests.cs b/tests/SearchService.IntegrationTests/ConsumerTests.cs index fa4a8f5..913d7ce 100644 --- a/tests/SearchService.IntegrationTests/ConsumerTests.cs +++ b/tests/SearchService.IntegrationTests/ConsumerTests.cs @@ -2,7 +2,7 @@ namespace SearchService.IntegrationTests { - public class ConsumerTests(CustomWebAppFactory factory) : IClassFixture + public sealed class ConsumerTests(CustomWebAppFactory factory) : IClassFixture { private readonly ITestHarness _testHarness = factory.Services.GetTestHarness(); private readonly Fixture _fixture = new(); @@ -24,4 +24,4 @@ public async Task AuctionCreated_ShouldCreateItemInDb() Assert.Equal(auction.Make, item.Make); } } -} \ No newline at end of file +} diff --git a/tests/SearchService.IntegrationTests/CustomWebAppFactory.cs b/tests/SearchService.IntegrationTests/CustomWebAppFactory.cs index de1a355..5a83330 100644 --- a/tests/SearchService.IntegrationTests/CustomWebAppFactory.cs +++ b/tests/SearchService.IntegrationTests/CustomWebAppFactory.cs @@ -1,6 +1,6 @@ namespace SearchService.IntegrationTests { - public class CustomWebAppFactory : WebApplicationFactory + public sealed class CustomWebAppFactory : WebApplicationFactory { private readonly MongoDbRunner _runner; @@ -16,7 +16,7 @@ public CustomWebAppFactory() .CreateAsync(); } - protected override void ConfigureWebHost(IWebHostBuilder builder) + protected sealed override void ConfigureWebHost(IWebHostBuilder builder) { builder.UseEnvironment("Testing"); builder.ConfigureTestServices(services => @@ -25,7 +25,7 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) }); } - protected override void Dispose(bool disposing) + protected sealed override void Dispose(bool disposing) { _runner.Dispose(); }