diff --git a/src/ApplicationCore/Entities/Basket.cs b/src/ApplicationCore/Entities/Basket.cs deleted file mode 100644 index 4792463..0000000 --- a/src/ApplicationCore/Entities/Basket.cs +++ /dev/null @@ -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 _items = new List(); - public IReadOnlyCollection 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; - } -} -} diff --git a/src/ApplicationCore/Entities/BasketAggregate/Basket.cs b/src/ApplicationCore/Entities/BasketAggregate/Basket.cs new file mode 100644 index 0000000..f671292 --- /dev/null +++ b/src/ApplicationCore/Entities/BasketAggregate/Basket.cs @@ -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 _items = new List(); + public IReadOnlyCollection 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; + } + } +} diff --git a/src/ApplicationCore/Entities/BasketItem.cs b/src/ApplicationCore/Entities/BasketAggregate/BasketItem.cs similarity index 72% rename from src/ApplicationCore/Entities/BasketItem.cs rename to src/ApplicationCore/Entities/BasketAggregate/BasketItem.cs index 5233ffd..2449b16 100644 --- a/src/ApplicationCore/Entities/BasketItem.cs +++ b/src/ApplicationCore/Entities/BasketAggregate/BasketItem.cs @@ -1,4 +1,4 @@ -namespace Microsoft.eShopWeb.ApplicationCore.Entities +namespace Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate { public class BasketItem : BaseEntity { diff --git a/src/ApplicationCore/Exceptions/GuardExtensions.cs b/src/ApplicationCore/Exceptions/GuardExtensions.cs index 0c840a0..5b3a84a 100644 --- a/src/ApplicationCore/Exceptions/GuardExtensions.cs +++ b/src/ApplicationCore/Exceptions/GuardExtensions.cs @@ -1,9 +1,10 @@ using ApplicationCore.Exceptions; using Microsoft.eShopWeb.ApplicationCore.Entities; +using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; namespace Ardalis.GuardClauses { - public static class FooGuard + public static class BasketGuards { public static void NullBasket(this IGuardClause guardClause, int basketId, Basket basket) { diff --git a/src/ApplicationCore/Services/BasketService.cs b/src/ApplicationCore/Services/BasketService.cs index f189812..93be695 100644 --- a/src/ApplicationCore/Services/BasketService.cs +++ b/src/ApplicationCore/Services/BasketService.cs @@ -5,6 +5,7 @@ using ApplicationCore.Specifications; using Microsoft.eShopWeb.ApplicationCore.Entities; using System.Linq; using Ardalis.GuardClauses; +using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; namespace ApplicationCore.Services { diff --git a/src/ApplicationCore/Services/OrderService.cs b/src/ApplicationCore/Services/OrderService.cs index 162e289..0c9373b 100644 --- a/src/ApplicationCore/Services/OrderService.cs +++ b/src/ApplicationCore/Services/OrderService.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using Microsoft.eShopWeb.ApplicationCore.Entities; using System.Collections.Generic; using Ardalis.GuardClauses; +using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; namespace ApplicationCore.Services { diff --git a/src/ApplicationCore/Specifications/BasketWithItemsSpecification.cs b/src/ApplicationCore/Specifications/BasketWithItemsSpecification.cs index cb3dc40..c18aa3b 100644 --- a/src/ApplicationCore/Specifications/BasketWithItemsSpecification.cs +++ b/src/ApplicationCore/Specifications/BasketWithItemsSpecification.cs @@ -1,4 +1,5 @@ using Microsoft.eShopWeb.ApplicationCore.Entities; +using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; namespace ApplicationCore.Specifications { diff --git a/src/Infrastructure/Data/CatalogContext.cs b/src/Infrastructure/Data/CatalogContext.cs index 4e71fb1..d66ed36 100644 --- a/src/Infrastructure/Data/CatalogContext.cs +++ b/src/Infrastructure/Data/CatalogContext.cs @@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.eShopWeb.ApplicationCore.Entities; +using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; namespace Infrastructure.Data { diff --git a/src/Web/Properties/launchSettings.json b/src/Web/Properties/launchSettings.json index 39a19ed..ebf2925 100644 --- a/src/Web/Properties/launchSettings.json +++ b/src/Web/Properties/launchSettings.json @@ -4,7 +4,7 @@ "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:5106/", - "sslPort": 44316 + "sslPort": 0 } }, "profiles": { @@ -16,7 +16,7 @@ } }, "eShopWeb": { - "commandName": "IISExpress", + "commandName": "Project", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" diff --git a/src/Web/Services/BasketViewModelService.cs b/src/Web/Services/BasketViewModelService.cs index e2a2e2d..4ff0479 100644 --- a/src/Web/Services/BasketViewModelService.cs +++ b/src/Web/Services/BasketViewModelService.cs @@ -1,6 +1,7 @@ using ApplicationCore.Interfaces; using ApplicationCore.Specifications; using Microsoft.eShopWeb.ApplicationCore.Entities; +using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; using Microsoft.eShopWeb.Interfaces; using Microsoft.eShopWeb.ViewModels; using System.Collections.Generic; diff --git a/src/WebRazorPages/Services/BasketViewModelService.cs b/src/WebRazorPages/Services/BasketViewModelService.cs index 7a38244..f658671 100644 --- a/src/WebRazorPages/Services/BasketViewModelService.cs +++ b/src/WebRazorPages/Services/BasketViewModelService.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using ApplicationCore.Specifications; using Microsoft.eShopWeb.RazorPages.Interfaces; using Microsoft.eShopWeb.RazorPages.ViewModels; +using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; namespace Microsoft.eShopWeb.RazorPages.Services { diff --git a/tests/UnitTests/ApplicationCore/Entities/BasketTests/AddItem.cs b/tests/UnitTests/ApplicationCore/Entities/BasketTests/AddItem.cs index f11c23f..e07e302 100644 --- a/tests/UnitTests/ApplicationCore/Entities/BasketTests/AddItem.cs +++ b/tests/UnitTests/ApplicationCore/Entities/BasketTests/AddItem.cs @@ -1,4 +1,5 @@ using Microsoft.eShopWeb.ApplicationCore.Entities; +using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; using System.Linq; using Xunit; diff --git a/tests/UnitTests/ApplicationCore/Services/BasketServiceTests/SetQuantities.cs b/tests/UnitTests/ApplicationCore/Services/BasketServiceTests/SetQuantities.cs index 8e98009..80716e8 100644 --- a/tests/UnitTests/ApplicationCore/Services/BasketServiceTests/SetQuantities.cs +++ b/tests/UnitTests/ApplicationCore/Services/BasketServiceTests/SetQuantities.cs @@ -2,6 +2,7 @@ using ApplicationCore.Interfaces; using ApplicationCore.Services; using Microsoft.eShopWeb.ApplicationCore.Entities; +using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; using Moq; using System; using Xunit; diff --git a/tests/UnitTests/ApplicationCore/Specifications/BasketWithItemsSpecification.cs b/tests/UnitTests/ApplicationCore/Specifications/BasketWithItemsSpecification.cs index a0fea71..f7e5e80 100644 --- a/tests/UnitTests/ApplicationCore/Specifications/BasketWithItemsSpecification.cs +++ b/tests/UnitTests/ApplicationCore/Specifications/BasketWithItemsSpecification.cs @@ -1,5 +1,6 @@ using ApplicationCore.Specifications; using Microsoft.eShopWeb.ApplicationCore.Entities; +using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; using System.Collections.Generic; using System.Linq; using Xunit;