diff --git a/src/ApplicationCore/ApplicationCore.csproj b/src/ApplicationCore/ApplicationCore.csproj index 57861cb..f92c57e 100644 --- a/src/ApplicationCore/ApplicationCore.csproj +++ b/src/ApplicationCore/ApplicationCore.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + netstandard2.1 Microsoft.eShopWeb.ApplicationCore diff --git a/src/Infrastructure/Data/CatalogContext.cs b/src/Infrastructure/Data/CatalogContext.cs index 021c0f4..03cda58 100644 --- a/src/Infrastructure/Data/CatalogContext.cs +++ b/src/Infrastructure/Data/CatalogContext.cs @@ -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 { @@ -23,142 +23,8 @@ namespace Microsoft.eShopWeb.Infrastructure.Data 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(ConfigureBasket); - builder.Entity(ConfigureCatalogBrand); - builder.Entity(ConfigureCatalogType); - builder.Entity(ConfigureCatalogItem); - builder.Entity(ConfigureOrder); - builder.Entity(ConfigureOrderItem); - builder.Entity
(ConfigureAddress); - builder.Entity(ConfigureCatalogItemOrdered); - builder.Entity(ConfigureBasketItem); - } - - private void ConfigureBasketItem(EntityTypeBuilder builder) - { - builder.Property(bi => bi.UnitPrice) - .IsRequired(true) - .HasColumnType("decimal(18,2)"); - } - - private void ConfigureCatalogItemOrdered(EntityTypeBuilder builder) - { - builder.Property(cio => cio.ProductName) - .HasMaxLength(50) - .IsRequired(); - } - - private void ConfigureAddress(EntityTypeBuilder
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 builder) - { - var navigation = builder.Metadata.FindNavigation(nameof(Basket.Items)); - - navigation.SetPropertyAccessMode(PropertyAccessMode.Field); - } - - private void ConfigureCatalogItem(EntityTypeBuilder 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 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 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 builder) - { - var navigation = builder.Metadata.FindNavigation(nameof(Order.OrderItems)); - - navigation.SetPropertyAccessMode(PropertyAccessMode.Field); - - builder.OwnsOne(o => o.ShipToAddress); - } - - private void ConfigureOrderItem(EntityTypeBuilder builder) - { - builder.OwnsOne(i => i.ItemOrdered); - - builder.Property(oi => oi.UnitPrice) - .IsRequired(true) - .HasColumnType("decimal(18,2)"); + base.OnModelCreating(builder); + builder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); } } } diff --git a/src/Infrastructure/Data/Config/AddressConfiguration.cs b/src/Infrastructure/Data/Config/AddressConfiguration.cs deleted file mode 100644 index ff940bd..0000000 --- a/src/Infrastructure/Data/Config/AddressConfiguration.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; -using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; - -namespace Microsoft.eShopWeb.Infrastructure.Data.Config -{ - public class AddressConfiguration : IEntityTypeConfiguration
- { - public void Configure(EntityTypeBuilder
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(); - } - } -} diff --git a/src/Infrastructure/Data/Config/BasketConfiguration.cs b/src/Infrastructure/Data/Config/BasketConfiguration.cs index c5d681d..fed7a73 100644 --- a/src/Infrastructure/Data/Config/BasketConfiguration.cs +++ b/src/Infrastructure/Data/Config/BasketConfiguration.cs @@ -13,7 +13,7 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Config builder.Property(b => b.BuyerId) .IsRequired() - .HasMaxLength(20); + .HasMaxLength(40); } } } diff --git a/src/Infrastructure/Data/Config/CatalogBrandConfiguration.cs b/src/Infrastructure/Data/Config/CatalogBrandConfiguration.cs index 4fb978a..c571bb0 100644 --- a/src/Infrastructure/Data/Config/CatalogBrandConfiguration.cs +++ b/src/Infrastructure/Data/Config/CatalogBrandConfiguration.cs @@ -11,7 +11,7 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Config builder.HasKey(ci => ci.Id); builder.Property(ci => ci.Id) - .ForSqlServerUseSequenceHiLo("catalog_brand_hilo") + .UseHiLo("catalog_brand_hilo") .IsRequired(); builder.Property(cb => cb.Brand) diff --git a/src/Infrastructure/Data/Config/CatalogItemConfiguration.cs b/src/Infrastructure/Data/Config/CatalogItemConfiguration.cs index 3a56b42..6a70a22 100644 --- a/src/Infrastructure/Data/Config/CatalogItemConfiguration.cs +++ b/src/Infrastructure/Data/Config/CatalogItemConfiguration.cs @@ -11,7 +11,7 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Config builder.ToTable("Catalog"); builder.Property(ci => ci.Id) - .ForSqlServerUseSequenceHiLo("catalog_hilo") + .UseHiLo("catalog_hilo") .IsRequired(); builder.Property(ci => ci.Name) diff --git a/src/Infrastructure/Data/Config/CatalogItemOrderedConfiguration.cs b/src/Infrastructure/Data/Config/CatalogItemOrderedConfiguration.cs deleted file mode 100644 index 8a750be..0000000 --- a/src/Infrastructure/Data/Config/CatalogItemOrderedConfiguration.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; -using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; - -namespace Microsoft.eShopWeb.Infrastructure.Data.Config -{ - public class CatalogItemOrderedConfiguration : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - builder.Property(cio => cio.ProductName) - .HasMaxLength(50) - .IsRequired(); - } - } -} diff --git a/src/Infrastructure/Data/Config/OrderConfiguration.cs b/src/Infrastructure/Data/Config/OrderConfiguration.cs index 3d1ce74..ddc9836 100644 --- a/src/Infrastructure/Data/Config/OrderConfiguration.cs +++ b/src/Infrastructure/Data/Config/OrderConfiguration.cs @@ -12,7 +12,29 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Config 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(); + }); } } } diff --git a/src/Infrastructure/Data/Config/OrderItemConfiguration.cs b/src/Infrastructure/Data/Config/OrderItemConfiguration.cs index 20b2617..41a92e9 100644 --- a/src/Infrastructure/Data/Config/OrderItemConfiguration.cs +++ b/src/Infrastructure/Data/Config/OrderItemConfiguration.cs @@ -8,7 +8,14 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Config { public void Configure(EntityTypeBuilder 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) diff --git a/src/Infrastructure/Data/Migrations/20191031185508_Post30Upgrade.Designer.cs b/src/Infrastructure/Data/Migrations/20191031185508_Post30Upgrade.Designer.cs new file mode 100644 index 0000000..e9e1fec --- /dev/null +++ b/src/Infrastructure/Data/Migrations/20191031185508_Post30Upgrade.Designer.cs @@ -0,0 +1,274 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Microsoft.eShopWeb.Infrastructure.Data; + +namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations +{ + [DbContext(typeof(CatalogContext))] + [Migration("20191031185508_Post30Upgrade")] + partial class Post30Upgrade + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("Relational:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("Relational:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("Relational:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate.Basket", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("BuyerId") + .IsRequired() + .HasColumnType("nvarchar(40)") + .HasMaxLength(40); + + b.HasKey("Id"); + + b.ToTable("Baskets"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate.BasketItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("BasketId") + .HasColumnType("int"); + + b.Property("CatalogItemId") + .HasColumnType("int"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.Property("UnitPrice") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.HasIndex("BasketId"); + + b.ToTable("BasketItems"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogBrand", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_brand_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Brand") + .IsRequired() + .HasColumnType("nvarchar(100)") + .HasMaxLength(100); + + b.HasKey("Id"); + + b.ToTable("CatalogBrands"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("CatalogBrandId") + .HasColumnType("int"); + + b.Property("CatalogTypeId") + .HasColumnType("int"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(50)") + .HasMaxLength(50); + + b.Property("PictureUri") + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.HasIndex("CatalogBrandId"); + + b.HasIndex("CatalogTypeId"); + + b.ToTable("Catalog"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_type_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Type") + .IsRequired() + .HasColumnType("nvarchar(100)") + .HasMaxLength(100); + + b.HasKey("Id"); + + b.ToTable("CatalogTypes"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("BuyerId") + .HasColumnType("nvarchar(max)"); + + b.Property("OrderDate") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.OrderItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("OrderId") + .HasColumnType("int"); + + b.Property("UnitPrice") + .HasColumnType("decimal(18,2)"); + + b.Property("Units") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.ToTable("OrderItems"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate.BasketItem", b => + { + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate.Basket", null) + .WithMany("Items") + .HasForeignKey("BasketId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogItem", b => + { + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogBrand", "CatalogBrand") + .WithMany() + .HasForeignKey("CatalogBrandId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogType", "CatalogType") + .WithMany() + .HasForeignKey("CatalogTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Order", b => + { + b.OwnsOne("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Address", "ShipToAddress", b1 => + { + b1.Property("OrderId") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b1.Property("City") + .HasColumnType("nvarchar(max)"); + + b1.Property("Country") + .HasColumnType("nvarchar(max)"); + + b1.Property("State") + .HasColumnType("nvarchar(max)"); + + b1.Property("Street") + .HasColumnType("nvarchar(max)"); + + b1.Property("ZipCode") + .HasColumnType("nvarchar(max)"); + + b1.HasKey("OrderId"); + + b1.ToTable("Orders"); + + b1.WithOwner() + .HasForeignKey("OrderId"); + }); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.OrderItem", b => + { + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Order", null) + .WithMany("OrderItems") + .HasForeignKey("OrderId"); + + b.OwnsOne("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.CatalogItemOrdered", "ItemOrdered", b1 => + { + b1.Property("OrderItemId") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b1.Property("CatalogItemId") + .HasColumnType("int"); + + b1.Property("PictureUri") + .HasColumnType("nvarchar(max)"); + + b1.Property("ProductName") + .HasColumnType("nvarchar(max)"); + + b1.HasKey("OrderItemId"); + + b1.ToTable("OrderItems"); + + b1.WithOwner() + .HasForeignKey("OrderItemId"); + }); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Infrastructure/Data/Migrations/20191031185508_Post30Upgrade.cs b/src/Infrastructure/Data/Migrations/20191031185508_Post30Upgrade.cs new file mode 100644 index 0000000..3bdf0d0 --- /dev/null +++ b/src/Infrastructure/Data/Migrations/20191031185508_Post30Upgrade.cs @@ -0,0 +1,224 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations +{ + public partial class Post30Upgrade : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Catalog_CatalogBrand_CatalogBrandId", + table: "Catalog"); + + migrationBuilder.DropForeignKey( + name: "FK_Catalog_CatalogType_CatalogTypeId", + table: "Catalog"); + + migrationBuilder.DropPrimaryKey( + name: "PK_CatalogType", + table: "CatalogType"); + + migrationBuilder.DropPrimaryKey( + name: "PK_CatalogBrand", + table: "CatalogBrand"); + + migrationBuilder.RenameTable( + name: "CatalogType", + newName: "CatalogTypes"); + + migrationBuilder.RenameTable( + name: "CatalogBrand", + newName: "CatalogBrands"); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_ZipCode", + table: "Orders", + nullable: true, + oldClrType: typeof(string), + oldMaxLength: 18, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_Street", + table: "Orders", + nullable: true, + oldClrType: typeof(string), + oldMaxLength: 180, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_State", + table: "Orders", + nullable: true, + oldClrType: typeof(string), + oldMaxLength: 60, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_Country", + table: "Orders", + nullable: true, + oldClrType: typeof(string), + oldMaxLength: 90, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_City", + table: "Orders", + nullable: true, + oldClrType: typeof(string), + oldMaxLength: 100, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ItemOrdered_ProductName", + table: "OrderItems", + nullable: true, + oldClrType: typeof(string), + oldMaxLength: 50, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "BuyerId", + table: "Baskets", + maxLength: 40, + nullable: false, + oldClrType: typeof(string), + oldNullable: true); + + migrationBuilder.AddPrimaryKey( + name: "PK_CatalogTypes", + table: "CatalogTypes", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_CatalogBrands", + table: "CatalogBrands", + column: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Catalog_CatalogBrands_CatalogBrandId", + table: "Catalog", + column: "CatalogBrandId", + principalTable: "CatalogBrands", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Catalog_CatalogTypes_CatalogTypeId", + table: "Catalog", + column: "CatalogTypeId", + principalTable: "CatalogTypes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Catalog_CatalogBrands_CatalogBrandId", + table: "Catalog"); + + migrationBuilder.DropForeignKey( + name: "FK_Catalog_CatalogTypes_CatalogTypeId", + table: "Catalog"); + + migrationBuilder.DropPrimaryKey( + name: "PK_CatalogTypes", + table: "CatalogTypes"); + + migrationBuilder.DropPrimaryKey( + name: "PK_CatalogBrands", + table: "CatalogBrands"); + + migrationBuilder.RenameTable( + name: "CatalogTypes", + newName: "CatalogType"); + + migrationBuilder.RenameTable( + name: "CatalogBrands", + newName: "CatalogBrand"); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_ZipCode", + table: "Orders", + maxLength: 18, + nullable: true, + oldClrType: typeof(string), + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_Street", + table: "Orders", + maxLength: 180, + nullable: true, + oldClrType: typeof(string), + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_State", + table: "Orders", + maxLength: 60, + nullable: true, + oldClrType: typeof(string), + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_Country", + table: "Orders", + maxLength: 90, + nullable: true, + oldClrType: typeof(string), + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_City", + table: "Orders", + maxLength: 100, + nullable: true, + oldClrType: typeof(string), + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ItemOrdered_ProductName", + table: "OrderItems", + maxLength: 50, + nullable: true, + oldClrType: typeof(string), + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "BuyerId", + table: "Baskets", + nullable: true, + oldClrType: typeof(string), + oldMaxLength: 40); + + migrationBuilder.AddPrimaryKey( + name: "PK_CatalogType", + table: "CatalogType", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_CatalogBrand", + table: "CatalogBrand", + column: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Catalog_CatalogBrand_CatalogBrandId", + table: "Catalog", + column: "CatalogBrandId", + principalTable: "CatalogBrand", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Catalog_CatalogType_CatalogTypeId", + table: "Catalog", + column: "CatalogTypeId", + principalTable: "CatalogType", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/src/Infrastructure/Data/Migrations/20191105161820_AddressAndCatalogItemOrderedChanges.Designer.cs b/src/Infrastructure/Data/Migrations/20191105161820_AddressAndCatalogItemOrderedChanges.Designer.cs new file mode 100644 index 0000000..243e548 --- /dev/null +++ b/src/Infrastructure/Data/Migrations/20191105161820_AddressAndCatalogItemOrderedChanges.Designer.cs @@ -0,0 +1,285 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Microsoft.eShopWeb.Infrastructure.Data; + +namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations +{ + [DbContext(typeof(CatalogContext))] + [Migration("20191105161820_AddressAndCatalogItemOrderedChanges")] + partial class AddressAndCatalogItemOrderedChanges + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("Relational:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("Relational:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("Relational:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate.Basket", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("BuyerId") + .IsRequired() + .HasColumnType("nvarchar(40)") + .HasMaxLength(40); + + b.HasKey("Id"); + + b.ToTable("Baskets"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate.BasketItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("BasketId") + .HasColumnType("int"); + + b.Property("CatalogItemId") + .HasColumnType("int"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.Property("UnitPrice") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.HasIndex("BasketId"); + + b.ToTable("BasketItems"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogBrand", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_brand_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Brand") + .IsRequired() + .HasColumnType("nvarchar(100)") + .HasMaxLength(100); + + b.HasKey("Id"); + + b.ToTable("CatalogBrands"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("CatalogBrandId") + .HasColumnType("int"); + + b.Property("CatalogTypeId") + .HasColumnType("int"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(50)") + .HasMaxLength(50); + + b.Property("PictureUri") + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.HasIndex("CatalogBrandId"); + + b.HasIndex("CatalogTypeId"); + + b.ToTable("Catalog"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_type_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Type") + .IsRequired() + .HasColumnType("nvarchar(100)") + .HasMaxLength(100); + + b.HasKey("Id"); + + b.ToTable("CatalogTypes"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("BuyerId") + .HasColumnType("nvarchar(max)"); + + b.Property("OrderDate") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.OrderItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("OrderId") + .HasColumnType("int"); + + b.Property("UnitPrice") + .HasColumnType("decimal(18,2)"); + + b.Property("Units") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.ToTable("OrderItems"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate.BasketItem", b => + { + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate.Basket", null) + .WithMany("Items") + .HasForeignKey("BasketId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogItem", b => + { + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogBrand", "CatalogBrand") + .WithMany() + .HasForeignKey("CatalogBrandId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogType", "CatalogType") + .WithMany() + .HasForeignKey("CatalogTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Order", b => + { + b.OwnsOne("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Address", "ShipToAddress", b1 => + { + b1.Property("OrderId") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b1.Property("City") + .IsRequired() + .HasColumnType("nvarchar(100)") + .HasMaxLength(100); + + b1.Property("Country") + .IsRequired() + .HasColumnType("nvarchar(90)") + .HasMaxLength(90); + + b1.Property("State") + .HasColumnType("nvarchar(60)") + .HasMaxLength(60); + + b1.Property("Street") + .IsRequired() + .HasColumnType("nvarchar(180)") + .HasMaxLength(180); + + b1.Property("ZipCode") + .IsRequired() + .HasColumnType("nvarchar(18)") + .HasMaxLength(18); + + b1.HasKey("OrderId"); + + b1.ToTable("Orders"); + + b1.WithOwner() + .HasForeignKey("OrderId"); + }); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.OrderItem", b => + { + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Order", null) + .WithMany("OrderItems") + .HasForeignKey("OrderId"); + + b.OwnsOne("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.CatalogItemOrdered", "ItemOrdered", b1 => + { + b1.Property("OrderItemId") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b1.Property("CatalogItemId") + .HasColumnType("int"); + + b1.Property("PictureUri") + .HasColumnType("nvarchar(max)"); + + b1.Property("ProductName") + .IsRequired() + .HasColumnType("nvarchar(50)") + .HasMaxLength(50); + + b1.HasKey("OrderItemId"); + + b1.ToTable("OrderItems"); + + b1.WithOwner() + .HasForeignKey("OrderItemId"); + }); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Infrastructure/Data/Migrations/20191105161820_AddressAndCatalogItemOrderedChanges.cs b/src/Infrastructure/Data/Migrations/20191105161820_AddressAndCatalogItemOrderedChanges.cs new file mode 100644 index 0000000..e539aac --- /dev/null +++ b/src/Infrastructure/Data/Migrations/20191105161820_AddressAndCatalogItemOrderedChanges.cs @@ -0,0 +1,121 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations +{ + public partial class AddressAndCatalogItemOrderedChanges : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "ShipToAddress_ZipCode", + table: "Orders", + maxLength: 18, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_Street", + table: "Orders", + maxLength: 180, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_State", + table: "Orders", + maxLength: 60, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_Country", + table: "Orders", + maxLength: 90, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_City", + table: "Orders", + maxLength: 100, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ItemOrdered_ProductName", + table: "OrderItems", + maxLength: 50, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "ShipToAddress_ZipCode", + table: "Orders", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldMaxLength: 18, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_Street", + table: "Orders", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldMaxLength: 180, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_State", + table: "Orders", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldMaxLength: 60, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_Country", + table: "Orders", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldMaxLength: 90, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_City", + table: "Orders", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldMaxLength: 100, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ItemOrdered_ProductName", + table: "OrderItems", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldMaxLength: 50, + oldNullable: true); + } + } +} diff --git a/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs b/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs index 8a678ff..ee39dff 100644 --- a/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs +++ b/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs @@ -15,7 +15,7 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "2.2.6-servicing-10079") + .HasAnnotation("ProductVersion", "3.0.0") .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("Relational:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'") .HasAnnotation("Relational:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'") @@ -26,9 +26,13 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() + .HasColumnType("int") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - b.Property("BuyerId"); + b.Property("BuyerId") + .IsRequired() + .HasColumnType("nvarchar(40)") + .HasMaxLength(40); b.HasKey("Id"); @@ -39,13 +43,17 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() + .HasColumnType("int") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - b.Property("BasketId"); + b.Property("BasketId") + .HasColumnType("int"); - b.Property("CatalogItemId"); + b.Property("CatalogItemId") + .HasColumnType("int"); - b.Property("Quantity"); + b.Property("Quantity") + .HasColumnType("int"); b.Property("UnitPrice") .HasColumnType("decimal(18,2)"); @@ -61,36 +69,44 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() + .HasColumnType("int") .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_brand_hilo") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); b.Property("Brand") .IsRequired() + .HasColumnType("nvarchar(100)") .HasMaxLength(100); b.HasKey("Id"); - b.ToTable("CatalogBrand"); + b.ToTable("CatalogBrands"); }); modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogItem", b => { b.Property("Id") .ValueGeneratedOnAdd() + .HasColumnType("int") .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_hilo") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); - b.Property("CatalogBrandId"); + b.Property("CatalogBrandId") + .HasColumnType("int"); - b.Property("CatalogTypeId"); + b.Property("CatalogTypeId") + .HasColumnType("int"); - b.Property("Description"); + b.Property("Description") + .HasColumnType("nvarchar(max)"); b.Property("Name") .IsRequired() + .HasColumnType("nvarchar(50)") .HasMaxLength(50); - b.Property("PictureUri"); + b.Property("PictureUri") + .HasColumnType("nvarchar(max)"); b.Property("Price") .HasColumnType("decimal(18,2)"); @@ -108,27 +124,32 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() + .HasColumnType("int") .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_type_hilo") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); b.Property("Type") .IsRequired() + .HasColumnType("nvarchar(100)") .HasMaxLength(100); b.HasKey("Id"); - b.ToTable("CatalogType"); + b.ToTable("CatalogTypes"); }); modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Order", b => { b.Property("Id") .ValueGeneratedOnAdd() + .HasColumnType("int") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - b.Property("BuyerId"); + b.Property("BuyerId") + .HasColumnType("nvarchar(max)"); - b.Property("OrderDate"); + b.Property("OrderDate") + .HasColumnType("datetimeoffset"); b.HasKey("Id"); @@ -139,14 +160,17 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() + .HasColumnType("int") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - b.Property("OrderId"); + b.Property("OrderId") + .HasColumnType("int"); b.Property("UnitPrice") .HasColumnType("decimal(18,2)"); - b.Property("Units"); + b.Property("Units") + .HasColumnType("int"); b.HasKey("Id"); @@ -157,10 +181,11 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate.BasketItem", b => { - b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate.Basket") + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate.Basket", null) .WithMany("Items") .HasForeignKey("BasketId") - .OnDelete(DeleteBehavior.Cascade); + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); }); modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogItem", b => @@ -168,12 +193,14 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogBrand", "CatalogBrand") .WithMany() .HasForeignKey("CatalogBrandId") - .OnDelete(DeleteBehavior.Cascade); + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogType", "CatalogType") .WithMany() .HasForeignKey("CatalogTypeId") - .OnDelete(DeleteBehavior.Cascade); + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); }); modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Order", b => @@ -182,41 +209,45 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations { b1.Property("OrderId") .ValueGeneratedOnAdd() + .HasColumnType("int") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); b1.Property("City") .IsRequired() + .HasColumnType("nvarchar(100)") .HasMaxLength(100); b1.Property("Country") .IsRequired() + .HasColumnType("nvarchar(90)") .HasMaxLength(90); b1.Property("State") + .HasColumnType("nvarchar(60)") .HasMaxLength(60); b1.Property("Street") .IsRequired() + .HasColumnType("nvarchar(180)") .HasMaxLength(180); b1.Property("ZipCode") .IsRequired() + .HasColumnType("nvarchar(18)") .HasMaxLength(18); b1.HasKey("OrderId"); b1.ToTable("Orders"); - b1.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Order") - .WithOne("ShipToAddress") - .HasForeignKey("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Address", "OrderId") - .OnDelete(DeleteBehavior.Cascade); + b1.WithOwner() + .HasForeignKey("OrderId"); }); }); modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.OrderItem", b => { - b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Order") + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Order", null) .WithMany("OrderItems") .HasForeignKey("OrderId"); @@ -224,24 +255,26 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations { b1.Property("OrderItemId") .ValueGeneratedOnAdd() + .HasColumnType("int") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - b1.Property("CatalogItemId"); + b1.Property("CatalogItemId") + .HasColumnType("int"); - b1.Property("PictureUri"); + b1.Property("PictureUri") + .HasColumnType("nvarchar(max)"); b1.Property("ProductName") .IsRequired() + .HasColumnType("nvarchar(50)") .HasMaxLength(50); b1.HasKey("OrderItemId"); b1.ToTable("OrderItems"); - b1.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.OrderItem") - .WithOne("ItemOrdered") - .HasForeignKey("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.CatalogItemOrdered", "OrderItemId") - .OnDelete(DeleteBehavior.Cascade); + b1.WithOwner() + .HasForeignKey("OrderItemId"); }); }); #pragma warning restore 612, 618 diff --git a/src/Infrastructure/Infrastructure.csproj b/src/Infrastructure/Infrastructure.csproj index 8c3a4b3..a819db4 100644 --- a/src/Infrastructure/Infrastructure.csproj +++ b/src/Infrastructure/Infrastructure.csproj @@ -1,16 +1,16 @@  - netstandard2.0 + netstandard2.1 Microsoft.eShopWeb.Infrastructure - - - + + + diff --git a/src/Web/Dockerfile b/src/Web/Dockerfile index 6bd2dba..a243642 100644 --- a/src/Web/Dockerfile +++ b/src/Web/Dockerfile @@ -7,7 +7,7 @@ # # RUN COMMAND # docker run --name eshopweb --rm -it -p 5106:5106 web -FROM microsoft/dotnet:2.2-sdk AS build +FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build WORKDIR /app COPY *.sln . @@ -17,7 +17,7 @@ RUN dotnet restore RUN dotnet publish -c Release -o out -FROM microsoft/dotnet:2.2-aspnetcore-runtime AS runtime +FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 AS runtime WORKDIR /app COPY --from=build /app/src/Web/out ./ diff --git a/src/Web/Program.cs b/src/Web/Program.cs index 3aa1551..0703f42 100644 --- a/src/Web/Program.cs +++ b/src/Web/Program.cs @@ -1,9 +1,9 @@ -using Microsoft.AspNetCore; -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Identity; using Microsoft.eShopWeb.Infrastructure.Data; using Microsoft.eShopWeb.Infrastructure.Identity; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using System; using System.Threading.Tasks; @@ -14,7 +14,7 @@ namespace Microsoft.eShopWeb.Web { public async static Task Main(string[] args) { - var host = CreateWebHostBuilder(args) + var host = CreateHostBuilder(args) .Build(); using (var scope = host.Services.CreateScope()) @@ -39,8 +39,11 @@ namespace Microsoft.eShopWeb.Web host.Run(); } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup(); + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); } } diff --git a/src/Web/Startup.cs b/src/Web/Startup.cs index f4b71a2..0335d62 100644 --- a/src/Web/Startup.cs +++ b/src/Web/Startup.cs @@ -4,10 +4,7 @@ using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Identity.UI; -using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ApplicationModels; -using Microsoft.AspNetCore.Routing; using Microsoft.EntityFrameworkCore; using Microsoft.eShopWeb.ApplicationCore.Interfaces; using Microsoft.eShopWeb.ApplicationCore.Services; @@ -15,14 +12,13 @@ using Microsoft.eShopWeb.Infrastructure.Data; using Microsoft.eShopWeb.Infrastructure.Identity; using Microsoft.eShopWeb.Infrastructure.Logging; using Microsoft.eShopWeb.Infrastructure.Services; -using Microsoft.eShopWeb.Web.HealthChecks; using Microsoft.eShopWeb.Web.Interfaces; using Microsoft.eShopWeb.Web.Services; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; +using Microsoft.Extensions.Hosting; using Newtonsoft.Json; -using Swashbuckle.AspNetCore.Swagger; using System; using System.Collections.Generic; using System.Linq; @@ -87,7 +83,6 @@ namespace Microsoft.eShopWeb.Web CreateIdentityIfNotCreated(services); services.AddScoped(typeof(IAsyncRepository<>), typeof(EfRepository<>)); - services.AddScoped(); services.AddScoped(); services.AddScoped(); @@ -96,7 +91,6 @@ namespace Microsoft.eShopWeb.Web services.AddScoped(); services.Configure(Configuration); services.AddSingleton(new UriComposer(Configuration.Get())); - services.AddScoped(typeof(IAppLogger<>), typeof(LoggerAdapter<>)); services.AddTransient(); @@ -114,25 +108,21 @@ namespace Microsoft.eShopWeb.Web { options.Conventions.Add(new RouteTokenTransformerConvention( new SlugifyParameterTransformer())); - - } - ) - .AddRazorPagesOptions(options => - { - options.Conventions.AuthorizePage("/Basket/Checkout"); - options.AllowAreas = true; - }) - .SetCompatibilityVersion(CompatibilityVersion.Version_2_2); + + }); + services.AddControllersWithViews(); + services.AddRazorPages(options => + { + options.Conventions.AuthorizePage("/Basket/Checkout"); + }); + + services.AddControllers(); services.AddHttpContextAccessor(); - services.AddSwaggerGen(c => - { - c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" }); - }); + + services.AddSwaggerGen(c => c.SwaggerDoc("v1", new OpenApi.Models.OpenApiInfo { Title = "My API", Version = "v1"})); - services.AddHealthChecks() - .AddCheck("home_page_health_check") - .AddCheck("api_health_check"); + services.AddHealthChecks(); services.Configure(config => { @@ -154,7 +144,7 @@ namespace Microsoft.eShopWeb.Web if(existingUserManager == null) { services.AddIdentity() - .AddDefaultUI(UIFramework.Bootstrap4) + .AddDefaultUI() .AddEntityFrameworkStores() .AddDefaultTokenProviders(); } @@ -183,9 +173,8 @@ namespace Microsoft.eShopWeb.Web } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { - //app.UseDeveloperExceptionPage(); app.UseHealthChecks("/health", new HealthCheckOptions { @@ -220,9 +209,11 @@ namespace Microsoft.eShopWeb.Web app.UseHttpsRedirection(); app.UseStaticFiles(); - app.UseCookiePolicy(); + app.UseRouting(); + app.UseCookiePolicy(); app.UseAuthentication(); + app.UseAuthorization(); // Enable middleware to serve generated Swagger as a JSON endpoint. app.UseSwagger(); @@ -234,11 +225,12 @@ namespace Microsoft.eShopWeb.Web c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); - app.UseMvc(routes => + app.UseEndpoints(endpoints => { - routes.MapRoute( - name: "default", - template: "{controller:slugify=Home}/{action:slugify=Index}/{id?}"); + endpoints.MapControllerRoute("default", "{controller:slugify=Home}/{action:slugify=Index}/{id?}"); + endpoints.MapRazorPages(); + endpoints.MapHealthChecks("home_page_health_check"); + endpoints.MapHealthChecks("api_health_check"); }); } } diff --git a/src/Web/Web.csproj b/src/Web/Web.csproj index 14b33ef..7bcfd3e 100644 --- a/src/Web/Web.csproj +++ b/src/Web/Web.csproj @@ -1,10 +1,9 @@  - netcoreapp2.2 + netcoreapp3.0 Microsoft.eShopWeb.Web aspnet-Web2-1FA3F72E-E7E3-4360-9E49-1CCCD7FE85F7 - InProcess latest @@ -16,12 +15,20 @@ - - - + + - + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/tests/FunctionalTests/FunctionalTests.csproj b/tests/FunctionalTests/FunctionalTests.csproj index 3b09b26..478bd82 100644 --- a/tests/FunctionalTests/FunctionalTests.csproj +++ b/tests/FunctionalTests/FunctionalTests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.2 + netcoreapp3.0 Microsoft.eShopWeb.FunctionalTests false @@ -13,15 +13,14 @@ - - + all runtime; build; native; contentfiles; analyzers - + diff --git a/tests/FunctionalTests/Web/Controllers/AccountControllerSignIn.cs b/tests/FunctionalTests/Web/Controllers/AccountControllerSignIn.cs index c706368..4595d6c 100644 --- a/tests/FunctionalTests/Web/Controllers/AccountControllerSignIn.cs +++ b/tests/FunctionalTests/Web/Controllers/AccountControllerSignIn.cs @@ -11,6 +11,7 @@ using Xunit; namespace Microsoft.eShopWeb.FunctionalTests.Web.Controllers { + [Collection("Sequential")] public class AccountControllerSignIn : IClassFixture> { public AccountControllerSignIn(CustomWebApplicationFactory factory) @@ -42,7 +43,7 @@ namespace Microsoft.eShopWeb.FunctionalTests.Web.Controllers string regexpression = @"name=""__RequestVerificationToken"" type=""hidden"" value=""([-A-Za-z0-9+=/\\_]+?)"""; var regex = new Regex(regexpression); var match = regex.Match(input); - var group = match.Groups.LastOrDefault(); + var group = match.Groups.Values.LastOrDefault(); Assert.NotNull(group); Assert.True(group.Value.Length > 50); } @@ -63,7 +64,7 @@ namespace Microsoft.eShopWeb.FunctionalTests.Web.Controllers string regexpression = @"name=""__RequestVerificationToken"" type=""hidden"" value=""([-A-Za-z0-9+=/\\_]+?)"""; var regex = new Regex(regexpression); var match = regex.Match(input); - return match.Groups.LastOrDefault().Value; + return match.Groups.Values.LastOrDefault().Value; } [Fact] diff --git a/tests/FunctionalTests/Web/Controllers/ApiCatalogControllerList.cs b/tests/FunctionalTests/Web/Controllers/ApiCatalogControllerList.cs index e3e675b..d5f79a5 100644 --- a/tests/FunctionalTests/Web/Controllers/ApiCatalogControllerList.cs +++ b/tests/FunctionalTests/Web/Controllers/ApiCatalogControllerList.cs @@ -8,6 +8,7 @@ using Xunit; namespace Microsoft.eShopWeb.FunctionalTests.Web.Controllers { + [Collection("Sequential")] public class ApiCatalogControllerList : IClassFixture> { public ApiCatalogControllerList(CustomWebApplicationFactory factory) diff --git a/tests/FunctionalTests/Web/Controllers/CatalogControllerIndex.cs b/tests/FunctionalTests/Web/Controllers/CatalogControllerIndex.cs index 8fec0cc..34c03cb 100644 --- a/tests/FunctionalTests/Web/Controllers/CatalogControllerIndex.cs +++ b/tests/FunctionalTests/Web/Controllers/CatalogControllerIndex.cs @@ -5,6 +5,7 @@ using Xunit; namespace Microsoft.eShopWeb.FunctionalTests.Web.Controllers { + [Collection("Sequential")] public class CatalogControllerIndex : IClassFixture> { public CatalogControllerIndex(CustomWebApplicationFactory factory) diff --git a/tests/FunctionalTests/Web/Controllers/OrderControllerIndex.cs b/tests/FunctionalTests/Web/Controllers/OrderControllerIndex.cs index ca43800..06aa483 100644 --- a/tests/FunctionalTests/Web/Controllers/OrderControllerIndex.cs +++ b/tests/FunctionalTests/Web/Controllers/OrderControllerIndex.cs @@ -7,6 +7,7 @@ using Xunit; namespace Microsoft.eShopWeb.FunctionalTests.Web.Controllers { + [Collection("Sequential")] public class OrderIndexOnGet : IClassFixture> { public OrderIndexOnGet(CustomWebApplicationFactory factory) diff --git a/tests/FunctionalTests/Web/CustomWebApplicationFactory.cs b/tests/FunctionalTests/Web/CustomWebApplicationFactory.cs index 14bf8eb..659abd9 100644 --- a/tests/FunctionalTests/Web/CustomWebApplicationFactory.cs +++ b/tests/FunctionalTests/Web/CustomWebApplicationFactory.cs @@ -40,11 +40,6 @@ namespace Microsoft.eShopWeb.FunctionalTests.Web.Controllers options.UseInternalServiceProvider(provider); }); - services.AddIdentity() - .AddDefaultUI(UIFramework.Bootstrap4) - .AddEntityFrameworkStores() - .AddDefaultTokenProviders(); - // Build the service provider. var sp = services.BuildServiceProvider(); diff --git a/tests/FunctionalTests/Web/Pages/BasketPageCheckout.cs b/tests/FunctionalTests/Web/Pages/BasketPageCheckout.cs index 128e13c..cc12b85 100644 --- a/tests/FunctionalTests/Web/Pages/BasketPageCheckout.cs +++ b/tests/FunctionalTests/Web/Pages/BasketPageCheckout.cs @@ -11,6 +11,7 @@ using Xunit; namespace Microsoft.eShopWeb.FunctionalTests.WebRazorPages { + [Collection("Sequential")] public class BasketPageCheckout : IClassFixture> { public BasketPageCheckout(CustomWebApplicationFactory factory) @@ -28,7 +29,7 @@ namespace Microsoft.eShopWeb.FunctionalTests.WebRazorPages string regexpression = @"name=""__RequestVerificationToken"" type=""hidden"" value=""([-A-Za-z0-9+=/\\_]+?)"""; var regex = new Regex(regexpression); var match = regex.Match(input); - return match.Groups.LastOrDefault().Value; + return match.Groups.Values.LastOrDefault().Value; } [Fact] diff --git a/tests/FunctionalTests/Web/Pages/HomePageOnGet.cs b/tests/FunctionalTests/Web/Pages/HomePageOnGet.cs index 1a795e1..73c62df 100644 --- a/tests/FunctionalTests/Web/Pages/HomePageOnGet.cs +++ b/tests/FunctionalTests/Web/Pages/HomePageOnGet.cs @@ -6,6 +6,7 @@ using Xunit; namespace Microsoft.eShopWeb.FunctionalTests.WebRazorPages { + [Collection("Sequential")] public class HomePageOnGet : IClassFixture> { public HomePageOnGet(CustomWebApplicationFactory factory) diff --git a/tests/IntegrationTests/IntegrationTests.csproj b/tests/IntegrationTests/IntegrationTests.csproj index b3ea50f..df9a526 100644 --- a/tests/IntegrationTests/IntegrationTests.csproj +++ b/tests/IntegrationTests/IntegrationTests.csproj @@ -1,15 +1,15 @@  - netcoreapp2.2 + netcoreapp3.0 Microsoft.eShopWeb.IntegrationTests false - + - + all diff --git a/tests/UnitTests/UnitTests.csproj b/tests/UnitTests/UnitTests.csproj index 4e8ed3c..bc747eb 100644 --- a/tests/UnitTests/UnitTests.csproj +++ b/tests/UnitTests/UnitTests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.2 + netcoreapp3.0 Microsoft.eShopWeb.UnitTests false @@ -9,7 +9,7 @@ - + all