From 9e5082c69f20d191ae6a964c87aa779745462d8d Mon Sep 17 00:00:00 2001 From: Jonas Anker Rasmussen Date: Mon, 11 Mar 2024 18:14:07 +0100 Subject: [PATCH] Introduce Feature Flag to control MobilePay Webhooks registration (#268) When migrating to the new MobilePay Vipps API, the existing MobilePay Webhooks API will be disabled, thus we need a way to disable the feature until the new integration has been developed. We use Feature Flags to disable registration to the Webhooks API. --- .../Configuration/DatabaseSettings.cs | 4 +- .../Configuration/EnvironmentSettings.cs | 4 +- .../Configuration/IdentitySettings.cs | 4 +- .../Configuration/LoginLimiterSettings.cs | 2 +- .../Configuration/MailgunSettings.cs | 4 +- .../Configuration/MobilePaySettingsV2.cs | 4 +- .../Errors/ConflictException.cs | 2 +- .../Errors/EntityNotFoundException.cs | 2 +- .../Errors/IllegalUserOperationException.cs | 2 +- .../Builder/BuilderGenerator.cs | 58 ++++---- .../CoffeeCard.Library.csproj | 6 +- .../20230503203850_AzureMigration.cs | 120 ++++++++--------- .../20230514103253_UserEmailIndexAdded.cs | 8 +- .../20230523163048_StatisticIndex.cs | 4 +- ...20230612202437_PurchaseStatus-Migration.cs | 4 +- ...612203926_Purchases-DropCompletedColumn.cs | 12 +- .../20230711144034_AddPurchaseTypes.cs | 12 +- .../20230711161456_PurchaseDataCleanup.cs | 18 +-- ...seOrderIdUniqueAndExternalTransactionId.cs | 18 +-- .../20230818201050_PurchaseTypeNonNullable.cs | 4 +- .../Migrations/20240111163619_NewIndexName.cs | 8 +- .../20240120143222_MenuItemProducts.cs | 32 ++--- .../20240213174936_addActiveToMenuItem.cs | 4 +- ...20240227174524_AddUserGroupIndexToUsers.cs | 4 +- .../Persistence/CoffeecardContext.cs | 22 +-- .../Services/AccountService.cs | 23 ++-- .../Services/EmailService.cs | 18 +-- .../Services/IAccountService.cs | 4 +- .../Services/IEmailService.cs | 2 +- .../Services/ILeaderboardService.cs | 4 +- .../Services/IMapperService.cs | 4 +- .../Services/IProductService.cs | 4 +- .../Services/IProgrammeService.cs | 4 +- .../Services/IPurchaseService.cs | 6 +- .../Services/ITicketService.cs | 8 +- .../Services/LoginLimiter.cs | 6 +- .../Services/MapperService.cs | 4 +- .../Services/ProductService.cs | 8 +- .../Services/ProgrammeService.cs | 6 +- .../Services/PurchaseService.cs | 20 +-- .../Services/TicketService.cs | 17 ++- .../Services/TokenService.cs | 16 +-- .../Services/v2/AccountService.cs | 24 ++-- .../Services/v2/IAccountService.cs | 7 +- .../Services/v2/ILeaderboardService.cs | 4 +- .../Services/v2/IMenuItemService.cs | 3 +- .../Services/v2/IProductService.cs | 6 +- .../Services/v2/IPurchaseService.cs | 8 +- .../Services/v2/ITicketService.cs | 4 +- .../Services/v2/IVoucherService.cs | 2 +- .../Services/v2/LeaderboardService.cs | 7 +- .../Services/v2/MenuItemService.cs | 16 +-- .../Services/v2/ProductService.cs | 15 +-- .../Services/v2/PurchaseService.cs | 21 ++- .../Services/v2/StatisticService.cs | 8 +- .../Services/v2/TicketService.cs | 14 +- .../Services/v2/VoucherService.cs | 18 ++- .../Services/v2/WebhookService.cs | 28 ++-- .../Utils/ClaimsUtilities.cs | 10 +- .../CoffeeCard.Library/Utils/FeatureFlags.cs | 10 ++ .../Utils/ProductExtensions.cs | 7 +- .../Program.cs | 6 +- .../Service/v2/IMobilePayPaymentsService.cs | 7 +- .../Service/v2/IMobilePayWebhooksService.cs | 4 +- .../Service/v2/MobilePayPaymentsService.cs | 6 +- .../Service/v2/MobilePayWebhooksService.cs | 10 +- .../MobilePayServiceCollectionExtension.cs | 8 +- .../AppConfig/AppConfigDTO.cs | 4 +- .../DataTransferObjects/Ticket/TicketDTO.cs | 4 +- .../Ticket/UseMultipleTicketDTO.cs | 2 +- .../DataTransferObjects/User/UserDTO.cs | 4 +- .../v2/AppConfig/AppConfig.cs | 4 +- .../v2/Leaderboard/LeaderboardPreset.cs | 4 +- .../v2/MenuItems/AddMenuItemRequest.cs | 5 +- .../v2/MenuItems/MenuItemResponse.cs | 2 +- .../v2/MenuItems/UpdateMenuItemRequest.cs | 5 +- .../v2/Product/AddProductRequest.cs | 2 +- .../v2/Product/UpdateProductRequest.cs | 2 +- .../v2/Products/ProductResponse.cs | 6 +- .../v2/Purchase/InitiatePurchaseRequest.cs | 3 +- .../v2/Purchase/PaymentType.cs | 2 +- .../v2/Ticket/TicketResponse.cs | 4 +- .../v2/User/AccountUserGroup.cs | 3 +- .../ResendAccountVerificationEmailRequest.cs | 3 +- .../v2/User/UpdateUserGroupRequest.cs | 2 +- .../v2/User/UserResponse.cs | 2 +- .../v2/User/WebhookUpdateUserGroupRequest.cs | 3 +- .../CoffeeCard.Models/Entities/MenuItem.cs | 4 +- .../CoffeeCard.Models/Entities/Product.cs | 2 - .../CoffeeCard.Models/Entities/Purchase.cs | 4 +- .../CoffeeCard.Models/Entities/Statistic.cs | 2 +- coffeecard/CoffeeCard.Models/Entities/User.cs | 13 +- .../CoffeeCard.Models/Entities/Voucher.cs | 2 +- .../Builders/BaseBuilder.cs | 2 +- .../Builders/ProductBuilder.cs | 2 +- .../Builders/ProgrammeBuilder.cs | 2 +- .../Builders/PurchaseBuilder.cs | 4 +- .../Builders/UserBuilder.cs | 10 +- .../Controllers/Account/GetAccountTest.cs | 12 +- .../Controllers/Account/LoginTest.cs | 12 +- .../WebApplication/BaseIntegrationTest.cs | 20 +-- .../CustomWebApplicationFactory.cs | 25 ++-- .../Services/AccountServiceTest.cs | 125 +++++++++--------- .../Services/LoginLimiterTests.cs | 14 +- .../Services/ProductServiceTest.cs | 62 ++++----- .../Services/TokenServiceTest.cs | 24 ++-- .../Services/v2/AccountServiceTest.cs | 108 +++++++-------- .../Services/v2/LeaderboardServiceTests.cs | 65 +++++---- .../Services/v2/ProductServiceTest.cs | 53 ++++---- .../Services/v2/PurchaseServiceTests.cs | 36 ++--- .../Services/v2/VoucherServiceTests.cs | 21 ++- .../Utils/ProductExtensionsTests.cs | 6 +- .../Utils/SemesterUtilTests.cs | 2 +- .../CoffeeCard.WebApi.csproj | 3 +- .../Controllers/AccountController.cs | 6 +- .../Controllers/AppConfigController.cs | 6 +- .../Controllers/CoffeeCardsController.cs | 3 +- .../Controllers/LeaderboardController.cs | 2 +- .../Controllers/MobilePayController.cs | 4 +- .../Controllers/PingController.cs | 2 +- .../Controllers/ProductsController.cs | 10 +- .../Controllers/ProgrammesController.cs | 6 +- .../Controllers/PurchasesController.cs | 5 +- .../Controllers/TicketsController.cs | 6 +- .../Controllers/v2/AccountController.cs | 16 +-- .../Controllers/v2/HealthController.cs | 6 +- .../Controllers/v2/LeaderboardController.cs | 6 +- .../Controllers/v2/MenuItemsController.cs | 7 +- .../Controllers/v2/MobilePayController.cs | 17 ++- .../Controllers/v2/ProductsController.cs | 8 +- .../Controllers/v2/PurchasesController.cs | 7 +- .../Controllers/v2/TicketsController.cs | 7 +- .../Controllers/v2/VouchersController.cs | 6 +- .../Controllers/v2/WebhooksController.cs | 2 +- .../Helpers/ApiExceptionFilter.cs | 4 +- .../Helpers/AuthorizeRoles.cs | 2 +- ...ConfigurationServiceCollectionExtension.cs | 14 +- .../CoffeeCard.WebApi/Helpers/PageUtils.cs | 6 +- .../Helpers/ReadableBodyFilter.cs | 1 - .../Swagger/RemoveApiVersionProcessor.cs | 6 +- .../CoffeeCard.WebApi/Logging/Enricher.cs | 4 +- .../Logging/LoggerConfigurationExtensions.cs | 2 +- .../CoffeeCard.WebApi/Pages/Recover.cshtml.cs | 5 +- .../Pages/VerifyDelete.cshtml.cs | 4 +- .../Pages/VerifyEmail.cshtml.cs | 4 +- coffeecard/CoffeeCard.WebApi/Program.cs | 22 +-- coffeecard/CoffeeCard.WebApi/Startup.cs | 125 +++++++++--------- coffeecard/CoffeeCard.WebApi/appsettings.json | 3 + 148 files changed, 877 insertions(+), 927 deletions(-) create mode 100644 coffeecard/CoffeeCard.Library/Utils/FeatureFlags.cs diff --git a/coffeecard/CoffeeCard.Common/Configuration/DatabaseSettings.cs b/coffeecard/CoffeeCard.Common/Configuration/DatabaseSettings.cs index 9234e5be..00b83d24 100644 --- a/coffeecard/CoffeeCard.Common/Configuration/DatabaseSettings.cs +++ b/coffeecard/CoffeeCard.Common/Configuration/DatabaseSettings.cs @@ -1,5 +1,5 @@ -using System.ComponentModel.DataAnnotations; -using NetEscapades.Configuration.Validation; +using NetEscapades.Configuration.Validation; +using System.ComponentModel.DataAnnotations; namespace CoffeeCard.Common.Configuration { diff --git a/coffeecard/CoffeeCard.Common/Configuration/EnvironmentSettings.cs b/coffeecard/CoffeeCard.Common/Configuration/EnvironmentSettings.cs index 5741fdd2..94dcc38c 100644 --- a/coffeecard/CoffeeCard.Common/Configuration/EnvironmentSettings.cs +++ b/coffeecard/CoffeeCard.Common/Configuration/EnvironmentSettings.cs @@ -1,5 +1,5 @@ -using System.ComponentModel.DataAnnotations; -using NetEscapades.Configuration.Validation; +using NetEscapades.Configuration.Validation; +using System.ComponentModel.DataAnnotations; namespace CoffeeCard.Common.Configuration { diff --git a/coffeecard/CoffeeCard.Common/Configuration/IdentitySettings.cs b/coffeecard/CoffeeCard.Common/Configuration/IdentitySettings.cs index f993325a..6a736363 100644 --- a/coffeecard/CoffeeCard.Common/Configuration/IdentitySettings.cs +++ b/coffeecard/CoffeeCard.Common/Configuration/IdentitySettings.cs @@ -1,5 +1,5 @@ -using System.ComponentModel.DataAnnotations; -using NetEscapades.Configuration.Validation; +using NetEscapades.Configuration.Validation; +using System.ComponentModel.DataAnnotations; namespace CoffeeCard.Common.Configuration { diff --git a/coffeecard/CoffeeCard.Common/Configuration/LoginLimiterSettings.cs b/coffeecard/CoffeeCard.Common/Configuration/LoginLimiterSettings.cs index 6e04ab67..d6757833 100644 --- a/coffeecard/CoffeeCard.Common/Configuration/LoginLimiterSettings.cs +++ b/coffeecard/CoffeeCard.Common/Configuration/LoginLimiterSettings.cs @@ -1,5 +1,5 @@ -using System.ComponentModel.DataAnnotations; using NetEscapades.Configuration.Validation; +using System.ComponentModel.DataAnnotations; namespace CoffeeCard.Common.Configuration { diff --git a/coffeecard/CoffeeCard.Common/Configuration/MailgunSettings.cs b/coffeecard/CoffeeCard.Common/Configuration/MailgunSettings.cs index ce71c62d..aa538f70 100644 --- a/coffeecard/CoffeeCard.Common/Configuration/MailgunSettings.cs +++ b/coffeecard/CoffeeCard.Common/Configuration/MailgunSettings.cs @@ -1,5 +1,5 @@ -using System.ComponentModel.DataAnnotations; -using NetEscapades.Configuration.Validation; +using NetEscapades.Configuration.Validation; +using System.ComponentModel.DataAnnotations; namespace CoffeeCard.Common.Configuration { diff --git a/coffeecard/CoffeeCard.Common/Configuration/MobilePaySettingsV2.cs b/coffeecard/CoffeeCard.Common/Configuration/MobilePaySettingsV2.cs index cfa5e325..33f87379 100644 --- a/coffeecard/CoffeeCard.Common/Configuration/MobilePaySettingsV2.cs +++ b/coffeecard/CoffeeCard.Common/Configuration/MobilePaySettingsV2.cs @@ -1,6 +1,6 @@ -using System; +using NetEscapades.Configuration.Validation; +using System; using System.ComponentModel.DataAnnotations; -using NetEscapades.Configuration.Validation; namespace CoffeeCard.Common.Configuration { diff --git a/coffeecard/CoffeeCard.Common/Errors/ConflictException.cs b/coffeecard/CoffeeCard.Common/Errors/ConflictException.cs index 23fc2664..a3bbc2de 100644 --- a/coffeecard/CoffeeCard.Common/Errors/ConflictException.cs +++ b/coffeecard/CoffeeCard.Common/Errors/ConflictException.cs @@ -1,6 +1,6 @@ +using Microsoft.AspNetCore.Http; using System; using System.Runtime.Serialization; -using Microsoft.AspNetCore.Http; namespace CoffeeCard.Common.Errors { diff --git a/coffeecard/CoffeeCard.Common/Errors/EntityNotFoundException.cs b/coffeecard/CoffeeCard.Common/Errors/EntityNotFoundException.cs index cdb4a1d1..158b0d59 100644 --- a/coffeecard/CoffeeCard.Common/Errors/EntityNotFoundException.cs +++ b/coffeecard/CoffeeCard.Common/Errors/EntityNotFoundException.cs @@ -1,6 +1,6 @@ +using Microsoft.AspNetCore.Http; using System; using System.Runtime.Serialization; -using Microsoft.AspNetCore.Http; namespace CoffeeCard.Common.Errors { diff --git a/coffeecard/CoffeeCard.Common/Errors/IllegalUserOperationException.cs b/coffeecard/CoffeeCard.Common/Errors/IllegalUserOperationException.cs index 928ef1d2..e780672c 100644 --- a/coffeecard/CoffeeCard.Common/Errors/IllegalUserOperationException.cs +++ b/coffeecard/CoffeeCard.Common/Errors/IllegalUserOperationException.cs @@ -1,6 +1,6 @@ +using Microsoft.AspNetCore.Http; using System; using System.Runtime.Serialization; -using Microsoft.AspNetCore.Http; namespace CoffeeCard.Common.Errors { diff --git a/coffeecard/CoffeeCard.Generators/Builder/BuilderGenerator.cs b/coffeecard/CoffeeCard.Generators/Builder/BuilderGenerator.cs index cf916185..ed00d727 100644 --- a/coffeecard/CoffeeCard.Generators/Builder/BuilderGenerator.cs +++ b/coffeecard/CoffeeCard.Generators/Builder/BuilderGenerator.cs @@ -1,7 +1,7 @@ -using System.Text; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Text; +using System.Text; namespace CoffeeCard.Generators.Builder; @@ -37,7 +37,7 @@ private static bool IsSyntaxTargetForGeneration( SyntaxNode syntaxNode, CancellationToken cancellationToken) { - return syntaxNode is ClassDeclarationSyntax classDeclaration; + return syntaxNode is ClassDeclarationSyntax; } private static INamedTypeSymbol GetSemanticTargetForGeneration(GeneratorAttributeSyntaxContext context, @@ -50,16 +50,16 @@ private string GenerateBuilderCode(INamedTypeSymbol typeSymbol, ITypeSymbol enti { var codeBuilder = new StringBuilder(); - codeBuilder.AppendLine("// "); - codeBuilder.AppendLine("using System;"); - codeBuilder.AppendLine("using AutoBogus.Conventions;"); - codeBuilder.AppendLine($"using {entity.ContainingNamespace};"); - codeBuilder.AppendLine(); - codeBuilder.AppendLine($"namespace {typeSymbol.ContainingNamespace};"); - codeBuilder.AppendLine(); + _ = codeBuilder.AppendLine("// "); + _ = codeBuilder.AppendLine("using System;"); + _ = codeBuilder.AppendLine("using AutoBogus.Conventions;"); + _ = codeBuilder.AppendLine($"using {entity.ContainingNamespace};"); + _ = codeBuilder.AppendLine(); + _ = codeBuilder.AppendLine($"namespace {typeSymbol.ContainingNamespace};"); + _ = codeBuilder.AppendLine(); - codeBuilder.AppendLine($"public partial class {typeSymbol.Name} : BaseBuilder<{entity.Name}>, IBuilder<{typeSymbol.Name}>"); - codeBuilder.AppendLine("{"); + _ = codeBuilder.AppendLine($"public partial class {typeSymbol.Name} : BaseBuilder<{entity.Name}>, IBuilder<{typeSymbol.Name}>"); + _ = codeBuilder.AppendLine("{"); // Retrieve all properties of the given entity var properties = entity.GetMembers().OfType().Where(p => p.Kind == SymbolKind.Property); @@ -71,7 +71,7 @@ private string GenerateBuilderCode(INamedTypeSymbol typeSymbol, ITypeSymbol enti { if (property.Name.Contains("Id")) { - configBuilder.AppendLine($" .WithSkip<{entity.Name}>(\"{property.Name}\")"); + _ = configBuilder.AppendLine($" .WithSkip<{entity.Name}>(\"{property.Name}\")"); } AddWithPropertyValueToCodeBuilder(codeBuilder: codeBuilder, typeSymbol: typeSymbol, @@ -87,7 +87,7 @@ private string GenerateBuilderCode(INamedTypeSymbol typeSymbol, ITypeSymbol enti AddPrivateConstructorToCodeBuilder(codeBuilder, typeSymbol, configBuilder); // End class - codeBuilder.AppendLine("}"); + _ = codeBuilder.AppendLine("}"); return codeBuilder.ToString(); } @@ -100,35 +100,35 @@ private string GenerateBuilderCode(INamedTypeSymbol typeSymbol, ITypeSymbol enti /// private void AddPrivateConstructorToCodeBuilder(StringBuilder codeBuilder, ITypeSymbol typeSymbol, StringBuilder configBuilder) { - codeBuilder.AppendLine( + _ = codeBuilder.AppendLine( $" private {typeSymbol.Name} ()"); - codeBuilder.AppendLine(" {"); - codeBuilder.AppendLine(" Faker.Configure(builder => builder"); - codeBuilder.Append($"{configBuilder}"); - codeBuilder.AppendLine(" .WithConventions());"); - codeBuilder.AppendLine(" }"); + _ = codeBuilder.AppendLine(" {"); + _ = codeBuilder.AppendLine(" Faker.Configure(builder => builder"); + _ = codeBuilder.Append($"{configBuilder}"); + _ = codeBuilder.AppendLine(" .WithConventions());"); + _ = codeBuilder.AppendLine(" }"); } private void AddWithPropertyValueToCodeBuilder(StringBuilder codeBuilder, ITypeSymbol typeSymbol, IPropertySymbol property, char entityNameChar) { - codeBuilder.AppendLine( + _ = codeBuilder.AppendLine( $" public {typeSymbol.Name} With{property.Name}({property.Type} {property.Name}Value)"); - codeBuilder.AppendLine(" {"); + _ = codeBuilder.AppendLine(" {"); - codeBuilder.AppendLine( + _ = codeBuilder.AppendLine( $" Faker.RuleFor({entityNameChar} => {entityNameChar}.{property.Name}, {property.Name}Value);"); - codeBuilder.AppendLine(" return this;"); - codeBuilder.AppendLine(" }"); + _ = codeBuilder.AppendLine(" return this;"); + _ = codeBuilder.AppendLine(" }"); } private void AddWithPropertySetterToCodeBuilder(StringBuilder codeBuilder, ITypeSymbol typeSymbol, IPropertySymbol property, char entityNameChar) { - codeBuilder.AppendLine( + _ = codeBuilder.AppendLine( $" public {typeSymbol.Name} With{property.Name}(Func {property.Name}Setter)"); - codeBuilder.AppendLine(" {"); + _ = codeBuilder.AppendLine(" {"); - codeBuilder.AppendLine( + _ = codeBuilder.AppendLine( $" Faker.RuleFor({entityNameChar} => {entityNameChar}.{property.Name}, {property.Name}Setter);"); - codeBuilder.AppendLine(" return this;"); - codeBuilder.AppendLine(" }"); + _ = codeBuilder.AppendLine(" return this;"); + _ = codeBuilder.AppendLine(" }"); } } \ No newline at end of file diff --git a/coffeecard/CoffeeCard.Library/CoffeeCard.Library.csproj b/coffeecard/CoffeeCard.Library/CoffeeCard.Library.csproj index 5b085de9..96b18496 100644 --- a/coffeecard/CoffeeCard.Library/CoffeeCard.Library.csproj +++ b/coffeecard/CoffeeCard.Library/CoffeeCard.Library.csproj @@ -5,13 +5,12 @@ - + + - - @@ -20,7 +19,6 @@ - diff --git a/coffeecard/CoffeeCard.Library/Migrations/20230503203850_AzureMigration.cs b/coffeecard/CoffeeCard.Library/Migrations/20230503203850_AzureMigration.cs index e785ba9b..6d42b3af 100644 --- a/coffeecard/CoffeeCard.Library/Migrations/20230503203850_AzureMigration.cs +++ b/coffeecard/CoffeeCard.Library/Migrations/20230503203850_AzureMigration.cs @@ -1,5 +1,5 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; +using System; #nullable disable @@ -9,10 +9,10 @@ public partial class AzureMigration : Migration { protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.EnsureSchema( + _ = migrationBuilder.EnsureSchema( name: "dbo"); - migrationBuilder.CreateTable( + _ = migrationBuilder.CreateTable( name: "Products", schema: "dbo", columns: table => new @@ -28,10 +28,10 @@ protected override void Up(MigrationBuilder migrationBuilder) }, constraints: table => { - table.PrimaryKey("PK_Products", x => x.Id); + _ = table.PrimaryKey("PK_Products", x => x.Id); }); - migrationBuilder.CreateTable( + _ = migrationBuilder.CreateTable( name: "Programmes", schema: "dbo", columns: table => new @@ -44,10 +44,10 @@ protected override void Up(MigrationBuilder migrationBuilder) }, constraints: table => { - table.PrimaryKey("PK_Programmes", x => x.Id); + _ = table.PrimaryKey("PK_Programmes", x => x.Id); }); - migrationBuilder.CreateTable( + _ = migrationBuilder.CreateTable( name: "WebhookConfigurations", schema: "dbo", columns: table => new @@ -60,10 +60,10 @@ protected override void Up(MigrationBuilder migrationBuilder) }, constraints: table => { - table.PrimaryKey("PK_WebhookConfigurations", x => x.Id); + _ = table.PrimaryKey("PK_WebhookConfigurations", x => x.Id); }); - migrationBuilder.CreateTable( + _ = migrationBuilder.CreateTable( name: "ProductUserGroups", schema: "dbo", columns: table => new @@ -73,8 +73,8 @@ protected override void Up(MigrationBuilder migrationBuilder) }, constraints: table => { - table.PrimaryKey("PK_ProductUserGroups", x => new { x.ProductId, x.UserGroup }); - table.ForeignKey( + _ = table.PrimaryKey("PK_ProductUserGroups", x => new { x.ProductId, x.UserGroup }); + _ = table.ForeignKey( name: "FK_ProductUserGroups_Products_ProductId", column: x => x.ProductId, principalSchema: "dbo", @@ -83,7 +83,7 @@ protected override void Up(MigrationBuilder migrationBuilder) onDelete: ReferentialAction.Cascade); }); - migrationBuilder.CreateTable( + _ = migrationBuilder.CreateTable( name: "Users", schema: "dbo", columns: table => new @@ -105,8 +105,8 @@ protected override void Up(MigrationBuilder migrationBuilder) }, constraints: table => { - table.PrimaryKey("PK_Users", x => x.Id); - table.ForeignKey( + _ = table.PrimaryKey("PK_Users", x => x.Id); + _ = table.ForeignKey( name: "FK_Users_Programmes_Programme_Id", column: x => x.Programme_Id, principalSchema: "dbo", @@ -115,7 +115,7 @@ protected override void Up(MigrationBuilder migrationBuilder) onDelete: ReferentialAction.Cascade); }); - migrationBuilder.CreateTable( + _ = migrationBuilder.CreateTable( name: "LoginAttempts", schema: "dbo", columns: table => new @@ -127,8 +127,8 @@ protected override void Up(MigrationBuilder migrationBuilder) }, constraints: table => { - table.PrimaryKey("PK_LoginAttempts", x => x.Id); - table.ForeignKey( + _ = table.PrimaryKey("PK_LoginAttempts", x => x.Id); + _ = table.ForeignKey( name: "FK_LoginAttempts_Users_User_Id", column: x => x.User_Id, principalSchema: "dbo", @@ -137,7 +137,7 @@ protected override void Up(MigrationBuilder migrationBuilder) onDelete: ReferentialAction.Cascade); }); - migrationBuilder.CreateTable( + _ = migrationBuilder.CreateTable( name: "Purchases", schema: "dbo", columns: table => new @@ -157,15 +157,15 @@ protected override void Up(MigrationBuilder migrationBuilder) }, constraints: table => { - table.PrimaryKey("PK_Purchases", x => x.Id); - table.ForeignKey( + _ = table.PrimaryKey("PK_Purchases", x => x.Id); + _ = table.ForeignKey( name: "FK_Purchases_Products_ProductId", column: x => x.ProductId, principalSchema: "dbo", principalTable: "Products", principalColumn: "Id", onDelete: ReferentialAction.Cascade); - table.ForeignKey( + _ = table.ForeignKey( name: "FK_Purchases_Users_PurchasedBy_Id", column: x => x.PurchasedBy_Id, principalSchema: "dbo", @@ -174,7 +174,7 @@ protected override void Up(MigrationBuilder migrationBuilder) onDelete: ReferentialAction.Cascade); }); - migrationBuilder.CreateTable( + _ = migrationBuilder.CreateTable( name: "Statistics", schema: "dbo", columns: table => new @@ -189,8 +189,8 @@ protected override void Up(MigrationBuilder migrationBuilder) }, constraints: table => { - table.PrimaryKey("PK_Statistics", x => x.Id); - table.ForeignKey( + _ = table.PrimaryKey("PK_Statistics", x => x.Id); + _ = table.ForeignKey( name: "FK_Statistics_Users_User_Id", column: x => x.User_Id, principalSchema: "dbo", @@ -199,7 +199,7 @@ protected override void Up(MigrationBuilder migrationBuilder) onDelete: ReferentialAction.Cascade); }); - migrationBuilder.CreateTable( + _ = migrationBuilder.CreateTable( name: "Tokens", schema: "dbo", columns: table => new @@ -211,8 +211,8 @@ protected override void Up(MigrationBuilder migrationBuilder) }, constraints: table => { - table.PrimaryKey("PK_Tokens", x => x.Id); - table.ForeignKey( + _ = table.PrimaryKey("PK_Tokens", x => x.Id); + _ = table.ForeignKey( name: "FK_Tokens_Users_User_Id", column: x => x.User_Id, principalSchema: "dbo", @@ -220,7 +220,7 @@ protected override void Up(MigrationBuilder migrationBuilder) principalColumn: "Id"); }); - migrationBuilder.CreateTable( + _ = migrationBuilder.CreateTable( name: "Vouchers", schema: "dbo", columns: table => new @@ -237,15 +237,15 @@ protected override void Up(MigrationBuilder migrationBuilder) }, constraints: table => { - table.PrimaryKey("PK_Vouchers", x => x.Id); - table.ForeignKey( + _ = table.PrimaryKey("PK_Vouchers", x => x.Id); + _ = table.ForeignKey( name: "FK_Vouchers_Products_Product_Id", column: x => x.Product_Id, principalSchema: "dbo", principalTable: "Products", principalColumn: "Id", onDelete: ReferentialAction.Cascade); - table.ForeignKey( + _ = table.ForeignKey( name: "FK_Vouchers_Users_User_Id", column: x => x.User_Id, principalSchema: "dbo", @@ -253,7 +253,7 @@ protected override void Up(MigrationBuilder migrationBuilder) principalColumn: "Id"); }); - migrationBuilder.CreateTable( + _ = migrationBuilder.CreateTable( name: "Tickets", schema: "dbo", columns: table => new @@ -269,15 +269,15 @@ protected override void Up(MigrationBuilder migrationBuilder) }, constraints: table => { - table.PrimaryKey("PK_Tickets", x => x.Id); - table.ForeignKey( + _ = table.PrimaryKey("PK_Tickets", x => x.Id); + _ = table.ForeignKey( name: "FK_Tickets_Purchases_Purchase_Id", column: x => x.Purchase_Id, principalSchema: "dbo", principalTable: "Purchases", principalColumn: "Id", onDelete: ReferentialAction.Cascade); - table.ForeignKey( + _ = table.ForeignKey( name: "FK_Tickets_Users_Owner_Id", column: x => x.Owner_Id, principalSchema: "dbo", @@ -285,80 +285,80 @@ protected override void Up(MigrationBuilder migrationBuilder) principalColumn: "Id"); }); - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_LoginAttempts_User_Id", schema: "dbo", table: "LoginAttempts", column: "User_Id"); - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_Purchases_OrderId", schema: "dbo", table: "Purchases", column: "OrderId"); - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_Purchases_ProductId", schema: "dbo", table: "Purchases", column: "ProductId"); - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_Purchases_PurchasedBy_Id", schema: "dbo", table: "Purchases", column: "PurchasedBy_Id"); - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_Purchases_TransactionId", schema: "dbo", table: "Purchases", column: "TransactionId"); - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_Statistics_User_Id", schema: "dbo", table: "Statistics", column: "User_Id"); - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_Tickets_Owner_Id", schema: "dbo", table: "Tickets", column: "Owner_Id"); - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_Tickets_Purchase_Id", schema: "dbo", table: "Tickets", column: "Purchase_Id"); - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_Tokens_User_Id", schema: "dbo", table: "Tokens", column: "User_Id"); - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_Users_Programme_Id", schema: "dbo", table: "Users", column: "Programme_Id"); - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_Vouchers_Code", schema: "dbo", table: "Vouchers", column: "Code", unique: true); - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_Vouchers_Product_Id", schema: "dbo", table: "Vouchers", column: "Product_Id"); - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_Vouchers_User_Id", schema: "dbo", table: "Vouchers", @@ -367,47 +367,47 @@ protected override void Up(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder) { - migrationBuilder.DropTable( + _ = migrationBuilder.DropTable( name: "LoginAttempts", schema: "dbo"); - migrationBuilder.DropTable( + _ = migrationBuilder.DropTable( name: "ProductUserGroups", schema: "dbo"); - migrationBuilder.DropTable( + _ = migrationBuilder.DropTable( name: "Statistics", schema: "dbo"); - migrationBuilder.DropTable( + _ = migrationBuilder.DropTable( name: "Tickets", schema: "dbo"); - migrationBuilder.DropTable( + _ = migrationBuilder.DropTable( name: "Tokens", schema: "dbo"); - migrationBuilder.DropTable( + _ = migrationBuilder.DropTable( name: "Vouchers", schema: "dbo"); - migrationBuilder.DropTable( + _ = migrationBuilder.DropTable( name: "WebhookConfigurations", schema: "dbo"); - migrationBuilder.DropTable( + _ = migrationBuilder.DropTable( name: "Purchases", schema: "dbo"); - migrationBuilder.DropTable( + _ = migrationBuilder.DropTable( name: "Products", schema: "dbo"); - migrationBuilder.DropTable( + _ = migrationBuilder.DropTable( name: "Users", schema: "dbo"); - migrationBuilder.DropTable( + _ = migrationBuilder.DropTable( name: "Programmes", schema: "dbo"); } diff --git a/coffeecard/CoffeeCard.Library/Migrations/20230514103253_UserEmailIndexAdded.cs b/coffeecard/CoffeeCard.Library/Migrations/20230514103253_UserEmailIndexAdded.cs index a607dd82..8f4a00f7 100644 --- a/coffeecard/CoffeeCard.Library/Migrations/20230514103253_UserEmailIndexAdded.cs +++ b/coffeecard/CoffeeCard.Library/Migrations/20230514103253_UserEmailIndexAdded.cs @@ -8,7 +8,7 @@ public partial class UserEmailIndexAdded : Migration { protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.AlterColumn( + _ = migrationBuilder.AlterColumn( name: "Email", schema: "dbo", table: "Users", @@ -17,7 +17,7 @@ protected override void Up(MigrationBuilder migrationBuilder) oldClrType: typeof(string), oldType: "nvarchar(max)"); - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_Users_Email", schema: "dbo", table: "Users", @@ -26,12 +26,12 @@ protected override void Up(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder) { - migrationBuilder.DropIndex( + _ = migrationBuilder.DropIndex( name: "IX_Users_Email", schema: "dbo", table: "Users"); - migrationBuilder.AlterColumn( + _ = migrationBuilder.AlterColumn( name: "Email", schema: "dbo", table: "Users", diff --git a/coffeecard/CoffeeCard.Library/Migrations/20230523163048_StatisticIndex.cs b/coffeecard/CoffeeCard.Library/Migrations/20230523163048_StatisticIndex.cs index 79e4039f..da2fa7af 100644 --- a/coffeecard/CoffeeCard.Library/Migrations/20230523163048_StatisticIndex.cs +++ b/coffeecard/CoffeeCard.Library/Migrations/20230523163048_StatisticIndex.cs @@ -8,7 +8,7 @@ public partial class StatisticIndex : Migration { protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_Statistics_Preset_ExpiryDate", schema: "dbo", table: "Statistics", @@ -17,7 +17,7 @@ protected override void Up(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder) { - migrationBuilder.DropIndex( + _ = migrationBuilder.DropIndex( name: "IX_Statistics_Preset_ExpiryDate", schema: "dbo", table: "Statistics"); diff --git a/coffeecard/CoffeeCard.Library/Migrations/20230612202437_PurchaseStatus-Migration.cs b/coffeecard/CoffeeCard.Library/Migrations/20230612202437_PurchaseStatus-Migration.cs index bbd3aadc..619d6810 100644 --- a/coffeecard/CoffeeCard.Library/Migrations/20230612202437_PurchaseStatus-Migration.cs +++ b/coffeecard/CoffeeCard.Library/Migrations/20230612202437_PurchaseStatus-Migration.cs @@ -8,8 +8,8 @@ public partial class PurchaseStatusMigration : Migration { protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.Sql("UPDATE dbo.Purchases SET Status = 'Completed' WHERE Completed = 1 AND Status IS NULL"); - migrationBuilder.Sql("UPDATE dbo.Purchases SET Status = 'Cancelled' WHERE Completed = 0 AND Status IS NULL"); + _ = migrationBuilder.Sql("UPDATE dbo.Purchases SET Status = 'Completed' WHERE Completed = 1 AND Status IS NULL"); + _ = migrationBuilder.Sql("UPDATE dbo.Purchases SET Status = 'Cancelled' WHERE Completed = 0 AND Status IS NULL"); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/coffeecard/CoffeeCard.Library/Migrations/20230612203926_Purchases-DropCompletedColumn.cs b/coffeecard/CoffeeCard.Library/Migrations/20230612203926_Purchases-DropCompletedColumn.cs index a3eb291d..2c9ce3c1 100644 --- a/coffeecard/CoffeeCard.Library/Migrations/20230612203926_Purchases-DropCompletedColumn.cs +++ b/coffeecard/CoffeeCard.Library/Migrations/20230612203926_Purchases-DropCompletedColumn.cs @@ -8,12 +8,12 @@ public partial class PurchasesDropCompletedColumn : Migration { protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.DropColumn( + _ = migrationBuilder.DropColumn( name: "Completed", schema: "dbo", table: "Purchases"); - migrationBuilder.AlterColumn( + _ = migrationBuilder.AlterColumn( name: "Status", schema: "dbo", table: "Purchases", @@ -27,7 +27,7 @@ protected override void Up(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder) { - migrationBuilder.AlterColumn( + _ = migrationBuilder.AlterColumn( name: "Status", schema: "dbo", table: "Purchases", @@ -36,7 +36,7 @@ protected override void Down(MigrationBuilder migrationBuilder) oldClrType: typeof(string), oldType: "nvarchar(max)"); - migrationBuilder.AddColumn( + _ = migrationBuilder.AddColumn( name: "Completed", schema: "dbo", table: "Purchases", @@ -44,8 +44,8 @@ protected override void Down(MigrationBuilder migrationBuilder) nullable: false, defaultValue: false); - migrationBuilder.Sql("UPDATE dbo.Purchases SET Completed = 0 WHERE Status != 'Completed'"); - migrationBuilder.Sql("UPDATE dbo.Purchases SET Completed = 1 WHERE Status = 'Completed'"); + _ = migrationBuilder.Sql("UPDATE dbo.Purchases SET Completed = 0 WHERE Status != 'Completed'"); + _ = migrationBuilder.Sql("UPDATE dbo.Purchases SET Completed = 1 WHERE Status = 'Completed'"); } } } diff --git a/coffeecard/CoffeeCard.Library/Migrations/20230711144034_AddPurchaseTypes.cs b/coffeecard/CoffeeCard.Library/Migrations/20230711144034_AddPurchaseTypes.cs index 5054536d..82704425 100644 --- a/coffeecard/CoffeeCard.Library/Migrations/20230711144034_AddPurchaseTypes.cs +++ b/coffeecard/CoffeeCard.Library/Migrations/20230711144034_AddPurchaseTypes.cs @@ -8,21 +8,21 @@ public partial class AddPurchaseTypes : Migration { protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.AddColumn( + _ = migrationBuilder.AddColumn( name: "PurchaseId", schema: "dbo", table: "Vouchers", type: "int", nullable: true); - migrationBuilder.AddColumn( + _ = migrationBuilder.AddColumn( name: "Type", schema: "dbo", table: "Purchases", type: "nvarchar(max)", nullable: true); - migrationBuilder.CreateTable( + _ = migrationBuilder.CreateTable( name: "PosPurchases", schema: "dbo", columns: table => new @@ -32,8 +32,8 @@ protected override void Up(MigrationBuilder migrationBuilder) }, constraints: table => { - table.PrimaryKey("PK_PosPurchases", x => x.PurchaseId); - table.ForeignKey( + _ = table.PrimaryKey("PK_PosPurchases", x => x.PurchaseId); + _ = table.ForeignKey( name: "FK_PosPurchases_Purchases_PurchaseId", column: x => x.PurchaseId, principalSchema: "dbo", @@ -45,7 +45,7 @@ protected override void Up(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder) { - migrationBuilder.DropTable( + _ = migrationBuilder.DropTable( name: "PosPurchases", schema: "dbo"); } diff --git a/coffeecard/CoffeeCard.Library/Migrations/20230711161456_PurchaseDataCleanup.cs b/coffeecard/CoffeeCard.Library/Migrations/20230711161456_PurchaseDataCleanup.cs index 1095fdc8..261064dc 100644 --- a/coffeecard/CoffeeCard.Library/Migrations/20230711161456_PurchaseDataCleanup.cs +++ b/coffeecard/CoffeeCard.Library/Migrations/20230711161456_PurchaseDataCleanup.cs @@ -9,20 +9,20 @@ public partial class PurchaseDataCleanup : Migration protected override void Up(MigrationBuilder migrationBuilder) { // Set the Type Column on the purchases table - migrationBuilder.Sql("UPDATE dbo.Purchases SET Type = 'Voucher' WHERE TransactionId like 'VOUCHER%'"); - migrationBuilder.Sql("UPDATE dbo.Purchases SET Type = 'Free' Where TransactionId = '00000000-0000-0000-0000-000000000000'"); - migrationBuilder.Sql("UPDATE dbo.Purchases SET Type = 'MobilePayV1' Where (len(TransactionId) < 36 and TransactionId not like 'VOUCHER%' and not OrderId = 'Analog')"); - migrationBuilder.Sql("UPDATE dbo.Purchases SET Type = 'MobilePayV1' Where TransactionId is null"); - migrationBuilder.Sql("UPDATE dbo.Purchases SET Type = 'MobilePayV2' Where (len(TransactionId) = 36 and not TransactionId = '00000000-0000-0000-0000-000000000000') "); - migrationBuilder.Sql("UPDATE dbo.Purchases SET Type = 'PointOfSale' Where OrderId like 'Analog'"); + _ = migrationBuilder.Sql("UPDATE dbo.Purchases SET Type = 'Voucher' WHERE TransactionId like 'VOUCHER%'"); + _ = migrationBuilder.Sql("UPDATE dbo.Purchases SET Type = 'Free' Where TransactionId = '00000000-0000-0000-0000-000000000000'"); + _ = migrationBuilder.Sql("UPDATE dbo.Purchases SET Type = 'MobilePayV1' Where (len(TransactionId) < 36 and TransactionId not like 'VOUCHER%' and not OrderId = 'Analog')"); + _ = migrationBuilder.Sql("UPDATE dbo.Purchases SET Type = 'MobilePayV1' Where TransactionId is null"); + _ = migrationBuilder.Sql("UPDATE dbo.Purchases SET Type = 'MobilePayV2' Where (len(TransactionId) = 36 and not TransactionId = '00000000-0000-0000-0000-000000000000') "); + _ = migrationBuilder.Sql("UPDATE dbo.Purchases SET Type = 'PointOfSale' Where OrderId like 'Analog'"); // Update vouchers with references to the purchase issued by its redemption - migrationBuilder.Sql("update Vouchers set PurchaseId = Purchases.Id from Purchases where Purchases.OrderId = Vouchers.Code"); + _ = migrationBuilder.Sql("update Vouchers set PurchaseId = Purchases.Id from Purchases where Purchases.OrderId = Vouchers.Code"); // Create new vouchers for purchases where the same voucher have been used to issue multiple purchase - migrationBuilder.Sql("insert into Vouchers (Code, DateCreated, DateUsed, Description, Requester, Product_Id, User_Id, PurchaseId) select Purchases.OrderId + '-' + cast(Purchases.Id as varchar), Purchases.DateCreated, Purchases.DateCreated, 'Creation of extra vouchers for purchases without references', 'AnalogIO', Purchases.ProductId, Purchases.PurchasedBy_Id, Id from Purchases where Type = 'Voucher' and Id not in (select PurchaseId from Vouchers where PurchaseId is not null)"); + _ = migrationBuilder.Sql("insert into Vouchers (Code, DateCreated, DateUsed, Description, Requester, Product_Id, User_Id, PurchaseId) select Purchases.OrderId + '-' + cast(Purchases.Id as varchar), Purchases.DateCreated, Purchases.DateCreated, 'Creation of extra vouchers for purchases without references', 'AnalogIO', Purchases.ProductId, Purchases.PurchasedBy_Id, Id from Purchases where Type = 'Voucher' and Id not in (select PurchaseId from Vouchers where PurchaseId is not null)"); // Insert data to the new Pos table - migrationBuilder.Sql("insert into PosPurchases (PurchaseId, BaristaInitials) select Id, TransactionId from Purchases where OrderId like 'Analog'"); + _ = migrationBuilder.Sql("insert into PosPurchases (PurchaseId, BaristaInitials) select Id, TransactionId from Purchases where OrderId like 'Analog'"); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/coffeecard/CoffeeCard.Library/Migrations/20230714211716_PurchaseOrderIdUniqueAndExternalTransactionId.cs b/coffeecard/CoffeeCard.Library/Migrations/20230714211716_PurchaseOrderIdUniqueAndExternalTransactionId.cs index 1ffd6457..1209e14c 100644 --- a/coffeecard/CoffeeCard.Library/Migrations/20230714211716_PurchaseOrderIdUniqueAndExternalTransactionId.cs +++ b/coffeecard/CoffeeCard.Library/Migrations/20230714211716_PurchaseOrderIdUniqueAndExternalTransactionId.cs @@ -9,26 +9,26 @@ public partial class PurchaseOrderIdUniqueAndExternalTransactionId : Migration protected override void Up(MigrationBuilder migrationBuilder) { // Make transactionId null, where not MobilePayV1, or MobilepayV2, and generate unique Guid orderIds - migrationBuilder.Sql("update Purchases set OrderId = NEWID(), TransactionId=null where Type != 'MobilePayV1' and Type != 'MobilePayV2' or OrderId = 'OLD PURCHASES'"); + _ = migrationBuilder.Sql("update Purchases set OrderId = NEWID(), TransactionId=null where Type != 'MobilePayV1' and Type != 'MobilePayV2' or OrderId = 'OLD PURCHASES'"); - migrationBuilder.DropIndex( + _ = migrationBuilder.DropIndex( name: "IX_Purchases_OrderId", schema: "dbo", table: "Purchases"); - migrationBuilder.RenameColumn( + _ = migrationBuilder.RenameColumn( name: "TransactionId", schema: "dbo", table: "Purchases", newName: "ExternalTransactionId"); - migrationBuilder.RenameIndex( + _ = migrationBuilder.RenameIndex( name: "IX_Purchases_TransactionId", schema: "dbo", table: "Purchases", newName: "IX_Purchases_ExternalTransactionId"); - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_Purchases_OrderId", schema: "dbo", table: "Purchases", @@ -38,24 +38,24 @@ protected override void Up(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder) { - migrationBuilder.DropIndex( + _ = migrationBuilder.DropIndex( name: "IX_Purchases_OrderId", schema: "dbo", table: "Purchases"); - migrationBuilder.RenameColumn( + _ = migrationBuilder.RenameColumn( name: "ExternalTransactionId", schema: "dbo", table: "Purchases", newName: "TransactionId"); - migrationBuilder.RenameIndex( + _ = migrationBuilder.RenameIndex( name: "IX_Purchases_ExternalTransactionId", schema: "dbo", table: "Purchases", newName: "IX_Purchases_TransactionId"); - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_Purchases_OrderId", schema: "dbo", table: "Purchases", diff --git a/coffeecard/CoffeeCard.Library/Migrations/20230818201050_PurchaseTypeNonNullable.cs b/coffeecard/CoffeeCard.Library/Migrations/20230818201050_PurchaseTypeNonNullable.cs index 47e60fdb..3d14f67f 100644 --- a/coffeecard/CoffeeCard.Library/Migrations/20230818201050_PurchaseTypeNonNullable.cs +++ b/coffeecard/CoffeeCard.Library/Migrations/20230818201050_PurchaseTypeNonNullable.cs @@ -8,7 +8,7 @@ public partial class PurchaseTypeNonNullable : Migration { protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.AlterColumn( + _ = migrationBuilder.AlterColumn( name: "Type", schema: "dbo", table: "Purchases", @@ -21,7 +21,7 @@ protected override void Up(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder) { - migrationBuilder.AlterColumn( + _ = migrationBuilder.AlterColumn( name: "Type", schema: "dbo", table: "Purchases", diff --git a/coffeecard/CoffeeCard.Library/Migrations/20240111163619_NewIndexName.cs b/coffeecard/CoffeeCard.Library/Migrations/20240111163619_NewIndexName.cs index 46fbab57..ddffcb82 100644 --- a/coffeecard/CoffeeCard.Library/Migrations/20240111163619_NewIndexName.cs +++ b/coffeecard/CoffeeCard.Library/Migrations/20240111163619_NewIndexName.cs @@ -8,7 +8,7 @@ public partial class NewIndexName : Migration { protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.AlterColumn( + _ = migrationBuilder.AlterColumn( name: "Name", schema: "dbo", table: "Users", @@ -17,7 +17,7 @@ protected override void Up(MigrationBuilder migrationBuilder) oldClrType: typeof(string), oldType: "nvarchar(max)"); - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_Users_Name", schema: "dbo", table: "Users", @@ -26,12 +26,12 @@ protected override void Up(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder) { - migrationBuilder.DropIndex( + _ = migrationBuilder.DropIndex( name: "IX_Users_Name", schema: "dbo", table: "Users"); - migrationBuilder.AlterColumn( + _ = migrationBuilder.AlterColumn( name: "Name", schema: "dbo", table: "Users", diff --git a/coffeecard/CoffeeCard.Library/Migrations/20240120143222_MenuItemProducts.cs b/coffeecard/CoffeeCard.Library/Migrations/20240120143222_MenuItemProducts.cs index c2fbb5c1..627303af 100644 --- a/coffeecard/CoffeeCard.Library/Migrations/20240120143222_MenuItemProducts.cs +++ b/coffeecard/CoffeeCard.Library/Migrations/20240120143222_MenuItemProducts.cs @@ -8,14 +8,14 @@ public partial class MenuItemProducts : Migration { protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.AddColumn( + _ = migrationBuilder.AddColumn( name: "UsedOnMenuItemId", schema: "dbo", table: "Tickets", type: "int", nullable: true); - migrationBuilder.CreateTable( + _ = migrationBuilder.CreateTable( name: "MenuItems", schema: "dbo", columns: table => new @@ -26,10 +26,10 @@ protected override void Up(MigrationBuilder migrationBuilder) }, constraints: table => { - table.PrimaryKey("PK_MenuItems", x => x.Id); + _ = table.PrimaryKey("PK_MenuItems", x => x.Id); }); - migrationBuilder.CreateTable( + _ = migrationBuilder.CreateTable( name: "MenuItemProducts", schema: "dbo", columns: table => new @@ -39,15 +39,15 @@ protected override void Up(MigrationBuilder migrationBuilder) }, constraints: table => { - table.PrimaryKey("PK_MenuItemProducts", x => new { x.MenuItemId, x.ProductId }); - table.ForeignKey( + _ = table.PrimaryKey("PK_MenuItemProducts", x => new { x.MenuItemId, x.ProductId }); + _ = table.ForeignKey( name: "FK_MenuItemProducts_MenuItems_MenuItemId", column: x => x.MenuItemId, principalSchema: "dbo", principalTable: "MenuItems", principalColumn: "Id", onDelete: ReferentialAction.Cascade); - table.ForeignKey( + _ = table.ForeignKey( name: "FK_MenuItemProducts_Products_ProductId", column: x => x.ProductId, principalSchema: "dbo", @@ -56,26 +56,26 @@ protected override void Up(MigrationBuilder migrationBuilder) onDelete: ReferentialAction.Cascade); }); - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_Tickets_UsedOnMenuItemId", schema: "dbo", table: "Tickets", column: "UsedOnMenuItemId"); - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_MenuItemProducts_ProductId", schema: "dbo", table: "MenuItemProducts", column: "ProductId"); - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_MenuItems_Name", schema: "dbo", table: "MenuItems", column: "Name", unique: true); - migrationBuilder.AddForeignKey( + _ = migrationBuilder.AddForeignKey( name: "FK_Tickets_MenuItems_UsedOnMenuItemId", schema: "dbo", table: "Tickets", @@ -87,25 +87,25 @@ protected override void Up(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder) { - migrationBuilder.DropForeignKey( + _ = migrationBuilder.DropForeignKey( name: "FK_Tickets_MenuItems_UsedOnMenuItemId", schema: "dbo", table: "Tickets"); - migrationBuilder.DropTable( + _ = migrationBuilder.DropTable( name: "MenuItemProducts", schema: "dbo"); - migrationBuilder.DropTable( + _ = migrationBuilder.DropTable( name: "MenuItems", schema: "dbo"); - migrationBuilder.DropIndex( + _ = migrationBuilder.DropIndex( name: "IX_Tickets_UsedOnMenuItemId", schema: "dbo", table: "Tickets"); - migrationBuilder.DropColumn( + _ = migrationBuilder.DropColumn( name: "UsedOnMenuItemId", schema: "dbo", table: "Tickets"); diff --git a/coffeecard/CoffeeCard.Library/Migrations/20240213174936_addActiveToMenuItem.cs b/coffeecard/CoffeeCard.Library/Migrations/20240213174936_addActiveToMenuItem.cs index 4cde052c..ea5ee29d 100644 --- a/coffeecard/CoffeeCard.Library/Migrations/20240213174936_addActiveToMenuItem.cs +++ b/coffeecard/CoffeeCard.Library/Migrations/20240213174936_addActiveToMenuItem.cs @@ -8,7 +8,7 @@ public partial class addActiveToMenuItem : Migration { protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.AddColumn( + _ = migrationBuilder.AddColumn( name: "Active", schema: "dbo", table: "MenuItems", @@ -19,7 +19,7 @@ protected override void Up(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder) { - migrationBuilder.DropColumn( + _ = migrationBuilder.DropColumn( name: "Active", schema: "dbo", table: "MenuItems"); diff --git a/coffeecard/CoffeeCard.Library/Migrations/20240227174524_AddUserGroupIndexToUsers.cs b/coffeecard/CoffeeCard.Library/Migrations/20240227174524_AddUserGroupIndexToUsers.cs index 3b18115e..2dec24a4 100644 --- a/coffeecard/CoffeeCard.Library/Migrations/20240227174524_AddUserGroupIndexToUsers.cs +++ b/coffeecard/CoffeeCard.Library/Migrations/20240227174524_AddUserGroupIndexToUsers.cs @@ -10,7 +10,7 @@ public partial class AddUserGroupIndexToUsers : Migration /// protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.CreateIndex( + _ = migrationBuilder.CreateIndex( name: "IX_Users_UserGroup", schema: "dbo", table: "Users", @@ -20,7 +20,7 @@ protected override void Up(MigrationBuilder migrationBuilder) /// protected override void Down(MigrationBuilder migrationBuilder) { - migrationBuilder.DropIndex( + _ = migrationBuilder.DropIndex( name: "IX_Users_UserGroup", schema: "dbo", table: "Users"); diff --git a/coffeecard/CoffeeCard.Library/Persistence/CoffeecardContext.cs b/coffeecard/CoffeeCard.Library/Persistence/CoffeecardContext.cs index 1ee05f1e..c471d654 100644 --- a/coffeecard/CoffeeCard.Library/Persistence/CoffeecardContext.cs +++ b/coffeecard/CoffeeCard.Library/Persistence/CoffeecardContext.cs @@ -36,20 +36,20 @@ public CoffeeCardContext(DbContextOptions options, DatabaseSe protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.HasDefaultSchema(_databaseSettings.SchemaName); + _ = modelBuilder.HasDefaultSchema(_databaseSettings.SchemaName); // Setup PUG compound primary key - modelBuilder.Entity() + _ = modelBuilder.Entity() .HasKey(pug => new { pug.ProductId, pug.UserGroup }); - modelBuilder.Entity() + _ = modelBuilder.Entity() .HasKey(mip => new { mip.MenuItemId, mip.ProductId }); - modelBuilder.Entity() + _ = modelBuilder.Entity() .HasMany(mi => mi.AssociatedProducts) .WithMany(p => p.EligibleMenuItems) .UsingEntity(); @@ -59,29 +59,29 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) // Use Enum to String for PurchaseTypes var purchaseTypeStringConverter = new EnumToStringConverter(); - modelBuilder.Entity() + _ = modelBuilder.Entity() .Property(u => u.UserGroup) .HasConversion(userGroupIntConverter); - modelBuilder.Entity() + _ = modelBuilder.Entity() .Property(p => p.Type) .HasConversion(purchaseTypeStringConverter); - modelBuilder.Entity().Property(u => u.UserState).HasConversion(); + _ = modelBuilder.Entity().Property(u => u.UserState).HasConversion(); - modelBuilder.Entity() + _ = modelBuilder.Entity() .Property(pug => pug.UserGroup) .HasConversion(userGroupIntConverter); - modelBuilder.Entity() + _ = modelBuilder.Entity() .Property(w => w.Status) .HasConversion(); - modelBuilder.Entity() + _ = modelBuilder.Entity() .Property(p => p.Status) .HasConversion(); - modelBuilder.Entity() + _ = modelBuilder.Entity() .HasOne(t => t.Owner) .WithMany(u => u.Tickets) .HasForeignKey(t => t.OwnerId) diff --git a/coffeecard/CoffeeCard.Library/Services/AccountService.cs b/coffeecard/CoffeeCard.Library/Services/AccountService.cs index 71a723b0..c292471e 100644 --- a/coffeecard/CoffeeCard.Library/Services/AccountService.cs +++ b/coffeecard/CoffeeCard.Library/Services/AccountService.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Text.RegularExpressions; -using System.Threading.Tasks; using CoffeeCard.Common.Configuration; using CoffeeCard.Common.Errors; using CoffeeCard.Library.Persistence; @@ -12,6 +6,11 @@ using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using Serilog; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using System.Text.RegularExpressions; +using System.Threading.Tasks; namespace CoffeeCard.Library.Services { @@ -129,8 +128,8 @@ public async Task RegisterAccountAsync(string name, string email, string p UserGroup = UserGroup.Customer }; - _context.Users.Add(user); - await _context.SaveChangesAsync(); + _ = _context.Users.Add(user); + _ = await _context.SaveChangesAsync(); var claims = new[] { @@ -198,7 +197,7 @@ public User UpdateAccount(IEnumerable claims, UpdateUserDto userDto) Log.Information("User changed password"); } - _context.SaveChanges(); + _ = _context.SaveChanges(); return user; } @@ -221,7 +220,7 @@ public void UpdateExperience(int userId, int exp) user.Experience += exp; - _context.SaveChanges(); + _ = _context.SaveChanges(); } public async Task ForgotPasswordAsync(string email) @@ -237,7 +236,7 @@ public async Task ForgotPasswordAsync(string email) }; var verificationToken = _tokenService.GenerateToken(claims); user.Tokens.Add(new Token(verificationToken)); - _context.SaveChanges(); + _ = _context.SaveChanges(); await _emailService.SendVerificationEmailForLostPwAsync(user, verificationToken); } @@ -260,7 +259,7 @@ public async Task RecoverUserAsync(string token, string newPassword) user.Password = hashedPassword; user.IsVerified = true; user.Tokens.Clear(); - await _context.SaveChangesAsync(); + _ = await _context.SaveChangesAsync(); return true; } diff --git a/coffeecard/CoffeeCard.Library/Services/EmailService.cs b/coffeecard/CoffeeCard.Library/Services/EmailService.cs index 2b3f8353..2b68bab7 100644 --- a/coffeecard/CoffeeCard.Library/Services/EmailService.cs +++ b/coffeecard/CoffeeCard.Library/Services/EmailService.cs @@ -1,7 +1,4 @@ -using System; -using System.IO; -using System.Threading.Tasks; -using CoffeeCard.Common.Configuration; +using CoffeeCard.Common.Configuration; using CoffeeCard.Models.DataTransferObjects.Purchase; using CoffeeCard.Models.DataTransferObjects.User; using CoffeeCard.Models.Entities; @@ -10,6 +7,9 @@ using RestSharp; using RestSharp.Authenticators; using Serilog; +using System; +using System.IO; +using System.Threading.Tasks; using TimeZoneConverter; namespace CoffeeCard.Library.Services @@ -159,12 +159,12 @@ private async Task SendEmailAsync(MimeMessage mail) }; var request = new RestRequest(); - request.AddParameter("domain", _mailgunSettings.Domain, ParameterType.UrlSegment); + _ = request.AddParameter("domain", _mailgunSettings.Domain, ParameterType.UrlSegment); request.Resource = "{domain}/messages"; - request.AddParameter("from", "Cafe Analog "); - request.AddParameter("to", mail.To[0].ToString()); - request.AddParameter("subject", mail.Subject); - request.AddParameter("html", mail.HtmlBody); + _ = request.AddParameter("from", "Cafe Analog "); + _ = request.AddParameter("to", mail.To[0].ToString()); + _ = request.AddParameter("subject", mail.Subject); + _ = request.AddParameter("html", mail.HtmlBody); request.Method = Method.Post; var response = await client.ExecutePostAsync(request); diff --git a/coffeecard/CoffeeCard.Library/Services/IAccountService.cs b/coffeecard/CoffeeCard.Library/Services/IAccountService.cs index e0e504fe..d942e832 100644 --- a/coffeecard/CoffeeCard.Library/Services/IAccountService.cs +++ b/coffeecard/CoffeeCard.Library/Services/IAccountService.cs @@ -1,8 +1,8 @@ +using CoffeeCard.Models.DataTransferObjects.User; +using CoffeeCard.Models.Entities; using System.Collections.Generic; using System.Security.Claims; using System.Threading.Tasks; -using CoffeeCard.Models.DataTransferObjects.User; -using CoffeeCard.Models.Entities; namespace CoffeeCard.Library.Services { diff --git a/coffeecard/CoffeeCard.Library/Services/IEmailService.cs b/coffeecard/CoffeeCard.Library/Services/IEmailService.cs index 5f89d0f3..f365a480 100644 --- a/coffeecard/CoffeeCard.Library/Services/IEmailService.cs +++ b/coffeecard/CoffeeCard.Library/Services/IEmailService.cs @@ -1,7 +1,7 @@ -using System.Threading.Tasks; using CoffeeCard.Models.DataTransferObjects.Purchase; using CoffeeCard.Models.DataTransferObjects.User; using CoffeeCard.Models.Entities; +using System.Threading.Tasks; namespace CoffeeCard.Library.Services { diff --git a/coffeecard/CoffeeCard.Library/Services/ILeaderboardService.cs b/coffeecard/CoffeeCard.Library/Services/ILeaderboardService.cs index 34d61230..60987631 100644 --- a/coffeecard/CoffeeCard.Library/Services/ILeaderboardService.cs +++ b/coffeecard/CoffeeCard.Library/Services/ILeaderboardService.cs @@ -1,6 +1,6 @@ -using System.Collections.Generic; -using CoffeeCard.Models.DataTransferObjects; +using CoffeeCard.Models.DataTransferObjects; using CoffeeCard.Models.Entities; +using System.Collections.Generic; namespace CoffeeCard.Library.Services { diff --git a/coffeecard/CoffeeCard.Library/Services/IMapperService.cs b/coffeecard/CoffeeCard.Library/Services/IMapperService.cs index e3f38614..e7a18b5c 100644 --- a/coffeecard/CoffeeCard.Library/Services/IMapperService.cs +++ b/coffeecard/CoffeeCard.Library/Services/IMapperService.cs @@ -1,10 +1,10 @@ -using System.Collections.Generic; -using CoffeeCard.Models.DataTransferObjects.Product; +using CoffeeCard.Models.DataTransferObjects.Product; using CoffeeCard.Models.DataTransferObjects.Programme; using CoffeeCard.Models.DataTransferObjects.Purchase; using CoffeeCard.Models.DataTransferObjects.Ticket; using CoffeeCard.Models.DataTransferObjects.User; using CoffeeCard.Models.Entities; +using System.Collections.Generic; namespace CoffeeCard.Library.Services { diff --git a/coffeecard/CoffeeCard.Library/Services/IProductService.cs b/coffeecard/CoffeeCard.Library/Services/IProductService.cs index be9cd8c2..603d78f5 100644 --- a/coffeecard/CoffeeCard.Library/Services/IProductService.cs +++ b/coffeecard/CoffeeCard.Library/Services/IProductService.cs @@ -1,7 +1,7 @@ -using System; +using CoffeeCard.Models.Entities; +using System; using System.Collections.Generic; using System.Threading.Tasks; -using CoffeeCard.Models.Entities; namespace CoffeeCard.Library.Services { diff --git a/coffeecard/CoffeeCard.Library/Services/IProgrammeService.cs b/coffeecard/CoffeeCard.Library/Services/IProgrammeService.cs index 00fbef38..3fdb4c7f 100644 --- a/coffeecard/CoffeeCard.Library/Services/IProgrammeService.cs +++ b/coffeecard/CoffeeCard.Library/Services/IProgrammeService.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; -using CoffeeCard.Models.Entities; +using CoffeeCard.Models.Entities; +using System.Collections.Generic; namespace CoffeeCard.Library.Services { diff --git a/coffeecard/CoffeeCard.Library/Services/IPurchaseService.cs b/coffeecard/CoffeeCard.Library/Services/IPurchaseService.cs index c8ff06c9..49186ef4 100644 --- a/coffeecard/CoffeeCard.Library/Services/IPurchaseService.cs +++ b/coffeecard/CoffeeCard.Library/Services/IPurchaseService.cs @@ -1,10 +1,8 @@ -using System; +using CoffeeCard.Models.Entities; +using System; using System.Collections.Generic; using System.Security.Claims; using System.Threading.Tasks; -using CoffeeCard.Models.DataTransferObjects.MobilePay; -using CoffeeCard.Models.DataTransferObjects.Purchase; -using CoffeeCard.Models.Entities; namespace CoffeeCard.Library.Services { diff --git a/coffeecard/CoffeeCard.Library/Services/ITicketService.cs b/coffeecard/CoffeeCard.Library/Services/ITicketService.cs index 37810037..81fbf729 100644 --- a/coffeecard/CoffeeCard.Library/Services/ITicketService.cs +++ b/coffeecard/CoffeeCard.Library/Services/ITicketService.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; -using System.Security.Claims; -using System.Threading.Tasks; -using CoffeeCard.Models.DataTransferObjects.CoffeeCard; +using CoffeeCard.Models.DataTransferObjects.CoffeeCard; using CoffeeCard.Models.DataTransferObjects.Ticket; using CoffeeCard.Models.Entities; +using System.Collections.Generic; +using System.Security.Claims; +using System.Threading.Tasks; namespace CoffeeCard.Library.Services { diff --git a/coffeecard/CoffeeCard.Library/Services/LoginLimiter.cs b/coffeecard/CoffeeCard.Library/Services/LoginLimiter.cs index 2d897ef1..841c9aad 100644 --- a/coffeecard/CoffeeCard.Library/Services/LoginLimiter.cs +++ b/coffeecard/CoffeeCard.Library/Services/LoginLimiter.cs @@ -1,8 +1,8 @@ -using System; -using System.Collections.Concurrent; using CoffeeCard.Common.Configuration; using CoffeeCard.Models.Entities; using Serilog; +using System; +using System.Collections.Concurrent; namespace CoffeeCard.Library.Services { @@ -69,7 +69,7 @@ public bool LoginAllowed(User user) /// public void ResetLoginAttemptsForUser(User user) { - _loginAttempts.TryRemove(user.Email, out var value); + _ = _loginAttempts.TryRemove(user.Email, out _); } } } \ No newline at end of file diff --git a/coffeecard/CoffeeCard.Library/Services/MapperService.cs b/coffeecard/CoffeeCard.Library/Services/MapperService.cs index fb371582..51c45303 100644 --- a/coffeecard/CoffeeCard.Library/Services/MapperService.cs +++ b/coffeecard/CoffeeCard.Library/Services/MapperService.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; -using System.Linq; using CoffeeCard.Library.Utils; using CoffeeCard.Models.DataTransferObjects.Product; using CoffeeCard.Models.DataTransferObjects.Programme; @@ -7,6 +5,8 @@ using CoffeeCard.Models.DataTransferObjects.Ticket; using CoffeeCard.Models.DataTransferObjects.User; using CoffeeCard.Models.Entities; +using System.Collections.Generic; +using System.Linq; namespace CoffeeCard.Library.Services { diff --git a/coffeecard/CoffeeCard.Library/Services/ProductService.cs b/coffeecard/CoffeeCard.Library/Services/ProductService.cs index 775b6497..8162c28c 100644 --- a/coffeecard/CoffeeCard.Library/Services/ProductService.cs +++ b/coffeecard/CoffeeCard.Library/Services/ProductService.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using CoffeeCard.Library.Persistence; +using CoffeeCard.Library.Persistence; using CoffeeCard.Models.Entities; using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; namespace CoffeeCard.Library.Services { diff --git a/coffeecard/CoffeeCard.Library/Services/ProgrammeService.cs b/coffeecard/CoffeeCard.Library/Services/ProgrammeService.cs index 1bc825d9..44e2717b 100644 --- a/coffeecard/CoffeeCard.Library/Services/ProgrammeService.cs +++ b/coffeecard/CoffeeCard.Library/Services/ProgrammeService.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; -using System.Linq; -using CoffeeCard.Library.Persistence; +using CoffeeCard.Library.Persistence; using CoffeeCard.Models.Entities; +using System.Collections.Generic; +using System.Linq; namespace CoffeeCard.Library.Services { diff --git a/coffeecard/CoffeeCard.Library/Services/PurchaseService.cs b/coffeecard/CoffeeCard.Library/Services/PurchaseService.cs index 04bd0895..900bad64 100644 --- a/coffeecard/CoffeeCard.Library/Services/PurchaseService.cs +++ b/coffeecard/CoffeeCard.Library/Services/PurchaseService.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; using CoffeeCard.Common; using CoffeeCard.Common.Errors; using CoffeeCard.Library.Persistence; @@ -11,6 +6,11 @@ using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using Serilog; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using System.Threading.Tasks; namespace CoffeeCard.Library.Services { @@ -51,15 +51,15 @@ public async Task RedeemVoucher(string voucherCode, IEnumerable user.Purchases.Add(purchase); - DeliverProductToUser(purchase, user, $"VOUCHER: {voucher.Id}"); + _ = DeliverProductToUser(purchase, user, $"VOUCHER: {voucher.Id}"); voucher.DateUsed = DateTime.UtcNow; voucher.User = user; voucher.Purchase = purchase; - _context.Vouchers.Attach(voucher); + _ = _context.Vouchers.Attach(voucher); _context.Entry(voucher).State = EntityState.Modified; - _context.SaveChanges(); + _ = _context.SaveChanges(); return purchase; } @@ -93,9 +93,9 @@ public Purchase DeliverProductToUser(Purchase purchase, User user, string transa purchase.ExternalTransactionId = transactionId; - _context.Users.Attach(user); + _ = _context.Users.Attach(user); _context.Entry(user).State = EntityState.Modified; - _context.SaveChanges(); + _ = _context.SaveChanges(); Log.Information( $"Delivery of product ({purchase.ProductId}) to userId: {user.Id} with orderId: {purchase.OrderId} succeeded!"); diff --git a/coffeecard/CoffeeCard.Library/Services/TicketService.cs b/coffeecard/CoffeeCard.Library/Services/TicketService.cs index fe54893e..65ad9687 100644 --- a/coffeecard/CoffeeCard.Library/Services/TicketService.cs +++ b/coffeecard/CoffeeCard.Library/Services/TicketService.cs @@ -1,19 +1,18 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using CoffeeCard.Common; +using CoffeeCard.Common; using CoffeeCard.Common.Errors; using CoffeeCard.Library.Persistence; using CoffeeCard.Library.Services.v2; -using CoffeeCard.Models.DataTransferObjects; using CoffeeCard.Models.DataTransferObjects.CoffeeCard; using CoffeeCard.Models.DataTransferObjects.Ticket; using CoffeeCard.Models.Entities; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using Serilog; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using System.Threading.Tasks; namespace CoffeeCard.Library.Services { @@ -55,7 +54,7 @@ public async Task UseTicket(IEnumerable claims, int productId) UpdateTicket(usedTicket); await UpdateUserRank(userId, 1); - _context.SaveChanges(); + _ = _context.SaveChanges(); return usedTicket; } @@ -106,7 +105,7 @@ public async Task> UseMultipleTickets(IEnumerable cla { // update user experience usedTickets.ForEach(x => _accountService.UpdateExperience(userId, GetExperienceByTicket(x.ProductId))); - _context.SaveChanges(); + _ = _context.SaveChanges(); Log.Information("All tickets were successfully used, updated and saved!"); } else diff --git a/coffeecard/CoffeeCard.Library/Services/TokenService.cs b/coffeecard/CoffeeCard.Library/Services/TokenService.cs index 581d01e8..14439f5d 100644 --- a/coffeecard/CoffeeCard.Library/Services/TokenService.cs +++ b/coffeecard/CoffeeCard.Library/Services/TokenService.cs @@ -1,10 +1,3 @@ -using System; -using System.Collections.Generic; -using System.IdentityModel.Tokens.Jwt; -using System.Linq; -using System.Security.Claims; -using System.Text; -using System.Threading.Tasks; using CoffeeCard.Common.Configuration; using CoffeeCard.Common.Errors; using CoffeeCard.Library.Utils; @@ -12,6 +5,13 @@ using Microsoft.AspNetCore.Http; using Microsoft.IdentityModel.Tokens; using Serilog; +using System; +using System.Collections.Generic; +using System.IdentityModel.Tokens.Jwt; +using System.Linq; +using System.Security.Claims; +using System.Text; +using System.Threading.Tasks; namespace CoffeeCard.Library.Services { @@ -72,7 +72,7 @@ public bool ValidateToken(string tokenString) ClockSkew = TimeSpan.Zero //the default for this setting is 5 minutes }; - securityTokenHandler.ValidateToken(tokenString, validationParameters, out _); // Throws exception if token is invalid + _ = securityTokenHandler.ValidateToken(tokenString, validationParameters, out _); // Throws exception if token is invalid } catch (Exception e) when (e is ArgumentException || e is SecurityTokenException) diff --git a/coffeecard/CoffeeCard.Library/Services/v2/AccountService.cs b/coffeecard/CoffeeCard.Library/Services/v2/AccountService.cs index 2e91b90b..ca9873ab 100644 --- a/coffeecard/CoffeeCard.Library/Services/v2/AccountService.cs +++ b/coffeecard/CoffeeCard.Library/Services/v2/AccountService.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; using CoffeeCard.Common.Errors; using CoffeeCard.Library.Persistence; using CoffeeCard.Models.DataTransferObjects.v2.User; @@ -10,6 +5,11 @@ using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using Serilog; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using System.Threading.Tasks; namespace CoffeeCard.Library.Services.v2 { @@ -56,8 +56,8 @@ public async Task RegisterAccountAsync(string name, string email, string p UserGroup = UserGroup.Customer }; - _context.Users.Add(user); - await _context.SaveChangesAsync(); + _ = _context.Users.Add(user); + _ = await _context.SaveChangesAsync(); await SendAccountVerificationEmail(user); @@ -117,7 +117,7 @@ public async Task UpdateAccountAsync(User user, UpdateUserRequest updateUs Log.Information("User changed password"); } - await _context.SaveChangesAsync(); + _ = await _context.SaveChangesAsync(); return user; } @@ -187,7 +187,7 @@ private async Task AnonymizeUserAsync(User user) user.DateUpdated = DateTime.Now; user.PrivacyActivated = true; user.UserState = UserState.Deleted; - await _context.SaveChangesAsync(); + _ = await _context.SaveChangesAsync(); } private async Task GetAccountByEmailAsync(string email) @@ -206,7 +206,7 @@ public async Task UpdateUserGroup(UserGroup userGroup, int userId) user.UserGroup = userGroup; - await _context.SaveChangesAsync(); + _ = await _context.SaveChangesAsync(); } @@ -278,13 +278,13 @@ private static string EscapeName(string name) public async Task UpdatePriviligedUserGroups(WebhookUpdateUserGroupRequest request) { - await _context.Users + _ = await _context.Users .Where(u => u.UserGroup != UserGroup.Customer) .ExecuteUpdateAsync(u => u.SetProperty(u => u.UserGroup, UserGroup.Customer)); foreach (var item in request.PrivilegedUsers) { - await _context.Users + _ = await _context.Users .Where(u => u.Id == item.AccountId) .ExecuteUpdateAsync(u => u.SetProperty(u => u.UserGroup, item.UserGroup)); } diff --git a/coffeecard/CoffeeCard.Library/Services/v2/IAccountService.cs b/coffeecard/CoffeeCard.Library/Services/v2/IAccountService.cs index cd5d90fc..b88501c0 100644 --- a/coffeecard/CoffeeCard.Library/Services/v2/IAccountService.cs +++ b/coffeecard/CoffeeCard.Library/Services/v2/IAccountService.cs @@ -1,11 +1,10 @@ +using CoffeeCard.Common.Errors; +using CoffeeCard.Models.DataTransferObjects.v2.User; +using CoffeeCard.Models.Entities; using System; using System.Collections.Generic; using System.Security.Claims; using System.Threading.Tasks; -using CoffeeCard.Common.Errors; -using CoffeeCard.Models.DataTransferObjects.v2.User; -using CoffeeCard.Models.Entities; -using Microsoft.AspNetCore.Mvc; namespace CoffeeCard.Library.Services.v2 { diff --git a/coffeecard/CoffeeCard.Library/Services/v2/ILeaderboardService.cs b/coffeecard/CoffeeCard.Library/Services/v2/ILeaderboardService.cs index 0c09e0fe..f889c8ab 100644 --- a/coffeecard/CoffeeCard.Library/Services/v2/ILeaderboardService.cs +++ b/coffeecard/CoffeeCard.Library/Services/v2/ILeaderboardService.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; -using System.Threading.Tasks; using CoffeeCard.Models.DataTransferObjects.v2.Leaderboard; using CoffeeCard.Models.Entities; +using System.Collections.Generic; +using System.Threading.Tasks; namespace CoffeeCard.Library.Services.v2 { diff --git a/coffeecard/CoffeeCard.Library/Services/v2/IMenuItemService.cs b/coffeecard/CoffeeCard.Library/Services/v2/IMenuItemService.cs index 6f85551d..c0650d72 100644 --- a/coffeecard/CoffeeCard.Library/Services/v2/IMenuItemService.cs +++ b/coffeecard/CoffeeCard.Library/Services/v2/IMenuItemService.cs @@ -1,8 +1,7 @@ +using CoffeeCard.Models.DataTransferObjects.v2.MenuItems; using System; using System.Collections.Generic; using System.Threading.Tasks; -using CoffeeCard.Models.DataTransferObjects.v2.Product; -using CoffeeCard.Models.DataTransferObjects.v2.Products; namespace CoffeeCard.Library.Services.v2 { diff --git a/coffeecard/CoffeeCard.Library/Services/v2/IProductService.cs b/coffeecard/CoffeeCard.Library/Services/v2/IProductService.cs index 0ff74568..35e9c631 100644 --- a/coffeecard/CoffeeCard.Library/Services/v2/IProductService.cs +++ b/coffeecard/CoffeeCard.Library/Services/v2/IProductService.cs @@ -1,9 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; using CoffeeCard.Models.DataTransferObjects.v2.Product; using CoffeeCard.Models.DataTransferObjects.v2.Products; using CoffeeCard.Models.Entities; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; namespace CoffeeCard.Library.Services.v2 { diff --git a/coffeecard/CoffeeCard.Library/Services/v2/IPurchaseService.cs b/coffeecard/CoffeeCard.Library/Services/v2/IPurchaseService.cs index c0f886ca..55f01ce5 100644 --- a/coffeecard/CoffeeCard.Library/Services/v2/IPurchaseService.cs +++ b/coffeecard/CoffeeCard.Library/Services/v2/IPurchaseService.cs @@ -1,9 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using CoffeeCard.Models.DataTransferObjects.v2.MobilePay; +using CoffeeCard.Models.DataTransferObjects.v2.MobilePay; using CoffeeCard.Models.DataTransferObjects.v2.Purchase; using CoffeeCard.Models.Entities; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; namespace CoffeeCard.Library.Services.v2 { diff --git a/coffeecard/CoffeeCard.Library/Services/v2/ITicketService.cs b/coffeecard/CoffeeCard.Library/Services/v2/ITicketService.cs index 924ef0b4..0511cdb7 100644 --- a/coffeecard/CoffeeCard.Library/Services/v2/ITicketService.cs +++ b/coffeecard/CoffeeCard.Library/Services/v2/ITicketService.cs @@ -1,8 +1,8 @@ +using CoffeeCard.Models.DataTransferObjects.v2.Ticket; +using CoffeeCard.Models.Entities; using System; using System.Collections.Generic; using System.Threading.Tasks; -using CoffeeCard.Models.DataTransferObjects.v2.Ticket; -using CoffeeCard.Models.Entities; namespace CoffeeCard.Library.Services.v2 { diff --git a/coffeecard/CoffeeCard.Library/Services/v2/IVoucherService.cs b/coffeecard/CoffeeCard.Library/Services/v2/IVoucherService.cs index f74c3b94..46052419 100644 --- a/coffeecard/CoffeeCard.Library/Services/v2/IVoucherService.cs +++ b/coffeecard/CoffeeCard.Library/Services/v2/IVoucherService.cs @@ -1,6 +1,6 @@ +using CoffeeCard.Models.DataTransferObjects.v2.Voucher; using System.Collections.Generic; using System.Threading.Tasks; -using CoffeeCard.Models.DataTransferObjects.v2.Voucher; namespace CoffeeCard.Library.Services.v2 { diff --git a/coffeecard/CoffeeCard.Library/Services/v2/LeaderboardService.cs b/coffeecard/CoffeeCard.Library/Services/v2/LeaderboardService.cs index e08a4aae..6668a933 100644 --- a/coffeecard/CoffeeCard.Library/Services/v2/LeaderboardService.cs +++ b/coffeecard/CoffeeCard.Library/Services/v2/LeaderboardService.cs @@ -1,12 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using CoffeeCard.Library.Persistence; using CoffeeCard.Library.Utils; using CoffeeCard.Models.DataTransferObjects.v2.Leaderboard; using CoffeeCard.Models.Entities; using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; namespace CoffeeCard.Library.Services.v2 { diff --git a/coffeecard/CoffeeCard.Library/Services/v2/MenuItemService.cs b/coffeecard/CoffeeCard.Library/Services/v2/MenuItemService.cs index d206423e..fd9d073e 100644 --- a/coffeecard/CoffeeCard.Library/Services/v2/MenuItemService.cs +++ b/coffeecard/CoffeeCard.Library/Services/v2/MenuItemService.cs @@ -1,14 +1,12 @@ -using System.Collections.Generic; -using System.Data; -using System.Linq; -using System.Threading.Tasks; using CoffeeCard.Common.Errors; using CoffeeCard.Library.Persistence; -using CoffeeCard.Models.DataTransferObjects.v2.Product; -using CoffeeCard.Models.DataTransferObjects.v2.Products; +using CoffeeCard.Models.DataTransferObjects.v2.MenuItems; using CoffeeCard.Models.Entities; using Microsoft.EntityFrameworkCore; using Serilog; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; namespace CoffeeCard.Library.Services.v2 { @@ -47,8 +45,8 @@ public async Task AddMenuItemAsync(AddMenuItemRequest newMenuI Name = newMenuItem.Name }; - _context.MenuItems.Add(menuItem); - await _context.SaveChangesAsync(); + _ = _context.MenuItems.Add(menuItem); + _ = await _context.SaveChangesAsync(); var result = new MenuItemResponse { @@ -92,7 +90,7 @@ public async Task UpdateMenuItemAsync(int id, UpdateMenuItemRe menuItem.Name = changedMenuItem.Name; menuItem.Active = changedMenuItem.Active; - await _context.SaveChangesAsync(); + _ = await _context.SaveChangesAsync(); var result = new MenuItemResponse { diff --git a/coffeecard/CoffeeCard.Library/Services/v2/ProductService.cs b/coffeecard/CoffeeCard.Library/Services/v2/ProductService.cs index cd16e9ea..edb04ad0 100644 --- a/coffeecard/CoffeeCard.Library/Services/v2/ProductService.cs +++ b/coffeecard/CoffeeCard.Library/Services/v2/ProductService.cs @@ -1,15 +1,14 @@ -using System.Collections.Generic; -using System.Data; -using System.Linq; -using System.Threading.Tasks; using CoffeeCard.Common.Errors; using CoffeeCard.Library.Persistence; +using CoffeeCard.Library.Utils; using CoffeeCard.Models.DataTransferObjects.v2.Product; using CoffeeCard.Models.DataTransferObjects.v2.Products; using CoffeeCard.Models.Entities; using Microsoft.EntityFrameworkCore; using Serilog; -using CoffeeCard.Library.Utils; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; namespace CoffeeCard.Library.Services.v2 { @@ -99,8 +98,8 @@ public async Task AddProduct(AddProductRequest newProduct) .ToList() }; - _context.Products.Add(product); - await _context.SaveChangesAsync(); + _ = _context.Products.Add(product); + _ = await _context.SaveChangesAsync(); return product.ToProductResponse(); } @@ -129,7 +128,7 @@ public async Task UpdateProduct(int productId, UpdateProductReq .Contains(mi.Id)) .ToList(); - await _context.SaveChangesAsync(); + _ = await _context.SaveChangesAsync(); return product.ToProductResponse(); } diff --git a/coffeecard/CoffeeCard.Library/Services/v2/PurchaseService.cs b/coffeecard/CoffeeCard.Library/Services/v2/PurchaseService.cs index 14db8914..f4d77d72 100644 --- a/coffeecard/CoffeeCard.Library/Services/v2/PurchaseService.cs +++ b/coffeecard/CoffeeCard.Library/Services/v2/PurchaseService.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using CoffeeCard.Common.Errors; using CoffeeCard.Library.Persistence; using CoffeeCard.MobilePay.Service.v2; @@ -9,9 +5,12 @@ using CoffeeCard.Models.DataTransferObjects.v2.Products; using CoffeeCard.Models.DataTransferObjects.v2.Purchase; using CoffeeCard.Models.Entities; -using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using Serilog; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; using Purchase = CoffeeCard.Models.Entities.Purchase; namespace CoffeeCard.Library.Services.v2 @@ -43,8 +42,8 @@ public async Task InitiatePurchase(InitiatePurchaseReq var (purchase, paymentDetails) = await InitiatePaymentAsync(initiateRequest, product, user); - await _context.Purchases.AddAsync(purchase); - await _context.SaveChangesAsync(); + _ = await _context.Purchases.AddAsync(purchase); + _ = await _context.SaveChangesAsync(); if (purchase.Status == PurchaseStatus.Completed) { @@ -239,7 +238,7 @@ private async Task CompletePurchase(Purchase purchase) await _ticketService.IssueTickets(purchase); purchase.Status = PurchaseStatus.Completed; - await _context.SaveChangesAsync(); + _ = await _context.SaveChangesAsync(); Log.Information("Completed purchase with Id {Id}, TransactionId {TransactionId}", purchase.Id, purchase.ExternalTransactionId); @@ -250,7 +249,7 @@ private async Task CancelPurchase(Purchase purchase) { await _mobilePayPaymentsService.CancelPayment(Guid.Parse(purchase.ExternalTransactionId)); purchase.Status = PurchaseStatus.Cancelled; - await _context.SaveChangesAsync(); + _ = await _context.SaveChangesAsync(); Log.Information("Purchase has been cancelled Purchase Id {PurchaseId}, Transaction Id {TransactionId}", purchase.Id, purchase.ExternalTransactionId); @@ -303,9 +302,9 @@ public async Task RedeemVoucher(string voucherCode, User voucher.User = user; voucher.Purchase = purchase; - _context.Vouchers.Attach(voucher); + _ = _context.Vouchers.Attach(voucher); _context.Entry(voucher).State = EntityState.Modified; - await _context.SaveChangesAsync(); + _ = await _context.SaveChangesAsync(); return new SimplePurchaseResponse { diff --git a/coffeecard/CoffeeCard.Library/Services/v2/StatisticService.cs b/coffeecard/CoffeeCard.Library/Services/v2/StatisticService.cs index 31985e2f..ba626b0e 100644 --- a/coffeecard/CoffeeCard.Library/Services/v2/StatisticService.cs +++ b/coffeecard/CoffeeCard.Library/Services/v2/StatisticService.cs @@ -1,10 +1,10 @@ -using System; -using System.Linq; -using System.Threading.Tasks; -using CoffeeCard.Library.Persistence; +using CoffeeCard.Library.Persistence; using CoffeeCard.Library.Utils; using CoffeeCard.Models.Entities; using Microsoft.EntityFrameworkCore; +using System; +using System.Linq; +using System.Threading.Tasks; namespace CoffeeCard.Library.Services.v2 { diff --git a/coffeecard/CoffeeCard.Library/Services/v2/TicketService.cs b/coffeecard/CoffeeCard.Library/Services/v2/TicketService.cs index 8fa169e7..aab553ad 100644 --- a/coffeecard/CoffeeCard.Library/Services/v2/TicketService.cs +++ b/coffeecard/CoffeeCard.Library/Services/v2/TicketService.cs @@ -1,13 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using CoffeeCard.Common.Errors; using CoffeeCard.Library.Persistence; using CoffeeCard.Models.DataTransferObjects.v2.Ticket; using CoffeeCard.Models.Entities; using Microsoft.EntityFrameworkCore; using Serilog; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; namespace CoffeeCard.Library.Services.v2 { @@ -38,7 +38,7 @@ public async Task IssueTickets(Purchase purchase) } await _context.Tickets.AddRangeAsync(tickets); - await _context.SaveChangesAsync(); + _ = await _context.SaveChangesAsync(); Log.Information("Issued {NoTickets} Tickets for ProductId {ProductId}, PurchaseId {PurchaseId}", purchase.NumberOfTickets, purchase.ProductId, purchase.Id); } @@ -77,7 +77,7 @@ public async Task UseTicketAsync(User user, int productId) await _statisticService.IncreaseStatisticsBy(user.Id, 1); } - await _context.SaveChangesAsync(); + _ = await _context.SaveChangesAsync(); return new UsedTicketResponse { @@ -111,7 +111,7 @@ public async Task UseTicketAsync(User user, int productId, i await _statisticService.IncreaseStatisticsBy(user.Id, 1); } - await _context.SaveChangesAsync(); + _ = await _context.SaveChangesAsync(); return new UsedTicketResponse { diff --git a/coffeecard/CoffeeCard.Library/Services/v2/VoucherService.cs b/coffeecard/CoffeeCard.Library/Services/v2/VoucherService.cs index 0cc99df1..1fcfd2e3 100644 --- a/coffeecard/CoffeeCard.Library/Services/v2/VoucherService.cs +++ b/coffeecard/CoffeeCard.Library/Services/v2/VoucherService.cs @@ -1,14 +1,12 @@ +using CoffeeCard.Common.Errors; +using CoffeeCard.Library.Persistence; +using CoffeeCard.Models.DataTransferObjects.v2.Voucher; +using CoffeeCard.Models.Entities; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using CoffeeCard.Common.Errors; -using CoffeeCard.Library.Persistence; -using CoffeeCard.Models.DataTransferObjects.v2.Voucher; -using CoffeeCard.Models.Entities; -using Microsoft.AspNetCore.Http; -using Microsoft.EntityFrameworkCore; namespace CoffeeCard.Library.Services.v2 { @@ -35,7 +33,7 @@ public async Task> CreateVouchers(IssueVoucher while (newCodes.Count < request.Amount) { var code = GenerateUniqueVoucherCode(8, request.VoucherPrefix, existingVouchers); // 8 character length gives 36^8 combos - newCodes.Add(code); + _ = newCodes.Add(code); } var vouchers = newCodes @@ -49,7 +47,7 @@ public async Task> CreateVouchers(IssueVoucher }).ToList(); await _context.Vouchers.AddRangeAsync(vouchers); - await _context.SaveChangesAsync(); + _ = await _context.SaveChangesAsync(); var responses = vouchers. Select(v => @@ -77,11 +75,11 @@ private string GenerateUniqueVoucherCode(int codeLength, string voucherPrefix, H while (String.IsNullOrEmpty(code.ToString()) || existingCodes.Contains(code.ToString())) { - code.Append($"{voucherPrefix}-"); // Ensure code starts with prefix + _ = code.Append($"{voucherPrefix}-"); // Ensure code starts with prefix for (var i = 0; i < codeLength; i++) { - code.Append(chars[_random.Next(chars.Length)]); + _ = code.Append(chars[_random.Next(chars.Length)]); } } return code.ToString(); diff --git a/coffeecard/CoffeeCard.Library/Services/v2/WebhookService.cs b/coffeecard/CoffeeCard.Library/Services/v2/WebhookService.cs index e31aa930..a5aac38d 100644 --- a/coffeecard/CoffeeCard.Library/Services/v2/WebhookService.cs +++ b/coffeecard/CoffeeCard.Library/Services/v2/WebhookService.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using CoffeeCard.Common.Configuration; +using CoffeeCard.Common.Configuration; using CoffeeCard.Common.Errors; using CoffeeCard.Library.Persistence; using CoffeeCard.MobilePay.Generated.Api.WebhooksApi; @@ -11,6 +7,10 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Caching.Memory; using Serilog; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; namespace CoffeeCard.Library.Services.v2 { @@ -54,7 +54,7 @@ public async Task GetSignatureKey() }; Log.Information("Set {SignatureKey} in Cache", MpSignatureKeyCacheKey); - _memoryCache.Set(MpSignatureKeyCacheKey, signatureKey, cacheExpiryOptions); + _ = _memoryCache.Set(MpSignatureKeyCacheKey, signatureKey, cacheExpiryOptions); } return signatureKey; @@ -86,16 +86,6 @@ private async Task SyncWebhook(WebhookConfiguration webhook) await DisableAndRegisterNewWebhook(webhook); return; } - - mobilePayWebhook = await _mobilePayWebhooksService.UpdateWebhook(mobilePayWebhook.WebhookId, - _mobilePaySettings.WebhookUrl, DefaultEvents); - - webhook.Url = mobilePayWebhook.Url; - webhook.SignatureKey = mobilePayWebhook.SignatureKey; - webhook.Status = WebhookStatus.Active; - webhook.LastUpdated = DateTime.UtcNow; - - await _context.SaveChangesAsync(); } catch (EntityNotFoundException) { @@ -106,7 +96,7 @@ private async Task SyncWebhook(WebhookConfiguration webhook) private async Task DisableAndRegisterNewWebhook(WebhookConfiguration webhook) { webhook.Status = WebhookStatus.Disabled; - await _context.SaveChangesAsync(); + _ = await _context.SaveChangesAsync(); await RegisterWebhook(); } @@ -125,8 +115,8 @@ private async Task RegisterWebhook() LastUpdated = DateTime.UtcNow }; - await _context.WebhookConfigurations.AddAsync(webhook); - await _context.SaveChangesAsync(); + _ = await _context.WebhookConfigurations.AddAsync(webhook); + _ = await _context.SaveChangesAsync(); } } } \ No newline at end of file diff --git a/coffeecard/CoffeeCard.Library/Utils/ClaimsUtilities.cs b/coffeecard/CoffeeCard.Library/Utils/ClaimsUtilities.cs index 38a482a1..6da66e76 100644 --- a/coffeecard/CoffeeCard.Library/Utils/ClaimsUtilities.cs +++ b/coffeecard/CoffeeCard.Library/Utils/ClaimsUtilities.cs @@ -1,13 +1,13 @@ -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using CoffeeCard.Common; +using CoffeeCard.Common; using CoffeeCard.Common.Errors; using CoffeeCard.Library.Persistence; using CoffeeCard.Models.Entities; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using System.Threading.Tasks; namespace CoffeeCard.Library.Utils { diff --git a/coffeecard/CoffeeCard.Library/Utils/FeatureFlags.cs b/coffeecard/CoffeeCard.Library/Utils/FeatureFlags.cs new file mode 100644 index 00000000..f277b138 --- /dev/null +++ b/coffeecard/CoffeeCard.Library/Utils/FeatureFlags.cs @@ -0,0 +1,10 @@ +namespace CoffeeCard.Library.Utils +{ + public class FeatureFlags + { + /// + /// Controls whether the API should manage the registration to the MobilePayWebhooks API at startup. Disabling this feature flag, assumes that the Webhook Registration is handled outside of the Analog Core API. + /// + public const string MobilePayManageWebhookRegistration = "MobilePayManageWebhookRegistration"; + } +} diff --git a/coffeecard/CoffeeCard.Library/Utils/ProductExtensions.cs b/coffeecard/CoffeeCard.Library/Utils/ProductExtensions.cs index 93d67c22..7ef3388d 100644 --- a/coffeecard/CoffeeCard.Library/Utils/ProductExtensions.cs +++ b/coffeecard/CoffeeCard.Library/Utils/ProductExtensions.cs @@ -1,7 +1,8 @@ -using System; -using System.Linq; -using CoffeeCard.Models.DataTransferObjects.v2.Products; +using CoffeeCard.Models.DataTransferObjects.v2.Products; using CoffeeCard.Models.Entities; +using System; +using System.Linq; +using CoffeeCard.Models.DataTransferObjects.v2.MenuItems; namespace CoffeeCard.Library.Utils { diff --git a/coffeecard/CoffeeCard.MobilePay.GenerateApi/Program.cs b/coffeecard/CoffeeCard.MobilePay.GenerateApi/Program.cs index 3e34c872..e2275f89 100644 --- a/coffeecard/CoffeeCard.MobilePay.GenerateApi/Program.cs +++ b/coffeecard/CoffeeCard.MobilePay.GenerateApi/Program.cs @@ -1,8 +1,8 @@ -using System; +using NSwag; +using NSwag.CodeGeneration.CSharp; +using System; using System.IO; using System.Threading.Tasks; -using NSwag; -using NSwag.CodeGeneration.CSharp; namespace CoffeeCard.MobilePay.GenerateApi { diff --git a/coffeecard/CoffeeCard.MobilePay/Service/v2/IMobilePayPaymentsService.cs b/coffeecard/CoffeeCard.MobilePay/Service/v2/IMobilePayPaymentsService.cs index 30492012..dc317425 100644 --- a/coffeecard/CoffeeCard.MobilePay/Service/v2/IMobilePayPaymentsService.cs +++ b/coffeecard/CoffeeCard.MobilePay/Service/v2/IMobilePayPaymentsService.cs @@ -1,9 +1,8 @@ -using System; -using System.Threading.Tasks; -using CoffeeCard.MobilePay.Exception.v2; -using CoffeeCard.MobilePay.Generated.Api.WebhooksApi; +using CoffeeCard.MobilePay.Exception.v2; using CoffeeCard.Models.DataTransferObjects.v2.MobilePay; using CoffeeCard.Models.DataTransferObjects.v2.Purchase; +using System; +using System.Threading.Tasks; namespace CoffeeCard.MobilePay.Service.v2 { diff --git a/coffeecard/CoffeeCard.MobilePay/Service/v2/IMobilePayWebhooksService.cs b/coffeecard/CoffeeCard.MobilePay/Service/v2/IMobilePayWebhooksService.cs index 16e6d23d..5bd64dfd 100644 --- a/coffeecard/CoffeeCard.MobilePay/Service/v2/IMobilePayWebhooksService.cs +++ b/coffeecard/CoffeeCard.MobilePay/Service/v2/IMobilePayWebhooksService.cs @@ -1,7 +1,7 @@ -using System; +using CoffeeCard.MobilePay.Generated.Api.WebhooksApi; +using System; using System.Collections.Generic; using System.Threading.Tasks; -using CoffeeCard.MobilePay.Generated.Api.WebhooksApi; namespace CoffeeCard.MobilePay.Service.v2 { diff --git a/coffeecard/CoffeeCard.MobilePay/Service/v2/MobilePayPaymentsService.cs b/coffeecard/CoffeeCard.MobilePay/Service/v2/MobilePayPaymentsService.cs index 9d37d7a5..875c59ed 100644 --- a/coffeecard/CoffeeCard.MobilePay/Service/v2/MobilePayPaymentsService.cs +++ b/coffeecard/CoffeeCard.MobilePay/Service/v2/MobilePayPaymentsService.cs @@ -1,11 +1,11 @@ -using System; -using System.Threading.Tasks; -using CoffeeCard.Common.Configuration; +using CoffeeCard.Common.Configuration; using CoffeeCard.MobilePay.Exception.v2; using CoffeeCard.MobilePay.Generated.Api.PaymentsApi; using CoffeeCard.Models.DataTransferObjects.v2.MobilePay; using CoffeeCard.Models.DataTransferObjects.v2.Purchase; using Serilog; +using System; +using System.Threading.Tasks; namespace CoffeeCard.MobilePay.Service.v2 { diff --git a/coffeecard/CoffeeCard.MobilePay/Service/v2/MobilePayWebhooksService.cs b/coffeecard/CoffeeCard.MobilePay/Service/v2/MobilePayWebhooksService.cs index 749f169a..9a3dd67b 100644 --- a/coffeecard/CoffeeCard.MobilePay/Service/v2/MobilePayWebhooksService.cs +++ b/coffeecard/CoffeeCard.MobilePay/Service/v2/MobilePayWebhooksService.cs @@ -1,11 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using CoffeeCard.Common.Errors; +using CoffeeCard.Common.Errors; using CoffeeCard.MobilePay.Exception.v2; using CoffeeCard.MobilePay.Generated.Api.WebhooksApi; using Serilog; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; using ApiException = CoffeeCard.MobilePay.Generated.Api.PaymentsApi.ApiException; namespace CoffeeCard.MobilePay.Service.v2 diff --git a/coffeecard/CoffeeCard.MobilePay/Utils/MobilePayServiceCollectionExtension.cs b/coffeecard/CoffeeCard.MobilePay/Utils/MobilePayServiceCollectionExtension.cs index 08b76900..4c5e94e7 100644 --- a/coffeecard/CoffeeCard.MobilePay/Utils/MobilePayServiceCollectionExtension.cs +++ b/coffeecard/CoffeeCard.MobilePay/Utils/MobilePayServiceCollectionExtension.cs @@ -1,8 +1,8 @@ -using System.Net.Http.Headers; -using CoffeeCard.Common.Configuration; +using CoffeeCard.Common.Configuration; using CoffeeCard.MobilePay.Generated.Api.PaymentsApi; using CoffeeCard.MobilePay.Generated.Api.WebhooksApi; using Microsoft.Extensions.DependencyInjection; +using System.Net.Http.Headers; namespace CoffeeCard.MobilePay.Utils { @@ -23,13 +23,13 @@ public static void AddMobilePayHttpClients(this IServiceCollection services, var apiKeyAuthentication = new AuthenticationHeaderValue("Bearer", mobilePaySettings.ApiKey); - services.AddHttpClient(client => + _ = services.AddHttpClient(client => { client.BaseAddress = mobilePaySettings.ApiUrl; client.DefaultRequestHeaders.Authorization = apiKeyAuthentication; }); - services.AddHttpClient(client => + _ = services.AddHttpClient(client => { client.BaseAddress = mobilePaySettings.ApiUrl; client.DefaultRequestHeaders.Authorization = apiKeyAuthentication; diff --git a/coffeecard/CoffeeCard.Models/DataTransferObjects/AppConfig/AppConfigDTO.cs b/coffeecard/CoffeeCard.Models/DataTransferObjects/AppConfig/AppConfigDTO.cs index 209cb096..27c35d78 100644 --- a/coffeecard/CoffeeCard.Models/DataTransferObjects/AppConfig/AppConfigDTO.cs +++ b/coffeecard/CoffeeCard.Models/DataTransferObjects/AppConfig/AppConfigDTO.cs @@ -1,5 +1,5 @@ -using System.ComponentModel.DataAnnotations; -using CoffeeCard.Common.Configuration; +using CoffeeCard.Common.Configuration; +using System.ComponentModel.DataAnnotations; namespace CoffeeCard.Models.DataTransferObjects.AppConfig { diff --git a/coffeecard/CoffeeCard.Models/DataTransferObjects/Ticket/TicketDTO.cs b/coffeecard/CoffeeCard.Models/DataTransferObjects/Ticket/TicketDTO.cs index ff882451..56126149 100644 --- a/coffeecard/CoffeeCard.Models/DataTransferObjects/Ticket/TicketDTO.cs +++ b/coffeecard/CoffeeCard.Models/DataTransferObjects/Ticket/TicketDTO.cs @@ -1,6 +1,6 @@ -using System; +using Newtonsoft.Json; +using System; using System.ComponentModel.DataAnnotations; -using Newtonsoft.Json; namespace CoffeeCard.Models.DataTransferObjects.Ticket { diff --git a/coffeecard/CoffeeCard.Models/DataTransferObjects/Ticket/UseMultipleTicketDTO.cs b/coffeecard/CoffeeCard.Models/DataTransferObjects/Ticket/UseMultipleTicketDTO.cs index f3b3411a..eac6b31b 100644 --- a/coffeecard/CoffeeCard.Models/DataTransferObjects/Ticket/UseMultipleTicketDTO.cs +++ b/coffeecard/CoffeeCard.Models/DataTransferObjects/Ticket/UseMultipleTicketDTO.cs @@ -22,6 +22,6 @@ public class UseMultipleTicketDto /// Product Ids /// 1, 2 [Required] - public List ProductIds { get; set; } = new List(); + public List ProductIds { get; set; } = []; } } \ No newline at end of file diff --git a/coffeecard/CoffeeCard.Models/DataTransferObjects/User/UserDTO.cs b/coffeecard/CoffeeCard.Models/DataTransferObjects/User/UserDTO.cs index 2e6711c3..ead24747 100644 --- a/coffeecard/CoffeeCard.Models/DataTransferObjects/User/UserDTO.cs +++ b/coffeecard/CoffeeCard.Models/DataTransferObjects/User/UserDTO.cs @@ -1,5 +1,5 @@ -using System.ComponentModel.DataAnnotations; -using CoffeeCard.Models.Entities; +using CoffeeCard.Models.Entities; +using System.ComponentModel.DataAnnotations; namespace CoffeeCard.Models.DataTransferObjects.User { diff --git a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/AppConfig/AppConfig.cs b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/AppConfig/AppConfig.cs index ff061c08..3dd3288a 100644 --- a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/AppConfig/AppConfig.cs +++ b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/AppConfig/AppConfig.cs @@ -1,5 +1,5 @@ -using System.ComponentModel.DataAnnotations; -using CoffeeCard.Common.Configuration; +using CoffeeCard.Common.Configuration; +using System.ComponentModel.DataAnnotations; namespace CoffeeCard.Models.DataTransferObjects.v2.AppConfig { diff --git a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Leaderboard/LeaderboardPreset.cs b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Leaderboard/LeaderboardPreset.cs index 74c780ac..724affde 100644 --- a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Leaderboard/LeaderboardPreset.cs +++ b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Leaderboard/LeaderboardPreset.cs @@ -1,6 +1,4 @@ -using CoffeeCard.Models.Entities; - -namespace CoffeeCard.Models.DataTransferObjects.v2.Leaderboard +namespace CoffeeCard.Models.DataTransferObjects.v2.Leaderboard { /// /// Preset for filtering Leaderboard based on date range diff --git a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/MenuItems/AddMenuItemRequest.cs b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/MenuItems/AddMenuItemRequest.cs index 89477462..574b408b 100644 --- a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/MenuItems/AddMenuItemRequest.cs +++ b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/MenuItems/AddMenuItemRequest.cs @@ -1,9 +1,6 @@ -using System.Collections.Generic; -using System.ComponentModel; using System.ComponentModel.DataAnnotations; -using CoffeeCard.Models.Entities; -namespace CoffeeCard.Models.DataTransferObjects.v2.Product +namespace CoffeeCard.Models.DataTransferObjects.v2.MenuItems { /// /// Initiate a new menuitem add request. diff --git a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/MenuItems/MenuItemResponse.cs b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/MenuItems/MenuItemResponse.cs index b2f695b1..901f6bfb 100644 --- a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/MenuItems/MenuItemResponse.cs +++ b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/MenuItems/MenuItemResponse.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace CoffeeCard.Models.DataTransferObjects.v2.Products +namespace CoffeeCard.Models.DataTransferObjects.v2.MenuItems { /// /// Represents a menu item that can be redeemed with a ticket diff --git a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/MenuItems/UpdateMenuItemRequest.cs b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/MenuItems/UpdateMenuItemRequest.cs index 91cf0c72..a0b5441c 100644 --- a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/MenuItems/UpdateMenuItemRequest.cs +++ b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/MenuItems/UpdateMenuItemRequest.cs @@ -1,9 +1,6 @@ -using System.Collections.Generic; -using System.ComponentModel; using System.ComponentModel.DataAnnotations; -using CoffeeCard.Models.Entities; -namespace CoffeeCard.Models.DataTransferObjects.v2.Product +namespace CoffeeCard.Models.DataTransferObjects.v2.MenuItems { /// /// /// Initiate an update product request. diff --git a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Product/AddProductRequest.cs b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Product/AddProductRequest.cs index 09c54a74..56c49831 100644 --- a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Product/AddProductRequest.cs +++ b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Product/AddProductRequest.cs @@ -1,7 +1,7 @@ +using CoffeeCard.Models.Entities; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; -using CoffeeCard.Models.Entities; namespace CoffeeCard.Models.DataTransferObjects.v2.Product { diff --git a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Product/UpdateProductRequest.cs b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Product/UpdateProductRequest.cs index 4300ae40..d8a282f0 100644 --- a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Product/UpdateProductRequest.cs +++ b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Product/UpdateProductRequest.cs @@ -1,7 +1,7 @@ +using CoffeeCard.Models.Entities; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; -using CoffeeCard.Models.Entities; namespace CoffeeCard.Models.DataTransferObjects.v2.Product { diff --git a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Products/ProductResponse.cs b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Products/ProductResponse.cs index cf79177b..c794c121 100644 --- a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Products/ProductResponse.cs +++ b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Products/ProductResponse.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using CoffeeCard.Models.DataTransferObjects.v2.Products; +using CoffeeCard.Models.DataTransferObjects.v2.MenuItems; using CoffeeCard.Models.Entities; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; namespace CoffeeCard.Models.DataTransferObjects.v2.Products { diff --git a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Purchase/InitiatePurchaseRequest.cs b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Purchase/InitiatePurchaseRequest.cs index b9e00e72..b82e0082 100644 --- a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Purchase/InitiatePurchaseRequest.cs +++ b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Purchase/InitiatePurchaseRequest.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; namespace CoffeeCard.Models.DataTransferObjects.v2.Purchase { diff --git a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Purchase/PaymentType.cs b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Purchase/PaymentType.cs index 9e0f7e6c..20e1fb7f 100644 --- a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Purchase/PaymentType.cs +++ b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Purchase/PaymentType.cs @@ -1,5 +1,5 @@ -using System; using CoffeeCard.Models.Entities; +using System; namespace CoffeeCard.Models.DataTransferObjects.v2.Purchase { diff --git a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Ticket/TicketResponse.cs b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Ticket/TicketResponse.cs index 1ada3574..80575f79 100644 --- a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Ticket/TicketResponse.cs +++ b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/Ticket/TicketResponse.cs @@ -1,6 +1,6 @@ -using System; +using Newtonsoft.Json; +using System; using System.ComponentModel.DataAnnotations; -using Newtonsoft.Json; namespace CoffeeCard.Models.DataTransferObjects.v2.Ticket { diff --git a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/User/AccountUserGroup.cs b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/User/AccountUserGroup.cs index d465b08b..5fb5f1b7 100644 --- a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/User/AccountUserGroup.cs +++ b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/User/AccountUserGroup.cs @@ -1,6 +1,7 @@ +using CoffeeCard.Models.Entities; using System.ComponentModel.DataAnnotations; -namespace CoffeeCard.Models.Entities; +namespace CoffeeCard.Models.DataTransferObjects.v2.User; /// /// Represents an account user group update diff --git a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/User/ResendAccountVerificationEmailRequest.cs b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/User/ResendAccountVerificationEmailRequest.cs index f829dd85..377dd5c1 100644 --- a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/User/ResendAccountVerificationEmailRequest.cs +++ b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/User/ResendAccountVerificationEmailRequest.cs @@ -1,5 +1,4 @@ -using System; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; namespace CoffeeCard.Models.DataTransferObjects.v2.User; diff --git a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/User/UpdateUserGroupRequest.cs b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/User/UpdateUserGroupRequest.cs index 49fb5c48..48245e3c 100644 --- a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/User/UpdateUserGroupRequest.cs +++ b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/User/UpdateUserGroupRequest.cs @@ -1,5 +1,5 @@ -using System.ComponentModel.DataAnnotations; using CoffeeCard.Models.Entities; +using System.ComponentModel.DataAnnotations; namespace CoffeeCard.Models.DataTransferObjects.v2.User { diff --git a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/User/UserResponse.cs b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/User/UserResponse.cs index a61ba73d..13e0e02d 100644 --- a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/User/UserResponse.cs +++ b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/User/UserResponse.cs @@ -1,5 +1,5 @@ -using System.ComponentModel.DataAnnotations; using CoffeeCard.Models.DataTransferObjects.v2.Programme; +using System.ComponentModel.DataAnnotations; namespace CoffeeCard.Models.DataTransferObjects.v2.User { diff --git a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/User/WebhookUpdateUserGroupRequest.cs b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/User/WebhookUpdateUserGroupRequest.cs index ae76c87d..8b0147de 100644 --- a/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/User/WebhookUpdateUserGroupRequest.cs +++ b/coffeecard/CoffeeCard.Models/DataTransferObjects/v2/User/WebhookUpdateUserGroupRequest.cs @@ -1,5 +1,4 @@ -using CoffeeCard.Models.Entities; -using System.Collections.Generic; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace CoffeeCard.Models.DataTransferObjects.v2.User diff --git a/coffeecard/CoffeeCard.Models/Entities/MenuItem.cs b/coffeecard/CoffeeCard.Models/Entities/MenuItem.cs index 0d5f0972..88cc561f 100644 --- a/coffeecard/CoffeeCard.Models/Entities/MenuItem.cs +++ b/coffeecard/CoffeeCard.Models/Entities/MenuItem.cs @@ -1,8 +1,6 @@ +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; -using System.ComponentModel; -using System.ComponentModel.DataAnnotations.Schema; -using Microsoft.EntityFrameworkCore; namespace CoffeeCard.Models.Entities; diff --git a/coffeecard/CoffeeCard.Models/Entities/Product.cs b/coffeecard/CoffeeCard.Models/Entities/Product.cs index c3fd0140..dbc5f040 100644 --- a/coffeecard/CoffeeCard.Models/Entities/Product.cs +++ b/coffeecard/CoffeeCard.Models/Entities/Product.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; namespace CoffeeCard.Models.Entities { diff --git a/coffeecard/CoffeeCard.Models/Entities/Purchase.cs b/coffeecard/CoffeeCard.Models/Entities/Purchase.cs index be03aab8..c86884b1 100644 --- a/coffeecard/CoffeeCard.Models/Entities/Purchase.cs +++ b/coffeecard/CoffeeCard.Models/Entities/Purchase.cs @@ -1,8 +1,8 @@ +using CoffeeCard.Models.DataTransferObjects.v2.Purchase; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; -using CoffeeCard.Models.DataTransferObjects.v2.Purchase; -using Microsoft.EntityFrameworkCore; namespace CoffeeCard.Models.Entities { diff --git a/coffeecard/CoffeeCard.Models/Entities/Statistic.cs b/coffeecard/CoffeeCard.Models/Entities/Statistic.cs index 67c04ffe..2c3e117d 100644 --- a/coffeecard/CoffeeCard.Models/Entities/Statistic.cs +++ b/coffeecard/CoffeeCard.Models/Entities/Statistic.cs @@ -1,6 +1,6 @@ +using Microsoft.EntityFrameworkCore; using System; using System.ComponentModel.DataAnnotations.Schema; -using Microsoft.EntityFrameworkCore; namespace CoffeeCard.Models.Entities { diff --git a/coffeecard/CoffeeCard.Models/Entities/User.cs b/coffeecard/CoffeeCard.Models/Entities/User.cs index fe493d58..bca91c19 100644 --- a/coffeecard/CoffeeCard.Models/Entities/User.cs +++ b/coffeecard/CoffeeCard.Models/Entities/User.cs @@ -1,9 +1,8 @@ +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.ComponentModel; -using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using Microsoft.EntityFrameworkCore; namespace CoffeeCard.Models.Entities { @@ -42,15 +41,15 @@ public class User public Programme Programme { get; set; } - public virtual ICollection LoginAttempts { get; set; } = new List(); + public virtual ICollection LoginAttempts { get; set; } = []; - public virtual ICollection Tokens { get; set; } = new List(); + public virtual ICollection Tokens { get; set; } = []; - public virtual ICollection Tickets { get; set; } = new List(); + public virtual ICollection Tickets { get; set; } = []; - public virtual ICollection Purchases { get; set; } = new List(); + public virtual ICollection Purchases { get; set; } = []; - public virtual ICollection Statistics { get; set; } = new List(); + public virtual ICollection Statistics { get; set; } = []; public override string ToString() { diff --git a/coffeecard/CoffeeCard.Models/Entities/Voucher.cs b/coffeecard/CoffeeCard.Models/Entities/Voucher.cs index 5900949a..2deabd46 100644 --- a/coffeecard/CoffeeCard.Models/Entities/Voucher.cs +++ b/coffeecard/CoffeeCard.Models/Entities/Voucher.cs @@ -1,6 +1,6 @@ +using Microsoft.EntityFrameworkCore; using System; using System.ComponentModel.DataAnnotations.Schema; -using Microsoft.EntityFrameworkCore; namespace CoffeeCard.Models.Entities { diff --git a/coffeecard/CoffeeCard.Tests.Common/Builders/BaseBuilder.cs b/coffeecard/CoffeeCard.Tests.Common/Builders/BaseBuilder.cs index 2762820a..53648382 100644 --- a/coffeecard/CoffeeCard.Tests.Common/Builders/BaseBuilder.cs +++ b/coffeecard/CoffeeCard.Tests.Common/Builders/BaseBuilder.cs @@ -8,7 +8,7 @@ public abstract class BaseBuilder where T : class protected readonly AutoFaker Faker = new(); protected BaseBuilder() { - Faker.Configure(builder => builder.WithConventions()); + _ = Faker.Configure(builder => builder.WithConventions()); } /// diff --git a/coffeecard/CoffeeCard.Tests.Common/Builders/ProductBuilder.cs b/coffeecard/CoffeeCard.Tests.Common/Builders/ProductBuilder.cs index 50db3e93..0a4ed473 100644 --- a/coffeecard/CoffeeCard.Tests.Common/Builders/ProductBuilder.cs +++ b/coffeecard/CoffeeCard.Tests.Common/Builders/ProductBuilder.cs @@ -11,7 +11,7 @@ public static ProductBuilder Simple() .WithName(f => f.Commerce.ProductName()) .WithDescription(f => f.Commerce.ProductDescription()) .WithNumberOfTickets(f => f.PickRandom(1, 10)) - .WithProductUserGroup(new List()); + .WithProductUserGroup([]); } public static ProductBuilder Typical() diff --git a/coffeecard/CoffeeCard.Tests.Common/Builders/ProgrammeBuilder.cs b/coffeecard/CoffeeCard.Tests.Common/Builders/ProgrammeBuilder.cs index bda9291d..e9f2a97a 100644 --- a/coffeecard/CoffeeCard.Tests.Common/Builders/ProgrammeBuilder.cs +++ b/coffeecard/CoffeeCard.Tests.Common/Builders/ProgrammeBuilder.cs @@ -8,7 +8,7 @@ public partial class ProgrammeBuilder public static ProgrammeBuilder Simple() { return new ProgrammeBuilder() - .WithUsers(new List()) + .WithUsers([]) .WithShortName(f => f.Random.String2(3)) .WithFullName(f => f.Commerce.Department()); } diff --git a/coffeecard/CoffeeCard.Tests.Common/Builders/PurchaseBuilder.cs b/coffeecard/CoffeeCard.Tests.Common/Builders/PurchaseBuilder.cs index 783fcdd5..9105fc8f 100644 --- a/coffeecard/CoffeeCard.Tests.Common/Builders/PurchaseBuilder.cs +++ b/coffeecard/CoffeeCard.Tests.Common/Builders/PurchaseBuilder.cs @@ -10,8 +10,8 @@ public static PurchaseBuilder Simple() var purchasedBy = UserBuilder.Simple().Build(); return new PurchaseBuilder().WithPurchasedBy(purchasedBy) .WithProductName(f => f.Commerce.ProductName()) - .WithTickets(new List()) - .WithTickets(new List()) + .WithTickets([]) + .WithTickets([]) .WithNumberOfTickets(0); } diff --git a/coffeecard/CoffeeCard.Tests.Common/Builders/UserBuilder.cs b/coffeecard/CoffeeCard.Tests.Common/Builders/UserBuilder.cs index 15b83e69..33b0bce2 100644 --- a/coffeecard/CoffeeCard.Tests.Common/Builders/UserBuilder.cs +++ b/coffeecard/CoffeeCard.Tests.Common/Builders/UserBuilder.cs @@ -11,12 +11,12 @@ public static UserBuilder Simple() return new UserBuilder() .WithProgramme(programme) - .WithPurchases(new List()) - .WithStatistics(new List()) - .WithLoginAttempts(new List()) - .WithTokens(new List()) + .WithPurchases([]) + .WithStatistics([]) + .WithLoginAttempts([]) + .WithTokens([]) .WithUserState(UserState.Active) - .WithTickets(new List()); + .WithTickets([]); } public static UserBuilder DefaultCustomer() diff --git a/coffeecard/CoffeeCard.Tests.Integration/Controllers/Account/GetAccountTest.cs b/coffeecard/CoffeeCard.Tests.Integration/Controllers/Account/GetAccountTest.cs index a35c64da..423f541a 100644 --- a/coffeecard/CoffeeCard.Tests.Integration/Controllers/Account/GetAccountTest.cs +++ b/coffeecard/CoffeeCard.Tests.Integration/Controllers/Account/GetAccountTest.cs @@ -1,10 +1,10 @@ -using System.Threading.Tasks; +using CoffeeCard.Models.DataTransferObjects.v2.User; +using CoffeeCard.Models.Entities; +using CoffeeCard.Tests.Common.Builders; using CoffeeCard.Tests.Integration.WebApplication; using CoffeeCard.WebApi; +using System.Threading.Tasks; using Xunit; -using CoffeeCard.Models.DataTransferObjects.v2.User; -using CoffeeCard.Tests.Common.Builders; -using CoffeeCard.Models.Entities; namespace CoffeeCard.Tests.Integration.Controllers.Account { @@ -20,8 +20,8 @@ public GetAccountTest(CustomWebApplicationFactory factory) : base(facto public async Task Get_account_succeeds_when_authenticated_for_existing_account() { var user = UserBuilder.DefaultCustomer().Build(); - await Context.Users.AddAsync(user); - await Context.SaveChangesAsync(); + _ = await Context.Users.AddAsync(user); + _ = await Context.SaveChangesAsync(); SetDefaultAuthHeader(user); var response = await Client.GetAsync(GetAccountUrl); diff --git a/coffeecard/CoffeeCard.Tests.Integration/Controllers/Account/LoginTest.cs b/coffeecard/CoffeeCard.Tests.Integration/Controllers/Account/LoginTest.cs index 191aa661..666a7f61 100644 --- a/coffeecard/CoffeeCard.Tests.Integration/Controllers/Account/LoginTest.cs +++ b/coffeecard/CoffeeCard.Tests.Integration/Controllers/Account/LoginTest.cs @@ -1,13 +1,13 @@ +using CoffeeCard.Models.DataTransferObjects.User; +using CoffeeCard.Tests.Common.Builders; +using CoffeeCard.Tests.Integration.WebApplication; +using CoffeeCard.WebApi; using System; using System.Net; using System.Net.Http; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; -using CoffeeCard.Models.DataTransferObjects.User; -using CoffeeCard.Tests.Common.Builders; -using CoffeeCard.Tests.Integration.WebApplication; -using CoffeeCard.WebApi; using Xunit; namespace CoffeeCard.Tests.Integration.Controllers.Account @@ -42,8 +42,8 @@ public async Task Known_user_login_succeeds_returns_token() var plaintextPassword = user.Password; user.Password = HashPassword(plaintextPassword + user.Salt); - await Context.Users.AddAsync(user); - await Context.SaveChangesAsync(); + _ = await Context.Users.AddAsync(user); + _ = await Context.SaveChangesAsync(); var loginRequest = new LoginDto { diff --git a/coffeecard/CoffeeCard.Tests.Integration/WebApplication/BaseIntegrationTest.cs b/coffeecard/CoffeeCard.Tests.Integration/WebApplication/BaseIntegrationTest.cs index 155d71f3..b6d489d8 100644 --- a/coffeecard/CoffeeCard.Tests.Integration/WebApplication/BaseIntegrationTest.cs +++ b/coffeecard/CoffeeCard.Tests.Integration/WebApplication/BaseIntegrationTest.cs @@ -1,10 +1,3 @@ -using System; -using System.Collections.Generic; -using System.IdentityModel.Tokens.Jwt; -using System.Net.Http; -using System.Security.Claims; -using System.Text; -using System.Threading.Tasks; using CoffeeCard.Common.Configuration; using CoffeeCard.Library.Persistence; using CoffeeCard.Models.Entities; @@ -12,6 +5,13 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.IdentityModel.Tokens; using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IdentityModel.Tokens.Jwt; +using System.Net.Http; +using System.Security.Claims; +using System.Text; +using System.Threading.Tasks; using Xunit; namespace CoffeeCard.Tests.Integration.WebApplication @@ -87,8 +87,8 @@ private CoffeeCardContext GetCoffeeCardContext() var context = scopedServices.GetRequiredService(); // Ensure the database is cleaned for each test run - context.Database.EnsureDeleted(); - context.Database.EnsureCreated(); + _ = context.Database.EnsureDeleted(); + _ = context.Database.EnsureCreated(); return context; } @@ -98,7 +98,7 @@ private CoffeeCardContext GetCoffeeCardContext() /// protected static async Task DeserializeResponseAsync(HttpResponseMessage response) { - response.EnsureSuccessStatusCode(); + _ = response.EnsureSuccessStatusCode(); var content = await response.Content.ReadAsStringAsync(); return JsonConvert.DeserializeObject(content); } diff --git a/coffeecard/CoffeeCard.Tests.Integration/WebApplication/CustomWebApplicationFactory.cs b/coffeecard/CoffeeCard.Tests.Integration/WebApplication/CustomWebApplicationFactory.cs index 8037cf50..af121d3a 100644 --- a/coffeecard/CoffeeCard.Tests.Integration/WebApplication/CustomWebApplicationFactory.cs +++ b/coffeecard/CoffeeCard.Tests.Integration/WebApplication/CustomWebApplicationFactory.cs @@ -1,5 +1,3 @@ -using System; -using System.Linq; using CoffeeCard.Common.Configuration; using CoffeeCard.Library.Persistence; using Microsoft.AspNetCore.Hosting; @@ -7,6 +5,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using System.Linq; namespace CoffeeCard.Tests.Integration.WebApplication { @@ -19,34 +18,34 @@ public class CustomWebApplicationFactory : WebApplicationFactory + _ = builder.ConfigureAppConfiguration(configuration => { - configuration.AddJsonFile("appsettings.json"); + _ = configuration.AddJsonFile("appsettings.json"); Configuration = configuration.Build(); }); - builder.ConfigureServices(services => + _ = builder.ConfigureServices(services => { - services.UseConfigurationValidation(); + _ = services.UseConfigurationValidation(); // Parse and setup settings from configuration - services.ConfigureValidatableSetting(Configuration.GetSection("DatabaseSettings")); - services.ConfigureValidatableSetting( + _ = services.ConfigureValidatableSetting(Configuration.GetSection("DatabaseSettings")); + _ = services.ConfigureValidatableSetting( Configuration.GetSection("EnvironmentSettings")); - services.ConfigureValidatableSetting(Configuration.GetSection("IdentitySettings")); - services.ConfigureValidatableSetting(Configuration.GetSection("MailgunSettings")); + _ = services.ConfigureValidatableSetting(Configuration.GetSection("IdentitySettings")); + _ = services.ConfigureValidatableSetting(Configuration.GetSection("MailgunSettings")); // Remove the app's ApplicationDbContext registration. var descriptor = services.SingleOrDefault( d => d.ServiceType == typeof(DbContextOptions)); - if (descriptor != null) services.Remove(descriptor); + if (descriptor != null) _ = services.Remove(descriptor); // Add ApplicationDbContext using an in-memory database for testing. - services.AddDbContext(options => + _ = services.AddDbContext(options => { - options.UseInMemoryDatabase("InMemoryDbForTesting"); + _ = options.UseInMemoryDatabase("InMemoryDbForTesting"); }); // Build the service provider diff --git a/coffeecard/CoffeeCard.Tests.Unit/Services/AccountServiceTest.cs b/coffeecard/CoffeeCard.Tests.Unit/Services/AccountServiceTest.cs index d3ca0612..d9ed9764 100644 --- a/coffeecard/CoffeeCard.Tests.Unit/Services/AccountServiceTest.cs +++ b/coffeecard/CoffeeCard.Tests.Unit/Services/AccountServiceTest.cs @@ -1,10 +1,3 @@ -using System; -using System.Collections.Generic; -using System.IdentityModel.Tokens.Jwt; -using System.Linq; -using System.Security.Claims; -using System.Text; -using System.Threading.Tasks; using CoffeeCard.Common.Configuration; using CoffeeCard.Common.Errors; using CoffeeCard.Library.Persistence; @@ -15,6 +8,13 @@ using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; using Moq; +using System; +using System.Collections.Generic; +using System.IdentityModel.Tokens.Jwt; +using System.Linq; +using System.Security.Claims; +using System.Text; +using System.Threading.Tasks; using Xunit; namespace CoffeeCard.Tests.Unit.Services @@ -85,8 +85,8 @@ public async Task RecoverUserGivenValidTokenReturnsTrue() var validToken = new JwtSecurityToken("analog", "all", claims); var tokenService = new Mock(); - tokenService.Setup(t => t.ReadToken("valid")).Returns(validToken); - tokenService.Setup(t => t.ValidateTokenIsUnusedAsync("valid")).ReturnsAsync(true); + _ = tokenService.Setup(t => t.ReadToken("valid")).Returns(validToken); + _ = tokenService.Setup(t => t.ValidateTokenIsUnusedAsync("valid")).ReturnsAsync(true); // Act await using var context = new CoffeeCardContext(builder.Options, databaseSettings, environmentSettings); @@ -95,8 +95,8 @@ public async Task RecoverUserGivenValidTokenReturnsTrue() var programme = new Programme { FullName = "fullName", ShortName = "shortName" }; var user = new User { Tokens = userTokens, Programme = programme, Email = "test@email.dk", Name = "test", Password = "pass", Salt = "salt" }; - await context.AddAsync(user); - await context.SaveChangesAsync(); + _ = await context.AddAsync(user); + _ = await context.SaveChangesAsync(); var accountService = new AccountService(context, environmentSettings, tokenService.Object, new Mock().Object, new Mock().Object, @@ -135,8 +135,8 @@ public async Task RecoverUserGivenValidTokenUpdatesPasswordAndResetsUsersTokens( var validToken = new JwtSecurityToken("analog", "all", claims); var tokenService = new Mock(); - tokenService.Setup(t => t.ReadToken("valid")).Returns(validToken); - tokenService.Setup(t => t.ValidateTokenIsUnusedAsync("valid")).ReturnsAsync(true); + _ = tokenService.Setup(t => t.ReadToken("valid")).Returns(validToken); + _ = tokenService.Setup(t => t.ValidateTokenIsUnusedAsync("valid")).ReturnsAsync(true); var userPass = "not set"; @@ -148,14 +148,14 @@ public async Task RecoverUserGivenValidTokenUpdatesPasswordAndResetsUsersTokens( var user = new User { Tokens = userTokens, Email = "test@email.dk", Name = "test", Programme = programme, Password = userPass, Salt = "salt" }; - await context.AddAsync(user); - await context.SaveChangesAsync(); + _ = await context.AddAsync(user); + _ = await context.SaveChangesAsync(); var accountService = new AccountService(context, environmentSettings, tokenService.Object, new Mock().Object, new Mock().Object, new Mock().Object, new Mock().Object, loginLimiterSettings); - await accountService.RecoverUserAsync("valid", "3433"); + _ = await accountService.RecoverUserAsync("valid", "3433"); var updatedUser = context.Users.FirstOrDefault(u => u.Email == user.Email); var newUserPass = updatedUser?.Password; @@ -204,20 +204,20 @@ public async Task LoginGivenValidCredentialsReturnsToken() }; var hasher = new Mock(); - hasher.Setup(h => h.Hash(user.Password + user.Salt)).Returns(user.Password); + _ = hasher.Setup(h => h.Hash(user.Password + user.Salt)).Returns(user.Password); var expectedToken = "valid"; var tokenService = new Mock(); - tokenService.Setup(t => t.GenerateToken(It.IsAny>())).Returns(expectedToken); + _ = tokenService.Setup(t => t.GenerateToken(It.IsAny>())).Returns(expectedToken); var loginLimiter = new Mock(); - loginLimiter.Setup(l => l.LoginAllowed(user)).Returns(true); + _ = loginLimiter.Setup(l => l.LoginAllowed(user)).Returns(true); // Act await using var context = new CoffeeCardContext(builder.Options, databaseSettings, environmentSettings); - await context.AddAsync(user); - await context.SaveChangesAsync(); + _ = await context.AddAsync(user); + _ = await context.SaveChangesAsync(); var accountService = new AccountService(context, environmentSettings, tokenService.Object, new Mock().Object, hasher.Object, @@ -267,22 +267,22 @@ public async Task LoginRejectsAfterFiveFailedLogins() var wrongPass = "wrongPassword"; var httpContextAccessor = new Mock(); - httpContextAccessor.Setup(h => h.HttpContext).Returns(new DefaultHttpContext().HttpContext); + _ = httpContextAccessor.Setup(h => h.HttpContext).Returns(new DefaultHttpContext().HttpContext); var loginLimiter = new Mock(); - loginLimiter.Setup(l => l.LoginAllowed(user)).Returns(true); + _ = loginLimiter.Setup(l => l.LoginAllowed(user)).Returns(true); // Act await using var context = new CoffeeCardContext(builder.Options, databaseSettings, environmentSettings); - await context.AddAsync(user); - await context.SaveChangesAsync(); + _ = await context.AddAsync(user); + _ = await context.SaveChangesAsync(); var accountService = new AccountService(context, environmentSettings, new Mock().Object, new Mock().Object, new HashService(), httpContextAccessor.Object, loginLimiter.Object, loginLimiterSettings); //Attempts to login - Assert.Throws(() => accountService.Login(user.Email, wrongPass, "2.1.0")); + _ = Assert.Throws(() => accountService.Login(user.Email, wrongPass, "2.1.0")); // Assert loginLimiter.Verify(l => l.LoginAllowed(user), Times.Once); @@ -326,22 +326,22 @@ public async Task LoginLimiterNotCalledWhenDisabled() var wrongPass = "wrongPassword"; var httpContextAccessor = new Mock(); - httpContextAccessor.Setup(h => h.HttpContext).Returns(new DefaultHttpContext().HttpContext); + _ = httpContextAccessor.Setup(h => h.HttpContext).Returns(new DefaultHttpContext().HttpContext); var loginLimiter = new Mock(); - loginLimiter.Setup(l => l.LoginAllowed(user)).Returns(true); + _ = loginLimiter.Setup(l => l.LoginAllowed(user)).Returns(true); // Act await using var context = new CoffeeCardContext(builder.Options, databaseSettings, environmentSettings); - await context.AddAsync(user); - await context.SaveChangesAsync(); + _ = await context.AddAsync(user); + _ = await context.SaveChangesAsync(); var accountService = new AccountService(context, environmentSettings, new Mock().Object, new Mock().Object, new HashService(), httpContextAccessor.Object, loginLimiter.Object, loginLimiterSettings); //Attempts to login - Assert.Throws(() => accountService.Login(user.Email, wrongPass, "2.1.0")); + _ = Assert.Throws(() => accountService.Login(user.Email, wrongPass, "2.1.0")); // Assert loginLimiter.Verify(l => l.LoginAllowed(user), Times.Never); @@ -384,19 +384,19 @@ public async Task LoginThrowsExceptionWhenLimitIsReached() var wrongPass = "wrongPassword"; var httpContextAccessor = new Mock(); - httpContextAccessor.Setup(h => h.HttpContext).Returns(new DefaultHttpContext().HttpContext); + _ = httpContextAccessor.Setup(h => h.HttpContext).Returns(new DefaultHttpContext().HttpContext); // Act await using var context = new CoffeeCardContext(builder.Options, databaseSettings, environmentSettings); - await context.AddAsync(user); - await context.SaveChangesAsync(); + _ = await context.AddAsync(user); + _ = await context.SaveChangesAsync(); var accountService = new AccountService(context, environmentSettings, new Mock().Object, new Mock().Object, new HashService(), httpContextAccessor.Object, new LoginLimiter(loginLimiterSettings), loginLimiterSettings); //Attempts to login with the wrong credentials - Assert.Throws(() => accountService.Login(user.Email, wrongPass, "2.1.0")); + _ = Assert.Throws(() => accountService.Login(user.Email, wrongPass, "2.1.0")); //Attempts to login a sixth time with the same credentials and captures the exception var tooManyLoginsException = @@ -446,11 +446,11 @@ public async Task LoginFailsIfEmailIsNotVerified() var somePass = "somePassword"; var httpContextAccessor = new Mock(); - httpContextAccessor.Setup(h => h.HttpContext).Returns(new DefaultHttpContext().HttpContext); + _ = httpContextAccessor.Setup(h => h.HttpContext).Returns(new DefaultHttpContext().HttpContext); await using var context = new CoffeeCardContext(builder.Options, databaseSettings, environmentSettings); - await context.AddAsync(user); - await context.SaveChangesAsync(); + _ = await context.AddAsync(user); + _ = await context.SaveChangesAsync(); // Act var accountService = new AccountService(context, environmentSettings, new Mock().Object, @@ -501,14 +501,14 @@ public async Task LoginSucceedsIfEmailIsVerified() IsVerified = true }; var httpContextAccessor = new Mock(); - httpContextAccessor.Setup(h => h.HttpContext).Returns(new DefaultHttpContext().HttpContext); + _ = httpContextAccessor.Setup(h => h.HttpContext).Returns(new DefaultHttpContext().HttpContext); var hashService = new Mock(); - hashService.Setup(m => m.Hash(It.IsAny())).Returns(somePass); + _ = hashService.Setup(m => m.Hash(It.IsAny())).Returns(somePass); await using var context = new CoffeeCardContext(builder.Options, databaseSettings, environmentSettings); - await context.AddAsync(user); - await context.SaveChangesAsync(); + _ = await context.AddAsync(user); + _ = await context.SaveChangesAsync(); // Act var accountService = new AccountService(context, environmentSettings, new Mock().Object, @@ -544,10 +544,10 @@ public async Task LoginWithUnknownUserThrowsApiException() var httpContextAccessor = new Mock(); - httpContextAccessor.Setup(h => h.HttpContext).Returns(new DefaultHttpContext().HttpContext); + _ = httpContextAccessor.Setup(h => h.HttpContext).Returns(new DefaultHttpContext().HttpContext); await using var context = new CoffeeCardContext(builder.Options, databaseSettings, environmentSettings); - await context.SaveChangesAsync(); + _ = await context.SaveChangesAsync(); // Act var accountService = new AccountService(context, environmentSettings, new Mock().Object, @@ -596,13 +596,13 @@ public async Task VerifyRegistrationReturnsFalseOnInvalidToken(string token) }; var tokenService = new TokenService(identitySettings, new ClaimsUtilities(context)); - httpContextAccessor.Setup(h => h.HttpContext).Returns(new DefaultHttpContext().HttpContext); + _ = httpContextAccessor.Setup(h => h.HttpContext).Returns(new DefaultHttpContext().HttpContext); var accountService = new AccountService(context, environmentSettings, tokenService, new Mock().Object, new Mock().Object, httpContextAccessor.Object, new LoginLimiter(loginLimiterSettings), loginLimiterSettings); //Act & Assert - await Assert.ThrowsAsync(() => accountService.VerifyRegistration(token)); + _ = await Assert.ThrowsAsync(() => accountService.VerifyRegistration(token)); } [Fact(DisplayName = "VerifyRegistration returns true given valid token")] @@ -636,16 +636,16 @@ public async Task VerifyRegistrationReturnsTrueGivenValidToken() }; var tokenService = new TokenService(identitySettings, new ClaimsUtilities(context)); - httpContextAccessor.Setup(h => h.HttpContext).Returns(new DefaultHttpContext().HttpContext); + _ = httpContextAccessor.Setup(h => h.HttpContext).Returns(new DefaultHttpContext().HttpContext); var accountService = new AccountService(context, environmentSettings, tokenService, new Mock().Object, new Mock().Object, httpContextAccessor.Object, new LoginLimiter(loginLimiterSettings), loginLimiterSettings); - var token = WriteTokenString(new List - { + var token = WriteTokenString( + [ new Claim(ClaimTypes.Role, "verification_token"), new Claim(ClaimTypes.Email, "test@test.test") - }); + ]); var programme = new Programme { FullName = "fullName", ShortName = "shortName" }; var user = new User @@ -657,8 +657,8 @@ public async Task VerifyRegistrationReturnsTrueGivenValidToken() Programme = programme }; - await context.Users.AddAsync(user); - await context.SaveChangesAsync(); + _ = await context.Users.AddAsync(user); + _ = await context.SaveChangesAsync(); //Act var result = await accountService.VerifyRegistration(token); @@ -673,23 +673,26 @@ public static IEnumerable TokenGenerator() "Malformed token" }; yield return new object[] { - WriteTokenString(new List // Incorrect role - { + WriteTokenString( + // Incorrect role + [ new Claim(ClaimTypes.Role, "") - }) + ]) }; yield return new object[] { - WriteTokenString(new List // No email claim - { + WriteTokenString( + // No email claim + [ new Claim(ClaimTypes.Role, "verification_token") - }) + ]) }; yield return new object[] { - WriteTokenString(new List // Good token, assuming user can be found in database - { + WriteTokenString( + // Good token, assuming user can be found in database + [ new Claim(ClaimTypes.Role, "verification_token"), new Claim(ClaimTypes.Email, "test@test.test") - }) + ]) }; } diff --git a/coffeecard/CoffeeCard.Tests.Unit/Services/LoginLimiterTests.cs b/coffeecard/CoffeeCard.Tests.Unit/Services/LoginLimiterTests.cs index 7500be05..ab44c969 100644 --- a/coffeecard/CoffeeCard.Tests.Unit/Services/LoginLimiterTests.cs +++ b/coffeecard/CoffeeCard.Tests.Unit/Services/LoginLimiterTests.cs @@ -1,8 +1,8 @@ -using System.Collections.Generic; -using System.Threading.Tasks; using CoffeeCard.Common.Configuration; using CoffeeCard.Library.Services; using CoffeeCard.Models.Entities; +using System.Collections.Generic; +using System.Threading.Tasks; using Xunit; namespace CoffeeCard.Tests.Unit.Services @@ -37,11 +37,11 @@ public async Task LoginAllowsLoginsAfterTimeout() // Act //Triggers the lockout by attempting login 5 times in a row - loginLimiter.LoginAllowed(user); - loginLimiter.LoginAllowed(user); - loginLimiter.LoginAllowed(user); - loginLimiter.LoginAllowed(user); - loginLimiter.LoginAllowed(user); + _ = loginLimiter.LoginAllowed(user); + _ = loginLimiter.LoginAllowed(user); + _ = loginLimiter.LoginAllowed(user); + _ = loginLimiter.LoginAllowed(user); + _ = loginLimiter.LoginAllowed(user); var lockedOutActual = loginLimiter.LoginAllowed(user); //Checks that you are actually locked after the initial attempts await Task.Delay(1100); diff --git a/coffeecard/CoffeeCard.Tests.Unit/Services/ProductServiceTest.cs b/coffeecard/CoffeeCard.Tests.Unit/Services/ProductServiceTest.cs index 79c6cd00..0b46b5a6 100644 --- a/coffeecard/CoffeeCard.Tests.Unit/Services/ProductServiceTest.cs +++ b/coffeecard/CoffeeCard.Tests.Unit/Services/ProductServiceTest.cs @@ -1,10 +1,10 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using CoffeeCard.Common.Configuration; +using CoffeeCard.Common.Configuration; using CoffeeCard.Library.Persistence; using CoffeeCard.Library.Services; using CoffeeCard.Models.Entities; using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; +using System.Threading.Tasks; using Xunit; namespace CoffeeCard.Tests.Unit.Services @@ -37,7 +37,7 @@ public async Task GetProductsForUserAsync_DoesNot_Return_NonVisible_Products() ExperienceWorth = 10, Visible = true }; - await context.AddAsync(p1); + _ = await context.AddAsync(p1); var p2 = new Product { @@ -49,20 +49,20 @@ public async Task GetProductsForUserAsync_DoesNot_Return_NonVisible_Products() ExperienceWorth = 20, Visible = false }; - await context.AddAsync(p2); - await context.SaveChangesAsync(); + _ = await context.AddAsync(p2); + _ = await context.SaveChangesAsync(); - await context.AddAsync(new ProductUserGroup + _ = await context.AddAsync(new ProductUserGroup { Product = p1, UserGroup = UserGroup.Barista }); - await context.AddAsync(new ProductUserGroup + _ = await context.AddAsync(new ProductUserGroup { Product = p2, UserGroup = UserGroup.Barista }); - await context.SaveChangesAsync(); + _ = await context.SaveChangesAsync(); using var productService = new ProductService(context); var expected = new List @@ -115,7 +115,7 @@ public async Task GetProductsForUserAsync_Return_Products_For_UserGroup() ExperienceWorth = 10, Visible = true }; - await context.AddAsync(p1); + _ = await context.AddAsync(p1); var p2 = new Product { @@ -127,7 +127,7 @@ public async Task GetProductsForUserAsync_Return_Products_For_UserGroup() ExperienceWorth = 20, Visible = true }; - await context.AddAsync(p2); + _ = await context.AddAsync(p2); var p3 = new Product { @@ -139,25 +139,25 @@ public async Task GetProductsForUserAsync_Return_Products_For_UserGroup() ExperienceWorth = 10, Visible = true }; - await context.AddAsync(p3); - await context.SaveChangesAsync(); + _ = await context.AddAsync(p3); + _ = await context.SaveChangesAsync(); - await context.AddAsync(new ProductUserGroup + _ = await context.AddAsync(new ProductUserGroup { Product = p1, UserGroup = UserGroup.Barista }); - await context.AddAsync(new ProductUserGroup + _ = await context.AddAsync(new ProductUserGroup { Product = p2, UserGroup = UserGroup.Barista }); - await context.AddAsync(new ProductUserGroup + _ = await context.AddAsync(new ProductUserGroup { Product = p3, UserGroup = UserGroup.Barista }); - await context.SaveChangesAsync(); + _ = await context.SaveChangesAsync(); using (var productService = new ProductService(context)) { @@ -233,7 +233,7 @@ public async Task GetPublicProducts_DoesNot_Return_NonVisible_Products() ExperienceWorth = 10, Visible = true }; - await context.AddAsync(p1); + _ = await context.AddAsync(p1); var p2 = new Product { @@ -245,20 +245,20 @@ public async Task GetPublicProducts_DoesNot_Return_NonVisible_Products() ExperienceWorth = 20, Visible = false }; - await context.AddAsync(p2); - await context.SaveChangesAsync(); + _ = await context.AddAsync(p2); + _ = await context.SaveChangesAsync(); - await context.AddAsync(new ProductUserGroup + _ = await context.AddAsync(new ProductUserGroup { Product = p1, UserGroup = UserGroup.Customer }); - await context.AddAsync(new ProductUserGroup + _ = await context.AddAsync(new ProductUserGroup { Product = p2, UserGroup = UserGroup.Customer }); - await context.SaveChangesAsync(); + _ = await context.SaveChangesAsync(); using var productService = new ProductService(context); var expected = new List @@ -308,7 +308,7 @@ public async Task GetPublicProducts_Return_All_NonBarista_Products() ExperienceWorth = 10, Visible = true }; - await context.AddAsync(p1); + _ = await context.AddAsync(p1); var p2 = new Product { @@ -320,7 +320,7 @@ public async Task GetPublicProducts_Return_All_NonBarista_Products() ExperienceWorth = 20, Visible = true }; - await context.AddAsync(p2); + _ = await context.AddAsync(p2); var p3 = new Product { @@ -332,25 +332,25 @@ public async Task GetPublicProducts_Return_All_NonBarista_Products() ExperienceWorth = 10, Visible = true }; - await context.AddAsync(p3); - await context.SaveChangesAsync(); + _ = await context.AddAsync(p3); + _ = await context.SaveChangesAsync(); - await context.AddAsync(new ProductUserGroup + _ = await context.AddAsync(new ProductUserGroup { Product = p1, UserGroup = UserGroup.Customer }); - await context.AddAsync(new ProductUserGroup + _ = await context.AddAsync(new ProductUserGroup { Product = p2, UserGroup = UserGroup.Customer }); - await context.AddAsync(new ProductUserGroup + _ = await context.AddAsync(new ProductUserGroup { Product = p3, UserGroup = UserGroup.Barista }); - await context.SaveChangesAsync(); + _ = await context.SaveChangesAsync(); using var productService = new ProductService(context); var expected = new List diff --git a/coffeecard/CoffeeCard.Tests.Unit/Services/TokenServiceTest.cs b/coffeecard/CoffeeCard.Tests.Unit/Services/TokenServiceTest.cs index 3c9ddb31..7cc421e5 100644 --- a/coffeecard/CoffeeCard.Tests.Unit/Services/TokenServiceTest.cs +++ b/coffeecard/CoffeeCard.Tests.Unit/Services/TokenServiceTest.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.IdentityModel.Tokens.Jwt; -using System.Security.Claims; -using System.Text; -using System.Threading.Tasks; using CoffeeCard.Common.Configuration; using CoffeeCard.Library.Persistence; using CoffeeCard.Library.Services; @@ -11,6 +5,12 @@ using CoffeeCard.Models.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; +using System; +using System.Collections.Generic; +using System.IdentityModel.Tokens.Jwt; +using System.Security.Claims; +using System.Text; +using System.Threading.Tasks; using Xunit; namespace CoffeeCard.Tests.Unit.Services @@ -77,8 +77,8 @@ public async Task ValidateTokenGivenValidTokenReturnsTrue() var token = tokenService.GenerateToken(claims); var userTokens = new List { new Token(token) }; var user = GenerateTestUser(tokens: userTokens); - await context.AddAsync(user); - await context.SaveChangesAsync(); + _ = await context.AddAsync(user); + _ = await context.SaveChangesAsync(); // Act result = await tokenService.ValidateTokenIsUnusedAsync(token); @@ -153,8 +153,8 @@ public async Task ValidateTokenGivenWelformedExpiredTokenReturnsFalse() var userTokens = new List { new Token(token) }; var user = GenerateTestUser(tokens: userTokens); - await context.AddAsync(user); - await context.SaveChangesAsync(); + _ = await context.AddAsync(user); + _ = await context.SaveChangesAsync(); // Act result = await tokenService.ValidateTokenIsUnusedAsync(token); @@ -185,8 +185,8 @@ public async Task ValidateTokenGivenWelformedUsedTokenReturnsFalse() var userTokens = new List(); //No tokens are added to the users list, therefore all tokens with a claim for this user will be assumed to be expired var user = GenerateTestUser(tokens: userTokens); - await context.AddAsync(user); - await context.SaveChangesAsync(); + _ = await context.AddAsync(user); + _ = await context.SaveChangesAsync(); // Act result = await tokenService.ValidateTokenIsUnusedAsync(token); diff --git a/coffeecard/CoffeeCard.Tests.Unit/Services/v2/AccountServiceTest.cs b/coffeecard/CoffeeCard.Tests.Unit/Services/v2/AccountServiceTest.cs index 1201f4bd..5bd8fb3f 100644 --- a/coffeecard/CoffeeCard.Tests.Unit/Services/v2/AccountServiceTest.cs +++ b/coffeecard/CoffeeCard.Tests.Unit/Services/v2/AccountServiceTest.cs @@ -1,23 +1,17 @@ -using System; -using System.Collections.Generic; -using System.IdentityModel.Tokens.Jwt; -using System.Linq; -using System.Security.Claims; -using System.Text; -using System.Threading.Tasks; using CoffeeCard.Common.Configuration; using CoffeeCard.Common.Errors; using CoffeeCard.Library.Persistence; using CoffeeCard.Library.Services; -using CoffeeCard.Library.Services.v2; -using CoffeeCard.Library.Utils; -using CoffeeCard.Models.DataTransferObjects.v2.Programme; using CoffeeCard.Models.DataTransferObjects.v2.User; using CoffeeCard.Models.Entities; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; -using Microsoft.IdentityModel.Tokens; using Moq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using System.Threading.Tasks; using Xunit; namespace CoffeeCard.Tests.Unit.Services.v2 @@ -50,8 +44,8 @@ public async Task GetAccountByClaimsReturnsUserClaimWithEmail() User result; using var context = CreateTestCoffeeCardContextWithName(nameof(GetAccountByClaimsReturnsUserClaimWithEmail)); - context.Users.Add(expected); - await context.SaveChangesAsync(); + _ = context.Users.Add(expected); + _ = await context.SaveChangesAsync(); // Act var accountService = new Library.Services.v2.AccountService(context, new Mock().Object, new Mock().Object, new Mock().Object); @@ -70,14 +64,14 @@ public async Task GetAccountByClaimsThrowsApiExceptionGivenInvalidClaim(IEnumera var validUser = new User() { Name = "User", Email = "test@test.test" }; using var context = CreateTestCoffeeCardContextWithName(nameof(GetAccountByClaimsThrowsApiExceptionGivenInvalidClaim) + claims.ToString()); - context.Users.Add(validUser); - await context.SaveChangesAsync(); + _ = context.Users.Add(validUser); + _ = await context.SaveChangesAsync(); // Act var accountService = new Library.Services.v2.AccountService(context, new Mock().Object, new Mock().Object, new Mock().Object); // Assert - await Assert.ThrowsAsync(async () => await accountService.GetAccountByClaimsAsync(claims)); + _ = await Assert.ThrowsAsync(async () => await accountService.GetAccountByClaimsAsync(claims)); } [Theory(DisplayName = "RegisterAccount returns user on valid input")] @@ -93,7 +87,7 @@ public async Task RegisterAccountReturnsUserOnValidInput(String name, String ema Id = programmeId, FullName = "test", ShortName = "t", - Users = new List() + Users = [] }; var expectedPass = "HashedPassword"; var expected = new User() @@ -109,16 +103,16 @@ public async Task RegisterAccountReturnsUserOnValidInput(String name, String ema // Using same context across all valid users to test creation of multiple users using var context = CreateTestCoffeeCardContextWithName(nameof(RegisterAccountReturnsUserOnValidInput)); var emailServiceMock = new Mock(); - emailServiceMock.Setup(e => e.SendRegistrationVerificationEmailAsync(It.IsAny(), It.IsAny())).Returns(Task.CompletedTask); + _ = emailServiceMock.Setup(e => e.SendRegistrationVerificationEmailAsync(It.IsAny(), It.IsAny())).Returns(Task.CompletedTask); var emailService = emailServiceMock.Object; var hashServiceMock = new Mock(); - hashServiceMock.Setup(h => h.GenerateSalt()).Returns(""); - hashServiceMock.Setup(h => h.Hash(password)).Returns(expectedPass); + _ = hashServiceMock.Setup(h => h.GenerateSalt()).Returns(""); + _ = hashServiceMock.Setup(h => h.Hash(password)).Returns(expectedPass); var hashService = hashServiceMock.Object; - context.Programmes.Add(programme); - await context.SaveChangesAsync(); + _ = context.Programmes.Add(programme); + _ = await context.SaveChangesAsync(); // Act var accountService = new Library.Services.v2.AccountService(context, new Mock().Object, emailService, hashService); @@ -136,16 +130,16 @@ public async Task RegisterAccountReturnsUserOnValidInput(String name, String ema public async Task RegisterAccountThrowsApiExceptionWithStatus409OnExistingEmail() { // Arrange - var programme = new Programme() { Id = 1, FullName = "test", ShortName = "t", SortPriority = 1, Users = new List() }; + var programme = new Programme() { Id = 1, FullName = "test", ShortName = "t", SortPriority = 1, Users = [] }; var email = "test@test.dk"; using var context = CreateTestCoffeeCardContextWithName(nameof(RegisterAccountThrowsApiExceptionWithStatus409OnExistingEmail)); - context.Programmes.Add(programme); - await context.SaveChangesAsync(); + _ = context.Programmes.Add(programme); + _ = await context.SaveChangesAsync(); var hashservice = new Mock(); - hashservice.Setup(h => h.GenerateSalt()).Returns(""); - hashservice.Setup(h => h.Hash("pass")).Returns(""); + _ = hashservice.Setup(h => h.GenerateSalt()).Returns(""); + _ = hashservice.Setup(h => h.Hash("pass")).Returns(""); // Act var accountService = new Library.Services.v2.AccountService(context, new Mock().Object, @@ -153,7 +147,7 @@ public async Task RegisterAccountThrowsApiExceptionWithStatus409OnExistingEmail( // Assert // Register the first user - await accountService.RegisterAccountAsync("name", email, "pass", 1); + _ = await accountService.RegisterAccountAsync("name", email, "pass", 1); // Try to register user with the sme email as before var exception = await Assert.ThrowsAsync( async () => await accountService.RegisterAccountAsync("name", email, "pass", 1)); @@ -184,7 +178,7 @@ public async Task RegisterAccountSendsVerificationEmailOnlyValidInput() Id = 1, FullName = "test", ShortName = "t", - Users = new List() + Users = [] }; var expectedPass = "HashedPassword"; var expected = new User() @@ -198,26 +192,26 @@ public async Task RegisterAccountSendsVerificationEmailOnlyValidInput() using var context = CreateTestCoffeeCardContextWithName(nameof(RegisterAccountSendsVerificationEmailOnlyValidInput)); var emailServiceMock = new Mock(); - emailServiceMock.Setup(e => e.SendRegistrationVerificationEmailAsync(It.IsAny(), It.IsAny())).Returns(Task.CompletedTask); + _ = emailServiceMock.Setup(e => e.SendRegistrationVerificationEmailAsync(It.IsAny(), It.IsAny())).Returns(Task.CompletedTask); var emailService = emailServiceMock.Object; var hashServiceMock = new Mock(); - hashServiceMock.Setup(h => h.GenerateSalt()).Returns(""); - hashServiceMock.Setup(h => h.Hash("password")).Returns(expectedPass); + _ = hashServiceMock.Setup(h => h.GenerateSalt()).Returns(""); + _ = hashServiceMock.Setup(h => h.Hash("password")).Returns(expectedPass); var hashService = hashServiceMock.Object; - context.Programmes.Add(programme); - await context.SaveChangesAsync(); + _ = context.Programmes.Add(programme); + _ = await context.SaveChangesAsync(); // Act var accountService = new Library.Services.v2.AccountService(context, new Mock().Object, emailService, hashService); - await accountService.RegisterAccountAsync("name", "email", "password", 1); + _ = await accountService.RegisterAccountAsync("name", "email", "password", 1); // Assert // Verify an email would have been send for the first registration emailServiceMock.Verify(e => e.SendRegistrationVerificationEmailAsync(It.IsAny(), It.IsAny()), Times.Exactly(1)); - await Assert.ThrowsAsync( + _ = await Assert.ThrowsAsync( async () => await accountService.RegisterAccountAsync("name", "email", "pass", 1)); // Verify no email was send for the second, failed registration emailServiceMock.Verify(e => e.SendRegistrationVerificationEmailAsync(It.IsAny(), It.IsAny()), Times.Exactly(1)); @@ -237,7 +231,7 @@ public async Task UpdateAccountUpdatesAllNonNullProperties(String name, String e Id = 1, FullName = "test", ShortName = "t", - Users = new List() + Users = [] }; var updateUserRequest = new UpdateUserRequest() { @@ -265,13 +259,13 @@ public async Task UpdateAccountUpdatesAllNonNullProperties(String name, String e }; using var context = CreateTestCoffeeCardContextWithName(nameof(UpdateAccountUpdatesAllNonNullProperties) + name); - context.Users.Add(user); + _ = context.Users.Add(user); - context.Programmes.Add(programme); - await context.SaveChangesAsync(); + _ = context.Programmes.Add(programme); + _ = await context.SaveChangesAsync(); var hashServiceMock = new Mock(); - hashServiceMock.Setup(h => h.Hash(It.IsAny())).Returns(password); + _ = hashServiceMock.Setup(h => h.Hash(It.IsAny())).Returns(password); var hashService = hashServiceMock.Object; // Act @@ -296,7 +290,7 @@ public async Task UpdateAccountThrowsApiExceptionOnInvalidProgrammeId() Id = 1, FullName = "test", ShortName = "t", - Users = new List() + Users = [] }; var updateUserRequest = new UpdateUserRequest() { @@ -316,10 +310,10 @@ public async Task UpdateAccountThrowsApiExceptionOnInvalidProgrammeId() }; using var context = CreateTestCoffeeCardContextWithName(nameof(UpdateAccountThrowsApiExceptionOnInvalidProgrammeId)); - context.Users.Add(user); + _ = context.Users.Add(user); - context.Programmes.Add(programme); - await context.SaveChangesAsync(); + _ = context.Programmes.Add(programme); + _ = await context.SaveChangesAsync(); // Act var accountService = new Library.Services.v2.AccountService(context, new Mock().Object, @@ -343,11 +337,11 @@ public async Task RequestAnonymizationSendsEmail() }; using var context = CreateTestCoffeeCardContextWithName(nameof(RequestAnonymizationSendsEmail)); - context.Users.Add(user); - await context.SaveChangesAsync(); + _ = context.Users.Add(user); + _ = await context.SaveChangesAsync(); var emailServiceMock = new Mock(); - emailServiceMock.Setup(e => e.SendVerificationEmailForDeleteAccount(It.IsAny(), It.IsAny())).Returns(Task.CompletedTask); + _ = emailServiceMock.Setup(e => e.SendVerificationEmailForDeleteAccount(It.IsAny(), It.IsAny())).Returns(Task.CompletedTask); var emailService = emailServiceMock.Object; // Act @@ -386,11 +380,11 @@ public async Task AnonymizeAccountRemovesIdentifyableInformationFromUser() }; await using var context = CreateTestCoffeeCardContextWithName(nameof(AnonymizeAccountRemovesIdentifyableInformationFromUser)); - context.Users.Add(user); - await context.SaveChangesAsync(); + _ = context.Users.Add(user); + _ = await context.SaveChangesAsync(); var tokenServiceMock = new Mock(); - tokenServiceMock.Setup(e => e.ValidateVerificationTokenAndGetEmail("test")).Returns(userEmail); + _ = tokenServiceMock.Setup(e => e.ValidateVerificationTokenAndGetEmail("test")).Returns(userEmail); // Act var accountService = new Library.Services.v2.AccountService(context, tokenServiceMock.Object, @@ -427,8 +421,8 @@ public async Task ResendVerificationEmailWhenAccountIsNotVerified() }; await using var context = CreateTestCoffeeCardContextWithName(nameof(ResendVerificationEmailWhenAccountIsNotVerified)); - context.Users.Add(user); - await context.SaveChangesAsync(); + _ = context.Users.Add(user); + _ = await context.SaveChangesAsync(); // Act var emailService = new Mock(); @@ -461,13 +455,13 @@ public async Task ResendVerificationEmailThrowsConflictExceptionWhenAccountIsAlr }; await using var context = CreateTestCoffeeCardContextWithName(nameof(ResendVerificationEmailThrowsConflictExceptionWhenAccountIsAlreadyVerified)); - context.Users.Add(user); - await context.SaveChangesAsync(); + _ = context.Users.Add(user); + _ = await context.SaveChangesAsync(); // Act var accountService = new Library.Services.v2.AccountService(context, new Mock().Object, new Mock().Object, new Mock().Object); - await Assert.ThrowsAsync(async () => await accountService.ResendAccountVerificationEmail(new ResendAccountVerificationEmailRequest + _ = await Assert.ThrowsAsync(async () => await accountService.ResendAccountVerificationEmail(new ResendAccountVerificationEmailRequest { Email = userEmail })); @@ -482,7 +476,7 @@ public async Task ResendVerificationEmailThrowsEntityNotFoundExceptionWhenEmailD // Act var accountService = new Library.Services.v2.AccountService(context, new Mock().Object, new Mock().Object, new Mock().Object); - await Assert.ThrowsAsync(async () => await accountService.ResendAccountVerificationEmail(new ResendAccountVerificationEmailRequest + _ = await Assert.ThrowsAsync(async () => await accountService.ResendAccountVerificationEmail(new ResendAccountVerificationEmailRequest { Email = "test@test.test" })); diff --git a/coffeecard/CoffeeCard.Tests.Unit/Services/v2/LeaderboardServiceTests.cs b/coffeecard/CoffeeCard.Tests.Unit/Services/v2/LeaderboardServiceTests.cs index 44729345..554ddf1f 100644 --- a/coffeecard/CoffeeCard.Tests.Unit/Services/v2/LeaderboardServiceTests.cs +++ b/coffeecard/CoffeeCard.Tests.Unit/Services/v2/LeaderboardServiceTests.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using CoffeeCard.Common.Configuration; using CoffeeCard.Library.Persistence; using CoffeeCard.Library.Services.v2; @@ -10,6 +6,9 @@ using CoffeeCard.Models.Entities; using Microsoft.EntityFrameworkCore; using Moq; +using System; +using System.Linq; +using System.Threading.Tasks; using Xunit; namespace CoffeeCard.Tests.Unit.Services.v2 @@ -51,7 +50,7 @@ public async Task GetLeaderboardEntryGivenUserAndPresetReturnsLeaderboardEntry( UserGroup = UserGroup.Customer, UserState = UserState.Active }; - context.Add(user1); + _ = context.Add(user1); var user2 = new User { @@ -66,7 +65,7 @@ public async Task GetLeaderboardEntryGivenUserAndPresetReturnsLeaderboardEntry( UserGroup = UserGroup.Customer, UserState = UserState.Active }; - context.Add(user2); + _ = context.Add(user2); var user1Statistics = new Statistic { @@ -77,7 +76,7 @@ public async Task GetLeaderboardEntryGivenUserAndPresetReturnsLeaderboardEntry( ExpiryDate = new DateTime(year: 2020, month: 11, day: 11), User = user1 }; - context.Add(user1Statistics); + _ = context.Add(user1Statistics); var user2Statistics = new Statistic { @@ -88,12 +87,12 @@ public async Task GetLeaderboardEntryGivenUserAndPresetReturnsLeaderboardEntry( ExpiryDate = new DateTime(year: 2020, month: 11, day: 11), User = user2 }; - context.Add(user2Statistics); + _ = context.Add(user2Statistics); - await context.SaveChangesAsync(); + _ = await context.SaveChangesAsync(); var dateTimeProvider = new Mock(); - dateTimeProvider.Setup(dtp => dtp.UtcNow()).Returns(new DateTime(2020, 11, 11)); + _ = dateTimeProvider.Setup(dtp => dtp.UtcNow()).Returns(new DateTime(2020, 11, 11)); var leaderboardService = new LeaderboardService(context, dateTimeProvider.Object); @@ -147,8 +146,8 @@ public async Task GetLeaderboardEntryGivenUserAndPresetWhenUserHasNoScoreReturns UserGroup = UserGroup.Customer, UserState = UserState.Active }; - context.Add(user1); - await context.SaveChangesAsync(); + _ = context.Add(user1); + _ = await context.SaveChangesAsync(); var dateTimeProvider = new Mock(); var leaderboardService = new LeaderboardService(context, dateTimeProvider.Object); @@ -201,7 +200,7 @@ public async Task GetTopLeaderboardEntriesPresetReturnsListLeaderboardEntry( UserGroup = UserGroup.Customer, UserState = UserState.Active }; - context.Add(user1); + _ = context.Add(user1); var user2 = new User { @@ -216,7 +215,7 @@ public async Task GetTopLeaderboardEntriesPresetReturnsListLeaderboardEntry( UserGroup = UserGroup.Customer, UserState = UserState.Active }; - context.Add(user2); + _ = context.Add(user2); var user1Statistics = new Statistic { @@ -227,7 +226,7 @@ public async Task GetTopLeaderboardEntriesPresetReturnsListLeaderboardEntry( ExpiryDate = new DateTime(year: 2020, month: 11, day: 11), User = user1 }; - context.Add(user1Statistics); + _ = context.Add(user1Statistics); var user2Statistics = new Statistic { @@ -238,12 +237,12 @@ public async Task GetTopLeaderboardEntriesPresetReturnsListLeaderboardEntry( ExpiryDate = new DateTime(year: 2020, month: 11, day: 11), User = user2 }; - context.Add(user2Statistics); + _ = context.Add(user2Statistics); - await context.SaveChangesAsync(); + _ = await context.SaveChangesAsync(); var dateTimeProvider = new Mock(); - dateTimeProvider.Setup(dtp => dtp.UtcNow()).Returns(new DateTime(2020, 11, 11)); + _ = dateTimeProvider.Setup(dtp => dtp.UtcNow()).Returns(new DateTime(2020, 11, 11)); var leaderboardService = new LeaderboardService(context, dateTimeProvider.Object); @@ -251,8 +250,8 @@ public async Task GetTopLeaderboardEntriesPresetReturnsListLeaderboardEntry( var result = await leaderboardService.GetTopLeaderboardEntries(inputPreset, 10); // Assert - Assert.Equal(new List - { + Assert.Equal( + [ new LeaderboardEntry { Id = user2.Id, @@ -267,7 +266,7 @@ public async Task GetTopLeaderboardEntriesPresetReturnsListLeaderboardEntry( Rank = 2, Score = 10 } - }, result.ToList()); + ], result.ToList()); } [Theory(DisplayName = "GetTopLeaderboardEntries given preset when statistics are expired returns empty list")] @@ -304,7 +303,7 @@ public async Task GetTopLeaderboardEntriesGivensPresetWhenStatisticsAreExpiredRe UserGroup = UserGroup.Customer, UserState = UserState.Active }; - context.Add(user1); + _ = context.Add(user1); var user2 = new User { @@ -319,7 +318,7 @@ public async Task GetTopLeaderboardEntriesGivensPresetWhenStatisticsAreExpiredRe UserGroup = UserGroup.Customer, UserState = UserState.Active }; - context.Add(user2); + _ = context.Add(user2); var user1Statistics = new Statistic { @@ -330,7 +329,7 @@ public async Task GetTopLeaderboardEntriesGivensPresetWhenStatisticsAreExpiredRe ExpiryDate = new DateTime(year: 2020, month: 11, day: 11), User = user1 }; - context.Add(user1Statistics); + _ = context.Add(user1Statistics); var user2Statistics = new Statistic { @@ -341,12 +340,12 @@ public async Task GetTopLeaderboardEntriesGivensPresetWhenStatisticsAreExpiredRe ExpiryDate = new DateTime(year: 2020, month: 11, day: 11), User = user2 }; - context.Add(user2Statistics); + _ = context.Add(user2Statistics); - await context.SaveChangesAsync(); + _ = await context.SaveChangesAsync(); var dateTimeProvider = new Mock(); - dateTimeProvider.Setup(dtp => dtp.UtcNow()).Returns(new DateTime(2021, 12, 31)); + _ = dateTimeProvider.Setup(dtp => dtp.UtcNow()).Returns(new DateTime(2021, 12, 31)); var leaderboardService = new LeaderboardService(context, dateTimeProvider.Object); @@ -423,7 +422,7 @@ public async Task GetTopLeaderboardEntriesGivenPresetDoesNotIncludeExpiredEntrie UserGroup = UserGroup.Customer, UserState = UserState.Active }; - context.Add(user1); + _ = context.Add(user1); var user2 = new User { @@ -438,7 +437,7 @@ public async Task GetTopLeaderboardEntriesGivenPresetDoesNotIncludeExpiredEntrie UserGroup = UserGroup.Customer, UserState = UserState.Active }; - context.Add(user2); + _ = context.Add(user2); var user1Statistics = new Statistic { @@ -449,7 +448,7 @@ public async Task GetTopLeaderboardEntriesGivenPresetDoesNotIncludeExpiredEntrie ExpiryDate = new DateTime(year: 2000, month: 11, day: 11), User = user1 }; - context.Add(user1Statistics); + _ = context.Add(user1Statistics); var user2Statistics = new Statistic { @@ -460,11 +459,11 @@ public async Task GetTopLeaderboardEntriesGivenPresetDoesNotIncludeExpiredEntrie ExpiryDate = new DateTime(year: 2000, month: 11, day: 11), User = user2 }; - context.Add(user2Statistics); - await context.SaveChangesAsync(); + _ = context.Add(user2Statistics); + _ = await context.SaveChangesAsync(); var dateTimeProvider = new Mock(); - dateTimeProvider.Setup(dtp => dtp.UtcNow()).Returns(new DateTime(2020, 11, 12)); + _ = dateTimeProvider.Setup(dtp => dtp.UtcNow()).Returns(new DateTime(2020, 11, 12)); var leaderboardService = new LeaderboardService(context, dateTimeProvider.Object); // Act diff --git a/coffeecard/CoffeeCard.Tests.Unit/Services/v2/ProductServiceTest.cs b/coffeecard/CoffeeCard.Tests.Unit/Services/v2/ProductServiceTest.cs index f44c5e98..167232be 100644 --- a/coffeecard/CoffeeCard.Tests.Unit/Services/v2/ProductServiceTest.cs +++ b/coffeecard/CoffeeCard.Tests.Unit/Services/v2/ProductServiceTest.cs @@ -1,14 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using CoffeeCard.Common.Configuration; using CoffeeCard.Library.Persistence; using CoffeeCard.Library.Services.v2; using CoffeeCard.Models.DataTransferObjects.v2.Product; -using CoffeeCard.Models.DataTransferObjects.v2.Products; using CoffeeCard.Models.Entities; using Microsoft.EntityFrameworkCore; +using System; +using System.Threading.Tasks; using Xunit; namespace CoffeeCard.Tests.Unit.Services.v2 @@ -41,33 +38,33 @@ public async Task UpdateProduct_Removes_Omitted_UserGroups() ExperienceWorth = 10, Visible = true }; - await context.AddAsync(p); - await context.SaveChangesAsync(); + _ = await context.AddAsync(p); + _ = await context.SaveChangesAsync(); - await context.AddAsync(new ProductUserGroup + _ = await context.AddAsync(new ProductUserGroup { Product = p, UserGroup = UserGroup.Barista }); - await context.AddAsync(new ProductUserGroup + _ = await context.AddAsync(new ProductUserGroup { Product = p, UserGroup = UserGroup.Manager }); - await context.SaveChangesAsync(); + _ = await context.SaveChangesAsync(); using var productService = new ProductService(context); - await productService.UpdateProduct(1, new UpdateProductRequest() + _ = await productService.UpdateProduct(1, new UpdateProductRequest() { Visible = true, Price = 10, NumberOfTickets = 10, Name = "Coffee", Description = "Coffee Clip card", - AllowedUserGroups = new List() { UserGroup.Customer, UserGroup.Board } + AllowedUserGroups = [UserGroup.Customer, UserGroup.Board] }); var result = await productService.GetProductAsync(1); @@ -107,10 +104,10 @@ public async Task AddProduct_Sets_Correct_UserGroups() NumberOfTickets = 10, Price = 10, Visible = true, - AllowedUserGroups = new List { UserGroup.Manager, UserGroup.Board } + AllowedUserGroups = [UserGroup.Manager, UserGroup.Board] }; - await productService.AddProduct(p); + _ = await productService.AddProduct(p); var result = await productService.GetProductAsync(1); @@ -147,7 +144,7 @@ public async Task GetAllProducts_Returns_Non_Visible_Products() Visible = true, AllowedUserGroups = Enum.GetValues() }; - await productService.AddProduct(p1); + _ = await productService.AddProduct(p1); var p2 = new AddProductRequest { @@ -158,7 +155,7 @@ public async Task GetAllProducts_Returns_Non_Visible_Products() Visible = false, AllowedUserGroups = Enum.GetValues() }; - await productService.AddProduct(p2); + _ = await productService.AddProduct(p2); var result = await productService.GetAllProductsAsync(); @@ -193,9 +190,9 @@ public async Task GetAllProducts_Returns_Products_For_All_UserGroups() NumberOfTickets = 10, Price = 10, Visible = true, - AllowedUserGroups = new List { UserGroup.Customer } + AllowedUserGroups = [UserGroup.Customer] }; - await productService.AddProduct(p1); + _ = await productService.AddProduct(p1); var p2 = new AddProductRequest { @@ -204,9 +201,9 @@ public async Task GetAllProducts_Returns_Products_For_All_UserGroups() NumberOfTickets = 10, Price = 170, Visible = true, - AllowedUserGroups = new List { UserGroup.Barista } + AllowedUserGroups = [UserGroup.Barista] }; - await productService.AddProduct(p2); + _ = await productService.AddProduct(p2); var p3 = new AddProductRequest { @@ -215,9 +212,9 @@ public async Task GetAllProducts_Returns_Products_For_All_UserGroups() NumberOfTickets = 1, Price = 35, Visible = true, - AllowedUserGroups = new List { UserGroup.Manager } + AllowedUserGroups = [UserGroup.Manager] }; - await productService.AddProduct(p3); + _ = await productService.AddProduct(p3); var p4 = new AddProductRequest { @@ -226,31 +223,31 @@ public async Task GetAllProducts_Returns_Products_For_All_UserGroups() NumberOfTickets = 1, Price = 19, Visible = true, - AllowedUserGroups = new List { UserGroup.Board } + AllowedUserGroups = [UserGroup.Board] }; - await productService.AddProduct(p4); + _ = await productService.AddProduct(p4); var result = await productService.GetAllProductsAsync(); Assert.Collection(result, e => { - Assert.Single(e.AllowedUserGroups); + _ = Assert.Single(e.AllowedUserGroups); Assert.Contains(UserGroup.Customer, e.AllowedUserGroups); }, e => { - Assert.Single(e.AllowedUserGroups); + _ = Assert.Single(e.AllowedUserGroups); Assert.Contains(UserGroup.Barista, e.AllowedUserGroups); }, e => { - Assert.Single(e.AllowedUserGroups); + _ = Assert.Single(e.AllowedUserGroups); Assert.Contains(UserGroup.Manager, e.AllowedUserGroups); }, e => { - Assert.Single(e.AllowedUserGroups); + _ = Assert.Single(e.AllowedUserGroups); Assert.Contains(UserGroup.Board, e.AllowedUserGroups); } ); diff --git a/coffeecard/CoffeeCard.Tests.Unit/Services/v2/PurchaseServiceTests.cs b/coffeecard/CoffeeCard.Tests.Unit/Services/v2/PurchaseServiceTests.cs index b52279fa..fa46dd6f 100644 --- a/coffeecard/CoffeeCard.Tests.Unit/Services/v2/PurchaseServiceTests.cs +++ b/coffeecard/CoffeeCard.Tests.Unit/Services/v2/PurchaseServiceTests.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; using CoffeeCard.Common.Configuration; using CoffeeCard.Common.Errors; using CoffeeCard.Library.Persistence; @@ -11,6 +8,9 @@ using CoffeeCard.Models.Entities; using Microsoft.EntityFrameworkCore; using Moq; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; using Xunit; using PurchaseService = CoffeeCard.Library.Services.v2.PurchaseService; @@ -55,7 +55,7 @@ public async Task InitiatePurchaseCheckUserIsAllowedToPurchaseProductThrowsExcep UserGroup = UserGroup.Customer, UserState = UserState.Active }; - context.Add(user); + _ = context.Add(user); var product1 = new Product { @@ -64,14 +64,14 @@ public async Task InitiatePurchaseCheckUserIsAllowedToPurchaseProductThrowsExcep Description = "desc", Price = 100 }; - context.Add(product1); + _ = context.Add(product1); var pug1 = new ProductUserGroup { UserGroup = UserGroup.Customer, Product = product1 }; - context.Add(pug1); + _ = context.Add(pug1); var product2 = new Product { @@ -80,16 +80,16 @@ public async Task InitiatePurchaseCheckUserIsAllowedToPurchaseProductThrowsExcep Description = "desc", Price = 100 }; - context.Add(product2); + _ = context.Add(product2); var pug2 = new ProductUserGroup { UserGroup = UserGroup.Barista, Product = product2 }; - context.Add(pug2); + _ = context.Add(pug2); - await context.SaveChangesAsync(); + _ = await context.SaveChangesAsync(); var mobilePayService = new Mock(); var mailService = new Mock(); @@ -106,7 +106,7 @@ public async Task InitiatePurchaseCheckUserIsAllowedToPurchaseProductThrowsExcep }; // Act, Assert - await Assert.ThrowsAsync(exceptionType, () => purchaseService.InitiatePurchase(request, user)); + _ = await Assert.ThrowsAsync(exceptionType, () => purchaseService.InitiatePurchase(request, user)); } [Fact(DisplayName = "InitiatePurchase for PaymentType MobilePay")] @@ -135,7 +135,7 @@ public async Task InitiatePurchasePaymentTypeMobilePay() Salt = "salt", UserGroup = UserGroup.Customer, }; - context.Add(user); + _ = context.Add(user); var product1 = new Product { @@ -144,16 +144,16 @@ public async Task InitiatePurchasePaymentTypeMobilePay() Description = "desc", Price = 100 }; - context.Add(product1); + _ = context.Add(product1); var pug1 = new ProductUserGroup { UserGroup = UserGroup.Customer, Product = product1 }; - context.Add(pug1); + _ = context.Add(pug1); - await context.SaveChangesAsync(); + _ = await context.SaveChangesAsync(); var mobilePayService = new Mock(); var mailService = new Mock(); @@ -172,7 +172,7 @@ public async Task InitiatePurchasePaymentTypeMobilePay() var mobilepayPaymentId = Guid.NewGuid().ToString(); var orderId = Guid.NewGuid().ToString(); var mpDeepLink = "mobilepay://merchant_payments?payment_id=186d2b31-ff25-4414-9fd1-bfe9807fa8b7"; - mobilePayService.Setup(mps => mps.InitiatePayment(It.IsAny())) + _ = mobilePayService.Setup(mps => mps.InitiatePayment(It.IsAny())) .ReturnsAsync(new MobilePayPaymentDetails(orderId, mpDeepLink, mobilepayPaymentId)); // Act @@ -234,9 +234,9 @@ public async Task InitiatePurchaseAddsTicketsToUserWhenFree(Product product) UserGroup = UserGroup.Customer, UserState = UserState.Active }; - context.Add(user); - context.Add(product); - await context.SaveChangesAsync(); + _ = context.Add(user); + _ = context.Add(product); + _ = await context.SaveChangesAsync(); var mobilePayService = new Mock(); var mailService = new Mock(); diff --git a/coffeecard/CoffeeCard.Tests.Unit/Services/v2/VoucherServiceTests.cs b/coffeecard/CoffeeCard.Tests.Unit/Services/v2/VoucherServiceTests.cs index 701018e8..4ab7f8c7 100644 --- a/coffeecard/CoffeeCard.Tests.Unit/Services/v2/VoucherServiceTests.cs +++ b/coffeecard/CoffeeCard.Tests.Unit/Services/v2/VoucherServiceTests.cs @@ -1,5 +1,3 @@ -using System.ComponentModel; -using System.Linq; using CoffeeCard.Common.Configuration; using CoffeeCard.Common.Errors; using CoffeeCard.Library.Persistence; @@ -7,6 +5,7 @@ using CoffeeCard.Models.DataTransferObjects.v2.Voucher; using CoffeeCard.Models.Entities; using Microsoft.EntityFrameworkCore; +using System.Linq; using Xunit; namespace CoffeeCard.Tests.Unit.Services.v2 @@ -37,8 +36,8 @@ public async void CreateVouchersReturnsUniqueResponses(int amount, int productId await using var context = new CoffeeCardContext(builder.Options, databaseSettings, environmentSettings); var product = new Product { Id = 1, Name = "product", Description = "desc" }; - await context.Products.AddAsync(product); - await context.SaveChangesAsync(); + _ = await context.Products.AddAsync(product); + _ = await context.SaveChangesAsync(); var voucherService = new VoucherService(context); // Act @@ -72,7 +71,7 @@ public async void CreateVouchersThrowsApiExceptionWhenNoProductIsFound() // Act var request = new IssueVoucherRequest { ProductId = 1, Amount = 10 }; - await Assert.ThrowsAsync(() => voucherService.CreateVouchers(request)); + _ = await Assert.ThrowsAsync(() => voucherService.CreateVouchers(request)); } [Fact(DisplayName = "CreateVouchers have length of 8 + 4 from userPrefix")] @@ -93,8 +92,8 @@ public async void CreateVouchersHaveGivenLength() await using var context = new CoffeeCardContext(builder.Options, databaseSettings, environmentSettings); var product = new Product { Id = 1, Name = "product", Description = "desc" }; - await context.Products.AddAsync(product); - await context.SaveChangesAsync(); + _ = await context.Products.AddAsync(product); + _ = await context.SaveChangesAsync(); var voucherService = new VoucherService(context); // Act @@ -124,8 +123,8 @@ public async void CreateVouchersSavesToDatabase() await using var context = new CoffeeCardContext(builder.Options, databaseSettings, environmentSettings); var product = new Product { Id = 1, Name = "product", Description = "desc" }; - await context.Products.AddAsync(product); - await context.SaveChangesAsync(); + _ = await context.Products.AddAsync(product); + _ = await context.SaveChangesAsync(); var voucherService = new VoucherService(context); // Act @@ -153,8 +152,8 @@ public async void CreateVouchersCreatesVouchersWithPrefix() await using var context = new CoffeeCardContext(builder.Options, databaseSettings, environmentSettings); var product = new Product { Id = 1, Name = "product", Description = "desc" }; - await context.Products.AddAsync(product); - await context.SaveChangesAsync(); + _ = await context.Products.AddAsync(product); + _ = await context.SaveChangesAsync(); var voucherService = new VoucherService(context); //Act diff --git a/coffeecard/CoffeeCard.Tests.Unit/Utils/ProductExtensionsTests.cs b/coffeecard/CoffeeCard.Tests.Unit/Utils/ProductExtensionsTests.cs index 523314dd..f7ff6ad0 100644 --- a/coffeecard/CoffeeCard.Tests.Unit/Utils/ProductExtensionsTests.cs +++ b/coffeecard/CoffeeCard.Tests.Unit/Utils/ProductExtensionsTests.cs @@ -1,7 +1,7 @@ -using System; using CoffeeCard.Library.Utils; using CoffeeCard.Models.DataTransferObjects.v2.Products; using CoffeeCard.Models.Entities; +using System; using Xunit; namespace CoffeeCard.Tests.Unit.Utils @@ -38,7 +38,7 @@ public void TestIsPerkThrowsArgumentNullException() ProductUserGroup = null }; - Assert.Throws(() => product.IsPerk()); + _ = Assert.Throws(() => product.IsPerk()); } [Fact(DisplayName = "ToProductResponse returns a ProductResponse with the correct values")] @@ -59,7 +59,7 @@ public void TestToProductResponse() var productResponse = product.ToProductResponse(); - Assert.IsType(productResponse); + _ = Assert.IsType(productResponse); } [Fact(DisplayName = "ToProductResponse converts ProductUserGroup to list of allowed user groups")] diff --git a/coffeecard/CoffeeCard.Tests.Unit/Utils/SemesterUtilTests.cs b/coffeecard/CoffeeCard.Tests.Unit/Utils/SemesterUtilTests.cs index 3e2b05c7..0c1f725b 100644 --- a/coffeecard/CoffeeCard.Tests.Unit/Utils/SemesterUtilTests.cs +++ b/coffeecard/CoffeeCard.Tests.Unit/Utils/SemesterUtilTests.cs @@ -1,5 +1,5 @@ -using System; using CoffeeCard.Library.Utils; +using System; using Xunit; namespace CoffeeCard.Tests.Unit.Utils diff --git a/coffeecard/CoffeeCard.WebApi/CoffeeCard.WebApi.csproj b/coffeecard/CoffeeCard.WebApi/CoffeeCard.WebApi.csproj index fb461de5..a835ac3b 100644 --- a/coffeecard/CoffeeCard.WebApi/CoffeeCard.WebApi.csproj +++ b/coffeecard/CoffeeCard.WebApi/CoffeeCard.WebApi.csproj @@ -21,8 +21,6 @@ - - @@ -31,6 +29,7 @@ + diff --git a/coffeecard/CoffeeCard.WebApi/Controllers/AccountController.cs b/coffeecard/CoffeeCard.WebApi/Controllers/AccountController.cs index 6979b270..a7c5c4bd 100644 --- a/coffeecard/CoffeeCard.WebApi/Controllers/AccountController.cs +++ b/coffeecard/CoffeeCard.WebApi/Controllers/AccountController.cs @@ -1,12 +1,12 @@ using CoffeeCard.Common.Errors; using CoffeeCard.Library.Services; +using CoffeeCard.Models.DataTransferObjects; +using CoffeeCard.Models.DataTransferObjects.User; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Serilog; using System.Threading.Tasks; -using CoffeeCard.Models.DataTransferObjects; -using CoffeeCard.Models.DataTransferObjects.User; namespace CoffeeCard.WebApi.Controllers { @@ -43,7 +43,7 @@ public AccountController(IAccountService accountService, IHttpContextAccessor ht [ProducesResponseType(typeof(MessageResponseDto), StatusCodes.Status409Conflict)] public async Task> Register([FromBody] RegisterDto registerDto) { - await _accountService.RegisterAccountAsync(registerDto.Name, registerDto.Email, registerDto.Password); + _ = await _accountService.RegisterAccountAsync(registerDto.Name, registerDto.Email, registerDto.Password); return Created(nameof(Get), new MessageResponseDto() { Message = diff --git a/coffeecard/CoffeeCard.WebApi/Controllers/AppConfigController.cs b/coffeecard/CoffeeCard.WebApi/Controllers/AppConfigController.cs index a5d49c7b..ea2227ec 100644 --- a/coffeecard/CoffeeCard.WebApi/Controllers/AppConfigController.cs +++ b/coffeecard/CoffeeCard.WebApi/Controllers/AppConfigController.cs @@ -1,9 +1,7 @@ -using System; -using CoffeeCard.Library.Services; -using CoffeeCard.Models.DataTransferObjects.AppConfig; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using System; namespace CoffeeCard.WebApi.Controllers { diff --git a/coffeecard/CoffeeCard.WebApi/Controllers/CoffeeCardsController.cs b/coffeecard/CoffeeCard.WebApi/Controllers/CoffeeCardsController.cs index 39402fce..7f93963e 100644 --- a/coffeecard/CoffeeCard.WebApi/Controllers/CoffeeCardsController.cs +++ b/coffeecard/CoffeeCard.WebApi/Controllers/CoffeeCardsController.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using CoffeeCard.Library.Services; +using CoffeeCard.Library.Services; using CoffeeCard.Models.DataTransferObjects.CoffeeCard; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; diff --git a/coffeecard/CoffeeCard.WebApi/Controllers/LeaderboardController.cs b/coffeecard/CoffeeCard.WebApi/Controllers/LeaderboardController.cs index 985766d9..0e04c0e2 100644 --- a/coffeecard/CoffeeCard.WebApi/Controllers/LeaderboardController.cs +++ b/coffeecard/CoffeeCard.WebApi/Controllers/LeaderboardController.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; using CoffeeCard.Models.DataTransferObjects; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; namespace CoffeeCard.WebApi.Controllers { diff --git a/coffeecard/CoffeeCard.WebApi/Controllers/MobilePayController.cs b/coffeecard/CoffeeCard.WebApi/Controllers/MobilePayController.cs index 97a25799..cf458809 100644 --- a/coffeecard/CoffeeCard.WebApi/Controllers/MobilePayController.cs +++ b/coffeecard/CoffeeCard.WebApi/Controllers/MobilePayController.cs @@ -1,10 +1,8 @@ -using System; -using System.Threading.Tasks; -using CoffeeCard.Models.DataTransferObjects; using CoffeeCard.Models.DataTransferObjects.MobilePay; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using System; namespace CoffeeCard.WebApi.Controllers { diff --git a/coffeecard/CoffeeCard.WebApi/Controllers/PingController.cs b/coffeecard/CoffeeCard.WebApi/Controllers/PingController.cs index e1342376..881a7077 100644 --- a/coffeecard/CoffeeCard.WebApi/Controllers/PingController.cs +++ b/coffeecard/CoffeeCard.WebApi/Controllers/PingController.cs @@ -1,6 +1,6 @@ -using System; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using System; namespace CoffeeCard.WebApi.Controllers { diff --git a/coffeecard/CoffeeCard.WebApi/Controllers/ProductsController.cs b/coffeecard/CoffeeCard.WebApi/Controllers/ProductsController.cs index 866d94a2..da27c0d5 100644 --- a/coffeecard/CoffeeCard.WebApi/Controllers/ProductsController.cs +++ b/coffeecard/CoffeeCard.WebApi/Controllers/ProductsController.cs @@ -1,16 +1,14 @@ -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using CoffeeCard.Common.Errors; +using CoffeeCard.Common.Errors; using CoffeeCard.Library.Services; using CoffeeCard.Library.Utils; using CoffeeCard.Models.DataTransferObjects.Product; using CoffeeCard.Models.Entities; -using CoffeeCard.WebApi.Helpers; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; namespace CoffeeCard.WebApi.Controllers { diff --git a/coffeecard/CoffeeCard.WebApi/Controllers/ProgrammesController.cs b/coffeecard/CoffeeCard.WebApi/Controllers/ProgrammesController.cs index 9966c16e..d1efb9f5 100644 --- a/coffeecard/CoffeeCard.WebApi/Controllers/ProgrammesController.cs +++ b/coffeecard/CoffeeCard.WebApi/Controllers/ProgrammesController.cs @@ -1,10 +1,10 @@ -using System.Collections.Generic; -using System.Linq; -using CoffeeCard.Library.Services; +using CoffeeCard.Library.Services; using CoffeeCard.Models.DataTransferObjects.Programme; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.Linq; namespace CoffeeCard.WebApi.Controllers { diff --git a/coffeecard/CoffeeCard.WebApi/Controllers/PurchasesController.cs b/coffeecard/CoffeeCard.WebApi/Controllers/PurchasesController.cs index 3066f2a2..c98fc92d 100644 --- a/coffeecard/CoffeeCard.WebApi/Controllers/PurchasesController.cs +++ b/coffeecard/CoffeeCard.WebApi/Controllers/PurchasesController.cs @@ -1,12 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; using CoffeeCard.Common.Errors; using CoffeeCard.Library.Services; using CoffeeCard.Models.DataTransferObjects.Purchase; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using System; +using System.Threading.Tasks; namespace CoffeeCard.WebApi.Controllers { diff --git a/coffeecard/CoffeeCard.WebApi/Controllers/TicketsController.cs b/coffeecard/CoffeeCard.WebApi/Controllers/TicketsController.cs index 02f3d9f0..31fcc672 100644 --- a/coffeecard/CoffeeCard.WebApi/Controllers/TicketsController.cs +++ b/coffeecard/CoffeeCard.WebApi/Controllers/TicketsController.cs @@ -1,6 +1,3 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using CoffeeCard.Common.Errors; using CoffeeCard.Library.Services; using CoffeeCard.Library.Utils; @@ -9,6 +6,9 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; namespace CoffeeCard.WebApi.Controllers { diff --git a/coffeecard/CoffeeCard.WebApi/Controllers/v2/AccountController.cs b/coffeecard/CoffeeCard.WebApi/Controllers/v2/AccountController.cs index 351639bf..645501bd 100644 --- a/coffeecard/CoffeeCard.WebApi/Controllers/v2/AccountController.cs +++ b/coffeecard/CoffeeCard.WebApi/Controllers/v2/AccountController.cs @@ -1,19 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using CoffeeCard.Common.Errors; +using CoffeeCard.Library.Services.v2; using CoffeeCard.Library.Utils; using CoffeeCard.Models.DataTransferObjects; -using CoffeeCard.Models.DataTransferObjects.v2.User; using CoffeeCard.Models.DataTransferObjects.v2.Programme; +using CoffeeCard.Models.DataTransferObjects.v2.User; +using CoffeeCard.Models.Entities; +using CoffeeCard.WebApi.Helpers; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using CoffeeCard.Library.Services.v2; -using CoffeeCard.Models.Entities; -using CoffeeCard.WebApi.Helpers; +using System; using System.ComponentModel.DataAnnotations; +using System.Threading.Tasks; namespace CoffeeCard.WebApi.Controllers.v2 { @@ -53,7 +51,7 @@ public AccountController(IAccountService accountService, ClaimsUtilities claimsU [ProducesResponseType(typeof(MessageResponseDto), StatusCodes.Status409Conflict)] public async Task> Register([FromBody] RegisterAccountRequest registerRequest) { - await _accountService.RegisterAccountAsync(registerRequest.Name, registerRequest.Email, + _ = await _accountService.RegisterAccountAsync(registerRequest.Name, registerRequest.Email, registerRequest.Password, registerRequest.ProgrammeId); return Created("/api/v2/account/Get", new MessageResponseDto diff --git a/coffeecard/CoffeeCard.WebApi/Controllers/v2/HealthController.cs b/coffeecard/CoffeeCard.WebApi/Controllers/v2/HealthController.cs index 7bc326f9..60130e62 100644 --- a/coffeecard/CoffeeCard.WebApi/Controllers/v2/HealthController.cs +++ b/coffeecard/CoffeeCard.WebApi/Controllers/v2/HealthController.cs @@ -1,12 +1,12 @@ -using System; -using System.Threading.Tasks; -using CoffeeCard.Library.Persistence; +using CoffeeCard.Library.Persistence; using CoffeeCard.MobilePay.Service.v2; using CoffeeCard.Models.DataTransferObjects.v2; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Serilog; +using System; +using System.Threading.Tasks; namespace CoffeeCard.WebApi.Controllers.v2 { diff --git a/coffeecard/CoffeeCard.WebApi/Controllers/v2/LeaderboardController.cs b/coffeecard/CoffeeCard.WebApi/Controllers/v2/LeaderboardController.cs index d0844af9..3b37454a 100644 --- a/coffeecard/CoffeeCard.WebApi/Controllers/v2/LeaderboardController.cs +++ b/coffeecard/CoffeeCard.WebApi/Controllers/v2/LeaderboardController.cs @@ -1,11 +1,11 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using CoffeeCard.Library.Services.v2; +using CoffeeCard.Library.Services.v2; using CoffeeCard.Library.Utils; using CoffeeCard.Models.DataTransferObjects.v2.Leaderboard; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.Threading.Tasks; namespace CoffeeCard.WebApi.Controllers.v2 { diff --git a/coffeecard/CoffeeCard.WebApi/Controllers/v2/MenuItemsController.cs b/coffeecard/CoffeeCard.WebApi/Controllers/v2/MenuItemsController.cs index 195e68af..3090b509 100644 --- a/coffeecard/CoffeeCard.WebApi/Controllers/v2/MenuItemsController.cs +++ b/coffeecard/CoffeeCard.WebApi/Controllers/v2/MenuItemsController.cs @@ -1,12 +1,11 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using CoffeeCard.Models.DataTransferObjects.v2.Product; -using CoffeeCard.Models.DataTransferObjects.v2.Products; +using CoffeeCard.Models.DataTransferObjects.v2.MenuItems; using CoffeeCard.Models.Entities; using CoffeeCard.WebApi.Helpers; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.Threading.Tasks; using IMenuItemService = CoffeeCard.Library.Services.v2.IMenuItemService; namespace CoffeeCard.WebApi.Controllers.v2 diff --git a/coffeecard/CoffeeCard.WebApi/Controllers/v2/MobilePayController.cs b/coffeecard/CoffeeCard.WebApi/Controllers/v2/MobilePayController.cs index f3373039..08c670c2 100644 --- a/coffeecard/CoffeeCard.WebApi/Controllers/v2/MobilePayController.cs +++ b/coffeecard/CoffeeCard.WebApi/Controllers/v2/MobilePayController.cs @@ -1,16 +1,15 @@ -using System; -using System.ComponentModel.DataAnnotations; -using System.IO; -using System.Security.Cryptography; -using System.Text; -using System.Threading.Tasks; -using CoffeeCard.Common.Configuration; +using CoffeeCard.Common.Configuration; using CoffeeCard.Library.Services.v2; using CoffeeCard.Models.DataTransferObjects.v2.MobilePay; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Caching.Memory; using Serilog; +using System; +using System.ComponentModel.DataAnnotations; +using System.IO; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; namespace CoffeeCard.WebApi.Controllers.v2 { @@ -74,7 +73,7 @@ private async Task VerifySignature(string mpSignatureHeader) Request.EnableBuffering(); } - HttpContext.Request.Body.Seek(0, SeekOrigin.Begin); + _ = HttpContext.Request.Body.Seek(0, SeekOrigin.Begin); string rawRequestBody; using (var stream = new StreamReader(HttpContext.Request.Body)) diff --git a/coffeecard/CoffeeCard.WebApi/Controllers/v2/ProductsController.cs b/coffeecard/CoffeeCard.WebApi/Controllers/v2/ProductsController.cs index 99e28bd5..4a1a6289 100644 --- a/coffeecard/CoffeeCard.WebApi/Controllers/v2/ProductsController.cs +++ b/coffeecard/CoffeeCard.WebApi/Controllers/v2/ProductsController.cs @@ -1,6 +1,3 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using CoffeeCard.Common.Errors; using CoffeeCard.Library.Utils; using CoffeeCard.Models.DataTransferObjects.v2.Product; @@ -10,6 +7,9 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; using IProductService = CoffeeCard.Library.Services.v2.IProductService; namespace CoffeeCard.WebApi.Controllers.v2 @@ -97,7 +97,7 @@ public async Task>> GetProducts() [ProducesResponseType(typeof(ApiError), StatusCodes.Status404NotFound)] public async Task> GetProduct([FromRoute(Name = "id")] int productId) { - await _claimsUtilities.ValidateAndReturnUserFromClaimAsync(User.Claims); + _ = await _claimsUtilities.ValidateAndReturnUserFromClaimAsync(User.Claims); var product = await _productService.GetProductAsync(productId); return Ok(product); } diff --git a/coffeecard/CoffeeCard.WebApi/Controllers/v2/PurchasesController.cs b/coffeecard/CoffeeCard.WebApi/Controllers/v2/PurchasesController.cs index b28dab21..b30414eb 100644 --- a/coffeecard/CoffeeCard.WebApi/Controllers/v2/PurchasesController.cs +++ b/coffeecard/CoffeeCard.WebApi/Controllers/v2/PurchasesController.cs @@ -1,13 +1,12 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using CoffeeCard.Library.Services.v2; +using CoffeeCard.Library.Services.v2; using CoffeeCard.Library.Utils; using CoffeeCard.Models.DataTransferObjects; using CoffeeCard.Models.DataTransferObjects.v2.Purchase; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.Threading.Tasks; namespace CoffeeCard.WebApi.Controllers.v2 { diff --git a/coffeecard/CoffeeCard.WebApi/Controllers/v2/TicketsController.cs b/coffeecard/CoffeeCard.WebApi/Controllers/v2/TicketsController.cs index 4ad040b7..1e2fde68 100644 --- a/coffeecard/CoffeeCard.WebApi/Controllers/v2/TicketsController.cs +++ b/coffeecard/CoffeeCard.WebApi/Controllers/v2/TicketsController.cs @@ -1,12 +1,11 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using CoffeeCard.Common.Errors; +using CoffeeCard.Common.Errors; using CoffeeCard.Library.Utils; -using CoffeeCard.Models.DataTransferObjects; using CoffeeCard.Models.DataTransferObjects.v2.Ticket; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.Threading.Tasks; using ITicketService = CoffeeCard.Library.Services.v2.ITicketService; namespace CoffeeCard.WebApi.Controllers.v2 diff --git a/coffeecard/CoffeeCard.WebApi/Controllers/v2/VouchersController.cs b/coffeecard/CoffeeCard.WebApi/Controllers/v2/VouchersController.cs index 8d28b043..a064dcc8 100644 --- a/coffeecard/CoffeeCard.WebApi/Controllers/v2/VouchersController.cs +++ b/coffeecard/CoffeeCard.WebApi/Controllers/v2/VouchersController.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Threading.Tasks; using CoffeeCard.Common.Errors; using CoffeeCard.Library.Services.v2; using CoffeeCard.Library.Utils; @@ -13,6 +9,8 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.Threading.Tasks; namespace CoffeeCard.WebApi.Controllers.v2 { diff --git a/coffeecard/CoffeeCard.WebApi/Controllers/v2/WebhooksController.cs b/coffeecard/CoffeeCard.WebApi/Controllers/v2/WebhooksController.cs index 94750f62..c510cadd 100644 --- a/coffeecard/CoffeeCard.WebApi/Controllers/v2/WebhooksController.cs +++ b/coffeecard/CoffeeCard.WebApi/Controllers/v2/WebhooksController.cs @@ -1,10 +1,10 @@ using CoffeeCard.Library.Services.v2; using CoffeeCard.Models.DataTransferObjects.v2.User; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; namespace CoffeeCard.WebApi.Controllers.v2 { diff --git a/coffeecard/CoffeeCard.WebApi/Helpers/ApiExceptionFilter.cs b/coffeecard/CoffeeCard.WebApi/Helpers/ApiExceptionFilter.cs index d631e3d9..37386cb1 100644 --- a/coffeecard/CoffeeCard.WebApi/Helpers/ApiExceptionFilter.cs +++ b/coffeecard/CoffeeCard.WebApi/Helpers/ApiExceptionFilter.cs @@ -1,9 +1,9 @@ -using System; -using CoffeeCard.Common.Errors; +using CoffeeCard.Common.Errors; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using Serilog; +using System; namespace CoffeeCard.WebApi.Helpers { diff --git a/coffeecard/CoffeeCard.WebApi/Helpers/AuthorizeRoles.cs b/coffeecard/CoffeeCard.WebApi/Helpers/AuthorizeRoles.cs index 978c5c7b..f115277e 100644 --- a/coffeecard/CoffeeCard.WebApi/Helpers/AuthorizeRoles.cs +++ b/coffeecard/CoffeeCard.WebApi/Helpers/AuthorizeRoles.cs @@ -1,7 +1,7 @@ -using System; using CoffeeCard.Models.Entities; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; +using System; namespace CoffeeCard.WebApi.Helpers { diff --git a/coffeecard/CoffeeCard.WebApi/Helpers/ConfigurationServiceCollectionExtension.cs b/coffeecard/CoffeeCard.WebApi/Helpers/ConfigurationServiceCollectionExtension.cs index 12d6269f..b558a2ce 100644 --- a/coffeecard/CoffeeCard.WebApi/Helpers/ConfigurationServiceCollectionExtension.cs +++ b/coffeecard/CoffeeCard.WebApi/Helpers/ConfigurationServiceCollectionExtension.cs @@ -16,15 +16,15 @@ public static class ConfigurationServiceCollectionExtension /// Reference to configuration file public static void AddConfigurationSettings(this IServiceCollection services, IConfiguration configuration) { - services.UseConfigurationValidation(); + _ = services.UseConfigurationValidation(); // Parse and setup settings from configuration - services.ConfigureValidatableSetting(configuration.GetSection("DatabaseSettings")); - services.ConfigureValidatableSetting(configuration.GetSection("EnvironmentSettings")); - services.ConfigureValidatableSetting(configuration.GetSection("LoginLimiterSettings")); - services.ConfigureValidatableSetting(configuration.GetSection("IdentitySettings")); - services.ConfigureValidatableSetting(configuration.GetSection("MailgunSettings")); - services.ConfigureValidatableSetting(configuration.GetSection("MobilePaySettingsV2")); + _ = services.ConfigureValidatableSetting(configuration.GetSection("DatabaseSettings")); + _ = services.ConfigureValidatableSetting(configuration.GetSection("EnvironmentSettings")); + _ = services.ConfigureValidatableSetting(configuration.GetSection("LoginLimiterSettings")); + _ = services.ConfigureValidatableSetting(configuration.GetSection("IdentitySettings")); + _ = services.ConfigureValidatableSetting(configuration.GetSection("MailgunSettings")); + _ = services.ConfigureValidatableSetting(configuration.GetSection("MobilePaySettingsV2")); } } } \ No newline at end of file diff --git a/coffeecard/CoffeeCard.WebApi/Helpers/PageUtils.cs b/coffeecard/CoffeeCard.WebApi/Helpers/PageUtils.cs index f9d60fd6..e7a1fdf2 100644 --- a/coffeecard/CoffeeCard.WebApi/Helpers/PageUtils.cs +++ b/coffeecard/CoffeeCard.WebApi/Helpers/PageUtils.cs @@ -1,10 +1,10 @@ -using System; -using System.Threading.Tasks; using CoffeeCard.Common.Errors; -using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Serilog; +using System; +using System.Threading.Tasks; namespace CoffeeCard.WebApi.Helpers diff --git a/coffeecard/CoffeeCard.WebApi/Helpers/ReadableBodyFilter.cs b/coffeecard/CoffeeCard.WebApi/Helpers/ReadableBodyFilter.cs index 8f09c7c9..2d490159 100644 --- a/coffeecard/CoffeeCard.WebApi/Helpers/ReadableBodyFilter.cs +++ b/coffeecard/CoffeeCard.WebApi/Helpers/ReadableBodyFilter.cs @@ -1,4 +1,3 @@ -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Filters; // For ASP.NET 3.1 diff --git a/coffeecard/CoffeeCard.WebApi/Helpers/Swagger/RemoveApiVersionProcessor.cs b/coffeecard/CoffeeCard.WebApi/Helpers/Swagger/RemoveApiVersionProcessor.cs index 8d94eca0..d3420217 100644 --- a/coffeecard/CoffeeCard.WebApi/Helpers/Swagger/RemoveApiVersionProcessor.cs +++ b/coffeecard/CoffeeCard.WebApi/Helpers/Swagger/RemoveApiVersionProcessor.cs @@ -1,6 +1,6 @@ -using System.Linq; -using NSwag.Generation.Processors; +using NSwag.Generation.Processors; using NSwag.Generation.Processors.Contexts; +using System.Linq; namespace CoffeeCard.WebApi.Helpers.Swagger { @@ -24,7 +24,7 @@ public bool Process(OperationProcessorContext context) { foreach (var parameter in versionParameter) { - context.OperationDescription.Operation.Parameters.Remove(parameter); + _ = context.OperationDescription.Operation.Parameters.Remove(parameter); } return true; diff --git a/coffeecard/CoffeeCard.WebApi/Logging/Enricher.cs b/coffeecard/CoffeeCard.WebApi/Logging/Enricher.cs index 67338b68..a8d62810 100644 --- a/coffeecard/CoffeeCard.WebApi/Logging/Enricher.cs +++ b/coffeecard/CoffeeCard.WebApi/Logging/Enricher.cs @@ -1,8 +1,8 @@ -using System; -using System.Linq; using Microsoft.AspNetCore.Http; using Serilog.Core; using Serilog.Events; +using System; +using System.Linq; using Constants = CoffeeCard.Common.Constants; namespace CoffeeCard.WebApi.Logging diff --git a/coffeecard/CoffeeCard.WebApi/Logging/LoggerConfigurationExtensions.cs b/coffeecard/CoffeeCard.WebApi/Logging/LoggerConfigurationExtensions.cs index 0c2e235d..8df0e5f7 100644 --- a/coffeecard/CoffeeCard.WebApi/Logging/LoggerConfigurationExtensions.cs +++ b/coffeecard/CoffeeCard.WebApi/Logging/LoggerConfigurationExtensions.cs @@ -1,6 +1,6 @@ -using System; using Serilog; using Serilog.Configuration; +using System; namespace CoffeeCard.WebApi.Logging { diff --git a/coffeecard/CoffeeCard.WebApi/Pages/Recover.cshtml.cs b/coffeecard/CoffeeCard.WebApi/Pages/Recover.cshtml.cs index fbc50812..3da1b9fb 100644 --- a/coffeecard/CoffeeCard.WebApi/Pages/Recover.cshtml.cs +++ b/coffeecard/CoffeeCard.WebApi/Pages/Recover.cshtml.cs @@ -1,11 +1,10 @@ -using System; -using System.Threading.Tasks; using CoffeeCard.Library.Services; using CoffeeCard.Models.PagesModels; using CoffeeCard.WebApi.Helpers; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using Serilog; +using System; +using System.Threading.Tasks; namespace CoffeeCard.WebApi.Pages { diff --git a/coffeecard/CoffeeCard.WebApi/Pages/VerifyDelete.cshtml.cs b/coffeecard/CoffeeCard.WebApi/Pages/VerifyDelete.cshtml.cs index 3742a40a..6d28d3ec 100644 --- a/coffeecard/CoffeeCard.WebApi/Pages/VerifyDelete.cshtml.cs +++ b/coffeecard/CoffeeCard.WebApi/Pages/VerifyDelete.cshtml.cs @@ -1,9 +1,9 @@ -using System; -using System.Threading.Tasks; using CoffeeCard.Library.Services.v2; using CoffeeCard.WebApi.Helpers; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using System; +using System.Threading.Tasks; namespace CoffeeCard.WebApi.Pages { diff --git a/coffeecard/CoffeeCard.WebApi/Pages/VerifyEmail.cshtml.cs b/coffeecard/CoffeeCard.WebApi/Pages/VerifyEmail.cshtml.cs index 61f27cb2..f0b653f2 100644 --- a/coffeecard/CoffeeCard.WebApi/Pages/VerifyEmail.cshtml.cs +++ b/coffeecard/CoffeeCard.WebApi/Pages/VerifyEmail.cshtml.cs @@ -1,9 +1,9 @@ -using System; -using System.Threading.Tasks; using CoffeeCard.Library.Services; using CoffeeCard.WebApi.Helpers; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using System; +using System.Threading.Tasks; namespace CoffeeCard.WebApi.Pages { diff --git a/coffeecard/CoffeeCard.WebApi/Program.cs b/coffeecard/CoffeeCard.WebApi/Program.cs index 50837ed2..6db309a4 100644 --- a/coffeecard/CoffeeCard.WebApi/Program.cs +++ b/coffeecard/CoffeeCard.WebApi/Program.cs @@ -1,16 +1,18 @@ -using System; -using System.IO; -using System.Threading.Tasks; -using CoffeeCard.Common.Configuration; +using CoffeeCard.Common.Configuration; using CoffeeCard.Library.Persistence; using CoffeeCard.Library.Services.v2; +using CoffeeCard.Library.Utils; using CoffeeCard.WebApi.Logging; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.FeatureManagement; using Serilog; +using System; +using System.IO; +using System.Threading.Tasks; namespace CoffeeCard.WebApi { @@ -55,12 +57,12 @@ private static IHostBuilder CreateHostBuilder(string[] args) return Host.CreateDefaultBuilder(args) .ConfigureAppConfiguration(((context, builder) => { - builder.AddJsonFile("appsettings.json", false, true); - builder.AddEnvironmentVariables(); + _ = builder.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true); + _ = builder.AddEnvironmentVariables(); })) .ConfigureWebHostDefaults(webBuilder => { - webBuilder.UseStartup(); + _ = webBuilder.UseStartup(); }) .UseSerilog(); } @@ -69,6 +71,7 @@ private static async Task PreStartupTasks(IHost webhost) { using var serviceScope = webhost.Services.CreateScope(); var environment = serviceScope.ServiceProvider.GetRequiredService(); + var featureManager = serviceScope.ServiceProvider.GetRequiredService(); Log.Information("Apply Database Migrations if any"); await using var context = serviceScope.ServiceProvider.GetRequiredService(); @@ -77,7 +80,10 @@ private static async Task PreStartupTasks(IHost webhost) context.Database.Migrate(); } - if (environment.EnvironmentType != EnvironmentType.LocalDevelopment) + var isMobilePayWebhookRegistrationManagementEnabled = await featureManager.IsEnabledAsync(FeatureFlags.MobilePayManageWebhookRegistration); + Log.Information("FeatureFlag {flag} has enablement state '{value}'", nameof(FeatureFlags.MobilePayManageWebhookRegistration), isMobilePayWebhookRegistrationManagementEnabled); + + if (environment.EnvironmentType != EnvironmentType.LocalDevelopment && isMobilePayWebhookRegistrationManagementEnabled) { var webhookService = serviceScope.ServiceProvider.GetRequiredService(); await webhookService.EnsureWebhookIsRegistered(); diff --git a/coffeecard/CoffeeCard.WebApi/Startup.cs b/coffeecard/CoffeeCard.WebApi/Startup.cs index 6a960e6a..b7d7ec35 100644 --- a/coffeecard/CoffeeCard.WebApi/Startup.cs +++ b/coffeecard/CoffeeCard.WebApi/Startup.cs @@ -1,8 +1,3 @@ -using System; -using System.Text; -using System.Text.Json; -using System.Text.Json.Serialization; -using System.Threading.Tasks; using AspNetCore.Authentication.ApiKey; using CoffeeCard.Common.Configuration; using CoffeeCard.Library.Persistence; @@ -23,13 +18,16 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.FeatureManagement; using Microsoft.IdentityModel.Tokens; -using Microsoft.Net.Http.Headers; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; using NJsonSchema.Generation; using NSwag; using NSwag.Generation.Processors.Security; +using System; +using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.Threading.Tasks; using AccountService = CoffeeCard.Library.Services.AccountService; using IAccountService = CoffeeCard.Library.Services.IAccountService; using IPurchaseService = CoffeeCard.Library.Services.IPurchaseService; @@ -58,49 +56,50 @@ public void ConfigureServices(IServiceCollection services) // Setup database connection var databaseSettings = _configuration.GetSection(nameof(DatabaseSettings)).Get(); - services.AddDbContext(opt => + _ = services.AddDbContext(opt => opt.UseSqlServer(databaseSettings.ConnectionString, c => c.MigrationsHistoryTable("__EFMigrationsHistory", databaseSettings.SchemaName))); // Setup cache - services.AddMemoryCache(); + _ = services.AddMemoryCache(); // Setup Dependency Injection - services.AddSingleton(_environment); - services.AddSingleton(); - services.AddScoped(); - services.AddTransient(); - services.AddSingleton(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddSingleton(_environment.ContentRootFileProvider); + _ = services.AddSingleton(_environment); + _ = services.AddSingleton(); + _ = services.AddScoped(); + _ = services.AddTransient(); + _ = services.AddSingleton(); + _ = services.AddScoped(); + _ = services.AddScoped(); + _ = services.AddScoped(); + _ = services.AddScoped(); + _ = services.AddScoped(); + _ = services.AddScoped(); + _ = services.AddScoped(); + _ = services.AddScoped(); + _ = services.AddScoped(); + _ = services.AddScoped(); + _ = services.AddScoped(); + _ = services.AddScoped(); + _ = services.AddSingleton(_environment.ContentRootFileProvider); - services.AddScoped(); - services.AddScoped(); + _ = services.AddScoped(); + _ = services.AddScoped(); services.AddMobilePayHttpClients(_configuration.GetSection("MobilePaySettingsV2").Get()); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); + _ = services.AddScoped(); + _ = services.AddScoped(); + _ = services.AddScoped(); + _ = services.AddScoped(); + _ = services.AddScoped(); + _ = services.AddScoped(); + _ = services.AddFeatureManagement(); // Azure Application Insights - services.AddApplicationInsightsTelemetry(); - services.AddSingleton(); + _ = services.AddApplicationInsightsTelemetry(); + _ = services.AddSingleton(); // Setup filter to catch outgoing exceptions - services.AddControllers(options => + _ = services.AddControllers(options => { options.Filters.Add(new ApiExceptionFilter()); options.Filters.Add(new ReadableBodyFilter()); @@ -112,21 +111,21 @@ public void ConfigureServices(IServiceCollection services) options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); }); - services.AddCors(options => options.AddDefaultPolicy(builder => + _ = services.AddCors(options => options.AddDefaultPolicy(builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader())); - services.AddApiVersioning(config => + _ = services.AddApiVersioning(config => { config.DefaultApiVersion = new ApiVersion(1, 0); config.AssumeDefaultVersionWhenUnspecified = true; config.ReportApiVersions = true; }); - services.AddVersionedApiExplorer(setup => + _ = services.AddVersionedApiExplorer(setup => { setup.GroupNameFormat = "'v'VVV"; setup.SubstituteApiVersionInUrl = true; }); - services.Configure(config => + _ = services.Configure(config => { config.SuppressMapClientErrors = true; }); @@ -134,12 +133,12 @@ public void ConfigureServices(IServiceCollection services) GenerateOpenApiDocument(services); // Setup razor pages - services.AddRazorPages(); - services.AddServerSideBlazor(); + _ = services.AddRazorPages(); + _ = services.AddServerSideBlazor(); // Setup Authentication var identitySettings = _configuration.GetSection("IdentitySettings").Get(); - services.AddAuthentication(options => + _ = services.AddAuthentication(options => { options.DefaultAuthenticateScheme = "jwt"; options.DefaultChallengeScheme = "jwt"; @@ -198,7 +197,7 @@ private static void GenerateOpenApiDocument(IServiceCollection services) foreach (var apiVersion in apiVersions.ApiVersionDescriptions) { // Add an OpenApi document per API version - services.AddOpenApiDocument(config => + _ = services.AddOpenApiDocument(config => { config.DefaultResponseReferenceTypeNullHandling = ReferenceTypeNullHandling.NotNull; config.Title = apiVersion.GroupName; @@ -255,36 +254,36 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApiVers // Important note! // The order of the below app configuration is sensitive and should be changed with care // UsePathBase must be first as several subsequent configuration depends on it - app.UsePathBase("/coffeecard"); + _ = app.UsePathBase("/coffeecard"); if (env.IsDevelopment()) - app.UseDeveloperExceptionPage(); + _ = app.UseDeveloperExceptionPage(); else - app.UseHsts(); + _ = app.UseHsts(); - app.UseOpenApi(); - app.UseSwaggerUi(); + _ = app.UseOpenApi(); + _ = app.UseSwaggerUi(); - app.UseHttpsRedirection(); + _ = app.UseHttpsRedirection(); - app.UseStaticFiles(); + _ = app.UseStaticFiles(); - app.UseRouting(); + _ = app.UseRouting(); - app.UseCors(); + _ = app.UseCors(); - app.UseAuthentication(); - app.UseAuthorization(); + _ = app.UseAuthentication(); + _ = app.UseAuthorization(); - app.UseEndpoints(endpoints => + _ = app.UseEndpoints(endpoints => { - endpoints.MapControllers(); - endpoints.MapRazorPages(); - endpoints.MapFallbackToPage("/result"); + _ = endpoints.MapControllers(); + _ = endpoints.MapRazorPages(); + _ = endpoints.MapFallbackToPage("/result"); }); // Enable Request Buffering so that a raw request body can be read after aspnet model binding - app.Use(next => context => + _ = app.Use(next => context => { context.Request.EnableBuffering(); return next(context); diff --git a/coffeecard/CoffeeCard.WebApi/appsettings.json b/coffeecard/CoffeeCard.WebApi/appsettings.json index 4e95fcb8..3dbe154b 100644 --- a/coffeecard/CoffeeCard.WebApi/appsettings.json +++ b/coffeecard/CoffeeCard.WebApi/appsettings.json @@ -60,5 +60,8 @@ } } ] + }, + "FeatureManagement": { + "MobilePayManageWebhookRegistration": false } } \ No newline at end of file