From d4cca7440eb3f94069bc97102be0f0262049ba02 Mon Sep 17 00:00:00 2001 From: Roma Marusyk Date: Sun, 28 Jan 2018 22:11:09 +0200 Subject: [PATCH] Code style refactoring for Ordering service --- .../Infrastructure/OrderingContextSeed.cs | 6 +-- .../AggregatesModel/BuyerAggregate/Buyer.cs | 12 +++--- .../BuyerAggregate/CardType.cs | 10 ++--- .../BuyerAggregate/IBuyerRepository.cs | 5 ++- .../BuyerAggregate/PaymentMethod.cs | 1 - .../AggregatesModel/OrderAggregate/Address.cs | 3 +- .../OrderAggregate/IOrderRepository.cs | 5 +-- .../AggregatesModel/OrderAggregate/Order.cs | 22 ++++++----- .../OrderAggregate/OrderItem.cs | 7 ++-- .../OrderAggregate/OrderStatus.cs | 11 ++---- .../Events/OrderStartedDomainEvent.cs | 5 +-- .../Exceptions/OrderingDomainException.cs | 2 - .../Ordering.Domain/SeedWork/Entity.cs | 39 +++++++++++-------- .../Ordering.Domain/SeedWork/Enumeration.cs | 15 +++---- .../SeedWork/IAggregateRoot.cs | 2 - .../Ordering.Domain/SeedWork/IUnitOfWork.cs | 5 ++- .../Ordering.Domain/SeedWork/ValueObject.cs | 1 + .../BuyerEntityTYpeConfiguration.cs | 2 +- .../Idempotency/RequestManager.cs | 3 +- .../OrderingContext.cs | 23 ++++++----- .../Repositories/BuyerRepository.cs | 14 ++----- .../Repositories/OrderRepository.cs | 9 +---- 22 files changed, 93 insertions(+), 109 deletions(-) diff --git a/src/Services/Ordering/Ordering.API/Infrastructure/OrderingContextSeed.cs b/src/Services/Ordering/Ordering.API/Infrastructure/OrderingContextSeed.cs index 53c53f052..d703a151b 100644 --- a/src/Services/Ordering/Ordering.API/Infrastructure/OrderingContextSeed.cs +++ b/src/Services/Ordering/Ordering.API/Infrastructure/OrderingContextSeed.cs @@ -26,20 +26,18 @@ await policy.ExecuteAsync(async () => { - var useCustomizationData = settings.Value .UseCustomizationData; var contentRootPath = env.ContentRootPath; - using (context) { context.Database.Migrate(); if (!context.CardTypes.Any()) { - context.CardTypes.AddRange(useCustomizationData + await context.CardTypes.AddRangeAsync(useCustomizationData ? GetCardTypesFromFile(contentRootPath, logger) : GetPredefinedCardTypes()); @@ -48,7 +46,7 @@ if (!context.OrderStatus.Any()) { - context.OrderStatus.AddRange(useCustomizationData + await context.OrderStatus.AddRangeAsync(useCustomizationData ? GetOrderStatusFromFile(contentRootPath, logger) : GetPredefinedOrderStatus()); } diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/Buyer.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/Buyer.cs index c806cebeb..e6fe48fda 100644 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/Buyer.cs +++ b/src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/Buyer.cs @@ -7,16 +7,16 @@ using System.Linq; namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate { public class Buyer - : Entity, IAggregateRoot + : Entity, IAggregateRoot { public string IdentityGuid { get; private set; } - private List _paymentMethods; + private List _paymentMethods; public IEnumerable PaymentMethods => _paymentMethods.AsReadOnly(); - protected Buyer() { - + protected Buyer() + { _paymentMethods = new List(); } @@ -29,8 +29,8 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B int cardTypeId, string alias, string cardNumber, 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) { diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/CardType.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/CardType.cs index 3b8ea4600..ca9e5a014 100644 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/CardType.cs +++ b/src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/CardType.cs @@ -5,20 +5,18 @@ using System.Linq; namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate { - public class CardType : 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() { } public CardType(int id, string name) : base(id, name) { - } public static IEnumerable List() @@ -33,7 +31,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B 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; diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/IBuyerRepository.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/IBuyerRepository.cs index d5a612614..9accfec03 100644 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/IBuyerRepository.cs +++ b/src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/IBuyerRepository.cs @@ -6,10 +6,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B //This is just the RepositoryContracts or Interface defined at the Domain Layer //as requisite for the Buyer Aggregate - public interface IBuyerRepository : IRepository + public interface IBuyerRepository + : IRepository { Buyer Add(Buyer buyer); Buyer Update(Buyer buyer); - Task FindAsync(string BuyerIdentityGuid); + Task FindAsync(string buyerIdentityGuid); } } diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/PaymentMethod.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/PaymentMethod.cs index b307604da..31ec38ad4 100644 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/PaymentMethod.cs +++ b/src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/PaymentMethod.cs @@ -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) { - _cardNumber = !string.IsNullOrWhiteSpace(cardNumber) ? cardNumber : throw new OrderingDomainException(nameof(cardNumber)); _securityNumber = !string.IsNullOrWhiteSpace(securityNumber) ? securityNumber : throw new OrderingDomainException(nameof(securityNumber)); _cardHolderName = !string.IsNullOrWhiteSpace(cardHolderName) ? cardHolderName : throw new OrderingDomainException(nameof(cardHolderName)); diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Address.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Address.cs index 9576940df..f6663ff4d 100644 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Address.cs +++ b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Address.cs @@ -4,7 +4,8 @@ using System.Collections.Generic; namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate { - public class Address : ValueObject + public class Address + : ValueObject { public String Street { get; private set; } public String City { get; private set; } diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/IOrderRepository.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/IOrderRepository.cs index d7346ee4f..1c5be647e 100644 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/IOrderRepository.cs +++ b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/IOrderRepository.cs @@ -6,12 +6,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O //This is just the RepositoryContracts or Interface defined at the Domain Layer //as requisite for the Order Aggregate - public interface IOrderRepository : IRepository + public interface IOrderRepository + : IRepository { Order Add(Order order); - void Update(Order order); - Task GetAsync(int orderId); } } diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs index d2e742b33..cfa0636eb 100644 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs +++ b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs @@ -34,10 +34,13 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O private int? _paymentMethodId; - protected Order() { _orderItems = new List(); } + protected Order() + { + _orderItems = new List(); + } 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(); _buyerId = buyerId; @@ -58,8 +61,8 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O // 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) { - var existingOrderForProduct = _orderItems.Where(o => o.ProductId == productId) - .SingleOrDefault(); + var existingOrderForProduct = _orderItems + .SingleOrDefault(o => o.ProductId == productId); if (existingOrderForProduct != null) { @@ -92,12 +95,12 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O } public void SetAwaitingValidationStatus() - { + { if (_orderStatusId == OrderStatus.Submitted.Id) { AddDomainEvent(new OrderStatusChangedToAwaitingValidationDomainEvent(Id, _orderItems)); _orderStatusId = OrderStatus.AwaitingValidation.Id; - } + } } public void SetStockConfirmedStatus() @@ -157,11 +160,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O var itemsStockRejectedDescription = string.Join(", ", itemsStockRejectedProductNames); _description = $"The product items don't have stock: ({itemsStockRejectedDescription})."; - } + } } 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, cardNumber, cardSecurityNumber, @@ -180,5 +183,4 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O return _orderItems.Sum(o => o.GetUnits() * o.GetUnitPrice()); } } -} - +} \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/OrderItem.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/OrderItem.cs index 1b7896dcc..28b8264c4 100644 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/OrderItem.cs +++ b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/OrderItem.cs @@ -1,6 +1,5 @@ using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork; using Ordering.Domain.Exceptions; -using System; namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate { @@ -20,7 +19,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O 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) { @@ -38,12 +37,12 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O _unitPrice = unitPrice; _discount = discount; _units = units; - _pictureUrl = PictureUrl; + _pictureUrl = pictureUrl; } public void SetPictureUri(string pictureUri) { - if (!String.IsNullOrWhiteSpace(pictureUri)) + if (!string.IsNullOrWhiteSpace(pictureUri)) { _pictureUrl = pictureUri; } diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/OrderStatus.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/OrderStatus.cs index bc07635ae..80618f9cf 100644 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/OrderStatus.cs +++ b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/OrderStatus.cs @@ -1,7 +1,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate { using global::Ordering.Domain.Exceptions; - using Seedwork; using SeedWork; using System; using System.Collections.Generic; @@ -17,9 +16,7 @@ public static OrderStatus Shipped = new OrderStatus(5, nameof(Shipped).ToLowerInvariant()); public static OrderStatus Cancelled = new OrderStatus(6, nameof(Cancelled).ToLowerInvariant()); - protected OrderStatus() - { - } + protected OrderStatus() { } public OrderStatus(int id, string name) : base(id, name) @@ -32,11 +29,11 @@ public static OrderStatus FromName(string name) { var state = List() - .SingleOrDefault(s => String.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase)); + .SingleOrDefault(s => string.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase)); 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; @@ -48,7 +45,7 @@ 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; diff --git a/src/Services/Ordering/Ordering.Domain/Events/OrderStartedDomainEvent.cs b/src/Services/Ordering/Ordering.Domain/Events/OrderStartedDomainEvent.cs index a457067f6..d625334ba 100644 --- a/src/Services/Ordering/Ordering.Domain/Events/OrderStartedDomainEvent.cs +++ b/src/Services/Ordering/Ordering.Domain/Events/OrderStartedDomainEvent.cs @@ -1,15 +1,14 @@ using MediatR; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; using System; -using System.Collections.Generic; -using System.Text; namespace Ordering.Domain.Events { /// /// Event used when an order is created /// - public class OrderStartedDomainEvent : INotification + public class OrderStartedDomainEvent + : INotification { public string UserId { get; private set; } public int CardTypeId { get; private set; } diff --git a/src/Services/Ordering/Ordering.Domain/Exceptions/OrderingDomainException.cs b/src/Services/Ordering/Ordering.Domain/Exceptions/OrderingDomainException.cs index 7a7320dbf..80c2262ca 100644 --- a/src/Services/Ordering/Ordering.Domain/Exceptions/OrderingDomainException.cs +++ b/src/Services/Ordering/Ordering.Domain/Exceptions/OrderingDomainException.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace Ordering.Domain.Exceptions { diff --git a/src/Services/Ordering/Ordering.Domain/SeedWork/Entity.cs b/src/Services/Ordering/Ordering.Domain/SeedWork/Entity.cs index 11b940218..ae8ad58cc 100644 --- a/src/Services/Ordering/Ordering.Domain/SeedWork/Entity.cs +++ b/src/Services/Ordering/Ordering.Domain/SeedWork/Entity.cs @@ -1,33 +1,27 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork { - using System; using MediatR; using System.Collections.Generic; public abstract class Entity { int? _requestedHashCode; - int _Id; + int _Id; public virtual int Id { - get - { - return _Id; - } - protected set - { - _Id = value; - } + get => _Id; + protected set => _Id = value; } private List _domainEvents; public List DomainEvents => _domainEvents; - + public void AddDomainEvent(INotification eventItem) { _domainEvents = _domainEvents ?? new List(); _domainEvents.Add(eventItem); } + public void RemoveDomainEvent(INotification eventItem) { if (_domainEvents is null) return; @@ -36,15 +30,15 @@ public bool IsTransient() { - return this.Id == default(Int32); + return this.Id == default(int); } public override bool Equals(object obj) { - if (obj == null || !(obj is Entity)) + if (!(obj is Entity)) return false; - if (Object.ReferenceEquals(this, obj)) + if (object.ReferenceEquals(this, obj)) return true; if (this.GetType() != obj.GetType()) @@ -53,9 +47,13 @@ Entity item = (Entity)obj; if (item.IsTransient() || this.IsTransient()) + { return false; + } else + { return item.Id == this.Id; + } } public override int GetHashCode() @@ -63,20 +61,27 @@ if (!IsTransient()) { 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) + } return _requestedHashCode.Value; } else + { return base.GetHashCode(); - + } } 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 + { return left.Equals(right); + } } public static bool operator !=(Entity left, Entity right) diff --git a/src/Services/Ordering/Ordering.Domain/SeedWork/Enumeration.cs b/src/Services/Ordering/Ordering.Domain/SeedWork/Enumeration.cs index ecf248be9..0a671b5ec 100644 --- a/src/Services/Ordering/Ordering.Domain/SeedWork/Enumeration.cs +++ b/src/Services/Ordering/Ordering.Domain/SeedWork/Enumeration.cs @@ -5,15 +5,14 @@ using System.Reflection; namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork { - public abstract class Enumeration : IComparable + public abstract class Enumeration + : IComparable { public string Name { get; private set; } public int Id { get; private set; } - protected Enumeration() - { - } + protected Enumeration() { } protected Enumeration(int id, string name) { @@ -34,9 +33,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork foreach (var info in fields) { var instance = new T(); - var locatedValue = info.GetValue(instance) as T; - - if (locatedValue != null) + if (info.GetValue(instance) is T locatedValue) { yield return locatedValue; } @@ -45,9 +42,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork public override bool Equals(object obj) { - var otherValue = obj as Enumeration; - - if (otherValue == null) + if (!(obj is Enumeration otherValue)) { return false; } diff --git a/src/Services/Ordering/Ordering.Domain/SeedWork/IAggregateRoot.cs b/src/Services/Ordering/Ordering.Domain/SeedWork/IAggregateRoot.cs index 198f37542..a195def31 100644 --- a/src/Services/Ordering/Ordering.Domain/SeedWork/IAggregateRoot.cs +++ b/src/Services/Ordering/Ordering.Domain/SeedWork/IAggregateRoot.cs @@ -1,6 +1,4 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork { - public interface IAggregateRoot { } - } diff --git a/src/Services/Ordering/Ordering.Domain/SeedWork/IUnitOfWork.cs b/src/Services/Ordering/Ordering.Domain/SeedWork/IUnitOfWork.cs index 810f0b2af..95a14eb60 100644 --- a/src/Services/Ordering/Ordering.Domain/SeedWork/IUnitOfWork.cs +++ b/src/Services/Ordering/Ordering.Domain/SeedWork/IUnitOfWork.cs @@ -4,8 +4,9 @@ using System.Threading.Tasks; namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork { - public interface IUnitOfWork : IDisposable - { + public interface IUnitOfWork + : IDisposable + { Task SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken)); Task SaveEntitiesAsync(CancellationToken cancellationToken = default(CancellationToken)); } diff --git a/src/Services/Ordering/Ordering.Domain/SeedWork/ValueObject.cs b/src/Services/Ordering/Ordering.Domain/SeedWork/ValueObject.cs index 40fb117e1..86b55cab4 100644 --- a/src/Services/Ordering/Ordering.Domain/SeedWork/ValueObject.cs +++ b/src/Services/Ordering/Ordering.Domain/SeedWork/ValueObject.cs @@ -27,6 +27,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork { return false; } + ValueObject other = (ValueObject)obj; IEnumerator thisValues = GetAtomicValues().GetEnumerator(); IEnumerator otherValues = other.GetAtomicValues().GetEnumerator(); diff --git a/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/BuyerEntityTYpeConfiguration.cs b/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/BuyerEntityTYpeConfiguration.cs index 177f68d91..c90e5775a 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/BuyerEntityTYpeConfiguration.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/BuyerEntityTYpeConfiguration.cs @@ -24,7 +24,7 @@ namespace Ordering.Infrastructure.EntityConfigurations .IsRequired(); buyerConfiguration.HasIndex("IdentityGuid") - .IsUnique(true); + .IsUnique(); buyerConfiguration.HasMany(b => b.PaymentMethods) .WithOne() diff --git a/src/Services/Ordering/Ordering.Infrastructure/Idempotency/RequestManager.cs b/src/Services/Ordering/Ordering.Infrastructure/Idempotency/RequestManager.cs index 6b6a96579..c7d24efff 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/Idempotency/RequestManager.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/Idempotency/RequestManager.cs @@ -4,7 +4,8 @@ using System.Threading.Tasks; namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency { - public class RequestManager : IRequestManager + public class RequestManager + : IRequestManager { private readonly OrderingContext _context; diff --git a/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs b/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs index a2cfb96a5..37f190796 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs @@ -12,7 +12,8 @@ using System.Threading.Tasks; namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure { - public class OrderingContext : DbContext, IUnitOfWork + public class OrderingContext + : DbContext, IUnitOfWork { public const string DEFAULT_SCHEMA = "ordering"; public DbSet Orders { get; set; } @@ -24,13 +25,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure private readonly IMediator _mediator; - private OrderingContext(DbContextOptions options) : base (options) { } + private OrderingContext(DbContextOptions options) + : base (options) { } - public OrderingContext(DbContextOptions options, IMediator mediator) : base(options) + public OrderingContext(DbContextOptions options, IMediator mediator) + : base(options) { _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); - 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) // performed throught the DbContext will be commited - var result = await base.SaveChangesAsync(); + var result = await base.SaveChangesAsync(cancellationToken); return true; - } + } } - public class OrderingContextDesignFactory : IDesignTimeDbContextFactory + public class OrderingContextDesignFactory + : IDesignTimeDbContextFactory { public OrderingContext CreateDbContext(string[] args) { @@ -73,9 +76,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure return new OrderingContext(optionsBuilder.Options,new NoMediator()); } - class NoMediator : IMediator + class NoMediator + : IMediator { - public Task Publish(TNotification notification, CancellationToken cancellationToken = default(CancellationToken)) where TNotification : INotification + public Task Publish(TNotification notification, CancellationToken cancellationToken = default(CancellationToken)) + where TNotification : INotification { return Task.CompletedTask; } diff --git a/src/Services/Ordering/Ordering.Infrastructure/Repositories/BuyerRepository.cs b/src/Services/Ordering/Ordering.Infrastructure/Repositories/BuyerRepository.cs index efc478092..a658a3af6 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/Repositories/BuyerRepository.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/Repositories/BuyerRepository.cs @@ -11,13 +11,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositor : IBuyerRepository { private readonly OrderingContext _context; - public IUnitOfWork UnitOfWork - { - get - { - return _context; - } - } + public IUnitOfWork UnitOfWork => _context; public BuyerRepository(OrderingContext context) { @@ -35,14 +29,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositor else { return buyer; - } + } } public Buyer Update(Buyer buyer) { return _context.Buyers - .Update(buyer) - .Entity; + .Update(buyer) + .Entity; } public async Task FindAsync(string identity) diff --git a/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs b/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs index 4aaf738af..797a54734 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs @@ -1,7 +1,6 @@ using Microsoft.EntityFrameworkCore; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork; -using Ordering.Domain.Exceptions; using System; using System.Threading.Tasks; @@ -12,13 +11,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositor { private readonly OrderingContext _context; - public IUnitOfWork UnitOfWork - { - get - { - return _context; - } - } + public IUnitOfWork UnitOfWork => _context; public OrderRepository(OrderingContext context) {