Browse Source

Merge d4cca7440e into 4267d24a3d

pull/486/merge
Roma Marusyk 7 years ago
committed by GitHub
parent
commit
e8b1ee8256
22 changed files with 93 additions and 109 deletions
  1. +2
    -4
      src/Services/Ordering/Ordering.API/Infrastructure/OrderingContextSeed.cs
  2. +6
    -6
      src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/Buyer.cs
  3. +4
    -6
      src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/CardType.cs
  4. +3
    -2
      src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/IBuyerRepository.cs
  5. +0
    -1
      src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/PaymentMethod.cs
  6. +2
    -1
      src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Address.cs
  7. +2
    -3
      src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/IOrderRepository.cs
  8. +12
    -10
      src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs
  9. +3
    -4
      src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/OrderItem.cs
  10. +4
    -7
      src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/OrderStatus.cs
  11. +2
    -3
      src/Services/Ordering/Ordering.Domain/Events/OrderStartedDomainEvent.cs
  12. +0
    -2
      src/Services/Ordering/Ordering.Domain/Exceptions/OrderingDomainException.cs
  13. +22
    -17
      src/Services/Ordering/Ordering.Domain/SeedWork/Entity.cs
  14. +5
    -10
      src/Services/Ordering/Ordering.Domain/SeedWork/Enumeration.cs
  15. +0
    -2
      src/Services/Ordering/Ordering.Domain/SeedWork/IAggregateRoot.cs
  16. +3
    -2
      src/Services/Ordering/Ordering.Domain/SeedWork/IUnitOfWork.cs
  17. +1
    -0
      src/Services/Ordering/Ordering.Domain/SeedWork/ValueObject.cs
  18. +1
    -1
      src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/BuyerEntityTYpeConfiguration.cs
  19. +2
    -1
      src/Services/Ordering/Ordering.Infrastructure/Idempotency/RequestManager.cs
  20. +14
    -9
      src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs
  21. +4
    -10
      src/Services/Ordering/Ordering.Infrastructure/Repositories/BuyerRepository.cs
  22. +1
    -8
      src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs

+ 2
- 4
src/Services/Ordering/Ordering.API/Infrastructure/OrderingContextSeed.cs View File

@ -26,20 +26,18 @@
await policy.ExecuteAsync(async () => await policy.ExecuteAsync(async () =>
{ {
var useCustomizationData = settings.Value var useCustomizationData = settings.Value
.UseCustomizationData; .UseCustomizationData;
var contentRootPath = env.ContentRootPath; var contentRootPath = env.ContentRootPath;
using (context) using (context)
{ {
context.Database.Migrate(); context.Database.Migrate();
if (!context.CardTypes.Any()) if (!context.CardTypes.Any())
{ {
context.CardTypes.AddRange(useCustomizationData
await context.CardTypes.AddRangeAsync(useCustomizationData
? GetCardTypesFromFile(contentRootPath, logger) ? GetCardTypesFromFile(contentRootPath, logger)
: GetPredefinedCardTypes()); : GetPredefinedCardTypes());
@ -48,7 +46,7 @@
if (!context.OrderStatus.Any()) if (!context.OrderStatus.Any())
{ {
context.OrderStatus.AddRange(useCustomizationData
await context.OrderStatus.AddRangeAsync(useCustomizationData
? GetOrderStatusFromFile(contentRootPath, logger) ? GetOrderStatusFromFile(contentRootPath, logger)
: GetPredefinedOrderStatus()); : GetPredefinedOrderStatus());
} }


+ 6
- 6
src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/Buyer.cs View File

@ -7,16 +7,16 @@ using System.Linq;
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate
{ {
public class Buyer public class Buyer
: Entity, IAggregateRoot
: Entity, IAggregateRoot
{ {
public string IdentityGuid { get; private set; } public string IdentityGuid { get; private set; }
private List<PaymentMethod> _paymentMethods;
private List<PaymentMethod> _paymentMethods;
public IEnumerable<PaymentMethod> PaymentMethods => _paymentMethods.AsReadOnly(); public IEnumerable<PaymentMethod> PaymentMethods => _paymentMethods.AsReadOnly();
protected Buyer() {
protected Buyer()
{
_paymentMethods = new List<PaymentMethod>(); _paymentMethods = new List<PaymentMethod>();
} }
@ -29,8 +29,8 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
int cardTypeId, string alias, string cardNumber, int cardTypeId, string alias, string cardNumber,
string securityNumber, string cardHolderName, DateTime expiration, int orderId) string securityNumber, string cardHolderName, DateTime expiration, int orderId)
{ {
var existingPayment = _paymentMethods.Where(p => p.IsEqualTo(cardTypeId, cardNumber, expiration))
.SingleOrDefault();
var existingPayment = _paymentMethods
.SingleOrDefault(p => p.IsEqualTo(cardTypeId, cardNumber, expiration));
if (existingPayment != null) if (existingPayment != null)
{ {


+ 4
- 6
src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/CardType.cs View File

@ -5,20 +5,18 @@ using System.Linq;
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate
{ {
public class CardType public class CardType
: Enumeration : Enumeration
{ {
public static CardType Amex = new CardType(1, "Amex");
public static CardType Visa = new CardType(2, "Visa");
public static CardType MasterCard = new CardType(3, "MasterCard");
public static readonly CardType Amex = new CardType(1, "Amex");
public static readonly CardType Visa = new CardType(2, "Visa");
public static readonly CardType MasterCard = new CardType(3, "MasterCard");
protected CardType() { } protected CardType() { }
public CardType(int id, string name) public CardType(int id, string name)
: base(id, name) : base(id, name)
{ {
} }
public static IEnumerable<CardType> List() public static IEnumerable<CardType> List()
@ -33,7 +31,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
if (state == null) if (state == null)
{ {
throw new ArgumentException($"Possible values for CardType: {String.Join(",", List().Select(s => s.Name))}");
throw new ArgumentException($"Possible values for CardType: {string.Join(",", List().Select(s => s.Name))}");
} }
return state; return state;


+ 3
- 2
src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/IBuyerRepository.cs View File

@ -6,10 +6,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
//This is just the RepositoryContracts or Interface defined at the Domain Layer //This is just the RepositoryContracts or Interface defined at the Domain Layer
//as requisite for the Buyer Aggregate //as requisite for the Buyer Aggregate
public interface IBuyerRepository : IRepository<Buyer>
public interface IBuyerRepository
: IRepository<Buyer>
{ {
Buyer Add(Buyer buyer); Buyer Add(Buyer buyer);
Buyer Update(Buyer buyer); Buyer Update(Buyer buyer);
Task<Buyer> FindAsync(string BuyerIdentityGuid);
Task<Buyer> FindAsync(string buyerIdentityGuid);
} }
} }

+ 0
- 1
src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/PaymentMethod.cs View File

@ -21,7 +21,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
public PaymentMethod(int cardTypeId, string alias, string cardNumber, string securityNumber, string cardHolderName, DateTime expiration) public PaymentMethod(int cardTypeId, string alias, string cardNumber, string securityNumber, string cardHolderName, DateTime expiration)
{ {
_cardNumber = !string.IsNullOrWhiteSpace(cardNumber) ? cardNumber : throw new OrderingDomainException(nameof(cardNumber)); _cardNumber = !string.IsNullOrWhiteSpace(cardNumber) ? cardNumber : throw new OrderingDomainException(nameof(cardNumber));
_securityNumber = !string.IsNullOrWhiteSpace(securityNumber) ? securityNumber : throw new OrderingDomainException(nameof(securityNumber)); _securityNumber = !string.IsNullOrWhiteSpace(securityNumber) ? securityNumber : throw new OrderingDomainException(nameof(securityNumber));
_cardHolderName = !string.IsNullOrWhiteSpace(cardHolderName) ? cardHolderName : throw new OrderingDomainException(nameof(cardHolderName)); _cardHolderName = !string.IsNullOrWhiteSpace(cardHolderName) ? cardHolderName : throw new OrderingDomainException(nameof(cardHolderName));


+ 2
- 1
src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Address.cs View File

@ -4,7 +4,8 @@ using System.Collections.Generic;
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
{ {
public class Address : ValueObject
public class Address
: ValueObject
{ {
public String Street { get; private set; } public String Street { get; private set; }
public String City { get; private set; } public String City { get; private set; }


+ 2
- 3
src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/IOrderRepository.cs View File

@ -6,12 +6,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
//This is just the RepositoryContracts or Interface defined at the Domain Layer //This is just the RepositoryContracts or Interface defined at the Domain Layer
//as requisite for the Order Aggregate //as requisite for the Order Aggregate
public interface IOrderRepository : IRepository<Order>
public interface IOrderRepository
: IRepository<Order>
{ {
Order Add(Order order); Order Add(Order order);
void Update(Order order); void Update(Order order);
Task<Order> GetAsync(int orderId); Task<Order> GetAsync(int orderId);
} }
} }

+ 12
- 10
src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs View File

@ -34,10 +34,13 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
private int? _paymentMethodId; private int? _paymentMethodId;
protected Order() { _orderItems = new List<OrderItem>(); }
protected Order()
{
_orderItems = new List<OrderItem>();
}
public Order(string userId, Address address, int cardTypeId, string cardNumber, string cardSecurityNumber, public Order(string userId, Address address, int cardTypeId, string cardNumber, string cardSecurityNumber,
string cardHolderName, DateTime cardExpiration, int? buyerId = null, int? paymentMethodId = null)
string cardHolderName, DateTime cardExpiration, int? buyerId = null, int? paymentMethodId = null)
{ {
_orderItems = new List<OrderItem>(); _orderItems = new List<OrderItem>();
_buyerId = buyerId; _buyerId = buyerId;
@ -58,8 +61,8 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
// in order to maintain consistency between the whole Aggregate. // in order to maintain consistency between the whole Aggregate.
public void AddOrderItem(int productId, string productName, decimal unitPrice, decimal discount, string pictureUrl, int units = 1) public void AddOrderItem(int productId, string productName, decimal unitPrice, decimal discount, string pictureUrl, int units = 1)
{ {
var existingOrderForProduct = _orderItems.Where(o => o.ProductId == productId)
.SingleOrDefault();
var existingOrderForProduct = _orderItems
.SingleOrDefault(o => o.ProductId == productId);
if (existingOrderForProduct != null) if (existingOrderForProduct != null)
{ {
@ -92,12 +95,12 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
} }
public void SetAwaitingValidationStatus() public void SetAwaitingValidationStatus()
{
{
if (_orderStatusId == OrderStatus.Submitted.Id) if (_orderStatusId == OrderStatus.Submitted.Id)
{ {
AddDomainEvent(new OrderStatusChangedToAwaitingValidationDomainEvent(Id, _orderItems)); AddDomainEvent(new OrderStatusChangedToAwaitingValidationDomainEvent(Id, _orderItems));
_orderStatusId = OrderStatus.AwaitingValidation.Id; _orderStatusId = OrderStatus.AwaitingValidation.Id;
}
}
} }
public void SetStockConfirmedStatus() public void SetStockConfirmedStatus()
@ -157,11 +160,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
var itemsStockRejectedDescription = string.Join(", ", itemsStockRejectedProductNames); var itemsStockRejectedDescription = string.Join(", ", itemsStockRejectedProductNames);
_description = $"The product items don't have stock: ({itemsStockRejectedDescription})."; _description = $"The product items don't have stock: ({itemsStockRejectedDescription}).";
}
}
} }
private void AddOrderStartedDomainEvent(string userId, int cardTypeId, string cardNumber, private void AddOrderStartedDomainEvent(string userId, int cardTypeId, string cardNumber,
string cardSecurityNumber, string cardHolderName, DateTime cardExpiration)
string cardSecurityNumber, string cardHolderName, DateTime cardExpiration)
{ {
var orderStartedDomainEvent = new OrderStartedDomainEvent(this, userId, cardTypeId, var orderStartedDomainEvent = new OrderStartedDomainEvent(this, userId, cardTypeId,
cardNumber, cardSecurityNumber, cardNumber, cardSecurityNumber,
@ -180,5 +183,4 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
return _orderItems.Sum(o => o.GetUnits() * o.GetUnitPrice()); return _orderItems.Sum(o => o.GetUnits() * o.GetUnitPrice());
} }
} }
}
}

+ 3
- 4
src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/OrderItem.cs View File

@ -1,6 +1,5 @@
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork; using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
using Ordering.Domain.Exceptions; using Ordering.Domain.Exceptions;
using System;
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
{ {
@ -20,7 +19,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
protected OrderItem() { } protected OrderItem() { }
public OrderItem(int productId, string productName, decimal unitPrice, decimal discount, string PictureUrl, int units = 1)
public OrderItem(int productId, string productName, decimal unitPrice, decimal discount, string pictureUrl, int units = 1)
{ {
if (units <= 0) if (units <= 0)
{ {
@ -38,12 +37,12 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
_unitPrice = unitPrice; _unitPrice = unitPrice;
_discount = discount; _discount = discount;
_units = units; _units = units;
_pictureUrl = PictureUrl;
_pictureUrl = pictureUrl;
} }
public void SetPictureUri(string pictureUri) public void SetPictureUri(string pictureUri)
{ {
if (!String.IsNullOrWhiteSpace(pictureUri))
if (!string.IsNullOrWhiteSpace(pictureUri))
{ {
_pictureUrl = pictureUri; _pictureUrl = pictureUri;
} }


+ 4
- 7
src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/OrderStatus.cs View File

@ -1,7 +1,6 @@
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
{ {
using global::Ordering.Domain.Exceptions; using global::Ordering.Domain.Exceptions;
using Seedwork;
using SeedWork; using SeedWork;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -17,9 +16,7 @@
public static OrderStatus Shipped = new OrderStatus(5, nameof(Shipped).ToLowerInvariant()); public static OrderStatus Shipped = new OrderStatus(5, nameof(Shipped).ToLowerInvariant());
public static OrderStatus Cancelled = new OrderStatus(6, nameof(Cancelled).ToLowerInvariant()); public static OrderStatus Cancelled = new OrderStatus(6, nameof(Cancelled).ToLowerInvariant());
protected OrderStatus()
{
}
protected OrderStatus() { }
public OrderStatus(int id, string name) public OrderStatus(int id, string name)
: base(id, name) : base(id, name)
@ -32,11 +29,11 @@
public static OrderStatus FromName(string name) public static OrderStatus FromName(string name)
{ {
var state = List() var state = List()
.SingleOrDefault(s => String.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase));
.SingleOrDefault(s => string.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase));
if (state == null) if (state == null)
{ {
throw new OrderingDomainException($"Possible values for OrderStatus: {String.Join(",", List().Select(s => s.Name))}");
throw new OrderingDomainException($"Possible values for OrderStatus: {string.Join(",", List().Select(s => s.Name))}");
} }
return state; return state;
@ -48,7 +45,7 @@
if (state == null) if (state == null)
{ {
throw new OrderingDomainException($"Possible values for OrderStatus: {String.Join(",", List().Select(s => s.Name))}");
throw new OrderingDomainException($"Possible values for OrderStatus: {string.Join(",", List().Select(s => s.Name))}");
} }
return state; return state;


+ 2
- 3
src/Services/Ordering/Ordering.Domain/Events/OrderStartedDomainEvent.cs View File

@ -1,15 +1,14 @@
using MediatR; using MediatR;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using System; using System;
using System.Collections.Generic;
using System.Text;
namespace Ordering.Domain.Events namespace Ordering.Domain.Events
{ {
/// <summary> /// <summary>
/// Event used when an order is created /// Event used when an order is created
/// </summary> /// </summary>
public class OrderStartedDomainEvent : INotification
public class OrderStartedDomainEvent
: INotification
{ {
public string UserId { get; private set; } public string UserId { get; private set; }
public int CardTypeId { get; private set; } public int CardTypeId { get; private set; }


+ 0
- 2
src/Services/Ordering/Ordering.Domain/Exceptions/OrderingDomainException.cs View File

@ -1,6 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Text;
namespace Ordering.Domain.Exceptions namespace Ordering.Domain.Exceptions
{ {


+ 22
- 17
src/Services/Ordering/Ordering.Domain/SeedWork/Entity.cs View File

@ -1,33 +1,27 @@
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork
{ {
using System;
using MediatR; using MediatR;
using System.Collections.Generic; using System.Collections.Generic;
public abstract class Entity public abstract class Entity
{ {
int? _requestedHashCode; int? _requestedHashCode;
int _Id;
int _Id;
public virtual int Id public virtual int Id
{ {
get
{
return _Id;
}
protected set
{
_Id = value;
}
get => _Id;
protected set => _Id = value;
} }
private List<INotification> _domainEvents; private List<INotification> _domainEvents;
public List<INotification> DomainEvents => _domainEvents; public List<INotification> DomainEvents => _domainEvents;
public void AddDomainEvent(INotification eventItem) public void AddDomainEvent(INotification eventItem)
{ {
_domainEvents = _domainEvents ?? new List<INotification>(); _domainEvents = _domainEvents ?? new List<INotification>();
_domainEvents.Add(eventItem); _domainEvents.Add(eventItem);
} }
public void RemoveDomainEvent(INotification eventItem) public void RemoveDomainEvent(INotification eventItem)
{ {
if (_domainEvents is null) return; if (_domainEvents is null) return;
@ -36,15 +30,15 @@
public bool IsTransient() public bool IsTransient()
{ {
return this.Id == default(Int32);
return this.Id == default(int);
} }
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj == null || !(obj is Entity))
if (!(obj is Entity))
return false; return false;
if (Object.ReferenceEquals(this, obj))
if (object.ReferenceEquals(this, obj))
return true; return true;
if (this.GetType() != obj.GetType()) if (this.GetType() != obj.GetType())
@ -53,9 +47,13 @@
Entity item = (Entity)obj; Entity item = (Entity)obj;
if (item.IsTransient() || this.IsTransient()) if (item.IsTransient() || this.IsTransient())
{
return false; return false;
}
else else
{
return item.Id == this.Id; return item.Id == this.Id;
}
} }
public override int GetHashCode() public override int GetHashCode()
@ -63,20 +61,27 @@
if (!IsTransient()) if (!IsTransient())
{ {
if (!_requestedHashCode.HasValue) if (!_requestedHashCode.HasValue)
{
_requestedHashCode = this.Id.GetHashCode() ^ 31; // XOR for random distribution (http://blogs.msdn.com/b/ericlippert/archive/2011/02/28/guidelines-and-rules-for-gethashcode.aspx) _requestedHashCode = this.Id.GetHashCode() ^ 31; // XOR for random distribution (http://blogs.msdn.com/b/ericlippert/archive/2011/02/28/guidelines-and-rules-for-gethashcode.aspx)
}
return _requestedHashCode.Value; return _requestedHashCode.Value;
} }
else else
{
return base.GetHashCode(); return base.GetHashCode();
}
} }
public static bool operator ==(Entity left, Entity right) public static bool operator ==(Entity left, Entity right)
{ {
if (Object.Equals(left, null))
return (Object.Equals(right, null)) ? true : false;
if (object.Equals(left, null))
{
return object.Equals(right, null);
}
else else
{
return left.Equals(right); return left.Equals(right);
}
} }
public static bool operator !=(Entity left, Entity right) public static bool operator !=(Entity left, Entity right)


+ 5
- 10
src/Services/Ordering/Ordering.Domain/SeedWork/Enumeration.cs View File

@ -5,15 +5,14 @@ using System.Reflection;
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork
{ {
public abstract class Enumeration : IComparable
public abstract class Enumeration
: IComparable
{ {
public string Name { get; private set; } public string Name { get; private set; }
public int Id { get; private set; } public int Id { get; private set; }
protected Enumeration()
{
}
protected Enumeration() { }
protected Enumeration(int id, string name) protected Enumeration(int id, string name)
{ {
@ -34,9 +33,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork
foreach (var info in fields) foreach (var info in fields)
{ {
var instance = new T(); var instance = new T();
var locatedValue = info.GetValue(instance) as T;
if (locatedValue != null)
if (info.GetValue(instance) is T locatedValue)
{ {
yield return locatedValue; yield return locatedValue;
} }
@ -45,9 +42,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
var otherValue = obj as Enumeration;
if (otherValue == null)
if (!(obj is Enumeration otherValue))
{ {
return false; return false;
} }


+ 0
- 2
src/Services/Ordering/Ordering.Domain/SeedWork/IAggregateRoot.cs View File

@ -1,6 +1,4 @@
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork
{ {
public interface IAggregateRoot { } public interface IAggregateRoot { }
} }

+ 3
- 2
src/Services/Ordering/Ordering.Domain/SeedWork/IUnitOfWork.cs View File

@ -4,8 +4,9 @@ using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork
{ {
public interface IUnitOfWork : IDisposable
{
public interface IUnitOfWork
: IDisposable
{
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken)); Task<int> SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken));
Task<bool> SaveEntitiesAsync(CancellationToken cancellationToken = default(CancellationToken)); Task<bool> SaveEntitiesAsync(CancellationToken cancellationToken = default(CancellationToken));
} }


+ 1
- 0
src/Services/Ordering/Ordering.Domain/SeedWork/ValueObject.cs View File

@ -27,6 +27,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork
{ {
return false; return false;
} }
ValueObject other = (ValueObject)obj; ValueObject other = (ValueObject)obj;
IEnumerator<object> thisValues = GetAtomicValues().GetEnumerator(); IEnumerator<object> thisValues = GetAtomicValues().GetEnumerator();
IEnumerator<object> otherValues = other.GetAtomicValues().GetEnumerator(); IEnumerator<object> otherValues = other.GetAtomicValues().GetEnumerator();


+ 1
- 1
src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/BuyerEntityTYpeConfiguration.cs View File

@ -24,7 +24,7 @@ namespace Ordering.Infrastructure.EntityConfigurations
.IsRequired(); .IsRequired();
buyerConfiguration.HasIndex("IdentityGuid") buyerConfiguration.HasIndex("IdentityGuid")
.IsUnique(true);
.IsUnique();
buyerConfiguration.HasMany(b => b.PaymentMethods) buyerConfiguration.HasMany(b => b.PaymentMethods)
.WithOne() .WithOne()


+ 2
- 1
src/Services/Ordering/Ordering.Infrastructure/Idempotency/RequestManager.cs View File

@ -4,7 +4,8 @@ using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency
{ {
public class RequestManager : IRequestManager
public class RequestManager
: IRequestManager
{ {
private readonly OrderingContext _context; private readonly OrderingContext _context;


+ 14
- 9
src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs View File

@ -12,7 +12,8 @@ using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
{ {
public class OrderingContext : DbContext, IUnitOfWork
public class OrderingContext
: DbContext, IUnitOfWork
{ {
public const string DEFAULT_SCHEMA = "ordering"; public const string DEFAULT_SCHEMA = "ordering";
public DbSet<Order> Orders { get; set; } public DbSet<Order> Orders { get; set; }
@ -24,13 +25,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
private readonly IMediator _mediator; private readonly IMediator _mediator;
private OrderingContext(DbContextOptions<OrderingContext> options) : base (options) { }
private OrderingContext(DbContextOptions<OrderingContext> options)
: base (options) { }
public OrderingContext(DbContextOptions<OrderingContext> options, IMediator mediator) : base(options)
public OrderingContext(DbContextOptions<OrderingContext> options, IMediator mediator)
: base(options)
{ {
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
System.Diagnostics.Debug.WriteLine("OrderingContext::ctor ->" + this.GetHashCode()); System.Diagnostics.Debug.WriteLine("OrderingContext::ctor ->" + this.GetHashCode());
} }
@ -57,13 +59,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
// After executing this line all the changes (from the Command Handler and Domain Event Handlers) // After executing this line all the changes (from the Command Handler and Domain Event Handlers)
// performed throught the DbContext will be commited // performed throught the DbContext will be commited
var result = await base.SaveChangesAsync();
var result = await base.SaveChangesAsync(cancellationToken);
return true; return true;
}
}
} }
public class OrderingContextDesignFactory : IDesignTimeDbContextFactory<OrderingContext>
public class OrderingContextDesignFactory
: IDesignTimeDbContextFactory<OrderingContext>
{ {
public OrderingContext CreateDbContext(string[] args) public OrderingContext CreateDbContext(string[] args)
{ {
@ -73,9 +76,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
return new OrderingContext(optionsBuilder.Options,new NoMediator()); return new OrderingContext(optionsBuilder.Options,new NoMediator());
} }
class NoMediator : IMediator
class NoMediator
: IMediator
{ {
public Task Publish<TNotification>(TNotification notification, CancellationToken cancellationToken = default(CancellationToken)) where TNotification : INotification
public Task Publish<TNotification>(TNotification notification, CancellationToken cancellationToken = default(CancellationToken))
where TNotification : INotification
{ {
return Task.CompletedTask; return Task.CompletedTask;
} }


+ 4
- 10
src/Services/Ordering/Ordering.Infrastructure/Repositories/BuyerRepository.cs View File

@ -11,13 +11,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositor
: IBuyerRepository : IBuyerRepository
{ {
private readonly OrderingContext _context; private readonly OrderingContext _context;
public IUnitOfWork UnitOfWork
{
get
{
return _context;
}
}
public IUnitOfWork UnitOfWork => _context;
public BuyerRepository(OrderingContext context) public BuyerRepository(OrderingContext context)
{ {
@ -35,14 +29,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositor
else else
{ {
return buyer; return buyer;
}
}
} }
public Buyer Update(Buyer buyer) public Buyer Update(Buyer buyer)
{ {
return _context.Buyers return _context.Buyers
.Update(buyer)
.Entity;
.Update(buyer)
.Entity;
} }
public async Task<Buyer> FindAsync(string identity) public async Task<Buyer> FindAsync(string identity)


+ 1
- 8
src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs View File

@ -1,7 +1,6 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork; using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
using Ordering.Domain.Exceptions;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -12,13 +11,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositor
{ {
private readonly OrderingContext _context; private readonly OrderingContext _context;
public IUnitOfWork UnitOfWork
{
get
{
return _context;
}
}
public IUnitOfWork UnitOfWork => _context;
public OrderRepository(OrderingContext context) public OrderRepository(OrderingContext context)
{ {


Loading…
Cancel
Save