Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

imp/removed-unused-imports-and-small-refactoring #1031

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion src/ApplicationCore/Entities/BasketAggregate/Basket.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/ApplicationCore/Entities/BuyerAggregate/Buyer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Buyer : BaseEntity, IAggregateRoot

public IEnumerable<PaymentMethod> 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()
Expand Down
2 changes: 1 addition & 1 deletion src/ApplicationCore/Entities/OrderAggregate/Address.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
4 changes: 2 additions & 2 deletions src/ApplicationCore/Entities/OrderAggregate/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<OrderItem> items)
{
Expand Down
4 changes: 2 additions & 2 deletions src/ApplicationCore/Entities/OrderAggregate/OrderItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
19 changes: 6 additions & 13 deletions src/ApplicationCore/Exceptions/EmptyBasketOnCheckoutException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
}
1 change: 0 additions & 1 deletion src/BlazorAdmin/Services/CatalogLookupDataService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Reflection;
Expand Down
4 changes: 2 additions & 2 deletions src/Infrastructure/Data/CatalogContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace Microsoft.eShopWeb.Infrastructure.Data;

public class CatalogContext : DbContext
{
#pragma warning disable CS8618 // Required by Entity Framework
public CatalogContext(DbContextOptions<CatalogContext> options) : base(options) {}
#pragma warning disable CS8618 // Required by Entity Framework
public CatalogContext(DbContextOptions<CatalogContext> options) : base(options) { }

public DbSet<Basket> Baskets { get; set; }
public DbSet<CatalogItem> CatalogItems { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Data/CatalogContextSeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ await catalogContext.CatalogItems.AddRangeAsync(
if (retryForAvailability >= 10) throw;

retryForAvailability++;

logger.LogError(ex.Message);
await SeedAsync(catalogContext, logger, retryForAvailability);
throw;
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Dependencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void ConfigureServices(IConfiguration configuration, IServiceColle
{
services.AddDbContext<CatalogContext>(c =>
c.UseInMemoryDatabase("Catalog"));

services.AddDbContext<AppIdentityDbContext>(options =>
options.UseInMemoryDatabase("Identity"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints;
/// Updates a Catalog Item
/// </summary>
public class UpdateCatalogItemEndpoint : IEndpoint<IResult, UpdateCatalogItemRequest, IRepository<CatalogItem>>
{
{
private readonly IUriComposer _uriComposer;

public UpdateCatalogItemEndpoint(IUriComposer uriComposer)
Expand Down
2 changes: 1 addition & 1 deletion src/PublicApi/Middleware/ExceptionMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task InvokeAsync(HttpContext httpContext)
}
catch (Exception ex)
{
await HandleExceptionAsync(httpContext, ex);
await HandleExceptionAsync(httpContext, ex);
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/Web/Areas/Identity/IdentityHostingStartup.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 1 addition & 5 deletions src/Web/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Web/Areas/Identity/Pages/Account/Login.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public async Task<IActionResult> 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)
Expand Down
6 changes: 1 addition & 5 deletions src/Web/Areas/Identity/Pages/Account/Register.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
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;
using Microsoft.AspNetCore.Identity.UI.Services;
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;

Expand Down
17 changes: 6 additions & 11 deletions src/Web/Configuration/ConfigureCookieSettings.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -14,10 +9,10 @@ public static IServiceCollection AddCookieSettings(this IServiceCollection servi
{
services.Configure<CookiePolicyOptions>(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 =>
{
Expand All @@ -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<RevokeAuthenticationEvents>();
Expand Down
5 changes: 2 additions & 3 deletions src/Web/Configuration/ConfigureWebServices.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<IBasketViewModelService, BasketViewModelService>();
services.AddScoped<CatalogViewModelService>();
Expand Down
5 changes: 1 addition & 4 deletions src/Web/Configuration/RevokeAuthenticationEvents.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/Web/Controllers/OrderController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public OrderController(IMediator mediator)

[HttpGet]
public async Task<IActionResult> MyOrders()
{
{
Guard.Against.Null(User?.Identity?.Name, nameof(User.Identity.Name));
var viewModel = await _mediator.Send(new GetMyOrders(User.Identity.Name));

Expand Down
4 changes: 1 addition & 3 deletions src/Web/Extensions/CacheHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;

namespace Microsoft.eShopWeb.Web.Extensions;
namespace Microsoft.eShopWeb.Web.Extensions;

public static class CacheHelpers
{
Expand Down
1 change: 0 additions & 1 deletion src/Web/Extensions/EmailSenderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using Microsoft.eShopWeb.ApplicationCore.Interfaces;

namespace Microsoft.eShopWeb.Web.Services;
Expand Down
5 changes: 1 addition & 4 deletions src/Web/HealthChecks/ApiHealthCheck.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
6 changes: 1 addition & 5 deletions src/Web/HealthChecks/HomePageHealthCheck.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
3 changes: 1 addition & 2 deletions src/Web/Interfaces/ICatalogItemViewModelService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using Microsoft.eShopWeb.Web.ViewModels;
using Microsoft.eShopWeb.Web.ViewModels;

namespace Microsoft.eShopWeb.Web.Interfaces;

Expand Down
4 changes: 1 addition & 3 deletions src/Web/Interfaces/ICatalogViewModelService.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/Web/Pages/Admin/EditCatalogItem.cshtml.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
8 changes: 1 addition & 7 deletions src/Web/Pages/Admin/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/Web/Pages/Basket/BasketItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
7 changes: 1 addition & 6 deletions src/Web/Pages/Basket/Success.cshtml.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/Web/Pages/Shared/Components/BasketComponent/Basket.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
Loading