diff --git a/.editorconfig b/.editorconfig index 459d75213..9c86cc4c3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,7 +5,7 @@ root = true # All files [*] indent_style = space - +end_of_line = crlf # XML project files [*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}] indent_size = 2 @@ -147,4 +147,4 @@ visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public ###################################### [{**/*Dto.cs,**/*Request.cs,**/*Response.cs}] # CS8618: Non-nullable field is uninitialized. Consider declaring as nullable. -dotnet_diagnostic.CS8618.severity = none +dotnet_diagnostic.CS8618.severity = none \ No newline at end of file diff --git a/src/ApplicationCore/Entities/BasketAggregate/Basket.cs b/src/ApplicationCore/Entities/BasketAggregate/Basket.cs index c49bae48a..7b6d00f84 100644 --- a/src/ApplicationCore/Entities/BasketAggregate/Basket.cs +++ b/src/ApplicationCore/Entities/BasketAggregate/Basket.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using Ardalis.GuardClauses; using Microsoft.eShopWeb.ApplicationCore.Interfaces; namespace Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; diff --git a/src/ApplicationCore/Entities/BuyerAggregate/Buyer.cs b/src/ApplicationCore/Entities/BuyerAggregate/Buyer.cs index 8a553f1d5..624806032 100644 --- a/src/ApplicationCore/Entities/BuyerAggregate/Buyer.cs +++ b/src/ApplicationCore/Entities/BuyerAggregate/Buyer.cs @@ -12,7 +12,7 @@ public class Buyer : BaseEntity, IAggregateRoot public IEnumerable PaymentMethods => _paymentMethods.AsReadOnly(); - #pragma warning disable CS8618 // Required by Entity Framework +#pragma warning disable CS8618 // Required by Entity Framework private Buyer() { } public Buyer(string identity) : this() diff --git a/src/ApplicationCore/Entities/OrderAggregate/Address.cs b/src/ApplicationCore/Entities/OrderAggregate/Address.cs index 8b651cd2a..a1bfaa588 100644 --- a/src/ApplicationCore/Entities/OrderAggregate/Address.cs +++ b/src/ApplicationCore/Entities/OrderAggregate/Address.cs @@ -12,7 +12,7 @@ public class Address // ValueObject public string ZipCode { get; private set; } - #pragma warning disable CS8618 // Required by Entity Framework +#pragma warning disable CS8618 // Required by Entity Framework private Address() { } public Address(string street, string city, string state, string country, string zipcode) diff --git a/src/ApplicationCore/Entities/OrderAggregate/CatalogItemOrdered.cs b/src/ApplicationCore/Entities/OrderAggregate/CatalogItemOrdered.cs index 59d1adb14..666d9295e 100644 --- a/src/ApplicationCore/Entities/OrderAggregate/CatalogItemOrdered.cs +++ b/src/ApplicationCore/Entities/OrderAggregate/CatalogItemOrdered.cs @@ -19,8 +19,8 @@ public CatalogItemOrdered(int catalogItemId, string productName, string pictureU PictureUri = pictureUri; } - #pragma warning disable CS8618 // Required by Entity Framework - private CatalogItemOrdered() {} +#pragma warning disable CS8618 // Required by Entity Framework + private CatalogItemOrdered() { } public int CatalogItemId { get; private set; } public string ProductName { get; private set; } diff --git a/src/ApplicationCore/Entities/OrderAggregate/Order.cs b/src/ApplicationCore/Entities/OrderAggregate/Order.cs index ca9a86e1f..1e9d80c98 100644 --- a/src/ApplicationCore/Entities/OrderAggregate/Order.cs +++ b/src/ApplicationCore/Entities/OrderAggregate/Order.cs @@ -7,8 +7,8 @@ namespace Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; public class Order : BaseEntity, IAggregateRoot { - #pragma warning disable CS8618 // Required by Entity Framework - private Order() {} +#pragma warning disable CS8618 // Required by Entity Framework + private Order() { } public Order(string buyerId, Address shipToAddress, List items) { diff --git a/src/ApplicationCore/Entities/OrderAggregate/OrderItem.cs b/src/ApplicationCore/Entities/OrderAggregate/OrderItem.cs index 43054d184..cd66a538c 100644 --- a/src/ApplicationCore/Entities/OrderAggregate/OrderItem.cs +++ b/src/ApplicationCore/Entities/OrderAggregate/OrderItem.cs @@ -6,8 +6,8 @@ public class OrderItem : BaseEntity public decimal UnitPrice { get; private set; } public int Units { get; private set; } - #pragma warning disable CS8618 // Required by Entity Framework - private OrderItem() {} +#pragma warning disable CS8618 // Required by Entity Framework + private OrderItem() { } public OrderItem(CatalogItemOrdered itemOrdered, decimal unitPrice, int units) { diff --git a/src/ApplicationCore/Exceptions/EmptyBasketOnCheckoutException.cs b/src/ApplicationCore/Exceptions/EmptyBasketOnCheckoutException.cs index 45e9ecccb..562945606 100644 --- a/src/ApplicationCore/Exceptions/EmptyBasketOnCheckoutException.cs +++ b/src/ApplicationCore/Exceptions/EmptyBasketOnCheckoutException.cs @@ -2,22 +2,15 @@ namespace Microsoft.eShopWeb.ApplicationCore.Exceptions; + public class EmptyBasketOnCheckoutException : Exception { public EmptyBasketOnCheckoutException() - : base($"Basket cannot have 0 items on checkout") - { - } - - protected EmptyBasketOnCheckoutException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) - { - } + : base("Basket cannot have 0 items on checkout") { } - public EmptyBasketOnCheckoutException(string message) : base(message) - { - } + public EmptyBasketOnCheckoutException(string message) + : base(message) { } - public EmptyBasketOnCheckoutException(string message, Exception innerException) : base(message, innerException) - { - } + public EmptyBasketOnCheckoutException(string message, Exception innerException) + : base(message, innerException) { } } diff --git a/src/BlazorAdmin/Services/CatalogLookupDataService.cs b/src/BlazorAdmin/Services/CatalogLookupDataService.cs index fa06b1608..a23fb3197 100644 --- a/src/BlazorAdmin/Services/CatalogLookupDataService.cs +++ b/src/BlazorAdmin/Services/CatalogLookupDataService.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using System.Net.Http; using System.Net.Http.Json; using System.Reflection; diff --git a/src/Infrastructure/Data/CatalogContext.cs b/src/Infrastructure/Data/CatalogContext.cs index fc2e4b6a2..5b2625342 100644 --- a/src/Infrastructure/Data/CatalogContext.cs +++ b/src/Infrastructure/Data/CatalogContext.cs @@ -8,8 +8,8 @@ namespace Microsoft.eShopWeb.Infrastructure.Data; public class CatalogContext : DbContext { - #pragma warning disable CS8618 // Required by Entity Framework - public CatalogContext(DbContextOptions options) : base(options) {} +#pragma warning disable CS8618 // Required by Entity Framework + public CatalogContext(DbContextOptions options) : base(options) { } public DbSet Baskets { get; set; } public DbSet CatalogItems { get; set; } diff --git a/src/Infrastructure/Data/CatalogContextSeed.cs b/src/Infrastructure/Data/CatalogContextSeed.cs index e1364f52e..0b0bb59d4 100644 --- a/src/Infrastructure/Data/CatalogContextSeed.cs +++ b/src/Infrastructure/Data/CatalogContextSeed.cs @@ -50,7 +50,7 @@ await catalogContext.CatalogItems.AddRangeAsync( if (retryForAvailability >= 10) throw; retryForAvailability++; - + logger.LogError(ex.Message); await SeedAsync(catalogContext, logger, retryForAvailability); throw; diff --git a/src/Infrastructure/Dependencies.cs b/src/Infrastructure/Dependencies.cs index 96456763e..29fd1e13a 100644 --- a/src/Infrastructure/Dependencies.cs +++ b/src/Infrastructure/Dependencies.cs @@ -20,7 +20,7 @@ public static void ConfigureServices(IConfiguration configuration, IServiceColle { services.AddDbContext(c => c.UseInMemoryDatabase("Catalog")); - + services.AddDbContext(options => options.UseInMemoryDatabase("Identity")); } diff --git a/src/PublicApi/CatalogItemEndpoints/UpdateCatalogItemEndpoint.cs b/src/PublicApi/CatalogItemEndpoints/UpdateCatalogItemEndpoint.cs index 15efa684f..69b10dd5c 100644 --- a/src/PublicApi/CatalogItemEndpoints/UpdateCatalogItemEndpoint.cs +++ b/src/PublicApi/CatalogItemEndpoints/UpdateCatalogItemEndpoint.cs @@ -14,7 +14,7 @@ namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints; /// Updates a Catalog Item /// public class UpdateCatalogItemEndpoint : IEndpoint> -{ +{ private readonly IUriComposer _uriComposer; public UpdateCatalogItemEndpoint(IUriComposer uriComposer) diff --git a/src/PublicApi/Middleware/ExceptionMiddleware.cs b/src/PublicApi/Middleware/ExceptionMiddleware.cs index 5773c2ee6..3ee5e79a7 100644 --- a/src/PublicApi/Middleware/ExceptionMiddleware.cs +++ b/src/PublicApi/Middleware/ExceptionMiddleware.cs @@ -24,7 +24,7 @@ public async Task InvokeAsync(HttpContext httpContext) } catch (Exception ex) { - await HandleExceptionAsync(httpContext, ex); + await HandleExceptionAsync(httpContext, ex); } } diff --git a/src/Web/Areas/Identity/IdentityHostingStartup.cs b/src/Web/Areas/Identity/IdentityHostingStartup.cs index cf6c773fd..0b3858dc8 100644 --- a/src/Web/Areas/Identity/IdentityHostingStartup.cs +++ b/src/Web/Areas/Identity/IdentityHostingStartup.cs @@ -1,6 +1,4 @@ -using Microsoft.AspNetCore.Hosting; - -[assembly: HostingStartup(typeof(Microsoft.eShopWeb.Web.Areas.Identity.IdentityHostingStartup))] +[assembly: HostingStartup(typeof(Microsoft.eShopWeb.Web.Areas.Identity.IdentityHostingStartup))] namespace Microsoft.eShopWeb.Web.Areas.Identity; public class IdentityHostingStartup : IHostingStartup diff --git a/src/Web/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs b/src/Web/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs index f85a02b3d..b5420bc56 100644 --- a/src/Web/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs +++ b/src/Web/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; diff --git a/src/Web/Areas/Identity/Pages/Account/Login.cshtml.cs b/src/Web/Areas/Identity/Pages/Account/Login.cshtml.cs index fe22ef767..eeb44c845 100644 --- a/src/Web/Areas/Identity/Pages/Account/Login.cshtml.cs +++ b/src/Web/Areas/Identity/Pages/Account/Login.cshtml.cs @@ -74,7 +74,7 @@ public async Task OnPostAsync(string? returnUrl = null) // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, set lockoutOnFailure: true //var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: true); - var result = await _signInManager.PasswordSignInAsync(Input!.Email!, Input!.Password!, + var result = await _signInManager.PasswordSignInAsync(Input!.Email!, Input!.Password!, false, true); if (result.Succeeded) diff --git a/src/Web/Areas/Identity/Pages/Account/Register.cshtml.cs b/src/Web/Areas/Identity/Pages/Account/Register.cshtml.cs index f0165fa1f..e72b7db4a 100644 --- a/src/Web/Areas/Identity/Pages/Account/Register.cshtml.cs +++ b/src/Web/Areas/Identity/Pages/Account/Register.cshtml.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using System.Text.Encodings.Web; -using System.Threading.Tasks; using Ardalis.GuardClauses; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; @@ -10,7 +7,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.eShopWeb.Infrastructure.Identity; -using Microsoft.Extensions.Logging; namespace Microsoft.eShopWeb.Web.Areas.Identity.Pages.Account; diff --git a/src/Web/Configuration/ConfigureCookieSettings.cs b/src/Web/Configuration/ConfigureCookieSettings.cs index 9462b4b18..28dd95b7c 100644 --- a/src/Web/Configuration/ConfigureCookieSettings.cs +++ b/src/Web/Configuration/ConfigureCookieSettings.cs @@ -1,9 +1,4 @@ -using System; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection; - -namespace Microsoft.eShopWeb.Web.Configuration; +namespace Microsoft.eShopWeb.Web.Configuration; public static class ConfigureCookieSettings { @@ -14,10 +9,10 @@ public static IServiceCollection AddCookieSettings(this IServiceCollection servi { services.Configure(options => { - // This lambda determines whether user consent for non-essential cookies is needed for a given request. - //TODO need to check that. - //options.CheckConsentNeeded = context => true; - options.MinimumSameSitePolicy = SameSiteMode.Strict; + // This lambda determines whether user consent for non-essential cookies is needed for a given request. + //TODO need to check that. + //options.CheckConsentNeeded = context => true; + options.MinimumSameSitePolicy = SameSiteMode.Strict; }); services.ConfigureApplicationCookie(options => { @@ -30,7 +25,7 @@ public static IServiceCollection AddCookieSettings(this IServiceCollection servi { Name = IdentifierCookieName, IsEssential = true // required for auth to work without explicit user consent; adjust to suit your privacy policy - }; + }; }); services.AddScoped(); diff --git a/src/Web/Configuration/ConfigureWebServices.cs b/src/Web/Configuration/ConfigureWebServices.cs index e282276e9..0e9ff2047 100644 --- a/src/Web/Configuration/ConfigureWebServices.cs +++ b/src/Web/Configuration/ConfigureWebServices.cs @@ -1,5 +1,4 @@ -using MediatR; -using Microsoft.eShopWeb.Web.Interfaces; +using Microsoft.eShopWeb.Web.Interfaces; using Microsoft.eShopWeb.Web.Services; namespace Microsoft.eShopWeb.Web.Configuration; @@ -8,7 +7,7 @@ public static class ConfigureWebServices { public static IServiceCollection AddWebServices(this IServiceCollection services, IConfiguration configuration) { - services.AddMediatR(cfg => + services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(BasketViewModelService).Assembly)); services.AddScoped(); services.AddScoped(); diff --git a/src/Web/Configuration/RevokeAuthenticationEvents.cs b/src/Web/Configuration/RevokeAuthenticationEvents.cs index 09ba74ab2..449b07255 100644 --- a/src/Web/Configuration/RevokeAuthenticationEvents.cs +++ b/src/Web/Configuration/RevokeAuthenticationEvents.cs @@ -1,10 +1,7 @@ -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; +using System.Security.Claims; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.Extensions.Caching.Memory; -using Microsoft.Extensions.Logging; namespace Microsoft.eShopWeb.Web.Configuration; diff --git a/src/Web/Controllers/OrderController.cs b/src/Web/Controllers/OrderController.cs index 5a2e1e1c4..5ebd4f5f9 100644 --- a/src/Web/Controllers/OrderController.cs +++ b/src/Web/Controllers/OrderController.cs @@ -21,7 +21,7 @@ public OrderController(IMediator mediator) [HttpGet] public async Task MyOrders() - { + { Guard.Against.Null(User?.Identity?.Name, nameof(User.Identity.Name)); var viewModel = await _mediator.Send(new GetMyOrders(User.Identity.Name)); diff --git a/src/Web/Extensions/CacheHelpers.cs b/src/Web/Extensions/CacheHelpers.cs index 9f0ed90f9..08a794365 100644 --- a/src/Web/Extensions/CacheHelpers.cs +++ b/src/Web/Extensions/CacheHelpers.cs @@ -1,6 +1,4 @@ -using System; - -namespace Microsoft.eShopWeb.Web.Extensions; +namespace Microsoft.eShopWeb.Web.Extensions; public static class CacheHelpers { diff --git a/src/Web/Extensions/EmailSenderExtensions.cs b/src/Web/Extensions/EmailSenderExtensions.cs index 0fb67e491..95b5b9bbf 100644 --- a/src/Web/Extensions/EmailSenderExtensions.cs +++ b/src/Web/Extensions/EmailSenderExtensions.cs @@ -1,5 +1,4 @@ using System.Text.Encodings.Web; -using System.Threading.Tasks; using Microsoft.eShopWeb.ApplicationCore.Interfaces; namespace Microsoft.eShopWeb.Web.Services; diff --git a/src/Web/HealthChecks/ApiHealthCheck.cs b/src/Web/HealthChecks/ApiHealthCheck.cs index 49f6634e5..007bd2c23 100644 --- a/src/Web/HealthChecks/ApiHealthCheck.cs +++ b/src/Web/HealthChecks/ApiHealthCheck.cs @@ -1,7 +1,4 @@ -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; -using BlazorShared; +using BlazorShared; using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Options; diff --git a/src/Web/HealthChecks/HomePageHealthCheck.cs b/src/Web/HealthChecks/HomePageHealthCheck.cs index 0896954db..087a6857f 100644 --- a/src/Web/HealthChecks/HomePageHealthCheck.cs +++ b/src/Web/HealthChecks/HomePageHealthCheck.cs @@ -1,8 +1,4 @@ -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Diagnostics.HealthChecks; +using Microsoft.Extensions.Diagnostics.HealthChecks; namespace Microsoft.eShopWeb.Web.HealthChecks; diff --git a/src/Web/Interfaces/ICatalogItemViewModelService.cs b/src/Web/Interfaces/ICatalogItemViewModelService.cs index ede5902e8..ba6d9d58d 100644 --- a/src/Web/Interfaces/ICatalogItemViewModelService.cs +++ b/src/Web/Interfaces/ICatalogItemViewModelService.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using Microsoft.eShopWeb.Web.ViewModels; +using Microsoft.eShopWeb.Web.ViewModels; namespace Microsoft.eShopWeb.Web.Interfaces; diff --git a/src/Web/Interfaces/ICatalogViewModelService.cs b/src/Web/Interfaces/ICatalogViewModelService.cs index 338f83dfc..8aab96c9b 100644 --- a/src/Web/Interfaces/ICatalogViewModelService.cs +++ b/src/Web/Interfaces/ICatalogViewModelService.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.eShopWeb.Web.ViewModels; namespace Microsoft.eShopWeb.Web.Services; diff --git a/src/Web/Pages/Admin/EditCatalogItem.cshtml.cs b/src/Web/Pages/Admin/EditCatalogItem.cshtml.cs index 7cd25693b..b9bf4e36c 100644 --- a/src/Web/Pages/Admin/EditCatalogItem.cshtml.cs +++ b/src/Web/Pages/Admin/EditCatalogItem.cshtml.cs @@ -1,8 +1,6 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.eShopWeb.ApplicationCore.Constants; using Microsoft.eShopWeb.Web.Interfaces; using Microsoft.eShopWeb.Web.ViewModels; diff --git a/src/Web/Pages/Admin/Index.cshtml.cs b/src/Web/Pages/Admin/Index.cshtml.cs index 8dfe0b9fb..38f4aaabe 100644 --- a/src/Web/Pages/Admin/Index.cshtml.cs +++ b/src/Web/Pages/Admin/Index.cshtml.cs @@ -1,11 +1,5 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.eShopWeb.ApplicationCore.Constants; -using Microsoft.eShopWeb.Web.Extensions; -using Microsoft.eShopWeb.Web.Services; -using Microsoft.eShopWeb.Web.ViewModels; -using Microsoft.Extensions.Caching.Memory; namespace Microsoft.eShopWeb.Web.Pages.Admin; diff --git a/src/Web/Pages/Basket/BasketItemViewModel.cs b/src/Web/Pages/Basket/BasketItemViewModel.cs index 8c3a142f2..c102dfb9b 100644 --- a/src/Web/Pages/Basket/BasketItemViewModel.cs +++ b/src/Web/Pages/Basket/BasketItemViewModel.cs @@ -12,6 +12,6 @@ public class BasketItemViewModel [Range(0, int.MaxValue, ErrorMessage = "Quantity must be bigger than 0")] public int Quantity { get; set; } - + public string? PictureUrl { get; set; } } diff --git a/src/Web/Pages/Basket/Success.cshtml.cs b/src/Web/Pages/Basket/Success.cshtml.cs index e105aa38e..fb5c7ed36 100644 --- a/src/Web/Pages/Basket/Success.cshtml.cs +++ b/src/Web/Pages/Basket/Success.cshtml.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc.RazorPages; namespace Microsoft.eShopWeb.Web.Pages.Basket; diff --git a/src/Web/Pages/Shared/Components/BasketComponent/Basket.cs b/src/Web/Pages/Shared/Components/BasketComponent/Basket.cs index 986c7b8a5..4a9c184be 100644 --- a/src/Web/Pages/Shared/Components/BasketComponent/Basket.cs +++ b/src/Web/Pages/Shared/Components/BasketComponent/Basket.cs @@ -1,6 +1,4 @@ -using System; -using System.Threading.Tasks; -using Ardalis.GuardClauses; +using Ardalis.GuardClauses; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.eShopWeb.Infrastructure.Identity; diff --git a/src/Web/Program.cs b/src/Web/Program.cs index 9761361dd..6e9da39bc 100644 --- a/src/Web/Program.cs +++ b/src/Web/Program.cs @@ -22,11 +22,13 @@ var builder = WebApplication.CreateBuilder(args); builder.Logging.AddConsole(); -if (builder.Environment.IsDevelopment() || builder.Environment.EnvironmentName == "Docker"){ +if (builder.Environment.IsDevelopment() || builder.Environment.EnvironmentName == "Docker") +{ // Configure SQL Server (local) Microsoft.eShopWeb.Infrastructure.Dependencies.ConfigureServices(builder.Configuration, builder.Services); } -else{ +else +{ // Configure SQL Server (prod) var credential = new ChainedTokenCredential(new AzureDeveloperCliCredential(), new DefaultAzureCredential()); builder.Configuration.AddAzureKeyVault(new Uri(builder.Configuration["AZURE_KEY_VAULT_ENDPOINT"] ?? ""), credential); @@ -195,7 +197,6 @@ app.MapRazorPages(); app.MapHealthChecks("home_page_health_check", new HealthCheckOptions { Predicate = check => check.Tags.Contains("homePageHealthCheck") }); app.MapHealthChecks("api_health_check", new HealthCheckOptions { Predicate = check => check.Tags.Contains("apiHealthCheck") }); -//endpoints.MapBlazorHub("/admin"); app.MapFallbackToFile("index.html"); app.Logger.LogInformation("LAUNCHING"); diff --git a/src/Web/Services/CachedCatalogViewModelService.cs b/src/Web/Services/CachedCatalogViewModelService.cs index e7a506b45..eb8ad874b 100644 --- a/src/Web/Services/CachedCatalogViewModelService.cs +++ b/src/Web/Services/CachedCatalogViewModelService.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.eShopWeb.Web.Extensions; using Microsoft.eShopWeb.Web.ViewModels; using Microsoft.Extensions.Caching.Memory; diff --git a/src/Web/Services/CatalogViewModelService.cs b/src/Web/Services/CatalogViewModelService.cs index 4b1b21660..84f38c784 100644 --- a/src/Web/Services/CatalogViewModelService.cs +++ b/src/Web/Services/CatalogViewModelService.cs @@ -1,13 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.eShopWeb.ApplicationCore.Entities; using Microsoft.eShopWeb.ApplicationCore.Interfaces; using Microsoft.eShopWeb.ApplicationCore.Specifications; using Microsoft.eShopWeb.Web.ViewModels; -using Microsoft.Extensions.Logging; namespace Microsoft.eShopWeb.Web.Services; diff --git a/src/Web/SlugifyParameterTransformer.cs b/src/Web/SlugifyParameterTransformer.cs index d2d1c568e..c219c0994 100644 --- a/src/Web/SlugifyParameterTransformer.cs +++ b/src/Web/SlugifyParameterTransformer.cs @@ -1,5 +1,4 @@ using System.Text.RegularExpressions; -using Microsoft.AspNetCore.Routing; namespace Microsoft.eShopWeb.Web; diff --git a/src/Web/ViewModels/Manage/EnableAuthenticatorViewModel.cs b/src/Web/ViewModels/Manage/EnableAuthenticatorViewModel.cs index 840858c16..04377e82f 100644 --- a/src/Web/ViewModels/Manage/EnableAuthenticatorViewModel.cs +++ b/src/Web/ViewModels/Manage/EnableAuthenticatorViewModel.cs @@ -1,5 +1,4 @@ -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using Microsoft.AspNetCore.Mvc.ModelBinding; namespace Microsoft.eShopWeb.Web.ViewModels.Manage; diff --git a/src/Web/ViewModels/Manage/ExternalLoginsViewModel.cs b/src/Web/ViewModels/Manage/ExternalLoginsViewModel.cs index 9f861355e..d5c866158 100644 --- a/src/Web/ViewModels/Manage/ExternalLoginsViewModel.cs +++ b/src/Web/ViewModels/Manage/ExternalLoginsViewModel.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Identity; namespace Microsoft.eShopWeb.Web.ViewModels.Manage; diff --git a/src/Web/Views/Manage/ManageNavPages.cs b/src/Web/Views/Manage/ManageNavPages.cs index 244a707e2..afed51e2b 100644 --- a/src/Web/Views/Manage/ManageNavPages.cs +++ b/src/Web/Views/Manage/ManageNavPages.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewFeatures; namespace Microsoft.eShopWeb.Web.Views.Manage; diff --git a/tests/FunctionalTests/PublicApi/ApiTokenHelper.cs b/tests/FunctionalTests/PublicApi/ApiTokenHelper.cs index 567f34b13..b118dccf9 100644 --- a/tests/FunctionalTests/PublicApi/ApiTokenHelper.cs +++ b/tests/FunctionalTests/PublicApi/ApiTokenHelper.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IdentityModel.Tokens.Jwt; +using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using System.Text; using Microsoft.eShopWeb.ApplicationCore.Constants; @@ -10,6 +8,10 @@ namespace Microsoft.eShopWeb.FunctionalTests.Web.Api; public class ApiTokenHelper { + protected ApiTokenHelper() + { + + } public static string GetAdminUserToken() { string userName = "admin@microsoft.com"; diff --git a/tests/FunctionalTests/Web/Controllers/CatalogControllerIndex.cs b/tests/FunctionalTests/Web/Controllers/CatalogControllerIndex.cs index 82c804b5c..6509f1f90 100644 --- a/tests/FunctionalTests/Web/Controllers/CatalogControllerIndex.cs +++ b/tests/FunctionalTests/Web/Controllers/CatalogControllerIndex.cs @@ -1,6 +1,4 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Xunit; +using Xunit; namespace Microsoft.eShopWeb.FunctionalTests.Web.Controllers; diff --git a/tests/FunctionalTests/Web/Controllers/OrderControllerIndex.cs b/tests/FunctionalTests/Web/Controllers/OrderControllerIndex.cs index 88b37bf1c..e8435c240 100644 --- a/tests/FunctionalTests/Web/Controllers/OrderControllerIndex.cs +++ b/tests/FunctionalTests/Web/Controllers/OrderControllerIndex.cs @@ -1,6 +1,4 @@ using System.Net; -using System.Net.Http; -using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Testing; using Xunit; diff --git a/tests/FunctionalTests/Web/Pages/Basket/CheckoutTest.cs b/tests/FunctionalTests/Web/Pages/Basket/CheckoutTest.cs index 8d6c0be11..e1400fd21 100644 --- a/tests/FunctionalTests/Web/Pages/Basket/CheckoutTest.cs +++ b/tests/FunctionalTests/Web/Pages/Basket/CheckoutTest.cs @@ -58,7 +58,7 @@ public async Task SucessfullyPay() new KeyValuePair("Items[0].Quantity", "1"), new KeyValuePair(WebPageHelpers.TokenTag, WebPageHelpers.GetRequestVerificationToken(loginStringResponse)) }; - var checkOutContent = new FormUrlEncodedContent(checkOutKeyValues); + var checkOutContent = new FormUrlEncodedContent(checkOutKeyValues); var checkOutResponse = await Client.PostAsync("/basket/checkout", checkOutContent); var stringCheckOutResponse = await checkOutResponse.Content.ReadAsStringAsync(); diff --git a/tests/FunctionalTests/Web/WebTestFixture.cs b/tests/FunctionalTests/Web/WebTestFixture.cs index d9bb49140..daf06734c 100644 --- a/tests/FunctionalTests/Web/WebTestFixture.cs +++ b/tests/FunctionalTests/Web/WebTestFixture.cs @@ -1,6 +1,4 @@ -using System; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.EntityFrameworkCore; using Microsoft.eShopWeb.Infrastructure.Data; @@ -8,7 +6,6 @@ using Microsoft.eShopWeb.Web.Interfaces; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; namespace Microsoft.eShopWeb.FunctionalTests.Web; diff --git a/tests/IntegrationTests/Repositories/BasketRepositoryTests/SetQuantities.cs b/tests/IntegrationTests/Repositories/BasketRepositoryTests/SetQuantities.cs index 95ba0e3e0..1d8de89fd 100644 --- a/tests/IntegrationTests/Repositories/BasketRepositoryTests/SetQuantities.cs +++ b/tests/IntegrationTests/Repositories/BasketRepositoryTests/SetQuantities.cs @@ -2,7 +2,6 @@ using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; -using Microsoft.eShopWeb.ApplicationCore.Interfaces; using Microsoft.eShopWeb.ApplicationCore.Services; using Microsoft.eShopWeb.Infrastructure.Data; using Microsoft.eShopWeb.UnitTests.Builders; @@ -35,6 +34,6 @@ public async Task RemoveEmptyQuantities() await basketService.SetQuantities(BasketBuilder.BasketId, new Dictionary() { { BasketBuilder.BasketId.ToString(), 0 } }); - Assert.Equal(0, basket.Items.Count); + Assert.Empty(basket.Items); } } diff --git a/tests/PublicApiIntegrationTests/ApiTokenHelper.cs b/tests/PublicApiIntegrationTests/ApiTokenHelper.cs index 75fd1b1a8..1f1f8f525 100644 --- a/tests/PublicApiIntegrationTests/ApiTokenHelper.cs +++ b/tests/PublicApiIntegrationTests/ApiTokenHelper.cs @@ -1,10 +1,10 @@ -using Microsoft.eShopWeb.ApplicationCore.Constants; -using Microsoft.IdentityModel.Tokens; -using System; +using System; using System.Collections.Generic; using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using System.Text; +using Microsoft.eShopWeb.ApplicationCore.Constants; +using Microsoft.IdentityModel.Tokens; namespace PublicApiIntegrationTests { diff --git a/tests/PublicApiIntegrationTests/CatalogItemEndpoints/CatalogItemGetByIdEndpointTest.cs b/tests/PublicApiIntegrationTests/CatalogItemEndpoints/CatalogItemGetByIdEndpointTest.cs index 9baefdec7..3d7e7c038 100644 --- a/tests/PublicApiIntegrationTests/CatalogItemEndpoints/CatalogItemGetByIdEndpointTest.cs +++ b/tests/PublicApiIntegrationTests/CatalogItemEndpoints/CatalogItemGetByIdEndpointTest.cs @@ -1,8 +1,8 @@ -using Microsoft.eShopWeb; +using System.Net; +using System.Threading.Tasks; +using Microsoft.eShopWeb; using Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Net; -using System.Threading.Tasks; namespace PublicApiIntegrationTests.CatalogItemEndpoints; diff --git a/tests/PublicApiIntegrationTests/CatalogItemEndpoints/CatalogItemListPagedEndpoint.cs b/tests/PublicApiIntegrationTests/CatalogItemEndpoints/CatalogItemListPagedEndpoint.cs index 547011154..9dc12a92d 100644 --- a/tests/PublicApiIntegrationTests/CatalogItemEndpoints/CatalogItemListPagedEndpoint.cs +++ b/tests/PublicApiIntegrationTests/CatalogItemEndpoints/CatalogItemListPagedEndpoint.cs @@ -1,12 +1,12 @@ -using Microsoft.eShopWeb; -using Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints; -using Microsoft.eShopWeb.Web.ViewModels; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using System.Net.Http; using System.Net; +using System.Net.Http; using System.Threading.Tasks; +using Microsoft.eShopWeb; +using Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints; +using Microsoft.eShopWeb.Web.ViewModels; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace PublicApiIntegrationTests.CatalogItemEndpoints; diff --git a/tests/PublicApiIntegrationTests/CatalogItemEndpoints/CreateCatalogItemEndpointTest.cs b/tests/PublicApiIntegrationTests/CatalogItemEndpoints/CreateCatalogItemEndpointTest.cs index 6c5d79e45..e036e024b 100644 --- a/tests/PublicApiIntegrationTests/CatalogItemEndpoints/CreateCatalogItemEndpointTest.cs +++ b/tests/PublicApiIntegrationTests/CatalogItemEndpoints/CreateCatalogItemEndpointTest.cs @@ -1,12 +1,12 @@ -using BlazorShared.Models; -using Microsoft.eShopWeb; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Net; +using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using System.Text.Json; using System.Threading.Tasks; +using BlazorShared.Models; +using Microsoft.eShopWeb; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace PublicApiIntegrationTests.AuthEndpoints; diff --git a/tests/PublicApiIntegrationTests/CatalogItemEndpoints/DeleteCatalogItemEndpointTest.cs b/tests/PublicApiIntegrationTests/CatalogItemEndpoints/DeleteCatalogItemEndpointTest.cs index 98c821238..b373bf077 100644 --- a/tests/PublicApiIntegrationTests/CatalogItemEndpoints/DeleteCatalogItemEndpointTest.cs +++ b/tests/PublicApiIntegrationTests/CatalogItemEndpoints/DeleteCatalogItemEndpointTest.cs @@ -1,9 +1,9 @@ -using BlazorShared.Models; -using Microsoft.eShopWeb; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Net; +using System.Net; using System.Net.Http.Headers; using System.Threading.Tasks; +using BlazorShared.Models; +using Microsoft.eShopWeb; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace PublicApiIntegrationTests.CatalogItemEndpoints; diff --git a/tests/PublicApiIntegrationTests/ProgramTest.cs b/tests/PublicApiIntegrationTests/ProgramTest.cs index 3f13136f4..cc10ddb2d 100644 --- a/tests/PublicApiIntegrationTests/ProgramTest.cs +++ b/tests/PublicApiIntegrationTests/ProgramTest.cs @@ -1,6 +1,6 @@ -using Microsoft.AspNetCore.Mvc.Testing; +using System.Net.Http; +using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Net.Http; namespace PublicApiIntegrationTests; diff --git a/tests/UnitTests/ApplicationCore/Entities/BasketTests/BasketAddItem.cs b/tests/UnitTests/ApplicationCore/Entities/BasketTests/BasketAddItem.cs index 6f3ad2ded..3e8399216 100644 --- a/tests/UnitTests/ApplicationCore/Entities/BasketTests/BasketAddItem.cs +++ b/tests/UnitTests/ApplicationCore/Entities/BasketTests/BasketAddItem.cs @@ -1,6 +1,4 @@ -using System; -using System.Linq; -using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; +using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; using Xunit; namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Entities.BasketTests; diff --git a/tests/UnitTests/ApplicationCore/Entities/BasketTests/BasketRemoveEmptyItems.cs b/tests/UnitTests/ApplicationCore/Entities/BasketTests/BasketRemoveEmptyItems.cs index 58aebb42f..585f72b26 100644 --- a/tests/UnitTests/ApplicationCore/Entities/BasketTests/BasketRemoveEmptyItems.cs +++ b/tests/UnitTests/ApplicationCore/Entities/BasketTests/BasketRemoveEmptyItems.cs @@ -16,6 +16,6 @@ public void RemovesEmptyBasketItems() basket.AddItem(_testCatalogItemId, _testUnitPrice, 0); basket.RemoveEmptyItems(); - Assert.Equal(0, basket.Items.Count); + Assert.Empty(basket.Items); } } diff --git a/tests/UnitTests/ApplicationCore/Entities/BasketTests/BasketTotalItems.cs b/tests/UnitTests/ApplicationCore/Entities/BasketTests/BasketTotalItems.cs index cedffaeaa..c7e218123 100644 --- a/tests/UnitTests/ApplicationCore/Entities/BasketTests/BasketTotalItems.cs +++ b/tests/UnitTests/ApplicationCore/Entities/BasketTests/BasketTotalItems.cs @@ -26,10 +26,10 @@ public void ReturnsTotalQuantityWithMultipleItems() { var basket = new Basket(_buyerId); basket.AddItem(_testCatalogItemId, _testUnitPrice, _testQuantity); - basket.AddItem(_testCatalogItemId, _testUnitPrice, _testQuantity*2); + basket.AddItem(_testCatalogItemId, _testUnitPrice, _testQuantity * 2); var result = basket.TotalItems; - Assert.Equal(_testQuantity*3, result); + Assert.Equal(_testQuantity * 3, result); } } diff --git a/tests/UnitTests/ApplicationCore/Entities/OrderTests/OrderTotal.cs b/tests/UnitTests/ApplicationCore/Entities/OrderTests/OrderTotal.cs index d6b3357c8..af655d12b 100644 --- a/tests/UnitTests/ApplicationCore/Entities/OrderTests/OrderTotal.cs +++ b/tests/UnitTests/ApplicationCore/Entities/OrderTests/OrderTotal.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; +using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; using Microsoft.eShopWeb.UnitTests.Builders; using Xunit; diff --git a/tests/UnitTests/ApplicationCore/Extensions/TestChild.cs b/tests/UnitTests/ApplicationCore/Extensions/TestChild.cs index 2b19d6667..807d5f9eb 100644 --- a/tests/UnitTests/ApplicationCore/Extensions/TestChild.cs +++ b/tests/UnitTests/ApplicationCore/Extensions/TestChild.cs @@ -1,5 +1,4 @@ -using System; -using System.Diagnostics; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Extensions; diff --git a/tests/UnitTests/ApplicationCore/Extensions/TestParent.cs b/tests/UnitTests/ApplicationCore/Extensions/TestParent.cs index ec791b410..4ce23999d 100644 --- a/tests/UnitTests/ApplicationCore/Extensions/TestParent.cs +++ b/tests/UnitTests/ApplicationCore/Extensions/TestParent.cs @@ -10,7 +10,7 @@ public class TestParent : IEquatable public IEnumerable? Children { get; set; } - public bool Equals([AllowNull] TestParent other) + public bool Equals([AllowNull] TestParent other) { if (other?.Id == Id && other?.Name == Name) { diff --git a/tests/UnitTests/ApplicationCore/Services/BasketServiceTests/AddItemToBasket.cs b/tests/UnitTests/ApplicationCore/Services/BasketServiceTests/AddItemToBasket.cs index 75e1744ef..2f05fae76 100644 --- a/tests/UnitTests/ApplicationCore/Services/BasketServiceTests/AddItemToBasket.cs +++ b/tests/UnitTests/ApplicationCore/Services/BasketServiceTests/AddItemToBasket.cs @@ -1,6 +1,4 @@ -using System.Threading.Tasks; -using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; -using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; +using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; using Microsoft.eShopWeb.ApplicationCore.Interfaces; using Microsoft.eShopWeb.ApplicationCore.Services; using Microsoft.eShopWeb.ApplicationCore.Specifications; diff --git a/tests/UnitTests/ApplicationCore/Services/BasketServiceTests/DeleteBasket.cs b/tests/UnitTests/ApplicationCore/Services/BasketServiceTests/DeleteBasket.cs index 0856d3d2a..4fb1a3cf4 100644 --- a/tests/UnitTests/ApplicationCore/Services/BasketServiceTests/DeleteBasket.cs +++ b/tests/UnitTests/ApplicationCore/Services/BasketServiceTests/DeleteBasket.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; +using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; using Microsoft.eShopWeb.ApplicationCore.Interfaces; using Microsoft.eShopWeb.ApplicationCore.Services; //using Moq; diff --git a/tests/UnitTests/ApplicationCore/Services/BasketServiceTests/TransferBasket.cs b/tests/UnitTests/ApplicationCore/Services/BasketServiceTests/TransferBasket.cs index a21afb319..bc0866e9d 100644 --- a/tests/UnitTests/ApplicationCore/Services/BasketServiceTests/TransferBasket.cs +++ b/tests/UnitTests/ApplicationCore/Services/BasketServiceTests/TransferBasket.cs @@ -1,6 +1,4 @@ -using System; -using System.Threading.Tasks; -using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; +using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; using Microsoft.eShopWeb.ApplicationCore.Interfaces; using Microsoft.eShopWeb.ApplicationCore.Services; using Microsoft.eShopWeb.ApplicationCore.Specifications; @@ -31,17 +29,17 @@ public Results Then(Func value) public T Next() { return values.Dequeue()(); } } - [Fact] + [Fact] public async Task InvokesBasketRepositoryFirstOrDefaultAsyncOnceIfAnonymousBasketNotExists() { - var anonymousBasket = null as Basket; - var userBasket = new Basket(_existentUserBasketBuyerId); - + var anonymousBasket = null as Basket; + var userBasket = new Basket(_existentUserBasketBuyerId); + var results = new Results(anonymousBasket) .Then(userBasket); - _mockBasketRepo.FirstOrDefaultAsync(Arg.Any(), default).Returns(x => results.Next()); + _mockBasketRepo.FirstOrDefaultAsync(Arg.Any(), default).Returns(x => results.Next()); var basketService = new BasketService(_mockBasketRepo, _mockLogger); await basketService.TransferBasketAsync(_nonexistentAnonymousBasketBuyerId, _existentUserBasketBuyerId); await _mockBasketRepo.Received().FirstOrDefaultAsync(Arg.Any(), default); diff --git a/tests/UnitTests/ApplicationCore/Specifications/BasketWithItemsSpecification.cs b/tests/UnitTests/ApplicationCore/Specifications/BasketWithItemsSpecification.cs index 009bc84ea..b0d0d0463 100644 --- a/tests/UnitTests/ApplicationCore/Specifications/BasketWithItemsSpecification.cs +++ b/tests/UnitTests/ApplicationCore/Specifications/BasketWithItemsSpecification.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Linq; -using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; +using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; using Microsoft.eShopWeb.ApplicationCore.Specifications; using NSubstitute; using Xunit; diff --git a/tests/UnitTests/ApplicationCore/Specifications/CatalogFilterSpecification.cs b/tests/UnitTests/ApplicationCore/Specifications/CatalogFilterSpecification.cs index cb065df30..8b6805dc9 100644 --- a/tests/UnitTests/ApplicationCore/Specifications/CatalogFilterSpecification.cs +++ b/tests/UnitTests/ApplicationCore/Specifications/CatalogFilterSpecification.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Linq; -using Microsoft.eShopWeb.ApplicationCore.Entities; +using Microsoft.eShopWeb.ApplicationCore.Entities; using Xunit; namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Specifications; @@ -21,7 +19,7 @@ public void MatchesExpectedNumberOfItems(int? brandId, int? typeId, int expected var result = spec.Evaluate(GetTestItemCollection()).ToList(); - Assert.Equal(expectedCount, result.Count()); + Assert.Equal(expectedCount, result.Count); } public List GetTestItemCollection() diff --git a/tests/UnitTests/ApplicationCore/Specifications/CatalogItemsSpecification.cs b/tests/UnitTests/ApplicationCore/Specifications/CatalogItemsSpecification.cs index f9fc04941..3d1351a5e 100644 --- a/tests/UnitTests/ApplicationCore/Specifications/CatalogItemsSpecification.cs +++ b/tests/UnitTests/ApplicationCore/Specifications/CatalogItemsSpecification.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Linq; -using Microsoft.eShopWeb.ApplicationCore.Entities; +using Microsoft.eShopWeb.ApplicationCore.Entities; using NSubstitute; using Xunit; diff --git a/tests/UnitTests/ApplicationCore/Specifications/CustomerOrdersWithItemsSpecification.cs b/tests/UnitTests/ApplicationCore/Specifications/CustomerOrdersWithItemsSpecification.cs index 0a066d075..94b05c094 100644 --- a/tests/UnitTests/ApplicationCore/Specifications/CustomerOrdersWithItemsSpecification.cs +++ b/tests/UnitTests/ApplicationCore/Specifications/CustomerOrdersWithItemsSpecification.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Linq; -using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; +using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; using Xunit; namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Specifications; @@ -8,7 +6,7 @@ namespace Microsoft.eShopWeb.UnitTests.ApplicationCore.Specifications; public class CustomerOrdersWithItemsSpecification { private readonly string _buyerId = "TestBuyerId"; - private Address _shipToAddress = new Address("Street", "City", "OH", "US", "11111"); + private readonly Address _shipToAddress = new Address("Street", "City", "OH", "US", "11111"); [Fact] public void ReturnsOrderWithOrderedItem() @@ -19,7 +17,7 @@ public void ReturnsOrderWithOrderedItem() Assert.NotNull(result); Assert.NotNull(result.OrderItems); - Assert.Equal(1, result.OrderItems.Count); + Assert.Single(result.OrderItems); Assert.NotNull(result.OrderItems.FirstOrDefault()?.ItemOrdered); } @@ -32,7 +30,7 @@ public void ReturnsAllOrderWithAllOrderedItem() Assert.NotNull(result); Assert.Equal(2, result.Count); - Assert.Equal(1, result[0].OrderItems.Count); + Assert.Single(result[0].OrderItems); Assert.NotNull(result[0].OrderItems.FirstOrDefault()?.ItemOrdered); Assert.Equal(2, result[1].OrderItems.Count); Assert.NotNull(result[1].OrderItems.ToList()[0].ItemOrdered); diff --git a/tests/UnitTests/Builders/OrderBuilder.cs b/tests/UnitTests/Builders/OrderBuilder.cs index bb9ee61d9..4387c0316 100644 --- a/tests/UnitTests/Builders/OrderBuilder.cs +++ b/tests/UnitTests/Builders/OrderBuilder.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; +using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; namespace Microsoft.eShopWeb.UnitTests.Builders; diff --git a/tests/UnitTests/MediatorHandlers/OrdersTests/GetMyOrders.cs b/tests/UnitTests/MediatorHandlers/OrdersTests/GetMyOrders.cs index ccb4129cf..6cff8e9e2 100644 --- a/tests/UnitTests/MediatorHandlers/OrdersTests/GetMyOrders.cs +++ b/tests/UnitTests/MediatorHandlers/OrdersTests/GetMyOrders.cs @@ -1,7 +1,4 @@ -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using Ardalis.Specification; +using Ardalis.Specification; using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; using Microsoft.eShopWeb.ApplicationCore.Interfaces; using Microsoft.eShopWeb.Web.Features.MyOrders; @@ -19,7 +16,7 @@ public GetMyOrders() var item = new OrderItem(new CatalogItemOrdered(1, "ProductName", "URI"), 10.00m, 10); var address = new Address("", "", "", "", ""); Order order = new Order("buyerId", address, new List { item }); - + _mockOrderRepository.ListAsync(Arg.Any>(), default).Returns(new List { order }); } diff --git a/tests/UnitTests/MediatorHandlers/OrdersTests/GetOrderDetails.cs b/tests/UnitTests/MediatorHandlers/OrdersTests/GetOrderDetails.cs index 625de042b..31da3ea5d 100644 --- a/tests/UnitTests/MediatorHandlers/OrdersTests/GetOrderDetails.cs +++ b/tests/UnitTests/MediatorHandlers/OrdersTests/GetOrderDetails.cs @@ -1,8 +1,4 @@ -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using Ardalis.Specification; -using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; +using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; using Microsoft.eShopWeb.ApplicationCore.Interfaces; using Microsoft.eShopWeb.ApplicationCore.Specifications; using Microsoft.eShopWeb.Web.Features.OrderDetails; @@ -13,14 +9,14 @@ namespace Microsoft.eShopWeb.UnitTests.MediatorHandlers.OrdersTests; public class GetOrderDetails { - private readonly IReadRepository _mockOrderRepository = Substitute.For>(); - + private readonly IReadRepository _mockOrderRepository = Substitute.For>(); + public GetOrderDetails() { var item = new OrderItem(new CatalogItemOrdered(1, "ProductName", "URI"), 10.00m, 10); var address = new Address("", "", "", "", ""); Order order = new Order("buyerId", address, new List { item }); - + _mockOrderRepository.FirstOrDefaultAsync(Arg.Any(), default) .Returns(order); }