Skip to content

Commit a17e634

Browse files
Improvements/code (#580)
* Fix logical operators in CustomerValidator.cs * Refactor to run application asynchronously * Remove unused code * Refactor filters to use constructor parameters * Refactor test assertion to use Assert.IsNull * Replace manual null check with ArgumentNullException.ThrowIfNull * Refactor filters to use primary constructors * Remove DebuggerToString method from ViewBuffer class * Refactor PageNavigationTagHelper to use Append method * Remove IDownloadService dependency and reformat code * Refactor argument validation for conciseness * Replace build.yml with sonarcube.yml for SonarQube integration * Remove unused using directive
1 parent 888a6a8 commit a17e634

File tree

114 files changed

+397
-864
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+397
-864
lines changed
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ jobs:
4242
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
4343
shell: powershell
4444
run: |
45-
.\.sonar\scanner\dotnet-sonarscanner begin /k:"grandnode_grandnode2" /o:"grandnode" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
46-
dotnet build
47-
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
45+
.\.sonar\scanner\dotnet-sonarscanner begin /k:"grandnode_grandnode2" /o:"grandnode" `
46+
/d:sonar.token="${{ secrets.SONAR_TOKEN }}" `
47+
/d:sonar.host.url="https://sonarcloud.io" `
48+
/d:sonar.coverage.exclusions="**" `
49+
/d:sonar.cpd.exclusions="**"

src/Aspire/Aspire.AppHost/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
var mongodb = mongo.AddDatabase("Mongodb");
77
builder.ConfigureGrandWebProject(mongodb);
88

9-
builder.Build().Run();
9+
await builder.Build().RunAsync();

src/Business/Grand.Business.Catalog/Commands/UpdateProductReviewTotalsCommandHandler.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ public UpdateProductReviewTotalsCommandHandler(IRepository<Product> productRepos
2020

2121
public async Task<bool> Handle(UpdateProductReviewTotalsCommand request, CancellationToken cancellationToken)
2222
{
23-
if (request.Product == null)
24-
throw new ArgumentNullException(nameof(request.Product));
23+
ArgumentNullException.ThrowIfNull(request.Product);
2524

2625
var approvedRatingSum = 0;
2726
var notApprovedRatingSum = 0;

src/Business/Grand.Business.Catalog/Services/Products/ProductAttributeService.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Grand.Data;
33
using Grand.Domain;
44
using Grand.Domain.Catalog;
5+
using Grand.Domain.Directory;
56
using Grand.Infrastructure.Caching;
67
using Grand.Infrastructure.Caching.Constants;
78
using Grand.Infrastructure.Extensions;
@@ -257,12 +258,10 @@ public virtual async Task InsertProductAttributeValue(ProductAttributeValue prod
257258
ArgumentNullException.ThrowIfNull(productAttributeValue);
258259

259260
var p = await _productRepository.GetByIdAsync(productId);
260-
if (p == null)
261-
throw new ArgumentNullException(nameof(p));
261+
ArgumentNullException.ThrowIfNull(p, nameof(p));
262262

263263
var pam = p.ProductAttributeMappings.FirstOrDefault(x => x.Id == productAttributeMappingId);
264-
if (pam == null)
265-
throw new ArgumentNullException(nameof(pam));
264+
ArgumentNullException.ThrowIfNull(pam, nameof(pam));
266265

267266
pam.ProductAttributeValues.Add(productAttributeValue);
268267
await _productRepository.UpdateToSet(productId, x => x.ProductAttributeMappings, z => z.Id,

src/Business/Grand.Business.Catalog/Services/Products/ProductCourseService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public virtual async Task<Product> GetProductByCourseId(string courseId)
2828

2929
public virtual async Task UpdateCourseOnProduct(string productId, string courseId)
3030
{
31-
if (string.IsNullOrEmpty(productId))
32-
throw new ArgumentNullException(nameof(productId));
31+
ArgumentNullException.ThrowIfNullOrEmpty(productId);
3332

3433
await _productRepository.UpdateField(productId, x => x.CourseId, courseId);
3534
await _productRepository.UpdateField(productId, x => x.UpdatedOnUtc, DateTime.UtcNow);

src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,8 +1181,8 @@ public virtual async Task DeleteProductWarehouseInventory(ProductWarehouseInvent
11811181

11821182
public virtual async Task DeleteDiscount(string discountId, string productId)
11831183
{
1184-
if (string.IsNullOrEmpty(discountId))
1185-
throw new ArgumentNullException(nameof(discountId));
1184+
ArgumentNullException.ThrowIfNullOrEmpty(discountId);
1185+
ArgumentNullException.ThrowIfNullOrEmpty(productId);
11861186

11871187
await _productRepository.Pull(productId, x => x.AppliedDiscounts, discountId);
11881188

src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/ActivatedValueForPurchasedVouchersCommandHandler.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public ActivatedValueForPurchasedGiftVouchersCommandHandler(
2828
public async Task<bool> Handle(ActivatedValueForPurchasedGiftVouchersCommand request,
2929
CancellationToken cancellationToken)
3030
{
31-
if (request.Order == null)
32-
throw new ArgumentNullException(nameof(request.Order));
31+
ArgumentNullException.ThrowIfNull(request.Order);
3332

3433
foreach (var orderItem in request.Order.OrderItems)
3534
{

src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/AwardLoyaltyPointsCommandHandler.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ public AwardLoyaltyPointsCommandHandler(
3434

3535
public async Task<bool> Handle(AwardLoyaltyPointsCommand request, CancellationToken cancellationToken)
3636
{
37-
if (request.Order == null)
38-
throw new ArgumentNullException(nameof(request.Order));
37+
ArgumentNullException.ThrowIfNull(request.Order);
3938

4039
var customer = await _customerService.GetCustomerById(request.Order.CustomerId);
4140
var currency = await _currencyService.GetCurrencyByCode(request.Order.CustomerCurrencyCode);

src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/CancelOrderCommandHandler.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ public CancelOrderCommandHandler(
4949

5050
public async Task<bool> Handle(CancelOrderCommand request, CancellationToken cancellationToken)
5151
{
52-
if (request.Order == null)
53-
throw new ArgumentNullException(nameof(request.Order));
52+
ArgumentNullException.ThrowIfNull(request.Order);
5453

5554
if (request.Order.OrderStatusId == (int)OrderStatusSystem.Cancelled)
5655
throw new Exception("Cannot do cancel for order.");

src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/CancelOrderItemCommandHandler.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@ public CancelOrderItemCommandHandler(
3333
public async Task<(bool error, string message)> Handle(CancelOrderItemCommand request,
3434
CancellationToken cancellationToken)
3535
{
36-
if (request.Order == null)
37-
throw new ArgumentNullException(nameof(request.Order));
38-
39-
if (request.OrderItem == null)
40-
throw new ArgumentNullException(nameof(request.OrderItem));
36+
ArgumentNullException.ThrowIfNull(request.Order);
37+
ArgumentNullException.ThrowIfNull(request.OrderItem);
4138

4239
var product = await _productService.GetProductById(request.OrderItem.ProductId);
4340
if (product == null)

0 commit comments

Comments
 (0)