Browse Source

Added field "Alias" to PaymentMethod and created EF migration for that

Refactoring related to OrderCommand (instead NewOrderCommand)
Refactoring in Buyer.IdentityGuid instead of fullname variables..
pull/49/merge
CESARDELATORRE 8 years ago
parent
commit
2babf6e4fe
13 changed files with 404 additions and 121 deletions
  1. +4
    -4
      src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommand.cs
  2. +33
    -23
      src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs
  3. +5
    -5
      src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs
  4. +1
    -1
      src/Services/Ordering/Ordering.API/Infrastructure/AutofacModules/MediatorModule.cs
  5. +233
    -0
      src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170118230807_PaymentMethodWithAlias.Designer.cs
  6. +28
    -0
      src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170118230807_PaymentMethodWithAlias.cs
  7. +79
    -73
      src/Services/Ordering/Ordering.API/Infrastructure/Migrations/OrderingContextModelSnapshot.cs
  8. +4
    -4
      src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/Buyer.cs
  9. +3
    -1
      src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/Payment.cs
  10. +1
    -1
      src/Services/Ordering/Ordering.Domain/RepositoryContracts/IBuyerRepository.cs
  11. +4
    -0
      src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs
  12. +2
    -2
      src/Services/Ordering/Ordering.Infrastructure/Repositories/BuyerRepository.cs
  13. +7
    -7
      test/Services/UnitTest/Ordering/Application/NewOrderCommandHandlerTest.cs

src/Services/Ordering/Ordering.API/Application/Commands/NewOrderCommand.cs → src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommand.cs View File

@ -10,10 +10,10 @@
//Need to create a different DTO class, like OrderLineDTO or similar...
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
public class NewOrderCommand
public class CreateOrderCommand
:IAsyncRequest<bool>
{
//(CDLTLL) TO DO: This is wrong, we must NOT use a child-entity class within a Command class!!
//(CDLTLL) TO DO: This is wrong, we must NOT use a child-entity class (OrderItem) within a Command class!!
//Need to create a different DTO class, like OrderLineDTO or similar...
private readonly List<OrderItem> _orderItems;
public string City { get; set; }
@ -36,7 +36,7 @@
public int CardTypeId { get; set; }
public string Buyer { get; set; }
public string BuyerIdentityGuid { get; set; }
public IEnumerable<OrderItem> OrderItems => _orderItems;
@ -45,7 +45,7 @@
_orderItems.Add(item);
}
public NewOrderCommand()
public CreateOrderCommand()
{
_orderItems = new List<OrderItem>();
}

src/Services/Ordering/Ordering.API/Application/Commands/NewOrderCommandHandler.cs → src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs View File

@ -9,13 +9,13 @@
using System.Threading.Tasks;
using Domain;
public class NewOrderCommandHandler
: IAsyncRequestHandler<NewOrderCommand, bool>
public class CreateOrderCommandHandler
: IAsyncRequestHandler<CreateOrderCommand, bool>
{
private readonly IBuyerRepository _buyerRepository;
private readonly IOrderRepository _orderRepository;
public NewOrderCommandHandler(IBuyerRepository buyerRepository,IOrderRepository orderRepository)
public CreateOrderCommandHandler(IBuyerRepository buyerRepository,IOrderRepository orderRepository)
{
if (buyerRepository == null)
{
@ -30,11 +30,11 @@
_buyerRepository = buyerRepository;
_orderRepository = orderRepository;
}
public async Task<bool> Handle(NewOrderCommand message)
public async Task<bool> Handle(CreateOrderCommand message)
{
//find buyer/payment or add a new one buyer/payment
var buyer = await _buyerRepository.FindAsync(message.Buyer);
var buyer = await _buyerRepository.FindAsync(message.BuyerIdentityGuid);
if (buyer == null)
{
@ -70,9 +70,32 @@
return result > 0;
}
Buyer CreateBuyer(CreateOrderCommand message)
{
return _buyerRepository.Add(
new Buyer(message.BuyerIdentityGuid));
}
Order CreateOrder(int buyerId, int paymentId, int addressId)
{
return new Order(buyerId, paymentId);
}
//TO DO:
//(CDLTLL) This is wrong. We shouldn't be able to create a PaymentMethod from a CommandHandler or anywhere in the Application Layer
//because a PaymentMethod is a child-entity, part of the Buyer Aggregate.
//So, any creation/update of a PaymentMethod should be done through its Aggregate-Root: the Buyer root entity.
//Need to move this logic to the Buyer Aggregate-Root and rename to "AddPaymentMethod()"
Payment CreatePayment(CreateOrderCommand message)
{
return new Payment("My Default Payment Method", message.CardNumber, message.CardSecurityNumber, message.CardHolderName, message.CardExpiration, message.CardTypeId);
}
Payment GetExistingPaymentOrAddANewOne(Buyer buyer, NewOrderCommand message)
//TO DO:
//(CDLTLL) This is wrong. As explained, this logic should be part of the
//Buyer Aggregate Root, as a PaymentMethod is a child-entity of that Aggregate.
Payment GetExistingPaymentOrAddANewOne(Buyer buyer, CreateOrderCommand message)
{
Payment payment = PaymentAlreadyExist(buyer, message);
@ -86,7 +109,10 @@
}
Payment PaymentAlreadyExist(Buyer buyer, NewOrderCommand message)
//TO DO:
//(CDLTLL) This is wrong. As explained, this logic should be part of the
//Buyer Aggregate Root, as a PaymentMethod is a child-entity of that Aggregate.
Payment PaymentAlreadyExist(Buyer buyer, CreateOrderCommand message)
{
return buyer.Payments
.SingleOrDefault(p =>
@ -100,21 +126,5 @@
p.SecurityNumber == message.CardSecurityNumber;
});
}
Buyer CreateBuyer(NewOrderCommand message)
{
return _buyerRepository.Add(
new Buyer(message.Buyer));
}
Order CreateOrder(int buyerId, int paymentId, int addressId)
{
return new Order(buyerId, paymentId);
}
Payment CreatePayment(NewOrderCommand message)
{
return new Payment(message.CardNumber, message.CardSecurityNumber, message.CardHolderName, message.CardExpiration, message.CardTypeId);
}
}
}

+ 5
- 5
src/Services/Ordering/Ordering.API/Controllers/OrdersController.cs View File

@ -43,14 +43,14 @@
[Route("new")]
[HttpPost]
public async Task<IActionResult> AddOrder([FromBody]NewOrderCommand order)
public async Task<IActionResult> AddOrder([FromBody]CreateOrderCommand createOrderCommand)
{
if (order.CardTypeId == 0)
order.CardTypeId = 1;
if (createOrderCommand.CardTypeId == 0)
createOrderCommand.CardTypeId = 1;
order.Buyer = _identityService.GetUserIdentity();
createOrderCommand.BuyerIdentityGuid = _identityService.GetUserIdentity();
var added = await _mediator.SendAsync(order);
var added = await _mediator.SendAsync(createOrderCommand);
if (added)
{
return Ok();


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

@ -16,7 +16,7 @@
builder.RegisterAssemblyTypes(typeof(IMediator).GetTypeInfo().Assembly)
.AsImplementedInterfaces();
builder.RegisterAssemblyTypes(typeof(NewOrderCommand).GetTypeInfo().Assembly)
builder.RegisterAssemblyTypes(typeof(CreateOrderCommand).GetTypeInfo().Assembly)
.As(o => o.GetInterfaces()
.Where(i => i.IsClosedTypeOf(typeof(IAsyncRequestHandler<,>)))
.Select(i => new KeyedService("IAsyncRequestHandler", i)));


+ 233
- 0
src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170118230807_PaymentMethodWithAlias.Designer.cs View File

@ -0,0 +1,233 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
namespace Ordering.API.Infrastructure.Migrations
{
[DbContext(typeof(OrderingContext))]
[Migration("20170118230807_PaymentMethodWithAlias")]
partial class PaymentMethodWithAlias
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "1.0.1")
.HasAnnotation("SqlServer:Sequence:ordering.buyerseq", "'buyerseq', 'ordering', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:Sequence:ordering.orderseq", "'orderseq', 'ordering', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:Sequence:ordering.paymentseq", "'paymentseq', 'ordering', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "buyerseq")
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<string>("FullName")
.IsRequired()
.HasAnnotation("MaxLength", 200);
b.HasKey("Id");
b.HasIndex("FullName")
.IsUnique();
b.ToTable("buyers","ordering");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.CardType", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasDefaultValue(1);
b.Property<string>("Name")
.IsRequired()
.HasAnnotation("MaxLength", 200);
b.HasKey("Id");
b.ToTable("cardtypes","ordering");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "paymentseq")
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<string>("Alias")
.IsRequired()
.HasAnnotation("MaxLength", 200);
b.Property<int>("BuyerId");
b.Property<string>("CardHolderName")
.IsRequired()
.HasAnnotation("MaxLength", 200);
b.Property<string>("CardNumber")
.IsRequired()
.HasAnnotation("MaxLength", 25);
b.Property<int>("CardTypeId");
b.Property<DateTime>("Expiration");
b.Property<string>("SecurityNumber");
b.HasKey("Id");
b.HasIndex("BuyerId");
b.HasIndex("CardTypeId");
b.ToTable("payments","ordering");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Address", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("City");
b.Property<string>("Country");
b.Property<string>("State");
b.Property<string>("Street");
b.Property<string>("ZipCode");
b.HasKey("Id");
b.ToTable("address","ordering");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "orderseq")
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<int>("BuyerId");
b.Property<DateTime>("OrderDate");
b.Property<int>("PaymentId");
b.Property<int?>("ShippingAddressId");
b.Property<int>("StatusId");
b.HasKey("Id");
b.HasIndex("BuyerId");
b.HasIndex("PaymentId");
b.HasIndex("ShippingAddressId");
b.HasIndex("StatusId");
b.ToTable("orders","ordering");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<decimal>("Discount");
b.Property<int>("OrderId");
b.Property<string>("PictureUrl");
b.Property<int>("ProductId");
b.Property<string>("ProductName")
.IsRequired();
b.Property<decimal>("UnitPrice");
b.Property<int>("Units")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:DefaultValue", 1);
b.HasKey("Id");
b.HasIndex("OrderId");
b.ToTable("orderItems","ordering");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderStatus", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasDefaultValue(1);
b.Property<string>("Name")
.IsRequired()
.HasAnnotation("MaxLength", 200);
b.HasKey("Id");
b.ToTable("orderstatus","ordering");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", b =>
{
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer")
.WithMany("Payments")
.HasForeignKey("BuyerId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.CardType", "CardType")
.WithMany()
.HasForeignKey("CardTypeId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
{
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer", "Buyer")
.WithMany()
.HasForeignKey("BuyerId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", "Payment")
.WithMany()
.HasForeignKey("PaymentId");
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Address", "ShippingAddress")
.WithMany()
.HasForeignKey("ShippingAddressId");
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderStatus", "Status")
.WithMany()
.HasForeignKey("StatusId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderItem", b =>
{
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order")
.WithMany("OrderItems")
.HasForeignKey("OrderId")
.OnDelete(DeleteBehavior.Cascade);
});
}
}
}

+ 28
- 0
src/Services/Ordering/Ordering.API/Infrastructure/Migrations/20170118230807_PaymentMethodWithAlias.cs View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Ordering.API.Infrastructure.Migrations
{
public partial class PaymentMethodWithAlias : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Alias",
schema: "ordering",
table: "payments",
maxLength: 200,
nullable: false,
defaultValue: "");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Alias",
schema: "ordering",
table: "payments");
}
}
}

+ 79
- 73
src/Services/Ordering/Ordering.API/Infrastructure/Migrations/OrderingContextModelSnapshot.cs View File

@ -19,62 +19,99 @@ namespace Ordering.API.Infrastructure.Migrations
.HasAnnotation("SqlServer:Sequence:ordering.paymentseq", "'paymentseq', 'ordering', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Address", b =>
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "buyerseq")
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<string>("City");
b.Property<string>("FullName")
.IsRequired()
.HasAnnotation("MaxLength", 200);
b.Property<string>("Country");
b.HasKey("Id");
b.Property<string>("State");
b.HasIndex("FullName")
.IsUnique();
b.Property<string>("Street");
b.ToTable("buyers","ordering");
});
b.Property<string>("ZipCode");
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.CardType", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasDefaultValue(1);
b.Property<string>("Name")
.IsRequired()
.HasAnnotation("MaxLength", 200);
b.HasKey("Id");
b.ToTable("address","ordering");
b.ToTable("cardtypes","ordering");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Buyer", b =>
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "buyerseq")
.HasAnnotation("SqlServer:HiLoSequenceName", "paymentseq")
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<string>("FullName")
b.Property<string>("Alias")
.IsRequired()
.HasAnnotation("MaxLength", 200);
b.Property<int>("BuyerId");
b.Property<string>("CardHolderName")
.IsRequired()
.HasAnnotation("MaxLength", 200);
b.Property<string>("CardNumber")
.IsRequired()
.HasAnnotation("MaxLength", 25);
b.Property<int>("CardTypeId");
b.Property<DateTime>("Expiration");
b.Property<string>("SecurityNumber");
b.HasKey("Id");
b.HasIndex("FullName")
.IsUnique();
b.HasIndex("BuyerId");
b.ToTable("buyers","ordering");
b.HasIndex("CardTypeId");
b.ToTable("payments","ordering");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.CardType", b =>
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Address", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasDefaultValue(1);
.ValueGeneratedOnAdd();
b.Property<string>("Name")
.IsRequired()
.HasAnnotation("MaxLength", 200);
b.Property<string>("City");
b.Property<string>("Country");
b.Property<string>("State");
b.Property<string>("Street");
b.Property<string>("ZipCode");
b.HasKey("Id");
b.ToTable("cardtypes","ordering");
b.ToTable("address","ordering");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Order", b =>
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
@ -105,7 +142,7 @@ namespace Ordering.API.Infrastructure.Migrations
b.ToTable("orders","ordering");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderItem", b =>
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
@ -114,6 +151,8 @@ namespace Ordering.API.Infrastructure.Migrations
b.Property<int>("OrderId");
b.Property<string>("PictureUrl");
b.Property<int>("ProductId");
b.Property<string>("ProductName")
@ -132,7 +171,7 @@ namespace Ordering.API.Infrastructure.Migrations
b.ToTable("orderItems","ordering");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderStatus", b =>
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderStatus", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
@ -147,80 +186,47 @@ namespace Ordering.API.Infrastructure.Migrations
b.ToTable("orderstatus","ordering");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", b =>
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "paymentseq")
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<int>("BuyerId");
b.Property<string>("CardHolderName")
.IsRequired()
.HasAnnotation("MaxLength", 200);
b.Property<string>("CardNumber")
.IsRequired()
.HasAnnotation("MaxLength", 25);
b.Property<int>("CardTypeId");
b.Property<DateTime>("Expiration");
b.Property<string>("SecurityNumber");
b.HasKey("Id");
b.HasIndex("BuyerId");
b.HasIndex("CardTypeId");
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer")
.WithMany("Payments")
.HasForeignKey("BuyerId")
.OnDelete(DeleteBehavior.Cascade);
b.ToTable("payments","ordering");
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.CardType", "CardType")
.WithMany()
.HasForeignKey("CardTypeId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Order", b =>
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order", b =>
{
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Buyer", "Buyer")
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Buyer", "Buyer")
.WithMany()
.HasForeignKey("BuyerId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", "Payment")
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate.Payment", "Payment")
.WithMany()
.HasForeignKey("PaymentId");
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Address", "ShippingAddress")
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Address", "ShippingAddress")
.WithMany()
.HasForeignKey("ShippingAddressId");
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderStatus", "Status")
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderStatus", "Status")
.WithMany()
.HasForeignKey("StatusId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderItem", b =>
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.OrderItem", b =>
{
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Order")
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate.Order")
.WithMany("OrderItems")
.HasForeignKey("OrderId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", b =>
{
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Buyer")
.WithMany("Payments")
.HasForeignKey("BuyerId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.CardType", "CardType")
.WithMany()
.HasForeignKey("CardTypeId")
.OnDelete(DeleteBehavior.Cascade);
});
}
}
}

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

@ -13,14 +13,14 @@
protected Buyer() { }
public Buyer(string fullName)
public Buyer(string IdentityGuid)
{
if (String.IsNullOrWhiteSpace(fullName))
if (String.IsNullOrWhiteSpace(IdentityGuid))
{
throw new ArgumentNullException(nameof(fullName));
throw new ArgumentNullException(nameof(IdentityGuid));
}
this.FullName = fullName;
this.FullName = IdentityGuid;
this.Payments = new HashSet<Payment>();
}
}


+ 3
- 1
src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/Payment.cs View File

@ -7,6 +7,7 @@
public class Payment
: Entity
{
public string Alias { get; private set; }
public int BuyerId { get; private set; }
public string CardNumber { get; private set; }
@ -23,7 +24,7 @@
protected Payment() { }
public Payment(string cardNumber, string securityNumber, string cardHolderName, DateTime expiration, int cardTypeId)
public Payment(string alias, string cardNumber, string securityNumber, string cardHolderName, DateTime expiration, int cardTypeId)
{
if (String.IsNullOrWhiteSpace(cardNumber))
{
@ -45,6 +46,7 @@
throw new ArgumentException(nameof(expiration));
}
this.Alias = alias;
this.CardNumber = cardNumber;
this.SecurityNumber = securityNumber;
this.CardHolderName = cardHolderName;


+ 1
- 1
src/Services/Ordering/Ordering.Domain/RepositoryContracts/IBuyerRepository.cs View File

@ -9,6 +9,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.RepositoryContrac
{
Buyer Add(Buyer buyer);
Task<Buyer> FindAsync(string name);
Task<Buyer> FindAsync(string BuyerIdentityGuid);
}
}

+ 4
- 0
src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs View File

@ -78,6 +78,10 @@
.HasMaxLength(200)
.IsRequired();
paymentConfiguration.Property(p => p.Alias)
.HasMaxLength(200)
.IsRequired();
paymentConfiguration.Property(p => p.CardNumber)
.HasMaxLength(25)
.IsRequired();


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

@ -39,11 +39,11 @@
.Entity;
}
public async Task<Buyer> FindAsync(string name)
public async Task<Buyer> FindAsync(string BuyerIdentityGuid)
{
var buyer = await _context.Buyers
.Include(b => b.Payments)
.Where(b => b.FullName == name)
.Where(b => b.FullName == BuyerIdentityGuid)
.SingleOrDefaultAsync();
return buyer;


+ 7
- 7
test/Services/UnitTest/Ordering/Application/NewOrderCommandHandlerTest.cs View File

@ -26,7 +26,7 @@
public async Task Handle_returns_true_when_order_is_persisted_succesfully()
{
// Arrange
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.FindAsync(FakeOrderRequestWithBuyer().Buyer))
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.FindAsync(FakeOrderRequestWithBuyer().BuyerIdentityGuid))
.Returns(Task.FromResult<Buyer>(FakeBuyer()));
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.UnitOfWork.SaveChangesAsync(default(CancellationToken)))
@ -39,7 +39,7 @@
.Returns(Task.FromResult(1));
//Act
var handler = new NewOrderCommandHandler(_buyerRepositoryMock.Object, _orderRepositoryMock.Object);
var handler = new CreateOrderCommandHandler(_buyerRepositoryMock.Object, _orderRepositoryMock.Object);
var result = await handler.Handle(FakeOrderRequestWithBuyer());
//Assert
@ -49,7 +49,7 @@
[Fact]
public async Task Handle_return_false_if_order_is_not_persisted()
{
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.FindAsync(FakeOrderRequestWithBuyer().Buyer))
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.FindAsync(FakeOrderRequestWithBuyer().BuyerIdentityGuid))
.Returns(Task.FromResult<Buyer>(FakeBuyer()));
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.UnitOfWork.SaveChangesAsync(default(CancellationToken)))
@ -60,7 +60,7 @@
.Returns(Task.FromResult(0));
//Act
var handler = new NewOrderCommandHandler(_buyerRepositoryMock.Object, _orderRepositoryMock.Object);
var handler = new CreateOrderCommandHandler(_buyerRepositoryMock.Object, _orderRepositoryMock.Object);
var result = await handler.Handle(FakeOrderRequestWithBuyer());
//Assert
@ -80,11 +80,11 @@
};
}
private NewOrderCommand FakeOrderRequestWithBuyer()
private CreateOrderCommand FakeOrderRequestWithBuyer()
{
return new NewOrderCommand
return new CreateOrderCommand
{
Buyer = "1234",
BuyerIdentityGuid = "1234",
CardNumber = "1234",
CardExpiration = DateTime.Now.AddYears(1),
CardSecurityNumber = "123",


Loading…
Cancel
Save