Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Updates based on documentation

* Getting the build passing

* Getting app functioning

* A few cleanups to confirm it's working as expected

* Fixing functional tests

* Updating dockerfile for 3.0

* Functional Tests now run sequentially

* Updating to latest version of moq

* Adding migration for post 3.0 upgrades

* Removing commented out lines

* Moving address and catalogitemordered configuration in to classes that own them

* Minor cleanups
  • Loading branch information
efleming18 authored and ardalis committed Nov 6, 2019
1 parent 9a21db6 commit 4442015
Show file tree
Hide file tree
Showing 29 changed files with 1,072 additions and 285 deletions.
2 changes: 1 addition & 1 deletion src/ApplicationCore/ApplicationCore.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>Microsoft.eShopWeb.ApplicationCore</RootNamespace>
</PropertyGroup>

Expand Down
140 changes: 3 additions & 137 deletions src/Infrastructure/Data/CatalogContext.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.eShopWeb.ApplicationCore.Entities;
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate;
using System.Reflection;

namespace Microsoft.eShopWeb.Infrastructure.Data
{
Expand All @@ -23,142 +23,8 @@ public CatalogContext(DbContextOptions<CatalogContext> options) : base(options)

protected override void OnModelCreating(ModelBuilder builder)
{
//Intentionally rolling back this change to fix issue: https://github.com/dotnet-architecture/eShopOnWeb/issues/292
//Will follow up after issue has been resolved.
//base.OnModelCreating(builder);
//builder.ApplyAllConfigurationsFromCurrentAssembly();

// alternately this is built-in to EF Core 2.2
//builder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());

builder.Entity<Basket>(ConfigureBasket);
builder.Entity<CatalogBrand>(ConfigureCatalogBrand);
builder.Entity<CatalogType>(ConfigureCatalogType);
builder.Entity<CatalogItem>(ConfigureCatalogItem);
builder.Entity<Order>(ConfigureOrder);
builder.Entity<OrderItem>(ConfigureOrderItem);
builder.Entity<Address>(ConfigureAddress);
builder.Entity<CatalogItemOrdered>(ConfigureCatalogItemOrdered);
builder.Entity<BasketItem>(ConfigureBasketItem);
}

private void ConfigureBasketItem(EntityTypeBuilder<BasketItem> builder)
{
builder.Property(bi => bi.UnitPrice)
.IsRequired(true)
.HasColumnType("decimal(18,2)");
}

private void ConfigureCatalogItemOrdered(EntityTypeBuilder<CatalogItemOrdered> builder)
{
builder.Property(cio => cio.ProductName)
.HasMaxLength(50)
.IsRequired();
}

private void ConfigureAddress(EntityTypeBuilder<Address> builder)
{
builder.Property(a => a.ZipCode)
.HasMaxLength(18)
.IsRequired();

builder.Property(a => a.Street)
.HasMaxLength(180)
.IsRequired();

builder.Property(a => a.State)
.HasMaxLength(60);

builder.Property(a => a.Country)
.HasMaxLength(90)
.IsRequired();

builder.Property(a => a.City)
.HasMaxLength(100)
.IsRequired();
}

private void ConfigureBasket(EntityTypeBuilder<Basket> builder)
{
var navigation = builder.Metadata.FindNavigation(nameof(Basket.Items));

navigation.SetPropertyAccessMode(PropertyAccessMode.Field);
}

private void ConfigureCatalogItem(EntityTypeBuilder<CatalogItem> builder)
{
builder.ToTable("Catalog");

builder.Property(ci => ci.Id)
.ForSqlServerUseSequenceHiLo("catalog_hilo")
.IsRequired();

builder.Property(ci => ci.Name)
.IsRequired(true)
.HasMaxLength(50);

builder.Property(ci => ci.Price)
.IsRequired(true)
.HasColumnType("decimal(18,2)");

builder.Property(ci => ci.PictureUri)
.IsRequired(false);

builder.HasOne(ci => ci.CatalogBrand)
.WithMany()
.HasForeignKey(ci => ci.CatalogBrandId);

builder.HasOne(ci => ci.CatalogType)
.WithMany()
.HasForeignKey(ci => ci.CatalogTypeId);
}

private void ConfigureCatalogBrand(EntityTypeBuilder<CatalogBrand> builder)
{
builder.ToTable("CatalogBrand");

builder.HasKey(ci => ci.Id);

builder.Property(ci => ci.Id)
.ForSqlServerUseSequenceHiLo("catalog_brand_hilo")
.IsRequired();

builder.Property(cb => cb.Brand)
.IsRequired()
.HasMaxLength(100);
}

private void ConfigureCatalogType(EntityTypeBuilder<CatalogType> builder)
{
builder.ToTable("CatalogType");

builder.HasKey(ci => ci.Id);

builder.Property(ci => ci.Id)
.ForSqlServerUseSequenceHiLo("catalog_type_hilo")
.IsRequired();

builder.Property(cb => cb.Type)
.IsRequired()
.HasMaxLength(100);
}

private void ConfigureOrder(EntityTypeBuilder<Order> builder)
{
var navigation = builder.Metadata.FindNavigation(nameof(Order.OrderItems));

navigation.SetPropertyAccessMode(PropertyAccessMode.Field);

builder.OwnsOne(o => o.ShipToAddress);
}

private void ConfigureOrderItem(EntityTypeBuilder<OrderItem> builder)
{
builder.OwnsOne(i => i.ItemOrdered);

builder.Property(oi => oi.UnitPrice)
.IsRequired(true)
.HasColumnType("decimal(18,2)");
base.OnModelCreating(builder);
builder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
}
}
}
31 changes: 0 additions & 31 deletions src/Infrastructure/Data/Config/AddressConfiguration.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Infrastructure/Data/Config/BasketConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void Configure(EntityTypeBuilder<Basket> builder)

builder.Property(b => b.BuyerId)
.IsRequired()
.HasMaxLength(20);
.HasMaxLength(40);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public void Configure(EntityTypeBuilder<CatalogBrand> builder)
builder.HasKey(ci => ci.Id);

builder.Property(ci => ci.Id)
.ForSqlServerUseSequenceHiLo("catalog_brand_hilo")
.UseHiLo("catalog_brand_hilo")
.IsRequired();

builder.Property(cb => cb.Brand)
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Data/Config/CatalogItemConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public void Configure(EntityTypeBuilder<CatalogItem> builder)
builder.ToTable("Catalog");

builder.Property(ci => ci.Id)
.ForSqlServerUseSequenceHiLo("catalog_hilo")
.UseHiLo("catalog_hilo")
.IsRequired();

builder.Property(ci => ci.Name)
Expand Down
16 changes: 0 additions & 16 deletions src/Infrastructure/Data/Config/CatalogItemOrderedConfiguration.cs

This file was deleted.

24 changes: 23 additions & 1 deletion src/Infrastructure/Data/Config/OrderConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,29 @@ public void Configure(EntityTypeBuilder<Order> builder)

navigation.SetPropertyAccessMode(PropertyAccessMode.Field);

builder.OwnsOne(o => o.ShipToAddress);
builder.OwnsOne(o => o.ShipToAddress, a =>
{
a.WithOwner();

a.Property(a => a.ZipCode)
.HasMaxLength(18)
.IsRequired();

a.Property(a => a.Street)
.HasMaxLength(180)
.IsRequired();

a.Property(a => a.State)
.HasMaxLength(60);

a.Property(a => a.Country)
.HasMaxLength(90)
.IsRequired();

a.Property(a => a.City)
.HasMaxLength(100)
.IsRequired();
});
}
}
}
9 changes: 8 additions & 1 deletion src/Infrastructure/Data/Config/OrderItemConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ public class OrderItemConfiguration : IEntityTypeConfiguration<OrderItem>
{
public void Configure(EntityTypeBuilder<OrderItem> builder)
{
builder.OwnsOne(i => i.ItemOrdered);
builder.OwnsOne(i => i.ItemOrdered, io =>
{
io.WithOwner();

io.Property(cio => cio.ProductName)
.HasMaxLength(50)
.IsRequired();
});

builder.Property(oi => oi.UnitPrice)
.IsRequired(true)
Expand Down
Loading

0 comments on commit 4442015

Please sign in to comment.