diff --git a/CQRS_Flow/.NET/Carts/Carts.Api.Tests/Carts/InitializingCart/InitializeCartTests.cs b/CQRS_Flow/.NET/Carts/Carts.Api.Tests/Carts/InitializingCart/InitializeCartTests.cs index c13eb2e..5bf0613 100644 --- a/CQRS_Flow/.NET/Carts/Carts.Api.Tests/Carts/InitializingCart/InitializeCartTests.cs +++ b/CQRS_Flow/.NET/Carts/Carts.Api.Tests/Carts/InitializingCart/InitializeCartTests.cs @@ -21,7 +21,7 @@ public class InitCartFixture: ApiFixture public override async Task InitializeAsync() { - CommandResponse = await Post(new InitializeCartRequest {ClientId = ClientId }); + CommandResponse = await Post(new InitializeCartRequest(ClientId)); } } diff --git a/CQRS_Flow/.NET/Carts/Carts.Api/Carts.Api.csproj b/CQRS_Flow/.NET/Carts/Carts.Api/Carts.Api.csproj index 75d93f1..4db8b29 100644 --- a/CQRS_Flow/.NET/Carts/Carts.Api/Carts.Api.csproj +++ b/CQRS_Flow/.NET/Carts/Carts.Api/Carts.Api.csproj @@ -9,12 +9,6 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - diff --git a/CQRS_Flow/.NET/Carts/Carts.Api/Controllers/CartsController.cs b/CQRS_Flow/.NET/Carts/Carts.Api/Controllers/CartsController.cs index 8f01706..992e751 100644 --- a/CQRS_Flow/.NET/Carts/Carts.Api/Controllers/CartsController.cs +++ b/CQRS_Flow/.NET/Carts/Carts.Api/Controllers/CartsController.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Ardalis.GuardClauses; using Carts.Api.Requests.Carts; using Carts.Carts.GettingCartAtVersion; using Carts.Carts.GettingCartById; @@ -27,19 +26,16 @@ public CartsController( IQueryBus queryBus, IIdGenerator idGenerator) { - Guard.Against.Null(commandBus, nameof(commandBus)); - Guard.Against.Null(queryBus, nameof(queryBus)); - Guard.Against.Null(idGenerator, nameof(idGenerator)); - this.commandBus = commandBus; this.queryBus = queryBus; this.idGenerator = idGenerator; } [HttpPost] - public async Task InitializeCart([FromBody] InitializeCartRequest request) + public async Task InitializeCart([FromBody] InitializeCartRequest? request) { - Guard.Against.Null(request, nameof(request)); + if (request == null) + throw new ArgumentNullException(nameof(request)); var cartId = idGenerator.New(); @@ -54,16 +50,16 @@ public async Task InitializeCart([FromBody] InitializeCartRequest } [HttpPost("{id}/products")] - public async Task AddProduct(Guid id, [FromBody] AddProductRequest request) + public async Task AddProduct(Guid id, [FromBody] AddProductRequest? request) { - Guard.Against.Null(request, nameof(request)); - Guard.Against.Null(request.ProductItem, nameof(request)); + if (request == null) + throw new ArgumentNullException(nameof(request)); var command = Carts.AddingProduct.AddProduct.Create( id, ProductItem.Create( - request.ProductItem.ProductId, - request.ProductItem.Quantity + request.ProductItem?.ProductId, + request.ProductItem?.Quantity ) ); @@ -73,17 +69,17 @@ public async Task AddProduct(Guid id, [FromBody] AddProductReques } [HttpDelete("{id}/products")] - public async Task RemoveProduct(Guid id, [FromBody] RemoveProductRequest request) + public async Task RemoveProduct(Guid id, [FromBody] RemoveProductRequest? request) { - Guard.Against.Null(request, nameof(request)); - Guard.Against.Null(request.ProductItem, nameof(request)); + if (request == null) + throw new ArgumentNullException(nameof(request)); var command = Carts.RemovingProduct.RemoveProduct.Create( id, PricedProductItem.Create( - request.ProductItem.ProductId, - request.ProductItem.Quantity, - request.ProductItem.UnitPrice + request.ProductItem?.ProductId, + request.ProductItem?.Quantity, + request.ProductItem?.UnitPrice ) ); @@ -124,9 +120,11 @@ public Task> GetHistory(Guid id) } [HttpGet("{id}/versions")] - public Task GetVersion(Guid id, [FromQuery] GetCartAtVersion query) + public Task GetVersion(Guid id, [FromQuery] GetCartAtVersion? query) { - Guard.Against.Null(query, nameof(query)); + if (query == null) + throw new ArgumentNullException(nameof(query)); + return queryBus.Send(GetCartAtVersion.Create(id, query.Version)); } } diff --git a/CQRS_Flow/.NET/Carts/Carts.Api/Requests/Carts/ConfirmCartRequest.cs b/CQRS_Flow/.NET/Carts/Carts.Api/Requests/Carts/ConfirmCartRequest.cs deleted file mode 100644 index 3c076b8..0000000 --- a/CQRS_Flow/.NET/Carts/Carts.Api/Requests/Carts/ConfirmCartRequest.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace Carts.Api.Requests.Carts -{ - public class ConfirmCartRequest - { - public Guid CartId { get; set; } - } -} diff --git a/CQRS_Flow/.NET/Carts/Carts.Api/Requests/Carts/InitializeCartRequest.cs b/CQRS_Flow/.NET/Carts/Carts.Api/Requests/Carts/InitializeCartRequest.cs index 3510ceb..4de9a2f 100644 --- a/CQRS_Flow/.NET/Carts/Carts.Api/Requests/Carts/InitializeCartRequest.cs +++ b/CQRS_Flow/.NET/Carts/Carts.Api/Requests/Carts/InitializeCartRequest.cs @@ -2,8 +2,7 @@ namespace Carts.Api.Requests.Carts { - public class InitializeCartRequest - { - public Guid ClientId { get; set; } - } + public record InitializeCartRequest( + Guid? ClientId + ); } diff --git a/CQRS_Flow/.NET/Carts/Carts.Api/Requests/Carts/ProductItemRequest.cs b/CQRS_Flow/.NET/Carts/Carts.Api/Requests/Carts/ProductItemRequest.cs index 35e0b49..60b13e1 100644 --- a/CQRS_Flow/.NET/Carts/Carts.Api/Requests/Carts/ProductItemRequest.cs +++ b/CQRS_Flow/.NET/Carts/Carts.Api/Requests/Carts/ProductItemRequest.cs @@ -2,10 +2,8 @@ namespace Carts.Api.Requests.Carts { - public class ProductItemRequest - { - public Guid ProductId { get; set; } - - public int Quantity { get; set; } - } + public record ProductItemRequest( + Guid? ProductId, + int? Quantity + ); } diff --git a/CQRS_Flow/.NET/Carts/Carts/Carts.csproj b/CQRS_Flow/.NET/Carts/Carts/Carts.csproj index 3c1ee81..ca49ecd 100644 --- a/CQRS_Flow/.NET/Carts/Carts/Carts.csproj +++ b/CQRS_Flow/.NET/Carts/Carts/Carts.csproj @@ -13,7 +13,6 @@ - diff --git a/CQRS_Flow/.NET/Carts/Carts/Carts/AddingProduct/AddProduct.cs b/CQRS_Flow/.NET/Carts/Carts/Carts/AddingProduct/AddProduct.cs index 2192d7c..f17b8a7 100644 --- a/CQRS_Flow/.NET/Carts/Carts/Carts/AddingProduct/AddProduct.cs +++ b/CQRS_Flow/.NET/Carts/Carts/Carts/AddingProduct/AddProduct.cs @@ -1,7 +1,6 @@ using System; using System.Threading; using System.Threading.Tasks; -using Ardalis.GuardClauses; using Carts.Carts.Products; using Carts.Pricing; using Core.Commands; @@ -12,7 +11,6 @@ namespace Carts.Carts.AddingProduct { public class AddProduct: ICommand { - public Guid CartId { get; } public ProductItem ProductItem { get; } @@ -24,8 +22,8 @@ private AddProduct(Guid cartId, ProductItem productItem) } public static AddProduct Create(Guid cartId, ProductItem productItem) { - Guard.Against.Default(cartId, nameof(cartId)); - Guard.Against.Null(productItem, nameof(productItem)); + if (cartId == Guid.Empty) + throw new ArgumentOutOfRangeException(nameof(cartId)); return new AddProduct(cartId, productItem); } diff --git a/CQRS_Flow/.NET/Carts/Carts/Carts/AddingProduct/ProductAdded.cs b/CQRS_Flow/.NET/Carts/Carts/Carts/AddingProduct/ProductAdded.cs index 1b22bcb..a5abb76 100644 --- a/CQRS_Flow/.NET/Carts/Carts/Carts/AddingProduct/ProductAdded.cs +++ b/CQRS_Flow/.NET/Carts/Carts/Carts/AddingProduct/ProductAdded.cs @@ -1,5 +1,4 @@ using System; -using Ardalis.GuardClauses; using Carts.Carts.Products; using Core.Events; @@ -19,8 +18,8 @@ private ProductAdded(Guid cartId, PricedProductItem productItem) public static ProductAdded Create(Guid cartId, PricedProductItem productItem) { - Guard.Against.Default(cartId, nameof(cartId)); - Guard.Against.Null(productItem, nameof(productItem)); + if (cartId == Guid.Empty) + throw new ArgumentOutOfRangeException(nameof(cartId)); return new ProductAdded(cartId, productItem); } diff --git a/CQRS_Flow/.NET/Carts/Carts/Carts/Cart.cs b/CQRS_Flow/.NET/Carts/Carts/Carts/Cart.cs index 26b8527..c189c50 100644 --- a/CQRS_Flow/.NET/Carts/Carts/Carts/Cart.cs +++ b/CQRS_Flow/.NET/Carts/Carts/Carts/Cart.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Ardalis.GuardClauses; using Carts.Carts.AddingProduct; using Carts.Carts.ConfirmingCart; using Carts.Carts.InitializingCart; @@ -31,7 +30,7 @@ public static Cart Initialize( } private Cart(){} - + public override void When(object @event) { switch (@event) @@ -79,9 +78,6 @@ public void AddProduct( IProductPriceCalculator productPriceCalculator, ProductItem productItem) { - Guard.Against.Null(productPriceCalculator, nameof(productPriceCalculator)); - Guard.Against.Null(productItem, nameof(productItem)); - if(Status != CartStatus.Pending) throw new InvalidOperationException($"Adding product for the cart in '{Status}' status is not allowed."); @@ -116,8 +112,6 @@ private void Apply(ProductAdded @event) public void RemoveProduct( PricedProductItem productItemToBeRemoved) { - Guard.Against.Null(productItemToBeRemoved, nameof(productItemToBeRemoved)); - if(Status != CartStatus.Pending) throw new InvalidOperationException($"Removing product from the cart in '{Status}' status is not allowed."); diff --git a/CQRS_Flow/.NET/Carts/Carts/Carts/Config.cs b/CQRS_Flow/.NET/Carts/Carts/Carts/Config.cs index dcea7e0..c558011 100644 --- a/CQRS_Flow/.NET/Carts/Carts/Carts/Config.cs +++ b/CQRS_Flow/.NET/Carts/Carts/Carts/Config.cs @@ -22,9 +22,8 @@ internal static class CartsConfig { internal static void AddCarts(this IServiceCollection services) { - services.AddScoped(); - - services.AddScoped, EventStoreDBRepository>(); + services.AddScoped() + .AddScoped, EventStoreDBRepository>(); AddCommandHandlers(services); AddProjections(services); diff --git a/CQRS_Flow/.NET/Carts/Carts/Carts/ConfirmingCart/CartConfirmed.cs b/CQRS_Flow/.NET/Carts/Carts/Carts/ConfirmingCart/CartConfirmed.cs index d5be9cf..ef6474a 100644 --- a/CQRS_Flow/.NET/Carts/Carts/Carts/ConfirmingCart/CartConfirmed.cs +++ b/CQRS_Flow/.NET/Carts/Carts/Carts/ConfirmingCart/CartConfirmed.cs @@ -1,18 +1,27 @@ using System; -using Ardalis.GuardClauses; using Core.Events; namespace Carts.Carts.ConfirmingCart { - public record CartConfirmed( - Guid CartId, - DateTime ConfirmedAt - ): IEvent + public class CartConfirmed: IEvent { + public Guid CartId { get; } + + public DateTime ConfirmedAt { get; } + + public CartConfirmed(Guid cartId, DateTime confirmedAt) + { + CartId = cartId; + ConfirmedAt = confirmedAt; + } + public static CartConfirmed Create(Guid cartId, DateTime confirmedAt) { - Guard.Against.Default(cartId, nameof(cartId)); - Guard.Against.Default(confirmedAt, nameof(confirmedAt)); + if (cartId == Guid.Empty) + throw new ArgumentOutOfRangeException(nameof(cartId)); + + if(confirmedAt == DateTime.MinValue || confirmedAt == DateTime.MaxValue) + throw new ArgumentOutOfRangeException(nameof(confirmedAt)); return new CartConfirmed(cartId, confirmedAt); } diff --git a/CQRS_Flow/.NET/Carts/Carts/Carts/ConfirmingCart/ConfirmCart.cs b/CQRS_Flow/.NET/Carts/Carts/Carts/ConfirmingCart/ConfirmCart.cs index f5eb862..e96f87a 100644 --- a/CQRS_Flow/.NET/Carts/Carts/Carts/ConfirmingCart/ConfirmCart.cs +++ b/CQRS_Flow/.NET/Carts/Carts/Carts/ConfirmingCart/ConfirmCart.cs @@ -1,7 +1,6 @@ using System; using System.Threading; using System.Threading.Tasks; -using Ardalis.GuardClauses; using Core.Commands; using Core.Repositories; using MediatR; @@ -19,7 +18,8 @@ private ConfirmCart(Guid cartId) public static ConfirmCart Create(Guid cartId) { - Guard.Against.Default(cartId, nameof(cartId)); + if (cartId == Guid.Empty) + throw new ArgumentOutOfRangeException(nameof(cartId)); return new ConfirmCart(cartId); } diff --git a/CQRS_Flow/.NET/Carts/Carts/Carts/GettingCartAtVersion/GetCartAtVersion.cs b/CQRS_Flow/.NET/Carts/Carts/Carts/GettingCartAtVersion/GetCartAtVersion.cs index 51b9a0b..bc57666 100644 --- a/CQRS_Flow/.NET/Carts/Carts/Carts/GettingCartAtVersion/GetCartAtVersion.cs +++ b/CQRS_Flow/.NET/Carts/Carts/Carts/GettingCartAtVersion/GetCartAtVersion.cs @@ -1,7 +1,6 @@ using System; using System.Threading; using System.Threading.Tasks; -using Ardalis.GuardClauses; using Carts.Carts.GettingCartById; using Core.EventStoreDB.Events; using Core.Exceptions; @@ -23,7 +22,8 @@ private GetCartAtVersion(Guid cartId, ulong version) public static GetCartAtVersion Create(Guid cartId, ulong version) { - Guard.Against.Default(cartId, nameof(cartId)); + if (cartId == Guid.Empty) + throw new ArgumentOutOfRangeException(nameof(cartId)); return new GetCartAtVersion(cartId, version); } diff --git a/CQRS_Flow/.NET/Carts/Carts/Carts/GettingCartById/GetCartById.cs b/CQRS_Flow/.NET/Carts/Carts/Carts/GettingCartById/GetCartById.cs index da41091..de35cd1 100644 --- a/CQRS_Flow/.NET/Carts/Carts/Carts/GettingCartById/GetCartById.cs +++ b/CQRS_Flow/.NET/Carts/Carts/Carts/GettingCartById/GetCartById.cs @@ -1,7 +1,6 @@ using System; using System.Threading; using System.Threading.Tasks; -using Ardalis.GuardClauses; using Core.ElasticSearch.Indices; using Core.Exceptions; using Core.Queries; @@ -20,7 +19,8 @@ private GetCartById(Guid cartId) public static GetCartById Create(Guid cartId) { - Guard.Against.Default(cartId, nameof(cartId)); + if (cartId == Guid.Empty) + throw new ArgumentOutOfRangeException(nameof(cartId)); return new GetCartById(cartId); } diff --git a/CQRS_Flow/.NET/Carts/Carts/Carts/GettingCartHistory/GetCartHistory.cs b/CQRS_Flow/.NET/Carts/Carts/Carts/GettingCartHistory/GetCartHistory.cs index c63eb82..6abd6fd 100644 --- a/CQRS_Flow/.NET/Carts/Carts/Carts/GettingCartHistory/GetCartHistory.cs +++ b/CQRS_Flow/.NET/Carts/Carts/Carts/GettingCartHistory/GetCartHistory.cs @@ -3,13 +3,12 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Ardalis.GuardClauses; using Core.Queries; using Nest; namespace Carts.Carts.GettingCartHistory { - public class GetCartHistory : IQuery> + public class GetCartHistory: IQuery> { public Guid CartId { get; } public int PageNumber { get; } @@ -24,14 +23,16 @@ private GetCartHistory(Guid cartId, int pageNumber, int pageSize) public static GetCartHistory Create(Guid cartId, int pageNumber = 1, int pageSize = 20) { - Guard.Against.NegativeOrZero(pageNumber, nameof(pageNumber)); - Guard.Against.NegativeOrZero(pageSize, nameof(pageSize)); + if (pageNumber <= 0) + throw new ArgumentOutOfRangeException(nameof(pageNumber)); + if (pageSize is <= 0 or > 100) + throw new ArgumentOutOfRangeException(nameof(pageSize)); return new GetCartHistory(cartId, pageNumber, pageSize); } } - internal class HandleGetCartHistory : + internal class HandleGetCartHistory: IQueryHandler> { private readonly IElasticClient elasticClient; @@ -56,4 +57,4 @@ public async Task> Handle(GetCartHistory request, return result.Documents.ToList(); } } -} \ No newline at end of file +} diff --git a/CQRS_Flow/.NET/Carts/Carts/Carts/GettingCarts/GetCarts.cs b/CQRS_Flow/.NET/Carts/Carts/Carts/GettingCarts/GetCarts.cs index c76eb6d..326f05b 100644 --- a/CQRS_Flow/.NET/Carts/Carts/Carts/GettingCarts/GetCarts.cs +++ b/CQRS_Flow/.NET/Carts/Carts/Carts/GettingCarts/GetCarts.cs @@ -1,8 +1,8 @@ +using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; -using Ardalis.GuardClauses; using Core.Queries; using Nest; @@ -21,8 +21,10 @@ private GetCarts(int pageNumber, int pageSize) public static GetCarts Create(int pageNumber = 1, int pageSize = 20) { - Guard.Against.NegativeOrZero(pageNumber, nameof(pageNumber)); - Guard.Against.NegativeOrZero(pageSize, nameof(pageSize)); + if (pageNumber <= 0) + throw new ArgumentOutOfRangeException(nameof(pageNumber)); + if (pageSize is <= 0 or > 100) + throw new ArgumentOutOfRangeException(nameof(pageSize)); return new GetCarts(pageNumber, pageSize); } @@ -50,4 +52,4 @@ public async Task> Handle(GetCarts request, return result.Documents.ToList(); } } -} \ No newline at end of file +} diff --git a/CQRS_Flow/.NET/Carts/Carts/Carts/InitializingCart/CartInitialized.cs b/CQRS_Flow/.NET/Carts/Carts/Carts/InitializingCart/CartInitialized.cs index c443228..6f75578 100644 --- a/CQRS_Flow/.NET/Carts/Carts/Carts/InitializingCart/CartInitialized.cs +++ b/CQRS_Flow/.NET/Carts/Carts/Carts/InitializingCart/CartInitialized.cs @@ -1,5 +1,4 @@ using System; -using Ardalis.GuardClauses; using Core.Events; namespace Carts.Carts.InitializingCart @@ -21,9 +20,12 @@ public CartInitialized(Guid cartId, Guid clientId, CartStatus cartStatus) public static CartInitialized Create(Guid cartId, Guid clientId, CartStatus cartStatus) { - Guard.Against.Default(cartId, nameof(cartId)); - Guard.Against.Default(clientId, nameof(clientId)); - Guard.Against.Default(cartStatus, nameof(cartStatus)); + if (cartId == Guid.Empty) + throw new ArgumentOutOfRangeException(nameof(cartId)); + if (clientId == Guid.Empty) + throw new ArgumentOutOfRangeException(nameof(clientId)); + if (cartStatus == default) + throw new ArgumentOutOfRangeException(nameof(cartStatus)); return new CartInitialized(cartId, clientId, cartStatus); } diff --git a/CQRS_Flow/.NET/Carts/Carts/Carts/InitializingCart/InitializeCart.cs b/CQRS_Flow/.NET/Carts/Carts/Carts/InitializingCart/InitializeCart.cs index bd51f8c..a4c380a 100644 --- a/CQRS_Flow/.NET/Carts/Carts/Carts/InitializingCart/InitializeCart.cs +++ b/CQRS_Flow/.NET/Carts/Carts/Carts/InitializingCart/InitializeCart.cs @@ -1,7 +1,6 @@ using System; using System.Threading; using System.Threading.Tasks; -using Ardalis.GuardClauses; using Core.Commands; using Core.Repositories; using MediatR; @@ -20,12 +19,14 @@ private InitializeCart(Guid cartId, Guid clientId) ClientId = clientId; } - public static InitializeCart Create(Guid cartId, Guid clientId) + public static InitializeCart Create(Guid? cartId, Guid? clientId) { - Guard.Against.Default(cartId, nameof(cartId)); - Guard.Against.Default(clientId, nameof(clientId)); + if (!cartId.HasValue|| cartId == Guid.Empty) + throw new ArgumentOutOfRangeException(nameof(cartId)); + if (!clientId.HasValue || clientId == Guid.Empty) + throw new ArgumentOutOfRangeException(nameof(clientId)); - return new InitializeCart(cartId, clientId); + return new InitializeCart(cartId.Value, clientId.Value); } } diff --git a/CQRS_Flow/.NET/Carts/Carts/Carts/Products/PricedProductItem.cs b/CQRS_Flow/.NET/Carts/Carts/Carts/Products/PricedProductItem.cs index 9218e8f..8601848 100644 --- a/CQRS_Flow/.NET/Carts/Carts/Carts/Products/PricedProductItem.cs +++ b/CQRS_Flow/.NET/Carts/Carts/Carts/Products/PricedProductItem.cs @@ -68,5 +68,22 @@ public bool HasTheSameQuantity(PricedProductItem pricedProductItem) { return ProductItem.HasTheSameQuantity(pricedProductItem.ProductItem); } + + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((PricedProductItem) obj); + } + + private bool Equals(PricedProductItem other) + { + return UnitPrice == other.UnitPrice && ProductItem.Equals(other.ProductItem); + } + + public override int GetHashCode() + { + return HashCode.Combine(UnitPrice, ProductItem); + } } } diff --git a/CQRS_Flow/.NET/Carts/Carts/Carts/Products/ProductItem.cs b/CQRS_Flow/.NET/Carts/Carts/Carts/Products/ProductItem.cs index dd036ff..da136d4 100644 --- a/CQRS_Flow/.NET/Carts/Carts/Carts/Products/ProductItem.cs +++ b/CQRS_Flow/.NET/Carts/Carts/Carts/Products/ProductItem.cs @@ -57,5 +57,22 @@ public bool HasTheSameQuantity(ProductItem productItem) { return Quantity == productItem.Quantity; } + + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((ProductItem) obj); + } + + private bool Equals(ProductItem other) + { + return ProductId.Equals(other.ProductId) && Quantity == other.Quantity; + } + + public override int GetHashCode() + { + return HashCode.Combine(ProductId, Quantity); + } } } diff --git a/CQRS_Flow/.NET/Carts/Carts/Carts/RemovingProduct/ProductRemoved.cs b/CQRS_Flow/.NET/Carts/Carts/Carts/RemovingProduct/ProductRemoved.cs index dde793b..80dc029 100644 --- a/CQRS_Flow/.NET/Carts/Carts/Carts/RemovingProduct/ProductRemoved.cs +++ b/CQRS_Flow/.NET/Carts/Carts/Carts/RemovingProduct/ProductRemoved.cs @@ -1,5 +1,4 @@ using System; -using Ardalis.GuardClauses; using Carts.Carts.Products; using Core.Events; @@ -19,8 +18,8 @@ public ProductRemoved(Guid cartId, PricedProductItem productItem) public static ProductRemoved Create(Guid cartId, PricedProductItem productItem) { - Guard.Against.Default(cartId, nameof(cartId)); - Guard.Against.Null(productItem, nameof(productItem)); + if (cartId == Guid.Empty) + throw new ArgumentOutOfRangeException(nameof(cartId)); return new ProductRemoved(cartId, productItem); } diff --git a/CQRS_Flow/.NET/Carts/Carts/Pricing/RandomProductPriceCalculator.cs b/CQRS_Flow/.NET/Carts/Carts/Pricing/RandomProductPriceCalculator.cs index cd75526..6a511f7 100644 --- a/CQRS_Flow/.NET/Carts/Carts/Pricing/RandomProductPriceCalculator.cs +++ b/CQRS_Flow/.NET/Carts/Carts/Pricing/RandomProductPriceCalculator.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Ardalis.GuardClauses; using Carts.Carts.Products; namespace Carts.Pricing @@ -10,7 +9,8 @@ public class RandomProductPriceCalculator: IProductPriceCalculator { public IReadOnlyList Calculate(params ProductItem[] productItems) { - Guard.Against.Zero(productItems.Length, "Product items count"); + if (productItems.Length == 0) + throw new ArgumentOutOfRangeException(nameof(productItems), "Product items cannot be an empty"); var random = new Random(); diff --git a/CQRS_Flow/.NET/ECommerce.sln b/CQRS_Flow/.NET/ECommerce.sln index 70994c7..4bf9e33 100644 --- a/CQRS_Flow/.NET/ECommerce.sln +++ b/CQRS_Flow/.NET/ECommerce.sln @@ -27,6 +27,11 @@ ProjectSection(SolutionItems) = preProject docker-compose.yml = docker-compose.yml EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{A33F3671-D99D-47A0-A584-16D444A2C238}" +ProjectSection(SolutionItems) = preProject + README.md = README.md +EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/CQRS_Flow/.NET/README.md b/CQRS_Flow/.NET/README.md index abcc5e1..833f60c 100644 --- a/CQRS_Flow/.NET/README.md +++ b/CQRS_Flow/.NET/README.md @@ -47,7 +47,7 @@ It uses: - Added hosted service [SubscribeToAllBackgroundWorker](./Core/Core.EventStoreDB/Subscriptions/SubscribeToAllBackgroundWorker.cs) to handle subscribing to all. It handles checkpointing and simple retries if the connection was dropped. - Added [ISubscriptionCheckpointRepository](./Core/Core.EventStoreDB/Subscriptions/ISubscriptionCheckpointRepository.cs) for handling Subscription checkpointing. - Added checkpointing to EventStoreDB stream with [EventStoreDBSubscriptionCheckpointRepository](./Core/Core.EventStoreDB/Subscriptions/EventStoreDBSubscriptionCheckpointRepository.cs) and dummy in-memory checkpointer [InMemorySubscriptionCheckpointRepository](./Core/Core.EventStoreDB/Subscriptions/InMemorySubscriptionCheckpointRepository.cs), -- Added [ElasticSearchProjection](./Core/Core.ElasticSearch/Projections/ElasticSearchProjection.cs) as a sample how to project with [`left-fold`](https://en.wikipedia.org/wiki/Fold_(higher-order_function)) into external storage. Another (e.g. ElasticSearch, EntityFramework) can be implemented the same way. +- Added [ElasticSearchProjection](./Core/Core.ElasticSearch/Projections/ElasticSearchProjection.cs) as a sample how to project with [`left-fold`](https://en.wikipedia.org/wiki/Fold_(higher-order_function)) into external storage. Another (e.g. MongoDB, EntityFramework) can be implemented the same way. ## Tests - Added sample of unit testing in [`Carts.Tests`](./Carts/Carts.Tests): diff --git a/CQRS_Flow/.NET/docker-compose.yml b/CQRS_Flow/.NET/docker-compose.yml index 090709e..5d23dbb 100644 --- a/CQRS_Flow/.NET/docker-compose.yml +++ b/CQRS_Flow/.NET/docker-compose.yml @@ -4,13 +4,13 @@ services: # EventStoreDB - Event Store ####################################################### eventstore.db: - image: eventstore/eventstore:21.2.0-buster-slim + image: eventstore/eventstore:21.6.0-buster-slim environment: - EVENTSTORE_CLUSTER_SIZE=1 - EVENTSTORE_RUN_PROJECTIONS=All - EVENTSTORE_START_STANDARD_PROJECTIONS=true - EVENTSTORE_EXT_TCP_PORT=1113 - - EVENTSTORE_EXT_HTTP_PORT=2113 + - EVENTSTORE_HTTP_PORT=2113 - EVENTSTORE_INSECURE=true - EVENTSTORE_ENABLE_EXTERNAL_TCP=true - EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP=true