Browse Source

Refactoring of idempotent elements and logic.

pull/144/head
dsanz 7 years ago
parent
commit
cea9600227
11 changed files with 20 additions and 18 deletions
  1. +2
    -0
      src/BuildingBlocks/EventBus/EventBus/Events/IntegrationEvent.cs
  2. +1
    -1
      src/BuildingBlocks/EventBus/IntegrationEventLogEF/IntegrationEventLogEntry.cs
  3. +4
    -4
      src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedIntegrationEventHandler.cs
  4. +1
    -1
      src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs
  5. +1
    -4
      src/Services/Ordering/Ordering.API/Application/Commands/IdentifierCommandHandler.cs
  6. +1
    -0
      src/Services/Ordering/Ordering.API/Infrastructure/AutofacModules/ApplicationModule.cs
  7. +1
    -1
      src/Services/Ordering/Ordering.Infrastructure/Idempotency/IRequestManager.cs
  8. +1
    -1
      src/Services/Ordering/Ordering.Infrastructure/Idempotency/RequestManager.cs
  9. +1
    -1
      test/Services/UnitTest/Ordering/Application/IdentifierCommandHandlerTest.cs
  10. +2
    -1
      test/Services/UnitTest/Ordering/Domain/BuyerAggregateTest.cs
  11. +5
    -4
      test/Services/UnitTest/Ordering/Domain/OrderAggregateTest.cs

+ 2
- 0
src/BuildingBlocks/EventBus/EventBus/Events/IntegrationEvent.cs View File

@ -9,8 +9,10 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events
public IntegrationEvent() public IntegrationEvent()
{ {
Id = Guid.NewGuid(); Id = Guid.NewGuid();
CreationDate = DateTime.UtcNow;
} }
public Guid Id { get; } public Guid Id { get; }
public DateTime CreationDate { get; }
} }
} }

+ 1
- 1
src/BuildingBlocks/EventBus/IntegrationEventLogEF/IntegrationEventLogEntry.cs View File

@ -12,7 +12,7 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF
public IntegrationEventLogEntry(IntegrationEvent @event) public IntegrationEventLogEntry(IntegrationEvent @event)
{ {
EventId = @event.Id; EventId = @event.Id;
CreationTime = DateTime.UtcNow;
CreationTime = @event.CreationDate;
EventTypeName = @event.GetType().FullName; EventTypeName = @event.GetType().FullName;
Content = JsonConvert.SerializeObject(@event); Content = JsonConvert.SerializeObject(@event);
State = EventStateEnum.NotPublished; State = EventStateEnum.NotPublished;


+ 4
- 4
src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedIntegrationEventHandler.cs View File

@ -20,18 +20,18 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even
foreach (var id in userIds) foreach (var id in userIds)
{ {
var basket = await _repository.GetBasket(id); 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(); var itemsToUpdate = basket?.Items?.Where(x => int.Parse(x.ProductId) == productId).ToList();
if (itemsToUpdate != null) if (itemsToUpdate != null)
{ {
foreach (var item in itemsToUpdate) foreach (var item in itemsToUpdate)
{ {
if(item.UnitPrice != newPrice)
if(item.UnitPrice == oldPrice)
{ {
var originalPrice = item.UnitPrice; var originalPrice = item.UnitPrice;
item.UnitPrice = newPrice; item.UnitPrice = newPrice;
@ -39,7 +39,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even
} }
} }
await _repository.UpdateBasket(basket); await _repository.UpdateBasket(basket);
}
}
} }
} }
} }


+ 1
- 1
src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs View File

@ -3,7 +3,7 @@
using Domain.AggregatesModel.OrderAggregate; using Domain.AggregatesModel.OrderAggregate;
using MediatR; using MediatR;
using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services; 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;
using System.Threading.Tasks; using System.Threading.Tasks;


+ 1
- 4
src/Services/Ordering/Ordering.API/Application/Commands/IdentifierCommandHandler.cs View File

@ -1,8 +1,5 @@
using MediatR; 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; using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands


+ 1
- 0
src/Services/Ordering/Ordering.API/Infrastructure/AutofacModules/ApplicationModule.cs View File

@ -2,6 +2,7 @@
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries; using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency;
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositories; using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositories;
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.AutofacModules namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.AutofacModules


src/Services/Ordering/Ordering.Infrastructure/Repositories/IRequestManager.cs → src/Services/Ordering/Ordering.Infrastructure/Idempotency/IRequestManager.cs View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositories
namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency
{ {
public interface IRequestManager public interface IRequestManager
{ {

src/Services/Ordering/Ordering.Infrastructure/Repositories/RequestManager.cs → src/Services/Ordering/Ordering.Infrastructure/Idempotency/RequestManager.cs View File

@ -5,7 +5,7 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositories
namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency
{ {
public class RequestManager : IRequestManager public class RequestManager : IRequestManager
{ {

+ 1
- 1
test/Services/UnitTest/Ordering/Application/IdentifierCommandHandlerTest.cs View File

@ -6,7 +6,7 @@ namespace UnitTest.Ordering.Application
{ {
using MediatR; using MediatR;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; 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 Moq;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;


+ 2
- 1
test/Services/UnitTest/Ordering/Domain/BuyerAggregateTest.cs View File

@ -1,4 +1,5 @@
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate;
using Ordering.Domain.Exceptions;
using System; using System;
using Xunit; using Xunit;
@ -82,7 +83,7 @@ public class BuyerAggregateTest
var expiration = DateTime.Now.AddYears(-1); var expiration = DateTime.Now.AddYears(-1);
//Act - Assert //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] [Fact]


+ 5
- 4
test/Services/UnitTest/Ordering/Domain/OrderAggregateTest.cs View File

@ -1,5 +1,6 @@
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Ordering.Domain.Events; using Ordering.Domain.Events;
using Ordering.Domain.Exceptions;
using System; using System;
using Xunit; using Xunit;
@ -38,7 +39,7 @@ public class OrderAggregateTest
var units = -1; var units = -1;
//Act - Assert //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] [Fact]
@ -53,7 +54,7 @@ public class OrderAggregateTest
var units = 1; var units = 1;
//Act - Assert //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] [Fact]
@ -71,7 +72,7 @@ public class OrderAggregateTest
var fakeOrderItem = new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units); var fakeOrderItem = new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units);
//Assert //Assert
Assert.Throws<ArgumentException>(() => fakeOrderItem.SetNewDiscount(-1));
Assert.Throws<OrderingDomainException>(() => fakeOrderItem.SetNewDiscount(-1));
} }
[Fact] [Fact]
@ -89,7 +90,7 @@ public class OrderAggregateTest
var fakeOrderItem = new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units); var fakeOrderItem = new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units);
//Assert //Assert
Assert.Throws<ArgumentException>(() => fakeOrderItem.AddUnits(-1));
Assert.Throws<OrderingDomainException>(() => fakeOrderItem.AddUnits(-1));
} }
[Fact] [Fact]


Loading…
Cancel
Save