diff --git a/src/BuildingBlocks/EventBus/EventBus/Events/IntegrationEvent.cs b/src/BuildingBlocks/EventBus/EventBus/Events/IntegrationEvent.cs index e1802704e..c9e60a0cf 100644 --- a/src/BuildingBlocks/EventBus/EventBus/Events/IntegrationEvent.cs +++ b/src/BuildingBlocks/EventBus/EventBus/Events/IntegrationEvent.cs @@ -9,8 +9,10 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events public IntegrationEvent() { Id = Guid.NewGuid(); + CreationDate = DateTime.UtcNow; } public Guid Id { get; } + public DateTime CreationDate { get; } } } diff --git a/src/BuildingBlocks/EventBus/IntegrationEventLogEF/IntegrationEventLogEntry.cs b/src/BuildingBlocks/EventBus/IntegrationEventLogEF/IntegrationEventLogEntry.cs index 0b68e56a0..3cab9e500 100644 --- a/src/BuildingBlocks/EventBus/IntegrationEventLogEF/IntegrationEventLogEntry.cs +++ b/src/BuildingBlocks/EventBus/IntegrationEventLogEF/IntegrationEventLogEntry.cs @@ -12,7 +12,7 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF public IntegrationEventLogEntry(IntegrationEvent @event) { EventId = @event.Id; - CreationTime = DateTime.UtcNow; + CreationTime = @event.CreationDate; EventTypeName = @event.GetType().FullName; Content = JsonConvert.SerializeObject(@event); State = EventStateEnum.NotPublished; diff --git a/src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedIntegrationEventHandler.cs b/src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedIntegrationEventHandler.cs index 28c9a9afa..08aa9704b 100644 --- a/src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedIntegrationEventHandler.cs +++ b/src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedIntegrationEventHandler.cs @@ -20,18 +20,18 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even foreach (var id in userIds) { var basket = await _repository.GetBasket(id); - await UpdatePriceInBasketItems(@event.ProductId, @event.NewPrice, basket); + await UpdatePriceInBasketItems(@event.ProductId, @event.NewPrice, @event.OldPrice, basket); } } - private async Task UpdatePriceInBasketItems(int productId, decimal newPrice, CustomerBasket basket) + private async Task UpdatePriceInBasketItems(int productId, decimal newPrice, decimal oldPrice, CustomerBasket basket) { var itemsToUpdate = basket?.Items?.Where(x => int.Parse(x.ProductId) == productId).ToList(); if (itemsToUpdate != null) { foreach (var item in itemsToUpdate) { - if(item.UnitPrice != newPrice) + if(item.UnitPrice == oldPrice) { var originalPrice = item.UnitPrice; item.UnitPrice = newPrice; @@ -39,7 +39,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even } } await _repository.UpdateBasket(basket); - } + } } } } diff --git a/src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs b/src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs index 2132d2983..eee53a670 100644 --- a/src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs @@ -3,7 +3,7 @@ using Domain.AggregatesModel.OrderAggregate; using MediatR; using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services; - using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositories; + using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency; using System; using System.Threading.Tasks; diff --git a/src/Services/Ordering/Ordering.API/Application/Commands/IdentifierCommandHandler.cs b/src/Services/Ordering/Ordering.API/Application/Commands/IdentifierCommandHandler.cs index 60a48ae89..de7dc4fea 100644 --- a/src/Services/Ordering/Ordering.API/Application/Commands/IdentifierCommandHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/Commands/IdentifierCommandHandler.cs @@ -1,8 +1,5 @@ using MediatR; -using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositories; -using System; -using System.Collections.Generic; -using System.Linq; +using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency; using System.Threading.Tasks; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands diff --git a/src/Services/Ordering/Ordering.API/Infrastructure/AutofacModules/ApplicationModule.cs b/src/Services/Ordering/Ordering.API/Infrastructure/AutofacModules/ApplicationModule.cs index 0d8e34476..6e87f385f 100644 --- a/src/Services/Ordering/Ordering.API/Infrastructure/AutofacModules/ApplicationModule.cs +++ b/src/Services/Ordering/Ordering.API/Infrastructure/AutofacModules/ApplicationModule.cs @@ -2,6 +2,7 @@ using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; +using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency; using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositories; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.AutofacModules diff --git a/src/Services/Ordering/Ordering.Infrastructure/Repositories/IRequestManager.cs b/src/Services/Ordering/Ordering.Infrastructure/Idempotency/IRequestManager.cs similarity index 93% rename from src/Services/Ordering/Ordering.Infrastructure/Repositories/IRequestManager.cs rename to src/Services/Ordering/Ordering.Infrastructure/Idempotency/IRequestManager.cs index ecb144695..a8a02f8ca 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/Repositories/IRequestManager.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/Idempotency/IRequestManager.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Text; using System.Threading.Tasks; -namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositories +namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency { public interface IRequestManager { diff --git a/src/Services/Ordering/Ordering.Infrastructure/Repositories/RequestManager.cs b/src/Services/Ordering/Ordering.Infrastructure/Idempotency/RequestManager.cs similarity index 98% rename from src/Services/Ordering/Ordering.Infrastructure/Repositories/RequestManager.cs rename to src/Services/Ordering/Ordering.Infrastructure/Idempotency/RequestManager.cs index a6d795214..0ef005161 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/Repositories/RequestManager.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/Idempotency/RequestManager.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Text; using System.Threading.Tasks; -namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositories +namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency { public class RequestManager : IRequestManager { diff --git a/test/Services/UnitTest/Ordering/Application/IdentifierCommandHandlerTest.cs b/test/Services/UnitTest/Ordering/Application/IdentifierCommandHandlerTest.cs index 63e2e01e1..66070c497 100644 --- a/test/Services/UnitTest/Ordering/Application/IdentifierCommandHandlerTest.cs +++ b/test/Services/UnitTest/Ordering/Application/IdentifierCommandHandlerTest.cs @@ -6,7 +6,7 @@ namespace UnitTest.Ordering.Application { using MediatR; using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; - using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositories; + using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency; using Moq; using System.Collections; using System.Collections.Generic; diff --git a/test/Services/UnitTest/Ordering/Domain/BuyerAggregateTest.cs b/test/Services/UnitTest/Ordering/Domain/BuyerAggregateTest.cs index 32e3bb807..76fd4e9a5 100644 --- a/test/Services/UnitTest/Ordering/Domain/BuyerAggregateTest.cs +++ b/test/Services/UnitTest/Ordering/Domain/BuyerAggregateTest.cs @@ -1,4 +1,5 @@ using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate; +using Ordering.Domain.Exceptions; using System; using Xunit; @@ -82,7 +83,7 @@ public class BuyerAggregateTest var expiration = DateTime.Now.AddYears(-1); //Act - Assert - Assert.Throws(() => new PaymentMethod(cardTypeId, alias, cardNumber, securityNumber, cardHolderName, expiration)); + Assert.Throws(() => new PaymentMethod(cardTypeId, alias, cardNumber, securityNumber, cardHolderName, expiration)); } [Fact] diff --git a/test/Services/UnitTest/Ordering/Domain/OrderAggregateTest.cs b/test/Services/UnitTest/Ordering/Domain/OrderAggregateTest.cs index 61fac6cf1..40bc66431 100644 --- a/test/Services/UnitTest/Ordering/Domain/OrderAggregateTest.cs +++ b/test/Services/UnitTest/Ordering/Domain/OrderAggregateTest.cs @@ -1,5 +1,6 @@ using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; using Ordering.Domain.Events; +using Ordering.Domain.Exceptions; using System; using Xunit; @@ -38,7 +39,7 @@ public class OrderAggregateTest var units = -1; //Act - Assert - Assert.Throws(() => new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units)); + Assert.Throws(() => new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units)); } [Fact] @@ -53,7 +54,7 @@ public class OrderAggregateTest var units = 1; //Act - Assert - Assert.Throws(() => new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units)); + Assert.Throws(() => new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units)); } [Fact] @@ -71,7 +72,7 @@ public class OrderAggregateTest var fakeOrderItem = new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units); //Assert - Assert.Throws(() => fakeOrderItem.SetNewDiscount(-1)); + Assert.Throws(() => fakeOrderItem.SetNewDiscount(-1)); } [Fact] @@ -89,7 +90,7 @@ public class OrderAggregateTest var fakeOrderItem = new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units); //Assert - Assert.Throws(() => fakeOrderItem.AddUnits(-1)); + Assert.Throws(() => fakeOrderItem.AddUnits(-1)); } [Fact]