Refactoring of idempotent elements and logic.
This commit is contained in:
parent
53bdf6de04
commit
cea9600227
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
{
|
@ -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
|
||||
{
|
@ -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;
|
||||
|
@ -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<ArgumentException>(() => new PaymentMethod(cardTypeId, alias, cardNumber, securityNumber, cardHolderName, expiration));
|
||||
Assert.Throws<OrderingDomainException>(() => new PaymentMethod(cardTypeId, alias, cardNumber, securityNumber, cardHolderName, expiration));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -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<ArgumentNullException>(() => new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units));
|
||||
Assert.Throws<OrderingDomainException>(() => new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -53,7 +54,7 @@ public class OrderAggregateTest
|
||||
var units = 1;
|
||||
|
||||
//Act - Assert
|
||||
Assert.Throws<ArgumentException>(() => new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units));
|
||||
Assert.Throws<OrderingDomainException>(() => 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<ArgumentException>(() => fakeOrderItem.SetNewDiscount(-1));
|
||||
Assert.Throws<OrderingDomainException>(() => fakeOrderItem.SetNewDiscount(-1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -89,7 +90,7 @@ public class OrderAggregateTest
|
||||
var fakeOrderItem = new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units);
|
||||
|
||||
//Assert
|
||||
Assert.Throws<ArgumentException>(() => fakeOrderItem.AddUnits(-1));
|
||||
Assert.Throws<OrderingDomainException>(() => fakeOrderItem.AddUnits(-1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
Loading…
x
Reference in New Issue
Block a user