From b68f044709a8db25672bd9e8d2465377485ac7b4 Mon Sep 17 00:00:00 2001 From: Eric Fleming Date: Fri, 18 Oct 2019 10:58:19 -0400 Subject: [PATCH 01/12] Updates based on documentation --- src/Web/Program.cs | 12 ++++++++---- src/Web/Startup.cs | 38 +++++++++++++++++++++++--------------- src/Web/Web.csproj | 10 ++++++---- 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/Web/Program.cs b/src/Web/Program.cs index 3aa1551..28ab640 100644 --- a/src/Web/Program.cs +++ b/src/Web/Program.cs @@ -4,6 +4,7 @@ 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 +15,7 @@ public class Program { public async static Task Main(string[] args) { - var host = CreateWebHostBuilder(args) + var host = CreateHostBuilder(args) .Build(); using (var scope = host.Services.CreateScope()) @@ -39,8 +40,11 @@ public async static Task Main(string[] args) 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..aa1d046 100644 --- a/src/Web/Startup.cs +++ b/src/Web/Startup.cs @@ -21,6 +21,7 @@ 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; @@ -110,19 +111,23 @@ public void ConfigureServices(IServiceCollection services) options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer); }); + //TODO: Still works the same services.AddMvc(options => { options.Conventions.Add(new RouteTokenTransformerConvention( new SlugifyParameterTransformer())); + + }); - } - ) - .AddRazorPagesOptions(options => - { - options.Conventions.AuthorizePage("/Basket/Checkout"); - options.AllowAreas = true; - }) - .SetCompatibilityVersion(CompatibilityVersion.Version_2_2); + services.AddRazorPages(options => + { + options.Conventions.AuthorizePage("/Basket/Checkout"); + //TODO: options.AllowAreas = true; + }); + + //TODO: See if needed + services.AddControllersWithViews(); + services.AddControllers(); services.AddHttpContextAccessor(); services.AddSwaggerGen(c => @@ -130,6 +135,7 @@ public void ConfigureServices(IServiceCollection services) c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" }); }); + //TODO: confirm health checks are working with the Endpoint section below services.AddHealthChecks() .AddCheck("home_page_health_check") .AddCheck("api_health_check"); @@ -183,7 +189,7 @@ private static void ConfigureCookieSettings(IServiceCollection services) } // 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", @@ -218,10 +224,11 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) app.UseHsts(); } - app.UseHttpsRedirection(); app.UseStaticFiles(); + app.UseRouting(); + + app.UseHttpsRedirection(); app.UseCookiePolicy(); - app.UseAuthentication(); // Enable middleware to serve generated Swagger as a JSON endpoint. @@ -234,11 +241,12 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) 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..96f24a5 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,15 @@ - - + + + + + From 88d23d559113f3f74e58a288ec303752b1b2b2dd Mon Sep 17 00:00:00 2001 From: Eric Fleming Date: Fri, 18 Oct 2019 11:25:19 -0400 Subject: [PATCH 02/12] Getting the build passing --- src/ApplicationCore/ApplicationCore.csproj | 2 +- src/Infrastructure/Infrastructure.csproj | 8 +- src/Web/Startup.cs | 14 +-- src/Web/Web.csproj | 11 +- tests/FunctionalTests/FunctionalTests.csproj | 6 +- .../Controllers/AccountControllerSignIn.cs | 106 +++++++++--------- .../Web/CustomWebApplicationFactory.cs | 2 +- .../Web/Pages/BasketPageCheckout.cs | 68 +++++------ .../IntegrationTests/IntegrationTests.csproj | 4 +- tests/UnitTests/UnitTests.csproj | 2 +- 10 files changed, 113 insertions(+), 110 deletions(-) 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/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/Startup.cs b/src/Web/Startup.cs index aa1d046..4be7633 100644 --- a/src/Web/Startup.cs +++ b/src/Web/Startup.cs @@ -4,10 +4,7 @@ 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; @@ -130,10 +127,11 @@ public void ConfigureServices(IServiceCollection services) services.AddControllers(); services.AddHttpContextAccessor(); - services.AddSwaggerGen(c => - { - c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" }); - }); + //TODO: fix swagger + //services.AddSwaggerGen(c => + //{ + // c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" }); + //}); //TODO: confirm health checks are working with the Endpoint section below services.AddHealthChecks() @@ -160,7 +158,7 @@ private static void CreateIdentityIfNotCreated(IServiceCollection services) if(existingUserManager == null) { services.AddIdentity() - .AddDefaultUI(UIFramework.Bootstrap4) + .AddDefaultUI() //TODO: Make sure this is good to go? .AddEntityFrameworkStores() .AddDefaultTokenProviders(); } diff --git a/src/Web/Web.csproj b/src/Web/Web.csproj index 96f24a5..9f97e4e 100644 --- a/src/Web/Web.csproj +++ b/src/Web/Web.csproj @@ -16,14 +16,19 @@ - + + - + + - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/tests/FunctionalTests/FunctionalTests.csproj b/tests/FunctionalTests/FunctionalTests.csproj index 3b09b26..57c1519 100644 --- a/tests/FunctionalTests/FunctionalTests.csproj +++ b/tests/FunctionalTests/FunctionalTests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.2 + netcoreapp3.0 Microsoft.eShopWeb.FunctionalTests false @@ -14,14 +14,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..77e0b45 100644 --- a/tests/FunctionalTests/Web/Controllers/AccountControllerSignIn.cs +++ b/tests/FunctionalTests/Web/Controllers/AccountControllerSignIn.cs @@ -23,67 +23,67 @@ public AccountControllerSignIn(CustomWebApplicationFactory factory) public HttpClient Client { get; } - [Fact] - public async Task ReturnsSignInScreenOnGet() - { - var response = await Client.GetAsync("/identity/account/login"); - response.EnsureSuccessStatusCode(); - var stringResponse = await response.Content.ReadAsStringAsync(); + //[Fact] + //public async Task ReturnsSignInScreenOnGet() + //{ + // var response = await Client.GetAsync("/identity/account/login"); + // response.EnsureSuccessStatusCode(); + // var stringResponse = await response.Content.ReadAsStringAsync(); - Assert.Contains("demouser@microsoft.com", stringResponse); - } + // Assert.Contains("demouser@microsoft.com", stringResponse); + //} - [Fact] - public void RegexMatchesValidRequestVerificationToken() - { - // TODO: Move to a unit test - // TODO: Move regex to a constant in test project - var input = @""; - 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(); - Assert.NotNull(group); - Assert.True(group.Value.Length > 50); - } + //[Fact] + //public void RegexMatchesValidRequestVerificationToken() + //{ + // // TODO: Move to a unit test + // // TODO: Move regex to a constant in test project + // var input = @""; + // 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(); + // Assert.NotNull(group); + // Assert.True(group.Value.Length > 50); + //} - [Fact] - public async Task ReturnsFormWithRequestVerificationToken() - { - var response = await Client.GetAsync("/identity/account/login"); - response.EnsureSuccessStatusCode(); - var stringResponse = await response.Content.ReadAsStringAsync(); + //[Fact] + //public async Task ReturnsFormWithRequestVerificationToken() + //{ + // var response = await Client.GetAsync("/identity/account/login"); + // response.EnsureSuccessStatusCode(); + // var stringResponse = await response.Content.ReadAsStringAsync(); - string token = GetRequestVerificationToken(stringResponse); - Assert.True(token.Length > 50); - } + // string token = GetRequestVerificationToken(stringResponse); + // Assert.True(token.Length > 50); + //} - private string GetRequestVerificationToken(string input) - { - 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; - } + //private string GetRequestVerificationToken(string input) + //{ + // 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; + //} - [Fact] - public async Task ReturnsSuccessfulSignInOnPostWithValidCredentials() - { - var getResponse = await Client.GetAsync("/identity/account/login"); - getResponse.EnsureSuccessStatusCode(); - var stringResponse1 = await getResponse.Content.ReadAsStringAsync(); - string token = GetRequestVerificationToken(stringResponse1); + //[Fact] + //public async Task ReturnsSuccessfulSignInOnPostWithValidCredentials() + //{ + // var getResponse = await Client.GetAsync("/identity/account/login"); + // getResponse.EnsureSuccessStatusCode(); + // var stringResponse1 = await getResponse.Content.ReadAsStringAsync(); + // string token = GetRequestVerificationToken(stringResponse1); - var keyValues = new List>(); - keyValues.Add(new KeyValuePair("Email", "demouser@microsoft.com")); - keyValues.Add(new KeyValuePair("Password", "Pass@word1")); + // var keyValues = new List>(); + // keyValues.Add(new KeyValuePair("Email", "demouser@microsoft.com")); + // keyValues.Add(new KeyValuePair("Password", "Pass@word1")); - keyValues.Add(new KeyValuePair("__RequestVerificationToken", token)); - var formContent = new FormUrlEncodedContent(keyValues); + // keyValues.Add(new KeyValuePair("__RequestVerificationToken", token)); + // var formContent = new FormUrlEncodedContent(keyValues); - var postResponse = await Client.PostAsync("/identity/account/login", formContent); - Assert.Equal(HttpStatusCode.Redirect, postResponse.StatusCode); - Assert.Equal(new System.Uri("/", UriKind.Relative), postResponse.Headers.Location); - } + // var postResponse = await Client.PostAsync("/identity/account/login", formContent); + // Assert.Equal(HttpStatusCode.Redirect, postResponse.StatusCode); + // Assert.Equal(new System.Uri("/", UriKind.Relative), postResponse.Headers.Location); + //} } } diff --git a/tests/FunctionalTests/Web/CustomWebApplicationFactory.cs b/tests/FunctionalTests/Web/CustomWebApplicationFactory.cs index 14bf8eb..6abd136 100644 --- a/tests/FunctionalTests/Web/CustomWebApplicationFactory.cs +++ b/tests/FunctionalTests/Web/CustomWebApplicationFactory.cs @@ -41,7 +41,7 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) }); services.AddIdentity() - .AddDefaultUI(UIFramework.Bootstrap4) + .AddDefaultUI() //TODO: check this one as well .AddEntityFrameworkStores() .AddDefaultTokenProviders(); diff --git a/tests/FunctionalTests/Web/Pages/BasketPageCheckout.cs b/tests/FunctionalTests/Web/Pages/BasketPageCheckout.cs index 128e13c..b2e773a 100644 --- a/tests/FunctionalTests/Web/Pages/BasketPageCheckout.cs +++ b/tests/FunctionalTests/Web/Pages/BasketPageCheckout.cs @@ -23,49 +23,49 @@ public BasketPageCheckout(CustomWebApplicationFactory factory) public HttpClient Client { get; } - private string GetRequestVerificationToken(string input) - { - 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; - } + //private string GetRequestVerificationToken(string input) + //{ + // 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; + //} - [Fact] - public async Task RedirectsToLoginIfNotAuthenticated() - { - // Arrange & Act + //[Fact] + //public async Task RedirectsToLoginIfNotAuthenticated() + //{ + // // Arrange & Act - // Load Home Page - var response = await Client.GetAsync("/"); - response.EnsureSuccessStatusCode(); - var stringResponse1 = await response.Content.ReadAsStringAsync(); + // // Load Home Page + // var response = await Client.GetAsync("/"); + // response.EnsureSuccessStatusCode(); + // var stringResponse1 = await response.Content.ReadAsStringAsync(); - string token = GetRequestVerificationToken(stringResponse1); + // string token = GetRequestVerificationToken(stringResponse1); - // Add Item to Cart - var keyValues = new List>(); - keyValues.Add(new KeyValuePair("id", "2")); - keyValues.Add(new KeyValuePair("name", "shirt")); + // // Add Item to Cart + // var keyValues = new List>(); + // keyValues.Add(new KeyValuePair("id", "2")); + // keyValues.Add(new KeyValuePair("name", "shirt")); - keyValues.Add(new KeyValuePair("price", "19.49")); - keyValues.Add(new KeyValuePair("__RequestVerificationToken", token)); + // keyValues.Add(new KeyValuePair("price", "19.49")); + // keyValues.Add(new KeyValuePair("__RequestVerificationToken", token)); - var formContent = new FormUrlEncodedContent(keyValues); + // var formContent = new FormUrlEncodedContent(keyValues); - var postResponse = await Client.PostAsync("/basket/index", formContent); - postResponse.EnsureSuccessStatusCode(); - var stringResponse = await postResponse.Content.ReadAsStringAsync(); + // var postResponse = await Client.PostAsync("/basket/index", formContent); + // postResponse.EnsureSuccessStatusCode(); + // var stringResponse = await postResponse.Content.ReadAsStringAsync(); - // Assert - Assert.Contains(".NET Black & White Mug", stringResponse); + // // Assert + // Assert.Contains(".NET Black & White Mug", stringResponse); - keyValues.Clear(); - keyValues.Add(new KeyValuePair("__RequestVerificationToken", token)); + // keyValues.Clear(); + // keyValues.Add(new KeyValuePair("__RequestVerificationToken", token)); - formContent = new FormUrlEncodedContent(keyValues); - var postResponse2 = await Client.PostAsync("/Basket/Checkout", formContent); - Assert.Contains("/Identity/Account/Login", postResponse2.RequestMessage.RequestUri.ToString()); - } + // formContent = new FormUrlEncodedContent(keyValues); + // var postResponse2 = await Client.PostAsync("/Basket/Checkout", formContent); + // Assert.Contains("/Identity/Account/Login", postResponse2.RequestMessage.RequestUri.ToString()); + //} } } diff --git a/tests/IntegrationTests/IntegrationTests.csproj b/tests/IntegrationTests/IntegrationTests.csproj index b3ea50f..7615c19 100644 --- a/tests/IntegrationTests/IntegrationTests.csproj +++ b/tests/IntegrationTests/IntegrationTests.csproj @@ -1,13 +1,13 @@  - netcoreapp2.2 + netcoreapp3.0 Microsoft.eShopWeb.IntegrationTests false - + diff --git a/tests/UnitTests/UnitTests.csproj b/tests/UnitTests/UnitTests.csproj index 4e8ed3c..79d92fa 100644 --- a/tests/UnitTests/UnitTests.csproj +++ b/tests/UnitTests/UnitTests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.2 + netcoreapp3.0 Microsoft.eShopWeb.UnitTests false From 4d540b5e0301d1db322d2256649d69c1f20e9de3 Mon Sep 17 00:00:00 2001 From: Eric Fleming Date: Fri, 18 Oct 2019 11:41:23 -0400 Subject: [PATCH 03/12] Getting app functioning --- src/Infrastructure/Data/CatalogContext.cs | 30 ++++++++++--------- .../Data/Config/AddressConfiguration.cs | 2 +- .../Config/CatalogItemOrderedConfiguration.cs | 2 +- src/Web/Startup.cs | 4 +-- src/Web/Web.csproj | 2 +- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/Infrastructure/Data/CatalogContext.cs b/src/Infrastructure/Data/CatalogContext.cs index 021c0f4..8263d71 100644 --- a/src/Infrastructure/Data/CatalogContext.cs +++ b/src/Infrastructure/Data/CatalogContext.cs @@ -1,8 +1,10 @@ -using Microsoft.EntityFrameworkCore; +using Ardalis.EFCore.Extensions; +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 { @@ -25,21 +27,21 @@ 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(); + 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); + 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) diff --git a/src/Infrastructure/Data/Config/AddressConfiguration.cs b/src/Infrastructure/Data/Config/AddressConfiguration.cs index ff940bd..7b2eef7 100644 --- a/src/Infrastructure/Data/Config/AddressConfiguration.cs +++ b/src/Infrastructure/Data/Config/AddressConfiguration.cs @@ -4,7 +4,7 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Config { - public class AddressConfiguration : IEntityTypeConfiguration
+ public class AddressConfiguration //: IEntityTypeConfiguration
{ public void Configure(EntityTypeBuilder
builder) { diff --git a/src/Infrastructure/Data/Config/CatalogItemOrderedConfiguration.cs b/src/Infrastructure/Data/Config/CatalogItemOrderedConfiguration.cs index 8a750be..8a726e7 100644 --- a/src/Infrastructure/Data/Config/CatalogItemOrderedConfiguration.cs +++ b/src/Infrastructure/Data/Config/CatalogItemOrderedConfiguration.cs @@ -4,7 +4,7 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Config { - public class CatalogItemOrderedConfiguration : IEntityTypeConfiguration + public class CatalogItemOrderedConfiguration //: IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { diff --git a/src/Web/Startup.cs b/src/Web/Startup.cs index 4be7633..e4348d6 100644 --- a/src/Web/Startup.cs +++ b/src/Web/Startup.cs @@ -132,7 +132,7 @@ public void ConfigureServices(IServiceCollection services) //{ // c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" }); //}); - + services.AddSwaggerGen(); //TODO: confirm health checks are working with the Endpoint section below services.AddHealthChecks() .AddCheck("home_page_health_check") @@ -228,7 +228,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseHttpsRedirection(); app.UseCookiePolicy(); app.UseAuthentication(); - + app.UseAuthorization(); // Enable middleware to serve generated Swagger as a JSON endpoint. app.UseSwagger(); diff --git a/src/Web/Web.csproj b/src/Web/Web.csproj index 9f97e4e..7bcfd3e 100644 --- a/src/Web/Web.csproj +++ b/src/Web/Web.csproj @@ -20,7 +20,7 @@ - + From 4fd8123d692798f84e591d03fd174575ef1f90db Mon Sep 17 00:00:00 2001 From: Eric Fleming Date: Fri, 18 Oct 2019 12:04:57 -0400 Subject: [PATCH 04/12] A few cleanups to confirm it's working as expected --- src/Web/Startup.cs | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/Web/Startup.cs b/src/Web/Startup.cs index e4348d6..48eb649 100644 --- a/src/Web/Startup.cs +++ b/src/Web/Startup.cs @@ -12,7 +12,6 @@ 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; @@ -20,7 +19,6 @@ 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; @@ -85,7 +83,6 @@ public void ConfigureServices(IServiceCollection services) CreateIdentityIfNotCreated(services); services.AddScoped(typeof(IAsyncRepository<>), typeof(EfRepository<>)); - services.AddScoped(); services.AddScoped(); services.AddScoped(); @@ -94,7 +91,6 @@ public void ConfigureServices(IServiceCollection services) services.AddScoped(); services.Configure(Configuration); services.AddSingleton(new UriComposer(Configuration.Get())); - services.AddScoped(typeof(IAppLogger<>), typeof(LoggerAdapter<>)); services.AddTransient(); @@ -108,35 +104,24 @@ public void ConfigureServices(IServiceCollection services) options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer); }); - //TODO: Still works the same services.AddMvc(options => { options.Conventions.Add(new RouteTokenTransformerConvention( new SlugifyParameterTransformer())); - }); - + }); services.AddRazorPages(options => { options.Conventions.AuthorizePage("/Basket/Checkout"); - //TODO: options.AllowAreas = true; }); - - //TODO: See if needed services.AddControllersWithViews(); services.AddControllers(); services.AddHttpContextAccessor(); - //TODO: fix swagger - //services.AddSwaggerGen(c => - //{ - // c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" }); - //}); - services.AddSwaggerGen(); - //TODO: confirm health checks are working with the Endpoint section below - services.AddHealthChecks() - .AddCheck("home_page_health_check") - .AddCheck("api_health_check"); + + services.AddSwaggerGen(c => c.SwaggerDoc("v1", new OpenApi.Models.OpenApiInfo { Title = "My API", Version = "v1"})); + + services.AddHealthChecks(); services.Configure(config => { @@ -158,7 +143,7 @@ private static void CreateIdentityIfNotCreated(IServiceCollection services) if(existingUserManager == null) { services.AddIdentity() - .AddDefaultUI() //TODO: Make sure this is good to go? + .AddDefaultUI() .AddEntityFrameworkStores() .AddDefaultTokenProviders(); } From 8aec301469ad375bfcd29671b5be5ffeabbc5101 Mon Sep 17 00:00:00 2001 From: Eric Fleming Date: Fri, 18 Oct 2019 13:39:18 -0400 Subject: [PATCH 05/12] Fixing functional tests --- src/Web/Program.cs | 3 +- tests/FunctionalTests/FunctionalTests.csproj | 1 - .../Controllers/AccountControllerSignIn.cs | 106 +++++++++--------- .../Web/CustomWebApplicationFactory.cs | 5 - .../Web/Pages/BasketPageCheckout.cs | 68 +++++------ 5 files changed, 88 insertions(+), 95 deletions(-) diff --git a/src/Web/Program.cs b/src/Web/Program.cs index 28ab640..0703f42 100644 --- a/src/Web/Program.cs +++ b/src/Web/Program.cs @@ -1,5 +1,4 @@ -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; diff --git a/tests/FunctionalTests/FunctionalTests.csproj b/tests/FunctionalTests/FunctionalTests.csproj index 57c1519..478bd82 100644 --- a/tests/FunctionalTests/FunctionalTests.csproj +++ b/tests/FunctionalTests/FunctionalTests.csproj @@ -13,7 +13,6 @@ - diff --git a/tests/FunctionalTests/Web/Controllers/AccountControllerSignIn.cs b/tests/FunctionalTests/Web/Controllers/AccountControllerSignIn.cs index 77e0b45..ec2ae33 100644 --- a/tests/FunctionalTests/Web/Controllers/AccountControllerSignIn.cs +++ b/tests/FunctionalTests/Web/Controllers/AccountControllerSignIn.cs @@ -23,67 +23,67 @@ public AccountControllerSignIn(CustomWebApplicationFactory factory) public HttpClient Client { get; } - //[Fact] - //public async Task ReturnsSignInScreenOnGet() - //{ - // var response = await Client.GetAsync("/identity/account/login"); - // response.EnsureSuccessStatusCode(); - // var stringResponse = await response.Content.ReadAsStringAsync(); + [Fact] + public async Task ReturnsSignInScreenOnGet() + { + var response = await Client.GetAsync("/identity/account/login"); + response.EnsureSuccessStatusCode(); + var stringResponse = await response.Content.ReadAsStringAsync(); - // Assert.Contains("demouser@microsoft.com", stringResponse); - //} + Assert.Contains("demouser@microsoft.com", stringResponse); + } - //[Fact] - //public void RegexMatchesValidRequestVerificationToken() - //{ - // // TODO: Move to a unit test - // // TODO: Move regex to a constant in test project - // var input = @""; - // 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(); - // Assert.NotNull(group); - // Assert.True(group.Value.Length > 50); - //} + [Fact] + public void RegexMatchesValidRequestVerificationToken() + { + // TODO: Move to a unit test + // TODO: Move regex to a constant in test project + var input = @""; + 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.Values.LastOrDefault(); + Assert.NotNull(group); + Assert.True(group.Value.Length > 50); + } - //[Fact] - //public async Task ReturnsFormWithRequestVerificationToken() - //{ - // var response = await Client.GetAsync("/identity/account/login"); - // response.EnsureSuccessStatusCode(); - // var stringResponse = await response.Content.ReadAsStringAsync(); + [Fact] + public async Task ReturnsFormWithRequestVerificationToken() + { + var response = await Client.GetAsync("/identity/account/login"); + response.EnsureSuccessStatusCode(); + var stringResponse = await response.Content.ReadAsStringAsync(); - // string token = GetRequestVerificationToken(stringResponse); - // Assert.True(token.Length > 50); - //} + string token = GetRequestVerificationToken(stringResponse); + Assert.True(token.Length > 50); + } - //private string GetRequestVerificationToken(string input) - //{ - // 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; - //} + private string GetRequestVerificationToken(string input) + { + string regexpression = @"name=""__RequestVerificationToken"" type=""hidden"" value=""([-A-Za-z0-9+=/\\_]+?)"""; + var regex = new Regex(regexpression); + var match = regex.Match(input); + return match.Groups.Values.LastOrDefault().Value; + } - //[Fact] - //public async Task ReturnsSuccessfulSignInOnPostWithValidCredentials() - //{ - // var getResponse = await Client.GetAsync("/identity/account/login"); - // getResponse.EnsureSuccessStatusCode(); - // var stringResponse1 = await getResponse.Content.ReadAsStringAsync(); - // string token = GetRequestVerificationToken(stringResponse1); + [Fact] + public async Task ReturnsSuccessfulSignInOnPostWithValidCredentials() + { + var getResponse = await Client.GetAsync("/identity/account/login"); + getResponse.EnsureSuccessStatusCode(); + var stringResponse1 = await getResponse.Content.ReadAsStringAsync(); + string token = GetRequestVerificationToken(stringResponse1); - // var keyValues = new List>(); - // keyValues.Add(new KeyValuePair("Email", "demouser@microsoft.com")); - // keyValues.Add(new KeyValuePair("Password", "Pass@word1")); + var keyValues = new List>(); + keyValues.Add(new KeyValuePair("Email", "demouser@microsoft.com")); + keyValues.Add(new KeyValuePair("Password", "Pass@word1")); - // keyValues.Add(new KeyValuePair("__RequestVerificationToken", token)); - // var formContent = new FormUrlEncodedContent(keyValues); + keyValues.Add(new KeyValuePair("__RequestVerificationToken", token)); + var formContent = new FormUrlEncodedContent(keyValues); - // var postResponse = await Client.PostAsync("/identity/account/login", formContent); - // Assert.Equal(HttpStatusCode.Redirect, postResponse.StatusCode); - // Assert.Equal(new System.Uri("/", UriKind.Relative), postResponse.Headers.Location); - //} + var postResponse = await Client.PostAsync("/identity/account/login", formContent); + Assert.Equal(HttpStatusCode.Redirect, postResponse.StatusCode); + Assert.Equal(new System.Uri("/", UriKind.Relative), postResponse.Headers.Location); + } } } diff --git a/tests/FunctionalTests/Web/CustomWebApplicationFactory.cs b/tests/FunctionalTests/Web/CustomWebApplicationFactory.cs index 6abd136..659abd9 100644 --- a/tests/FunctionalTests/Web/CustomWebApplicationFactory.cs +++ b/tests/FunctionalTests/Web/CustomWebApplicationFactory.cs @@ -40,11 +40,6 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) options.UseInternalServiceProvider(provider); }); - services.AddIdentity() - .AddDefaultUI() //TODO: check this one as well - .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 b2e773a..05613ba 100644 --- a/tests/FunctionalTests/Web/Pages/BasketPageCheckout.cs +++ b/tests/FunctionalTests/Web/Pages/BasketPageCheckout.cs @@ -23,49 +23,49 @@ public BasketPageCheckout(CustomWebApplicationFactory factory) public HttpClient Client { get; } - //private string GetRequestVerificationToken(string input) - //{ - // 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; - //} + private string GetRequestVerificationToken(string input) + { + string regexpression = @"name=""__RequestVerificationToken"" type=""hidden"" value=""([-A-Za-z0-9+=/\\_]+?)"""; + var regex = new Regex(regexpression); + var match = regex.Match(input); + return match.Groups.Values.LastOrDefault().Value; + } - //[Fact] - //public async Task RedirectsToLoginIfNotAuthenticated() - //{ - // // Arrange & Act + [Fact] + public async Task RedirectsToLoginIfNotAuthenticated() + { + // Arrange & Act - // // Load Home Page - // var response = await Client.GetAsync("/"); - // response.EnsureSuccessStatusCode(); - // var stringResponse1 = await response.Content.ReadAsStringAsync(); + // Load Home Page + var response = await Client.GetAsync("/"); + response.EnsureSuccessStatusCode(); + var stringResponse1 = await response.Content.ReadAsStringAsync(); - // string token = GetRequestVerificationToken(stringResponse1); + string token = GetRequestVerificationToken(stringResponse1); - // // Add Item to Cart - // var keyValues = new List>(); - // keyValues.Add(new KeyValuePair("id", "2")); - // keyValues.Add(new KeyValuePair("name", "shirt")); + // Add Item to Cart + var keyValues = new List>(); + keyValues.Add(new KeyValuePair("id", "2")); + keyValues.Add(new KeyValuePair("name", "shirt")); - // keyValues.Add(new KeyValuePair("price", "19.49")); - // keyValues.Add(new KeyValuePair("__RequestVerificationToken", token)); + keyValues.Add(new KeyValuePair("price", "19.49")); + keyValues.Add(new KeyValuePair("__RequestVerificationToken", token)); - // var formContent = new FormUrlEncodedContent(keyValues); + var formContent = new FormUrlEncodedContent(keyValues); - // var postResponse = await Client.PostAsync("/basket/index", formContent); - // postResponse.EnsureSuccessStatusCode(); - // var stringResponse = await postResponse.Content.ReadAsStringAsync(); + var postResponse = await Client.PostAsync("/basket/index", formContent); + postResponse.EnsureSuccessStatusCode(); + var stringResponse = await postResponse.Content.ReadAsStringAsync(); - // // Assert - // Assert.Contains(".NET Black & White Mug", stringResponse); + // Assert + Assert.Contains(".NET Black & White Mug", stringResponse); - // keyValues.Clear(); - // keyValues.Add(new KeyValuePair("__RequestVerificationToken", token)); + keyValues.Clear(); + keyValues.Add(new KeyValuePair("__RequestVerificationToken", token)); - // formContent = new FormUrlEncodedContent(keyValues); - // var postResponse2 = await Client.PostAsync("/Basket/Checkout", formContent); - // Assert.Contains("/Identity/Account/Login", postResponse2.RequestMessage.RequestUri.ToString()); - //} + formContent = new FormUrlEncodedContent(keyValues); + var postResponse2 = await Client.PostAsync("/Basket/Checkout", formContent); + Assert.Contains("/Identity/Account/Login", postResponse2.RequestMessage.RequestUri.ToString()); + } } } From bb184b7a5c51111797cb3374fb603954777c2894 Mon Sep 17 00:00:00 2001 From: Eric Fleming Date: Fri, 18 Oct 2019 14:12:11 -0400 Subject: [PATCH 06/12] Updating dockerfile for 3.0 --- src/Web/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 ./ From ebeb9ae3b0462a1ae0f35c54dd513228db6f6ef3 Mon Sep 17 00:00:00 2001 From: Eric Fleming Date: Mon, 21 Oct 2019 14:59:52 -0400 Subject: [PATCH 07/12] Functional Tests now run sequentially --- tests/FunctionalTests/Web/Controllers/AccountControllerSignIn.cs | 1 + .../FunctionalTests/Web/Controllers/ApiCatalogControllerList.cs | 1 + tests/FunctionalTests/Web/Controllers/CatalogControllerIndex.cs | 1 + tests/FunctionalTests/Web/Controllers/OrderControllerIndex.cs | 1 + tests/FunctionalTests/Web/Pages/BasketPageCheckout.cs | 1 + tests/FunctionalTests/Web/Pages/HomePageOnGet.cs | 1 + 6 files changed, 6 insertions(+) diff --git a/tests/FunctionalTests/Web/Controllers/AccountControllerSignIn.cs b/tests/FunctionalTests/Web/Controllers/AccountControllerSignIn.cs index ec2ae33..4595d6c 100644 --- a/tests/FunctionalTests/Web/Controllers/AccountControllerSignIn.cs +++ b/tests/FunctionalTests/Web/Controllers/AccountControllerSignIn.cs @@ -11,6 +11,7 @@ namespace Microsoft.eShopWeb.FunctionalTests.Web.Controllers { + [Collection("Sequential")] public class AccountControllerSignIn : IClassFixture> { public AccountControllerSignIn(CustomWebApplicationFactory factory) 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 @@ 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 @@ 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 @@ namespace Microsoft.eShopWeb.FunctionalTests.Web.Controllers { + [Collection("Sequential")] public class OrderIndexOnGet : IClassFixture> { public OrderIndexOnGet(CustomWebApplicationFactory factory) diff --git a/tests/FunctionalTests/Web/Pages/BasketPageCheckout.cs b/tests/FunctionalTests/Web/Pages/BasketPageCheckout.cs index 05613ba..cc12b85 100644 --- a/tests/FunctionalTests/Web/Pages/BasketPageCheckout.cs +++ b/tests/FunctionalTests/Web/Pages/BasketPageCheckout.cs @@ -11,6 +11,7 @@ namespace Microsoft.eShopWeb.FunctionalTests.WebRazorPages { + [Collection("Sequential")] public class BasketPageCheckout : IClassFixture> { public BasketPageCheckout(CustomWebApplicationFactory factory) 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 @@ namespace Microsoft.eShopWeb.FunctionalTests.WebRazorPages { + [Collection("Sequential")] public class HomePageOnGet : IClassFixture> { public HomePageOnGet(CustomWebApplicationFactory factory) From 2a1b588fc86ee68e52ae89c036eb1aab53ccadf7 Mon Sep 17 00:00:00 2001 From: Eric Fleming Date: Thu, 24 Oct 2019 13:47:47 -0400 Subject: [PATCH 08/12] Updating to latest version of moq --- tests/IntegrationTests/IntegrationTests.csproj | 2 +- tests/UnitTests/UnitTests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/IntegrationTests/IntegrationTests.csproj b/tests/IntegrationTests/IntegrationTests.csproj index 7615c19..df9a526 100644 --- a/tests/IntegrationTests/IntegrationTests.csproj +++ b/tests/IntegrationTests/IntegrationTests.csproj @@ -9,7 +9,7 @@ - + all diff --git a/tests/UnitTests/UnitTests.csproj b/tests/UnitTests/UnitTests.csproj index 79d92fa..bc747eb 100644 --- a/tests/UnitTests/UnitTests.csproj +++ b/tests/UnitTests/UnitTests.csproj @@ -9,7 +9,7 @@ - + all From 80210ab329c11fb152121e58dae871ed68b3eeab Mon Sep 17 00:00:00 2001 From: Eric Fleming Date: Thu, 31 Oct 2019 14:58:08 -0400 Subject: [PATCH 09/12] Adding migration for post 3.0 upgrades --- .../Data/Config/BasketConfiguration.cs | 2 +- .../20191031185508_Post30Upgrade.Designer.cs | 274 ++++++++++++++++++ .../20191031185508_Post30Upgrade.cs | 224 ++++++++++++++ .../Migrations/CatalogContextModelSnapshot.cs | 104 ++++--- 4 files changed, 562 insertions(+), 42 deletions(-) create mode 100644 src/Infrastructure/Data/Migrations/20191031185508_Post30Upgrade.Designer.cs create mode 100644 src/Infrastructure/Data/Migrations/20191031185508_Post30Upgrade.cs 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 @@ public void Configure(EntityTypeBuilder builder) builder.Property(b => b.BuyerId) .IsRequired() - .HasMaxLength(20); + .HasMaxLength(40); } } } 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/CatalogContextModelSnapshot.cs b/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs index 8a678ff..9d380fa 100644 --- a/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs +++ b/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs @@ -15,7 +15,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #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 @@ protected override void BuildModel(ModelBuilder modelBuilder) { 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 @@ protected override void BuildModel(ModelBuilder modelBuilder) { 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 @@ protected override void BuildModel(ModelBuilder modelBuilder) { 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 @@ protected override void BuildModel(ModelBuilder modelBuilder) { 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 @@ protected override void BuildModel(ModelBuilder modelBuilder) { 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 @@ protected override void BuildModel(ModelBuilder modelBuilder) 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 @@ protected override void BuildModel(ModelBuilder modelBuilder) 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,36 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b1.Property("OrderId") .ValueGeneratedOnAdd() + .HasColumnType("int") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); b1.Property("City") - .IsRequired() - .HasMaxLength(100); + .HasColumnType("nvarchar(max)"); b1.Property("Country") - .IsRequired() - .HasMaxLength(90); + .HasColumnType("nvarchar(max)"); b1.Property("State") - .HasMaxLength(60); + .HasColumnType("nvarchar(max)"); b1.Property("Street") - .IsRequired() - .HasMaxLength(180); + .HasColumnType("nvarchar(max)"); b1.Property("ZipCode") - .IsRequired() - .HasMaxLength(18); + .HasColumnType("nvarchar(max)"); 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 +246,24 @@ protected override void BuildModel(ModelBuilder modelBuilder) { 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() - .HasMaxLength(50); + .HasColumnType("nvarchar(max)"); 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 From be79a01e034b53dde1ea34e70ffdcd76179d6b9e Mon Sep 17 00:00:00 2001 From: Eric Fleming Date: Fri, 1 Nov 2019 11:15:25 -0400 Subject: [PATCH 10/12] Removing commented out lines --- src/Infrastructure/Data/CatalogContext.cs | 138 +----------------- .../Data/Config/AddressConfiguration.cs | 5 +- .../Config/CatalogItemOrderedConfiguration.cs | 5 +- 3 files changed, 5 insertions(+), 143 deletions(-) diff --git a/src/Infrastructure/Data/CatalogContext.cs b/src/Infrastructure/Data/CatalogContext.cs index 8263d71..03cda58 100644 --- a/src/Infrastructure/Data/CatalogContext.cs +++ b/src/Infrastructure/Data/CatalogContext.cs @@ -1,6 +1,4 @@ -using Ardalis.EFCore.Extensions; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.EntityFrameworkCore; using Microsoft.eShopWeb.ApplicationCore.Entities; using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; @@ -25,142 +23,8 @@ public CatalogContext(DbContextOptions 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(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)"); } } } diff --git a/src/Infrastructure/Data/Config/AddressConfiguration.cs b/src/Infrastructure/Data/Config/AddressConfiguration.cs index 7b2eef7..b5b57d3 100644 --- a/src/Infrastructure/Data/Config/AddressConfiguration.cs +++ b/src/Infrastructure/Data/Config/AddressConfiguration.cs @@ -1,10 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; namespace Microsoft.eShopWeb.Infrastructure.Data.Config { - public class AddressConfiguration //: IEntityTypeConfiguration
+ public class AddressConfiguration { public void Configure(EntityTypeBuilder
builder) { diff --git a/src/Infrastructure/Data/Config/CatalogItemOrderedConfiguration.cs b/src/Infrastructure/Data/Config/CatalogItemOrderedConfiguration.cs index 8a726e7..c6e1ff3 100644 --- a/src/Infrastructure/Data/Config/CatalogItemOrderedConfiguration.cs +++ b/src/Infrastructure/Data/Config/CatalogItemOrderedConfiguration.cs @@ -1,10 +1,9 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; namespace Microsoft.eShopWeb.Infrastructure.Data.Config { - public class CatalogItemOrderedConfiguration //: IEntityTypeConfiguration + public class CatalogItemOrderedConfiguration { public void Configure(EntityTypeBuilder builder) { From 0450c12d4f96f5f4f5a52588e6d031f1b95247c2 Mon Sep 17 00:00:00 2001 From: Eric Fleming Date: Tue, 5 Nov 2019 11:30:20 -0500 Subject: [PATCH 11/12] Moving address and catalogitemordered configuration in to classes that own them --- .../Data/Config/AddressConfiguration.cs | 30 -- .../Data/Config/CatalogBrandConfiguration.cs | 2 +- .../Data/Config/CatalogItemConfiguration.cs | 2 +- .../Config/CatalogItemOrderedConfiguration.cs | 15 - .../Data/Config/OrderConfiguration.cs | 24 +- .../Data/Config/OrderItemConfiguration.cs | 9 +- ...ssAndCatalogItemOrderedChanges.Designer.cs | 285 ++++++++++++++++++ ...820_AddressAndCatalogItemOrderedChanges.cs | 121 ++++++++ .../Migrations/CatalogContextModelSnapshot.cs | 23 +- 9 files changed, 456 insertions(+), 55 deletions(-) delete mode 100644 src/Infrastructure/Data/Config/AddressConfiguration.cs delete mode 100644 src/Infrastructure/Data/Config/CatalogItemOrderedConfiguration.cs create mode 100644 src/Infrastructure/Data/Migrations/20191105161820_AddressAndCatalogItemOrderedChanges.Designer.cs create mode 100644 src/Infrastructure/Data/Migrations/20191105161820_AddressAndCatalogItemOrderedChanges.cs diff --git a/src/Infrastructure/Data/Config/AddressConfiguration.cs b/src/Infrastructure/Data/Config/AddressConfiguration.cs deleted file mode 100644 index b5b57d3..0000000 --- a/src/Infrastructure/Data/Config/AddressConfiguration.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Microsoft.EntityFrameworkCore.Metadata.Builders; -using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; - -namespace Microsoft.eShopWeb.Infrastructure.Data.Config -{ - public class AddressConfiguration - { - 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/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 @@ public void Configure(EntityTypeBuilder 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) 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 @@ public void Configure(EntityTypeBuilder builder) 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 c6e1ff3..0000000 --- a/src/Infrastructure/Data/Config/CatalogItemOrderedConfiguration.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Microsoft.EntityFrameworkCore.Metadata.Builders; -using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; - -namespace Microsoft.eShopWeb.Infrastructure.Data.Config -{ - public class CatalogItemOrderedConfiguration - { - 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 @@ public void Configure(EntityTypeBuilder 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(); + }); } } } 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 @@ public class OrderItemConfiguration : IEntityTypeConfiguration { 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/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 9d380fa..ee39dff 100644 --- a/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs +++ b/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs @@ -213,19 +213,28 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); b1.Property("City") - .HasColumnType("nvarchar(max)"); + .IsRequired() + .HasColumnType("nvarchar(100)") + .HasMaxLength(100); b1.Property("Country") - .HasColumnType("nvarchar(max)"); + .IsRequired() + .HasColumnType("nvarchar(90)") + .HasMaxLength(90); b1.Property("State") - .HasColumnType("nvarchar(max)"); + .HasColumnType("nvarchar(60)") + .HasMaxLength(60); b1.Property("Street") - .HasColumnType("nvarchar(max)"); + .IsRequired() + .HasColumnType("nvarchar(180)") + .HasMaxLength(180); b1.Property("ZipCode") - .HasColumnType("nvarchar(max)"); + .IsRequired() + .HasColumnType("nvarchar(18)") + .HasMaxLength(18); b1.HasKey("OrderId"); @@ -256,7 +265,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("nvarchar(max)"); b1.Property("ProductName") - .HasColumnType("nvarchar(max)"); + .IsRequired() + .HasColumnType("nvarchar(50)") + .HasMaxLength(50); b1.HasKey("OrderItemId"); From 1f05543ec824f977749b2701dca0a8f24f2b18a7 Mon Sep 17 00:00:00 2001 From: Eric Fleming Date: Wed, 6 Nov 2019 09:20:19 -0500 Subject: [PATCH 12/12] Minor cleanups --- src/Web/Startup.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Web/Startup.cs b/src/Web/Startup.cs index 48eb649..0335d62 100644 --- a/src/Web/Startup.cs +++ b/src/Web/Startup.cs @@ -109,12 +109,13 @@ public void ConfigureServices(IServiceCollection services) options.Conventions.Add(new RouteTokenTransformerConvention( new SlugifyParameterTransformer())); - }); + }); + services.AddControllersWithViews(); services.AddRazorPages(options => { options.Conventions.AuthorizePage("/Basket/Checkout"); }); - services.AddControllersWithViews(); + services.AddControllers(); services.AddHttpContextAccessor(); @@ -174,7 +175,6 @@ private static void ConfigureCookieSettings(IServiceCollection services) // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { - //app.UseDeveloperExceptionPage(); app.UseHealthChecks("/health", new HealthCheckOptions { @@ -207,13 +207,14 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseHsts(); } + app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); - - app.UseHttpsRedirection(); + app.UseCookiePolicy(); app.UseAuthentication(); app.UseAuthorization(); + // Enable middleware to serve generated Swagger as a JSON endpoint. app.UseSwagger();