Steve Smith
8 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with
43 additions and
32 deletions
-
src/ApplicationCore/Entities/Basket.cs
-
src/ApplicationCore/Entities/BasketAggregate/Basket.cs
-
src/ApplicationCore/Entities/BasketAggregate/BasketItem.cs
-
src/ApplicationCore/Exceptions/GuardExtensions.cs
-
src/ApplicationCore/Services/BasketService.cs
-
src/ApplicationCore/Services/OrderService.cs
-
src/ApplicationCore/Specifications/BasketWithItemsSpecification.cs
-
src/Infrastructure/Data/CatalogContext.cs
-
src/Web/Properties/launchSettings.json
-
src/Web/Services/BasketViewModelService.cs
-
src/WebRazorPages/Services/BasketViewModelService.cs
-
tests/UnitTests/ApplicationCore/Entities/BasketTests/AddItem.cs
-
tests/UnitTests/ApplicationCore/Services/BasketServiceTests/SetQuantities.cs
-
tests/UnitTests/ApplicationCore/Specifications/BasketWithItemsSpecification.cs
|
|
@ -1,28 +0,0 @@ |
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.Linq; |
|
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.eShopWeb.ApplicationCore.Entities |
|
|
|
|
|
{ |
|
|
|
|
|
public class Basket : BaseEntity |
|
|
|
|
|
{ |
|
|
|
|
|
public string BuyerId { get; set; } |
|
|
|
|
|
private readonly List<BasketItem> _items = new List<BasketItem>(); |
|
|
|
|
|
public IReadOnlyCollection<BasketItem> Items => _items.AsReadOnly(); |
|
|
|
|
|
|
|
|
|
|
|
public void AddItem(int catalogItemId, decimal unitPrice, int quantity = 1) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!Items.Any(i => i.CatalogItemId == catalogItemId)) |
|
|
|
|
|
{ |
|
|
|
|
|
_items.Add(new BasketItem() |
|
|
|
|
|
{ |
|
|
|
|
|
CatalogItemId = catalogItemId, |
|
|
|
|
|
Quantity = quantity, |
|
|
|
|
|
UnitPrice = unitPrice |
|
|
|
|
|
}); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
var existingItem = Items.FirstOrDefault(i => i.CatalogItemId == catalogItemId); |
|
|
|
|
|
existingItem.Quantity += quantity; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
@ -0,0 +1,29 @@ |
|
|
|
|
|
using ApplicationCore.Interfaces; |
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.Linq; |
|
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate |
|
|
|
|
|
{ |
|
|
|
|
|
public class Basket : BaseEntity, IAggregateRoot |
|
|
|
|
|
{ |
|
|
|
|
|
public string BuyerId { get; set; } |
|
|
|
|
|
private readonly List<BasketItem> _items = new List<BasketItem>(); |
|
|
|
|
|
public IReadOnlyCollection<BasketItem> Items => _items.AsReadOnly(); |
|
|
|
|
|
|
|
|
|
|
|
public void AddItem(int catalogItemId, decimal unitPrice, int quantity = 1) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!Items.Any(i => i.CatalogItemId == catalogItemId)) |
|
|
|
|
|
{ |
|
|
|
|
|
_items.Add(new BasketItem() |
|
|
|
|
|
{ |
|
|
|
|
|
CatalogItemId = catalogItemId, |
|
|
|
|
|
Quantity = quantity, |
|
|
|
|
|
UnitPrice = unitPrice |
|
|
|
|
|
}); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
var existingItem = Items.FirstOrDefault(i => i.CatalogItemId == catalogItemId); |
|
|
|
|
|
existingItem.Quantity += quantity; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
@ -1,4 +1,4 @@ |
|
|
namespace Microsoft.eShopWeb.ApplicationCore.Entities |
|
|
namespace Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate |
|
|
{ |
|
|
{ |
|
|
public class BasketItem : BaseEntity |
|
|
public class BasketItem : BaseEntity |
|
|
{ |
|
|
{ |
|
|
@ -1,9 +1,10 @@ |
|
|
using ApplicationCore.Exceptions; |
|
|
using ApplicationCore.Exceptions; |
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|
|
|
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; |
|
|
|
|
|
|
|
|
namespace Ardalis.GuardClauses |
|
|
namespace Ardalis.GuardClauses |
|
|
{ |
|
|
{ |
|
|
public static class FooGuard |
|
|
public static class BasketGuards |
|
|
{ |
|
|
{ |
|
|
public static void NullBasket(this IGuardClause guardClause, int basketId, Basket basket) |
|
|
public static void NullBasket(this IGuardClause guardClause, int basketId, Basket basket) |
|
|
{ |
|
|
{ |
|
|
|
|
|
@ -5,6 +5,7 @@ using ApplicationCore.Specifications; |
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
using Ardalis.GuardClauses; |
|
|
using Ardalis.GuardClauses; |
|
|
|
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; |
|
|
|
|
|
|
|
|
namespace ApplicationCore.Services |
|
|
namespace ApplicationCore.Services |
|
|
{ |
|
|
{ |
|
|
|
|
|
@ -4,6 +4,7 @@ using System.Threading.Tasks; |
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using Ardalis.GuardClauses; |
|
|
using Ardalis.GuardClauses; |
|
|
|
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; |
|
|
|
|
|
|
|
|
namespace ApplicationCore.Services |
|
|
namespace ApplicationCore.Services |
|
|
{ |
|
|
{ |
|
|
|
|
|
@ -1,4 +1,5 @@ |
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|
|
|
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; |
|
|
|
|
|
|
|
|
namespace ApplicationCore.Specifications |
|
|
namespace ApplicationCore.Specifications |
|
|
{ |
|
|
{ |
|
|
|
|
|
@ -2,6 +2,7 @@ |
|
|
using Microsoft.EntityFrameworkCore; |
|
|
using Microsoft.EntityFrameworkCore; |
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders; |
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders; |
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|
|
|
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; |
|
|
|
|
|
|
|
|
namespace Infrastructure.Data |
|
|
namespace Infrastructure.Data |
|
|
{ |
|
|
{ |
|
|
|
|
|
@ -4,7 +4,7 @@ |
|
|
"anonymousAuthentication": true, |
|
|
"anonymousAuthentication": true, |
|
|
"iisExpress": { |
|
|
"iisExpress": { |
|
|
"applicationUrl": "http://localhost:5106/", |
|
|
"applicationUrl": "http://localhost:5106/", |
|
|
"sslPort": 44316 |
|
|
"sslPort": 0 |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
"profiles": { |
|
|
"profiles": { |
|
|
@ -16,7 +16,7 @@ |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
"eShopWeb": { |
|
|
"eShopWeb": { |
|
|
"commandName": "IISExpress", |
|
|
"commandName": "Project", |
|
|
"launchBrowser": true, |
|
|
"launchBrowser": true, |
|
|
"environmentVariables": { |
|
|
"environmentVariables": { |
|
|
"ASPNETCORE_ENVIRONMENT": "Development" |
|
|
"ASPNETCORE_ENVIRONMENT": "Development" |
|
|
|
|
|
@ -1,6 +1,7 @@ |
|
|
using ApplicationCore.Interfaces; |
|
|
using ApplicationCore.Interfaces; |
|
|
using ApplicationCore.Specifications; |
|
|
using ApplicationCore.Specifications; |
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|
|
|
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; |
|
|
using Microsoft.eShopWeb.Interfaces; |
|
|
using Microsoft.eShopWeb.Interfaces; |
|
|
using Microsoft.eShopWeb.ViewModels; |
|
|
using Microsoft.eShopWeb.ViewModels; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
|
|
|
@ -6,6 +6,7 @@ using System.Collections.Generic; |
|
|
using ApplicationCore.Specifications; |
|
|
using ApplicationCore.Specifications; |
|
|
using Microsoft.eShopWeb.RazorPages.Interfaces; |
|
|
using Microsoft.eShopWeb.RazorPages.Interfaces; |
|
|
using Microsoft.eShopWeb.RazorPages.ViewModels; |
|
|
using Microsoft.eShopWeb.RazorPages.ViewModels; |
|
|
|
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; |
|
|
|
|
|
|
|
|
namespace Microsoft.eShopWeb.RazorPages.Services |
|
|
namespace Microsoft.eShopWeb.RazorPages.Services |
|
|
{ |
|
|
{ |
|
|
|
|
|
@ -1,4 +1,5 @@ |
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|
|
|
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
using Xunit; |
|
|
using Xunit; |
|
|
|
|
|
|
|
|
|
|
|
@ -2,6 +2,7 @@ |
|
|
using ApplicationCore.Interfaces; |
|
|
using ApplicationCore.Interfaces; |
|
|
using ApplicationCore.Services; |
|
|
using ApplicationCore.Services; |
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|
|
|
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; |
|
|
using Moq; |
|
|
using Moq; |
|
|
using System; |
|
|
using System; |
|
|
using Xunit; |
|
|
using Xunit; |
|
|
|
|
|
@ -1,5 +1,6 @@ |
|
|
using ApplicationCore.Specifications; |
|
|
using ApplicationCore.Specifications; |
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|
|
|
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
using Xunit; |
|
|
using Xunit; |
|
|
|