Refactor to introduce nullable types and reduce compiler warnings (#801)

* Introduce nullable types to Core, Infrastructure and PublicApi projects

* Refactor unit tests

* Fixed failing tests

* Introduce Parameter object for CatalogItem update method

* Refactor CataloItemDetails param object

* Refactor following PR comments
This commit is contained in:
Philippe Vaillancourt
2022-10-04 16:57:40 +01:00
committed by GitHub
parent aa6305eab1
commit a72dd775ee
51 changed files with 168 additions and 256 deletions

View File

@@ -1,5 +1,6 @@
using System.Text;
using System.Text.Encodings.Web;
using Ardalis.GuardClauses;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
@@ -119,6 +120,7 @@ public class ManageController : Controller
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
Guard.Against.Null(callbackUrl, nameof(callbackUrl));
var email = user.Email;
await _emailSender.SendEmailConfirmationAsync(email, callbackUrl);
@@ -405,7 +407,7 @@ public class ManageController : Controller
}
// Strip spaces and hypens
var verificationCode = model.Code.Replace(" ", string.Empty).Replace("-", string.Empty);
var verificationCode = model.Code?.Replace(" ", string.Empty).Replace("-", string.Empty);
var is2faTokenValid = await _userManager.VerifyTwoFactorTokenAsync(
user, _userManager.Options.Tokens.AuthenticatorTokenProvider, verificationCode);

View File

@@ -1,4 +1,5 @@
using MediatR;
using Ardalis.GuardClauses;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.eShopWeb.Web.Features.MyOrders;
@@ -20,7 +21,8 @@ public class OrderController : Controller
[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));
return View(viewModel);
@@ -29,6 +31,7 @@ public class OrderController : Controller
[HttpGet("{orderId}")]
public async Task<IActionResult> Detail(int orderId)
{
Guard.Against.Null(User?.Identity?.Name, nameof(User.Identity.Name));
var viewModel = await _mediator.Send(new GetOrderDetails(User.Identity.Name, orderId));
if (viewModel == null)

View File

@@ -28,7 +28,7 @@ public class UserController : ControllerBase
private async Task<UserInfo> CreateUserInfo(ClaimsPrincipal claimsPrincipal)
{
if (!claimsPrincipal.Identity.IsAuthenticated)
if (claimsPrincipal.Identity == null || claimsPrincipal.Identity.Name == null || !claimsPrincipal.Identity.IsAuthenticated)
{
return UserInfo.Anonymous;
}