From 6c41a1bab99c6097313d5ce4d3ad6e06c024847e Mon Sep 17 00:00:00 2001 From: Steve Smith Date: Fri, 28 Dec 2018 10:04:35 -0800 Subject: [PATCH] Upgrade to 2.2 (#171) * Initial Web2 project working * Initial WebRazorPages project working * Adding additional sln files * Removing old project * Fixed integration tests * Getting FunctionalTests working. * Got Swagger working in Web * Moved web2 to web --- eShopOnWeb.sln | 28 +-- .../Areas/Identity/Pages/_ViewStart.cshtml | 3 + src/Web/Controllers/AccountController.cs | 8 +- src/Web/Controllers/Api/BaseApiController.cs | 1 + src/Web/Controllers/BasketController.cs | 15 +- src/Web/Controllers/CatalogController.cs | 7 +- src/Web/Controllers/ManageController.cs | 9 +- src/Web/Controllers/OrderController.cs | 17 +- src/Web/Data/ApplicationDbContext.cs | 16 ++ ...000000000_CreateIdentitySchema.Designer.cs | 236 ++++++++++++++++++ .../00000000000000_CreateIdentitySchema.cs | 220 ++++++++++++++++ .../ApplicationDbContextModelSnapshot.cs | 234 +++++++++++++++++ src/Web/Models/ErrorViewModel.cs | 11 + src/Web/Program.cs | 15 +- src/Web/Properties/launchSettings.json | 14 +- src/Web/Startup.cs | 92 +++++-- src/Web/Views/Home/Index.cshtml | 8 + src/Web/Views/Home/Privacy.cshtml | 6 + .../Views/Shared/_CookieConsentPartial.cshtml | 25 ++ src/Web/Web.csproj | 196 ++++++++++++--- src/Web/appsettings.Development.json | 3 +- src/Web/appsettings.json | 3 +- src/Web/bundleconfig.json | 24 -- src/Web/compilerconfig.json | 42 ---- .../Areas/Identity/Pages/_ViewStart.cshtml | 3 + .../Data/ApplicationDbContext.cs | 16 ++ ...000000000_CreateIdentitySchema.Designer.cs | 236 ++++++++++++++++++ .../00000000000000_CreateIdentitySchema.cs | 220 ++++++++++++++++ .../ApplicationDbContextModelSnapshot.cs | 234 +++++++++++++++++ .../Pages/Basket/Index.cshtml.cs | 12 +- src/WebRazorPages/Pages/Error.cshtml | 7 +- src/WebRazorPages/Pages/Error.cshtml.cs | 4 +- src/WebRazorPages/Pages/Privacy.cshtml | 8 + src/WebRazorPages/Pages/Privacy.cshtml.cs | 11 + .../Pages/Shared/_CookieConsentPartial.cshtml | 25 ++ src/WebRazorPages/Pages/Shared/_Layout.cshtml | 53 ++-- .../Pages/Shared/_LoginPartial.cshtml | 99 ++++---- .../Shared/_ValidationScriptsPartial.cshtml | 8 +- src/WebRazorPages/Pages/_ViewImports.cshtml | 4 +- src/WebRazorPages/Program.cs | 9 +- .../Properties/launchSettings.json | 19 +- src/WebRazorPages/Startup.cs | 54 ++-- src/WebRazorPages/WebRazorPages.csproj | 39 +-- .../appsettings.Development.json | 3 +- src/WebRazorPages/appsettings.json | 9 +- tests/FunctionalTests/FunctionalTests.csproj | 44 ++-- .../CustomWebApplicationFactory.cs | 8 +- .../Web/Controllers/OrderControllerIndex.cs | 2 +- .../CustomWebRazorPagesApplicationFactory.cs | 10 +- .../WebRazorPages/OrderIndexOnGet.cs | 4 +- .../IntegrationTests/IntegrationTests.csproj | 40 +-- tests/UnitTests/UnitTests.csproj | 44 ++-- tests/XUnitTestProject1/UnitTest1.cs | 14 ++ .../XUnitTestProject1.csproj | 15 ++ 54 files changed, 2088 insertions(+), 399 deletions(-) create mode 100644 src/Web/Areas/Identity/Pages/_ViewStart.cshtml create mode 100644 src/Web/Data/ApplicationDbContext.cs create mode 100644 src/Web/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs create mode 100644 src/Web/Data/Migrations/00000000000000_CreateIdentitySchema.cs create mode 100644 src/Web/Data/Migrations/ApplicationDbContextModelSnapshot.cs create mode 100644 src/Web/Models/ErrorViewModel.cs create mode 100644 src/Web/Views/Home/Index.cshtml create mode 100644 src/Web/Views/Home/Privacy.cshtml create mode 100644 src/Web/Views/Shared/_CookieConsentPartial.cshtml delete mode 100644 src/Web/bundleconfig.json delete mode 100644 src/Web/compilerconfig.json create mode 100644 src/WebRazorPages/Areas/Identity/Pages/_ViewStart.cshtml create mode 100644 src/WebRazorPages/Data/ApplicationDbContext.cs create mode 100644 src/WebRazorPages/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs create mode 100644 src/WebRazorPages/Data/Migrations/00000000000000_CreateIdentitySchema.cs create mode 100644 src/WebRazorPages/Data/Migrations/ApplicationDbContextModelSnapshot.cs create mode 100644 src/WebRazorPages/Pages/Privacy.cshtml create mode 100644 src/WebRazorPages/Pages/Privacy.cshtml.cs create mode 100644 src/WebRazorPages/Pages/Shared/_CookieConsentPartial.cshtml create mode 100644 tests/XUnitTestProject1/UnitTest1.cs create mode 100644 tests/XUnitTestProject1/XUnitTestProject1.csproj diff --git a/eShopOnWeb.sln b/eShopOnWeb.sln index ab44fde..ef492ec 100644 --- a/eShopOnWeb.sln +++ b/eShopOnWeb.sln @@ -7,8 +7,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{419A6ACE-041 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Infrastructure", "src\Infrastructure\Infrastructure.csproj", "{7C461394-ABDC-43CD-A798-71249C58BA67}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Web", "src\Web\Web.csproj", "{9CB6566E-E86A-4C07-BB8D-E0B95BCD4BD2}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationCore", "src\ApplicationCore\ApplicationCore.csproj", "{7FED7440-2311-4D1E-958B-3E887C585CD2}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{15EA4737-125B-4E6E-A806-E13B7EBCDCCF}" @@ -19,13 +17,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntegrationTests", "tests\I EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunctionalTests", "tests\FunctionalTests\FunctionalTests.csproj", "{7EFB5482-F942-4C3D-94B0-9B70596E6D0A}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebRazorPages", "src\WebRazorPages\WebRazorPages.csproj", "{3CA62E98-218E-4A74-BF79-1098900BD421}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0BD72BEA-EF42-4B72-8B69-12A39EC76FBA}" ProjectSection(SolutionItems) = preProject docker-compose.yml = docker-compose.yml EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Web", "src\Web\Web.csproj", "{227CF035-29B0-448D-97E4-944F9EA850E5}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebRazorPages", "src\WebRazorPages\WebRazorPages.csproj", "{E2D75FD9-84A8-46B1-97E4-9AC67F919D11}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -36,10 +36,6 @@ Global {7C461394-ABDC-43CD-A798-71249C58BA67}.Debug|Any CPU.Build.0 = Debug|Any CPU {7C461394-ABDC-43CD-A798-71249C58BA67}.Release|Any CPU.ActiveCfg = Release|Any CPU {7C461394-ABDC-43CD-A798-71249C58BA67}.Release|Any CPU.Build.0 = Release|Any CPU - {9CB6566E-E86A-4C07-BB8D-E0B95BCD4BD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9CB6566E-E86A-4C07-BB8D-E0B95BCD4BD2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9CB6566E-E86A-4C07-BB8D-E0B95BCD4BD2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9CB6566E-E86A-4C07-BB8D-E0B95BCD4BD2}.Release|Any CPU.Build.0 = Release|Any CPU {7FED7440-2311-4D1E-958B-3E887C585CD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7FED7440-2311-4D1E-958B-3E887C585CD2}.Debug|Any CPU.Build.0 = Debug|Any CPU {7FED7440-2311-4D1E-958B-3E887C585CD2}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -56,22 +52,26 @@ Global {7EFB5482-F942-4C3D-94B0-9B70596E6D0A}.Debug|Any CPU.Build.0 = Debug|Any CPU {7EFB5482-F942-4C3D-94B0-9B70596E6D0A}.Release|Any CPU.ActiveCfg = Release|Any CPU {7EFB5482-F942-4C3D-94B0-9B70596E6D0A}.Release|Any CPU.Build.0 = Release|Any CPU - {3CA62E98-218E-4A74-BF79-1098900BD421}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3CA62E98-218E-4A74-BF79-1098900BD421}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3CA62E98-218E-4A74-BF79-1098900BD421}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3CA62E98-218E-4A74-BF79-1098900BD421}.Release|Any CPU.Build.0 = Release|Any CPU + {227CF035-29B0-448D-97E4-944F9EA850E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {227CF035-29B0-448D-97E4-944F9EA850E5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {227CF035-29B0-448D-97E4-944F9EA850E5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {227CF035-29B0-448D-97E4-944F9EA850E5}.Release|Any CPU.Build.0 = Release|Any CPU + {E2D75FD9-84A8-46B1-97E4-9AC67F919D11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E2D75FD9-84A8-46B1-97E4-9AC67F919D11}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E2D75FD9-84A8-46B1-97E4-9AC67F919D11}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E2D75FD9-84A8-46B1-97E4-9AC67F919D11}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {7C461394-ABDC-43CD-A798-71249C58BA67} = {419A6ACE-0419-4315-A6FB-B0E63D39432E} - {9CB6566E-E86A-4C07-BB8D-E0B95BCD4BD2} = {419A6ACE-0419-4315-A6FB-B0E63D39432E} {7FED7440-2311-4D1E-958B-3E887C585CD2} = {419A6ACE-0419-4315-A6FB-B0E63D39432E} {EF6877E6-59CB-43A7-8C2C-E70DD70CC5B6} = {15EA4737-125B-4E6E-A806-E13B7EBCDCCF} {0F576306-7E2D-49B7-87B1-EB5D94CFD5FC} = {15EA4737-125B-4E6E-A806-E13B7EBCDCCF} {7EFB5482-F942-4C3D-94B0-9B70596E6D0A} = {15EA4737-125B-4E6E-A806-E13B7EBCDCCF} - {3CA62E98-218E-4A74-BF79-1098900BD421} = {419A6ACE-0419-4315-A6FB-B0E63D39432E} + {227CF035-29B0-448D-97E4-944F9EA850E5} = {419A6ACE-0419-4315-A6FB-B0E63D39432E} + {E2D75FD9-84A8-46B1-97E4-9AC67F919D11} = {419A6ACE-0419-4315-A6FB-B0E63D39432E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {49813262-5DA3-4D61-ABD3-493C74CE8C2B} diff --git a/src/Web/Areas/Identity/Pages/_ViewStart.cshtml b/src/Web/Areas/Identity/Pages/_ViewStart.cshtml new file mode 100644 index 0000000..c4284f6 --- /dev/null +++ b/src/Web/Areas/Identity/Pages/_ViewStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "/Views/Shared/_Layout.cshtml"; +} diff --git a/src/Web/Controllers/AccountController.cs b/src/Web/Controllers/AccountController.cs index f3dfbf1..a03a963 100644 --- a/src/Web/Controllers/AccountController.cs +++ b/src/Web/Controllers/AccountController.cs @@ -1,15 +1,16 @@ -using Microsoft.eShopWeb.ApplicationCore.Interfaces; -using Microsoft.eShopWeb.Infrastructure.Identity; -using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; +using Microsoft.eShopWeb.ApplicationCore.Interfaces; +using Microsoft.eShopWeb.Infrastructure.Identity; using Microsoft.eShopWeb.Web.ViewModels.Account; using System; using System.Threading.Tasks; namespace Microsoft.eShopWeb.Web.Controllers { + [ApiExplorerSettings(IgnoreApi = true)] [Route("[controller]/[action]")] [Authorize] public class AccountController : Controller @@ -153,6 +154,7 @@ namespace Microsoft.eShopWeb.Web.Controllers } [AllowAnonymous] + [HttpGet] public IActionResult Register() { return View(); diff --git a/src/Web/Controllers/Api/BaseApiController.cs b/src/Web/Controllers/Api/BaseApiController.cs index 4acc787..dbf2837 100644 --- a/src/Web/Controllers/Api/BaseApiController.cs +++ b/src/Web/Controllers/Api/BaseApiController.cs @@ -3,6 +3,7 @@ namespace Microsoft.eShopWeb.Web.Controllers.Api { [Route("api/[controller]/[action]")] + [ApiController] public class BaseApiController : Controller { } } diff --git a/src/Web/Controllers/BasketController.cs b/src/Web/Controllers/BasketController.cs index 97fdf43..1f679a8 100644 --- a/src/Web/Controllers/BasketController.cs +++ b/src/Web/Controllers/BasketController.cs @@ -1,18 +1,19 @@ -using Microsoft.AspNetCore.Mvc; -using System.Threading.Tasks; -using Microsoft.eShopWeb.ApplicationCore.Interfaces; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; -using Microsoft.eShopWeb.Web.ViewModels; using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; +using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; +using Microsoft.eShopWeb.ApplicationCore.Interfaces; using Microsoft.eShopWeb.Infrastructure.Identity; +using Microsoft.eShopWeb.Web.Interfaces; +using Microsoft.eShopWeb.Web.ViewModels; using System; using System.Collections.Generic; -using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; -using Microsoft.AspNetCore.Authorization; -using Microsoft.eShopWeb.Web.Interfaces; +using System.Threading.Tasks; namespace Microsoft.eShopWeb.Web.Controllers { + [ApiExplorerSettings(IgnoreApi = true)] [Route("[controller]/[action]")] public class BasketController : Controller { diff --git a/src/Web/Controllers/CatalogController.cs b/src/Web/Controllers/CatalogController.cs index d7fa4b5..e32d24a 100644 --- a/src/Web/Controllers/CatalogController.cs +++ b/src/Web/Controllers/CatalogController.cs @@ -1,9 +1,10 @@ -using Microsoft.eShopWeb.Web.Services; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; +using Microsoft.eShopWeb.Web.Services; using System.Threading.Tasks; namespace Microsoft.eShopWeb.Web.Controllers { + [ApiExplorerSettings(IgnoreApi = true)] [Route("")] public class CatalogController : Controller { @@ -15,7 +16,7 @@ namespace Microsoft.eShopWeb.Web.Controllers [HttpPost] public async Task Index(int? brandFilterApplied, int? typesFilterApplied, int? page) { - var itemsPage = 10; + var itemsPage = 10; var catalogModel = await _catalogService.GetCatalogItems(page ?? 0, itemsPage, brandFilterApplied, typesFilterApplied); return View(catalogModel); } diff --git a/src/Web/Controllers/ManageController.cs b/src/Web/Controllers/ManageController.cs index ff21d58..ed88ef7 100644 --- a/src/Web/Controllers/ManageController.cs +++ b/src/Web/Controllers/ManageController.cs @@ -1,11 +1,11 @@ -using Microsoft.eShopWeb.ApplicationCore.Interfaces; -using Microsoft.eShopWeb.Infrastructure.Identity; -using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; -using Microsoft.eShopWeb.Web.ViewModels.Manage; +using Microsoft.eShopWeb.ApplicationCore.Interfaces; +using Microsoft.eShopWeb.Infrastructure.Identity; using Microsoft.eShopWeb.Web.Services; +using Microsoft.eShopWeb.Web.ViewModels.Manage; using System; using System.Linq; using System.Text; @@ -14,6 +14,7 @@ using System.Threading.Tasks; namespace Microsoft.eShopWeb.Web.Controllers { + [ApiExplorerSettings(IgnoreApi = true)] [Authorize] [Route("[controller]/[action]")] public class ManageController : Controller diff --git a/src/Web/Controllers/OrderController.cs b/src/Web/Controllers/OrderController.cs index 7ab4d80..c93aefa 100644 --- a/src/Web/Controllers/OrderController.cs +++ b/src/Web/Controllers/OrderController.cs @@ -1,23 +1,26 @@ -using Microsoft.AspNetCore.Mvc; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.eShopWeb.Web.ViewModels; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; using Microsoft.eShopWeb.ApplicationCore.Interfaces; -using System.Linq; using Microsoft.eShopWeb.ApplicationCore.Specifications; +using Microsoft.eShopWeb.Web.ViewModels; +using System.Linq; +using System.Threading.Tasks; namespace Microsoft.eShopWeb.Web.Controllers { + [ApiExplorerSettings(IgnoreApi = true)] [Authorize] [Route("[controller]/[action]")] public class OrderController : Controller { private readonly IOrderRepository _orderRepository; - public OrderController(IOrderRepository orderRepository) { + public OrderController(IOrderRepository orderRepository) + { _orderRepository = orderRepository; } - + + [HttpGet] public async Task Index() { var orders = await _orderRepository.ListAsync(new CustomerOrdersWithItemsSpecification(User.Identity.Name)); diff --git a/src/Web/Data/ApplicationDbContext.cs b/src/Web/Data/ApplicationDbContext.cs new file mode 100644 index 0000000..ae1405f --- /dev/null +++ b/src/Web/Data/ApplicationDbContext.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; + +namespace Web2.Data +{ + public class ApplicationDbContext : IdentityDbContext + { + public ApplicationDbContext(DbContextOptions options) + : base(options) + { + } + } +} diff --git a/src/Web/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs b/src/Web/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs new file mode 100644 index 0000000..7b549de --- /dev/null +++ b/src/Web/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs @@ -0,0 +1,236 @@ +// +using System; +using Web2.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace Web2.Data.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("00000000000000_CreateIdentitySchema")] + partial class CreateIdentitySchema + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.2.0-preview1") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Name") + .HasMaxLength(256); + + b.Property("NormalizedName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("RoleId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AccessFailedCount"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Email") + .HasMaxLength(256); + + b.Property("EmailConfirmed"); + + b.Property("LockoutEnabled"); + + b.Property("LockoutEnd"); + + b.Property("NormalizedEmail") + .HasMaxLength(256); + + b.Property("NormalizedUserName") + .HasMaxLength(256); + + b.Property("PasswordHash"); + + b.Property("PhoneNumber"); + + b.Property("PhoneNumberConfirmed"); + + b.Property("SecurityStamp"); + + b.Property("TwoFactorEnabled"); + + b.Property("UserName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasMaxLength(128); + + b.Property("ProviderKey") + .HasMaxLength(128); + + b.Property("ProviderDisplayName"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId"); + + b.Property("RoleId"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId"); + + b.Property("LoginProvider") + .HasMaxLength(128); + + b.Property("Name") + .HasMaxLength(128); + + b.Property("Value"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Web/Data/Migrations/00000000000000_CreateIdentitySchema.cs b/src/Web/Data/Migrations/00000000000000_CreateIdentitySchema.cs new file mode 100644 index 0000000..f75aae2 --- /dev/null +++ b/src/Web/Data/Migrations/00000000000000_CreateIdentitySchema.cs @@ -0,0 +1,220 @@ +using System; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Web2.Data.Migrations +{ + public partial class CreateIdentitySchema : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AspNetRoles", + columns: table => new + { + Id = table.Column(nullable: false), + Name = table.Column(maxLength: 256, nullable: true), + NormalizedName = table.Column(maxLength: 256, nullable: true), + ConcurrencyStamp = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetUsers", + columns: table => new + { + Id = table.Column(nullable: false), + UserName = table.Column(maxLength: 256, nullable: true), + NormalizedUserName = table.Column(maxLength: 256, nullable: true), + Email = table.Column(maxLength: 256, nullable: true), + NormalizedEmail = table.Column(maxLength: 256, nullable: true), + EmailConfirmed = table.Column(nullable: false), + PasswordHash = table.Column(nullable: true), + SecurityStamp = table.Column(nullable: true), + ConcurrencyStamp = table.Column(nullable: true), + PhoneNumber = table.Column(nullable: true), + PhoneNumberConfirmed = table.Column(nullable: false), + TwoFactorEnabled = table.Column(nullable: false), + LockoutEnd = table.Column(nullable: true), + LockoutEnabled = table.Column(nullable: false), + AccessFailedCount = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUsers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetRoleClaims", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + RoleId = table.Column(nullable: false), + ClaimType = table.Column(nullable: true), + ClaimValue = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserClaims", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + UserId = table.Column(nullable: false), + ClaimType = table.Column(nullable: true), + ClaimValue = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetUserClaims_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserLogins", + columns: table => new + { + LoginProvider = table.Column(maxLength: 128, nullable: false), + ProviderKey = table.Column(maxLength: 128, nullable: false), + ProviderDisplayName = table.Column(nullable: true), + UserId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); + table.ForeignKey( + name: "FK_AspNetUserLogins_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserRoles", + columns: table => new + { + UserId = table.Column(nullable: false), + RoleId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserTokens", + columns: table => new + { + UserId = table.Column(nullable: false), + LoginProvider = table.Column(maxLength: 128, nullable: false), + Name = table.Column(maxLength: 128, nullable: false), + Value = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); + table.ForeignKey( + name: "FK_AspNetUserTokens_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_AspNetRoleClaims_RoleId", + table: "AspNetRoleClaims", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "RoleNameIndex", + table: "AspNetRoles", + column: "NormalizedName", + unique: true, + filter: "[NormalizedName] IS NOT NULL"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserClaims_UserId", + table: "AspNetUserClaims", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserLogins_UserId", + table: "AspNetUserLogins", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserRoles_RoleId", + table: "AspNetUserRoles", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "EmailIndex", + table: "AspNetUsers", + column: "NormalizedEmail"); + + migrationBuilder.CreateIndex( + name: "UserNameIndex", + table: "AspNetUsers", + column: "NormalizedUserName", + unique: true, + filter: "[NormalizedUserName] IS NOT NULL"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AspNetRoleClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserLogins"); + + migrationBuilder.DropTable( + name: "AspNetUserRoles"); + + migrationBuilder.DropTable( + name: "AspNetUserTokens"); + + migrationBuilder.DropTable( + name: "AspNetRoles"); + + migrationBuilder.DropTable( + name: "AspNetUsers"); + } + } +} diff --git a/src/Web/Data/Migrations/ApplicationDbContextModelSnapshot.cs b/src/Web/Data/Migrations/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 0000000..e468eb0 --- /dev/null +++ b/src/Web/Data/Migrations/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,234 @@ +// +using System; +using Web2.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace Web2.Data.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.2.0-preview1") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Name") + .HasMaxLength(256); + + b.Property("NormalizedName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("RoleId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AccessFailedCount"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Email") + .HasMaxLength(256); + + b.Property("EmailConfirmed"); + + b.Property("LockoutEnabled"); + + b.Property("LockoutEnd"); + + b.Property("NormalizedEmail") + .HasMaxLength(256); + + b.Property("NormalizedUserName") + .HasMaxLength(256); + + b.Property("PasswordHash"); + + b.Property("PhoneNumber"); + + b.Property("PhoneNumberConfirmed"); + + b.Property("SecurityStamp"); + + b.Property("TwoFactorEnabled"); + + b.Property("UserName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasMaxLength(128); + + b.Property("ProviderKey") + .HasMaxLength(128); + + b.Property("ProviderDisplayName"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId"); + + b.Property("RoleId"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId"); + + b.Property("LoginProvider") + .HasMaxLength(128); + + b.Property("Name") + .HasMaxLength(128); + + b.Property("Value"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Web/Models/ErrorViewModel.cs b/src/Web/Models/ErrorViewModel.cs new file mode 100644 index 0000000..e8187a1 --- /dev/null +++ b/src/Web/Models/ErrorViewModel.cs @@ -0,0 +1,11 @@ +using System; + +namespace Web2.Models +{ + public class ErrorViewModel + { + public string RequestId { get; set; } + + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + } +} \ No newline at end of file diff --git a/src/Web/Program.cs b/src/Web/Program.cs index 9629b8f..1abbbcd 100644 --- a/src/Web/Program.cs +++ b/src/Web/Program.cs @@ -1,11 +1,11 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.eShopWeb.Infrastructure.Data; -using System; -using Microsoft.Extensions.Logging; -using Microsoft.eShopWeb.Infrastructure.Identity; +using Microsoft.AspNetCore; +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.Logging; +using System; namespace Microsoft.eShopWeb.Web { @@ -41,7 +41,6 @@ namespace Microsoft.eShopWeb.Web public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) - .UseUrls("http://0.0.0.0:5106") .UseStartup(); } } diff --git a/src/Web/Properties/launchSettings.json b/src/Web/Properties/launchSettings.json index ebf2925..b1b4320 100644 --- a/src/Web/Properties/launchSettings.json +++ b/src/Web/Properties/launchSettings.json @@ -1,10 +1,10 @@ -{ +{ "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:5106/", - "sslPort": 0 + "applicationUrl": "http://localhost:17469", + "sslPort": 44315 } }, "profiles": { @@ -15,13 +15,13 @@ "ASPNETCORE_ENVIRONMENT": "Development" } }, - "eShopWeb": { + "Web": { "commandName": "Project", "launchBrowser": true, + "applicationUrl": "https://localhost:5001;http://localhost:5000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "http://localhost:5106" + } } } -} \ No newline at end of file +} diff --git a/src/Web/Startup.cs b/src/Web/Startup.cs index c3bd22c..e2d10e7 100644 --- a/src/Web/Startup.cs +++ b/src/Web/Startup.cs @@ -1,18 +1,21 @@ -using Microsoft.eShopWeb.ApplicationCore.Interfaces; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.UI; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.eShopWeb.ApplicationCore.Interfaces; using Microsoft.eShopWeb.ApplicationCore.Services; using Microsoft.eShopWeb.Infrastructure.Data; using Microsoft.eShopWeb.Infrastructure.Identity; using Microsoft.eShopWeb.Infrastructure.Logging; using Microsoft.eShopWeb.Infrastructure.Services; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Identity; -using Microsoft.EntityFrameworkCore; using Microsoft.eShopWeb.Web.Interfaces; using Microsoft.eShopWeb.Web.Services; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Swashbuckle.AspNetCore.Swagger; using System; using System.Text; @@ -65,23 +68,17 @@ namespace Microsoft.eShopWeb.Web ConfigureServices(services); } + + + // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddIdentity() - .AddEntityFrameworkStores() - .AddDefaultTokenProviders(); + ConfigureCookieSettings(services); - services.ConfigureApplicationCookie(options => - { - options.Cookie.HttpOnly = true; - options.ExpireTimeSpan = TimeSpan.FromHours(1); - options.LoginPath = "/Account/Signin"; - options.LogoutPath = "/Account/Signout"; - options.Cookie = new CookieBuilder - { - IsEssential = true // required for auth to work without explicit user consent; adjust to suit your privacy policy - }; - }); + services.AddIdentity() + .AddDefaultUI(UIFramework.Bootstrap4) + .AddEntityFrameworkStores() + .AddDefaultTokenProviders(); services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>)); services.AddScoped(typeof(IAsyncRepository<>), typeof(EfRepository<>)); @@ -101,15 +98,37 @@ namespace Microsoft.eShopWeb.Web // Add memory cache services services.AddMemoryCache(); - services.AddMvc() - .SetCompatibilityVersion(AspNetCore.Mvc.CompatibilityVersion.Version_2_1); + services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" }); + }); + _services = services; // used to debug registered services + } - _services = services; + private static void ConfigureCookieSettings(IServiceCollection services) + { + services.Configure(options => + { + // This lambda determines whether user consent for non-essential cookies is needed for a given request. + options.CheckConsentNeeded = context => true; + options.MinimumSameSitePolicy = SameSiteMode.None; + }); + services.ConfigureApplicationCookie(options => + { + options.Cookie.HttpOnly = true; + options.ExpireTimeSpan = TimeSpan.FromHours(1); + options.LoginPath = "/Account/Signin"; + options.LogoutPath = "/Account/Signout"; + options.Cookie = new CookieBuilder + { + IsEssential = true // required for auth to work without explicit user consent; adjust to suit your privacy policy + }; + }); } // 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, IHostingEnvironment env) { if (env.IsDevelopment()) { @@ -119,15 +138,33 @@ namespace Microsoft.eShopWeb.Web } else { - app.UseExceptionHandler("/Catalog/Error"); + app.UseExceptionHandler("/Home/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); + app.UseCookiePolicy(); + app.UseAuthentication(); - app.UseMvc(); + // Enable middleware to serve generated Swagger as a JSON endpoint. + app.UseSwagger(); + + // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), + // specifying the Swagger JSON endpoint. + app.UseSwaggerUI(c => + { + c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); + }); + + app.UseMvc(routes => + { + routes.MapRoute( + name: "default", + template: "{controller=Home}/{action=Index}/{id?}"); + }); } private void ListAllRegisteredServices(IApplicationBuilder app) @@ -151,5 +188,6 @@ namespace Microsoft.eShopWeb.Web await context.Response.WriteAsync(sb.ToString()); })); } + } } diff --git a/src/Web/Views/Home/Index.cshtml b/src/Web/Views/Home/Index.cshtml new file mode 100644 index 0000000..d2d19bd --- /dev/null +++ b/src/Web/Views/Home/Index.cshtml @@ -0,0 +1,8 @@ +@{ + ViewData["Title"] = "Home Page"; +} + +
+

Welcome

+

Learn about building Web apps with ASP.NET Core.

+
diff --git a/src/Web/Views/Home/Privacy.cshtml b/src/Web/Views/Home/Privacy.cshtml new file mode 100644 index 0000000..af4fb19 --- /dev/null +++ b/src/Web/Views/Home/Privacy.cshtml @@ -0,0 +1,6 @@ +@{ + ViewData["Title"] = "Privacy Policy"; +} +

@ViewData["Title"]

+ +

Use this page to detail your site's privacy policy.

diff --git a/src/Web/Views/Shared/_CookieConsentPartial.cshtml b/src/Web/Views/Shared/_CookieConsentPartial.cshtml new file mode 100644 index 0000000..a535ea4 --- /dev/null +++ b/src/Web/Views/Shared/_CookieConsentPartial.cshtml @@ -0,0 +1,25 @@ +@using Microsoft.AspNetCore.Http.Features + +@{ + var consentFeature = Context.Features.Get(); + var showBanner = !consentFeature?.CanTrack ?? false; + var cookieString = consentFeature?.CreateConsentCookie(); +} + +@if (showBanner) +{ + + +} diff --git a/src/Web/Web.csproj b/src/Web/Web.csproj index 12cc2b1..9aebe5c 100644 --- a/src/Web/Web.csproj +++ b/src/Web/Web.csproj @@ -1,42 +1,164 @@  - - netcoreapp2.1 - Microsoft.eShopWeb.Web - + + netcoreapp2.2 + Microsoft.eShopWeb.Web + aspnet-Web2-1FA3F72E-E7E3-4360-9E49-1CCCD7FE85F7 + InProcess + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Always - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Always + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + + + + <_ContentIncludedByDefault Remove="Views\Account\Lockout.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Account\LoginWith2fa.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Account\Register.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Account\Signin.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Basket\Checkout.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Basket\Index.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Catalog\Index.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Catalog\_pagination.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Catalog\_product.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Manage\ChangePassword.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Manage\Disable2fa.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Manage\EnableAuthenticator.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Manage\ExternalLogins.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Manage\GenerateRecoveryCodes.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Manage\Index.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Manage\ResetAuthenticator.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Manage\SetPassword.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Manage\TwoFactorAuthentication.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Manage\_Layout.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Manage\_ManageNav.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Manage\_StatusMessage.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Manage\_ViewImports.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Order\Detail.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Order\Index.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Shared\Components\Basket\Default.cshtml" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Web/appsettings.Development.json b/src/Web/appsettings.Development.json index fa8ce71..e203e94 100644 --- a/src/Web/appsettings.Development.json +++ b/src/Web/appsettings.Development.json @@ -1,6 +1,5 @@ -{ +{ "Logging": { - "IncludeScopes": false, "LogLevel": { "Default": "Debug", "System": "Information", diff --git a/src/Web/appsettings.json b/src/Web/appsettings.json index 20d2185..dd8d5ff 100644 --- a/src/Web/appsettings.json +++ b/src/Web/appsettings.json @@ -10,6 +10,7 @@ "Default": "Warning", "Microsoft": "Warning", "System": "Warning" - } + }, + "AllowedHosts": "*" } } diff --git a/src/Web/bundleconfig.json b/src/Web/bundleconfig.json deleted file mode 100644 index 0914b21..0000000 --- a/src/Web/bundleconfig.json +++ /dev/null @@ -1,24 +0,0 @@ -// Configure bundling and minification for the project. -// More info at https://go.microsoft.com/fwlink/?LinkId=808241 -[ - { - "outputFileName": "wwwroot/css/app.min.css", - // An array of relative input file paths. Globbing patterns supported - "inputFiles": [ - "wwwroot/css/app.css" - ] - }, - { - "outputFileName": "wwwroot/js/site.min.js", - "inputFiles": [ - "wwwroot/js/site.js" - ], - // Optionally specify minification options - "minify": { - "enabled": true, - "renameLocals": true - }, - // Optionally generate .map file - "sourceMap": false - } -] diff --git a/src/Web/compilerconfig.json b/src/Web/compilerconfig.json deleted file mode 100644 index 73e8abe..0000000 --- a/src/Web/compilerconfig.json +++ /dev/null @@ -1,42 +0,0 @@ -[ - { - "outputFile": "wwwroot/css/orders/orders.component.css", - "inputFile": "wwwroot/css/orders/orders.component.scss" - }, - //{ - // "outputFile": "wwwroot/css/orders/orders-new/orders-new.component.css", - // "inputFile": "wwwroot/css/orders/orders-new/orders-new.component.scss" - //}, - //{ - // "outputFile": "wwwroot/css/orders/orders-detail/orders-detail.component.css", - // "inputFile": "wwwroot/css/orders/orders-detail/orders-detail.component.scss" - //}, - { - "outputFile": "wwwroot/css/catalog/catalog.component.css", - "inputFile": "wwwroot/css/catalog/catalog.component.scss" - }, - { - "outputFile": "wwwroot/css/basket/basket.component.css", - "inputFile": "wwwroot/css/basket/basket.component.scss" - }, - { - "outputFile": "wwwroot/css/basket/basket-status/basket-status.component.css", - "inputFile": "wwwroot/css/basket/basket-status/basket-status.component.scss" - }, - //{ - // "outputFile": "wwwroot/css/shared/components/header/header.css", - // "inputFile": "wwwroot/css/shared/components/header/header.scss" - //}, - //{ - // "outputFile": "wwwroot/css/shared/components/identity/identity.css", - // "inputFile": "wwwroot/css/shared/components/identity/identity.scss" - //}, - //{ - // "outputFile": "wwwroot/css/shared/components/pager/pager.css", - // "inputFile": "wwwroot/css/shared/components/pager/pager.scss" - //}, - { - "outputFile": "wwwroot/css/app.component.css", - "inputFile": "wwwroot/css/app.component.scss" - } -] \ No newline at end of file diff --git a/src/WebRazorPages/Areas/Identity/Pages/_ViewStart.cshtml b/src/WebRazorPages/Areas/Identity/Pages/_ViewStart.cshtml new file mode 100644 index 0000000..7bd9b6b --- /dev/null +++ b/src/WebRazorPages/Areas/Identity/Pages/_ViewStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "/Pages/Shared/_Layout.cshtml"; +} diff --git a/src/WebRazorPages/Data/ApplicationDbContext.cs b/src/WebRazorPages/Data/ApplicationDbContext.cs new file mode 100644 index 0000000..2390eb2 --- /dev/null +++ b/src/WebRazorPages/Data/ApplicationDbContext.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; + +namespace WebRazorPages.Data +{ + public class ApplicationDbContext : IdentityDbContext + { + public ApplicationDbContext(DbContextOptions options) + : base(options) + { + } + } +} diff --git a/src/WebRazorPages/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs b/src/WebRazorPages/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs new file mode 100644 index 0000000..2e20bbd --- /dev/null +++ b/src/WebRazorPages/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs @@ -0,0 +1,236 @@ +// +using System; +using WebRazorPages.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace WebRazorPages.Data.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("00000000000000_CreateIdentitySchema")] + partial class CreateIdentitySchema + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.2.0-preview1") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Name") + .HasMaxLength(256); + + b.Property("NormalizedName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("RoleId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AccessFailedCount"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Email") + .HasMaxLength(256); + + b.Property("EmailConfirmed"); + + b.Property("LockoutEnabled"); + + b.Property("LockoutEnd"); + + b.Property("NormalizedEmail") + .HasMaxLength(256); + + b.Property("NormalizedUserName") + .HasMaxLength(256); + + b.Property("PasswordHash"); + + b.Property("PhoneNumber"); + + b.Property("PhoneNumberConfirmed"); + + b.Property("SecurityStamp"); + + b.Property("TwoFactorEnabled"); + + b.Property("UserName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasMaxLength(128); + + b.Property("ProviderKey") + .HasMaxLength(128); + + b.Property("ProviderDisplayName"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId"); + + b.Property("RoleId"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId"); + + b.Property("LoginProvider") + .HasMaxLength(128); + + b.Property("Name") + .HasMaxLength(128); + + b.Property("Value"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/WebRazorPages/Data/Migrations/00000000000000_CreateIdentitySchema.cs b/src/WebRazorPages/Data/Migrations/00000000000000_CreateIdentitySchema.cs new file mode 100644 index 0000000..ab4ad76 --- /dev/null +++ b/src/WebRazorPages/Data/Migrations/00000000000000_CreateIdentitySchema.cs @@ -0,0 +1,220 @@ +using System; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace WebRazorPages.Data.Migrations +{ + public partial class CreateIdentitySchema : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AspNetRoles", + columns: table => new + { + Id = table.Column(nullable: false), + Name = table.Column(maxLength: 256, nullable: true), + NormalizedName = table.Column(maxLength: 256, nullable: true), + ConcurrencyStamp = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetUsers", + columns: table => new + { + Id = table.Column(nullable: false), + UserName = table.Column(maxLength: 256, nullable: true), + NormalizedUserName = table.Column(maxLength: 256, nullable: true), + Email = table.Column(maxLength: 256, nullable: true), + NormalizedEmail = table.Column(maxLength: 256, nullable: true), + EmailConfirmed = table.Column(nullable: false), + PasswordHash = table.Column(nullable: true), + SecurityStamp = table.Column(nullable: true), + ConcurrencyStamp = table.Column(nullable: true), + PhoneNumber = table.Column(nullable: true), + PhoneNumberConfirmed = table.Column(nullable: false), + TwoFactorEnabled = table.Column(nullable: false), + LockoutEnd = table.Column(nullable: true), + LockoutEnabled = table.Column(nullable: false), + AccessFailedCount = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUsers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetRoleClaims", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + RoleId = table.Column(nullable: false), + ClaimType = table.Column(nullable: true), + ClaimValue = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserClaims", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + UserId = table.Column(nullable: false), + ClaimType = table.Column(nullable: true), + ClaimValue = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetUserClaims_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserLogins", + columns: table => new + { + LoginProvider = table.Column(maxLength: 128, nullable: false), + ProviderKey = table.Column(maxLength: 128, nullable: false), + ProviderDisplayName = table.Column(nullable: true), + UserId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); + table.ForeignKey( + name: "FK_AspNetUserLogins_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserRoles", + columns: table => new + { + UserId = table.Column(nullable: false), + RoleId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserTokens", + columns: table => new + { + UserId = table.Column(nullable: false), + LoginProvider = table.Column(maxLength: 128, nullable: false), + Name = table.Column(maxLength: 128, nullable: false), + Value = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); + table.ForeignKey( + name: "FK_AspNetUserTokens_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_AspNetRoleClaims_RoleId", + table: "AspNetRoleClaims", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "RoleNameIndex", + table: "AspNetRoles", + column: "NormalizedName", + unique: true, + filter: "[NormalizedName] IS NOT NULL"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserClaims_UserId", + table: "AspNetUserClaims", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserLogins_UserId", + table: "AspNetUserLogins", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserRoles_RoleId", + table: "AspNetUserRoles", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "EmailIndex", + table: "AspNetUsers", + column: "NormalizedEmail"); + + migrationBuilder.CreateIndex( + name: "UserNameIndex", + table: "AspNetUsers", + column: "NormalizedUserName", + unique: true, + filter: "[NormalizedUserName] IS NOT NULL"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AspNetRoleClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserLogins"); + + migrationBuilder.DropTable( + name: "AspNetUserRoles"); + + migrationBuilder.DropTable( + name: "AspNetUserTokens"); + + migrationBuilder.DropTable( + name: "AspNetRoles"); + + migrationBuilder.DropTable( + name: "AspNetUsers"); + } + } +} diff --git a/src/WebRazorPages/Data/Migrations/ApplicationDbContextModelSnapshot.cs b/src/WebRazorPages/Data/Migrations/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 0000000..1c2ffc9 --- /dev/null +++ b/src/WebRazorPages/Data/Migrations/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,234 @@ +// +using System; +using WebRazorPages.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace WebRazorPages.Data.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.2.0-preview1") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Name") + .HasMaxLength(256); + + b.Property("NormalizedName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("RoleId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AccessFailedCount"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Email") + .HasMaxLength(256); + + b.Property("EmailConfirmed"); + + b.Property("LockoutEnabled"); + + b.Property("LockoutEnd"); + + b.Property("NormalizedEmail") + .HasMaxLength(256); + + b.Property("NormalizedUserName") + .HasMaxLength(256); + + b.Property("PasswordHash"); + + b.Property("PhoneNumber"); + + b.Property("PhoneNumberConfirmed"); + + b.Property("SecurityStamp"); + + b.Property("TwoFactorEnabled"); + + b.Property("UserName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasMaxLength(128); + + b.Property("ProviderKey") + .HasMaxLength(128); + + b.Property("ProviderDisplayName"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId"); + + b.Property("RoleId"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId"); + + b.Property("LoginProvider") + .HasMaxLength(128); + + b.Property("Name") + .HasMaxLength(128); + + b.Property("Value"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/WebRazorPages/Pages/Basket/Index.cshtml.cs b/src/WebRazorPages/Pages/Basket/Index.cshtml.cs index d7ccf30..904bf6f 100644 --- a/src/WebRazorPages/Pages/Basket/Index.cshtml.cs +++ b/src/WebRazorPages/Pages/Basket/Index.cshtml.cs @@ -1,14 +1,14 @@ -using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.eShopWeb.RazorPages.ViewModels; -using Microsoft.eShopWeb.RazorPages.Interfaces; using Microsoft.eShopWeb.ApplicationCore.Interfaces; -using Microsoft.AspNetCore.Identity; using Microsoft.eShopWeb.Infrastructure.Identity; +using Microsoft.eShopWeb.RazorPages.Interfaces; +using Microsoft.eShopWeb.RazorPages.ViewModels; using System; -using Microsoft.AspNetCore.Http; using System.Collections.Generic; +using System.Threading.Tasks; namespace Microsoft.eShopWeb.RazorPages.Pages.Basket { @@ -54,7 +54,7 @@ namespace Microsoft.eShopWeb.RazorPages.Pages.Basket return RedirectToPage(); } - public async Task OnPostUpdate(Dictionary items) + public async Task OnPostUpdate(Dictionary items) { await SetBasketModelAsync(); await _basketService.SetQuantities(BasketModel.Id, items); diff --git a/src/WebRazorPages/Pages/Error.cshtml b/src/WebRazorPages/Pages/Error.cshtml index b1f3143..6f92b95 100644 --- a/src/WebRazorPages/Pages/Error.cshtml +++ b/src/WebRazorPages/Pages/Error.cshtml @@ -16,8 +16,11 @@

Development Mode

- Swapping to Development environment will display more detailed information about the error that occurred. + Swapping to the Development environment displays detailed information about the error that occurred.

- Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application. + The Development environment shouldn't be enabled for deployed applications. + It can result in displaying sensitive information from exceptions to end users. + For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development + and restarting the app.

diff --git a/src/WebRazorPages/Pages/Error.cshtml.cs b/src/WebRazorPages/Pages/Error.cshtml.cs index 6fc7fb5..284ffb2 100644 --- a/src/WebRazorPages/Pages/Error.cshtml.cs +++ b/src/WebRazorPages/Pages/Error.cshtml.cs @@ -1,8 +1,10 @@ -using System.Diagnostics; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using System.Diagnostics; namespace Microsoft.eShopWeb.RazorPages.Pages { + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public class ErrorModel : PageModel { public string RequestId { get; set; } diff --git a/src/WebRazorPages/Pages/Privacy.cshtml b/src/WebRazorPages/Pages/Privacy.cshtml new file mode 100644 index 0000000..46ba966 --- /dev/null +++ b/src/WebRazorPages/Pages/Privacy.cshtml @@ -0,0 +1,8 @@ +@page +@model PrivacyModel +@{ + ViewData["Title"] = "Privacy Policy"; +} +

@ViewData["Title"]

+ +

Use this page to detail your site's privacy policy.

diff --git a/src/WebRazorPages/Pages/Privacy.cshtml.cs b/src/WebRazorPages/Pages/Privacy.cshtml.cs new file mode 100644 index 0000000..3201f6a --- /dev/null +++ b/src/WebRazorPages/Pages/Privacy.cshtml.cs @@ -0,0 +1,11 @@ +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace Microsoft.eShopWeb.RazorPages.Pages +{ + public class PrivacyModel : PageModel + { + public void OnGet() + { + } + } +} diff --git a/src/WebRazorPages/Pages/Shared/_CookieConsentPartial.cshtml b/src/WebRazorPages/Pages/Shared/_CookieConsentPartial.cshtml new file mode 100644 index 0000000..7df65c4 --- /dev/null +++ b/src/WebRazorPages/Pages/Shared/_CookieConsentPartial.cshtml @@ -0,0 +1,25 @@ +@using Microsoft.AspNetCore.Http.Features + +@{ + var consentFeature = Context.Features.Get(); + var showBanner = !consentFeature?.CanTrack ?? false; + var cookieString = consentFeature?.CreateConsentCookie(); +} + +@if (showBanner) +{ + + +} diff --git a/src/WebRazorPages/Pages/Shared/_Layout.cshtml b/src/WebRazorPages/Pages/Shared/_Layout.cshtml index 970be6f..65b772d 100644 --- a/src/WebRazorPages/Pages/Shared/_Layout.cshtml +++ b/src/WebRazorPages/Pages/Shared/_Layout.cshtml @@ -3,16 +3,17 @@ - @ViewData["Title"] - Microsoft.eShopOnWeb - - + @ViewData["Title"] - WebRazorPages + - - + + asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" + crossorigin="anonymous" + integrity="sha256-eSi1q2PG6J7g7ib17yAaWMcrr5GrtohYChqibrV7PBE=" /> @@ -26,7 +27,6 @@ - + @RenderBody() -
-
-
-
- - + - - + @**@ + - - - - - - @RenderSection("scripts", required: false) + + @RenderSection("Scripts", required: false) diff --git a/src/WebRazorPages/Pages/Shared/_LoginPartial.cshtml b/src/WebRazorPages/Pages/Shared/_LoginPartial.cshtml index 38886cc..35e7f60 100644 --- a/src/WebRazorPages/Pages/Shared/_LoginPartial.cshtml +++ b/src/WebRazorPages/Pages/Shared/_LoginPartial.cshtml @@ -1,61 +1,56 @@ +@inject SignInManager SignInManager +@inject UserManager UserManager @if (Context.User.Identity.IsAuthenticated) { -
- -
- -
- @await Component.InvokeAsync("Basket") -
+
+ @await Component.InvokeAsync("Basket") +
} else { -
-
-
-
+
+
+
+ +
+
+
- - Login - -
-
-
-
- -
- @await Component.InvokeAsync("Basket") -
+
+ @await Component.InvokeAsync("Basket") +
} diff --git a/src/WebRazorPages/Pages/Shared/_ValidationScriptsPartial.cshtml b/src/WebRazorPages/Pages/Shared/_ValidationScriptsPartial.cshtml index a2b13b3..c442042 100644 --- a/src/WebRazorPages/Pages/Shared/_ValidationScriptsPartial.cshtml +++ b/src/WebRazorPages/Pages/Shared/_ValidationScriptsPartial.cshtml @@ -3,16 +3,16 @@
- - diff --git a/src/WebRazorPages/Pages/_ViewImports.cshtml b/src/WebRazorPages/Pages/_ViewImports.cshtml index 1d6b867..3b07c91 100644 --- a/src/WebRazorPages/Pages/_ViewImports.cshtml +++ b/src/WebRazorPages/Pages/_ViewImports.cshtml @@ -1,6 +1,6 @@ -@using Microsoft.eShopWeb.RazorPages +@using Microsoft.eShopWeb.RazorPages @using Microsoft.eShopWeb.RazorPages.ViewModels @using Microsoft.AspNetCore.Identity @using Microsoft.eShopWeb.Infrastructure.Identity @namespace Microsoft.eShopWeb.RazorPages.Pages -@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers diff --git a/src/WebRazorPages/Program.cs b/src/WebRazorPages/Program.cs index e5030f5..4f38455 100644 --- a/src/WebRazorPages/Program.cs +++ b/src/WebRazorPages/Program.cs @@ -1,11 +1,11 @@ -using System; -using Microsoft.AspNetCore; +using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Logging; +using Microsoft.AspNetCore.Identity; using Microsoft.eShopWeb.Infrastructure.Data; using Microsoft.eShopWeb.Infrastructure.Identity; using Microsoft.Extensions.DependencyInjection; -using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Logging; +using System; namespace Microsoft.eShopWeb.RazorPages { @@ -41,7 +41,6 @@ namespace Microsoft.eShopWeb.RazorPages public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) - .UseUrls("http://0.0.0.0:5107") .UseStartup(); } } diff --git a/src/WebRazorPages/Properties/launchSettings.json b/src/WebRazorPages/Properties/launchSettings.json index fb21aef..fb9ac93 100644 --- a/src/WebRazorPages/Properties/launchSettings.json +++ b/src/WebRazorPages/Properties/launchSettings.json @@ -1,10 +1,10 @@ -{ +{ "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, + "windowsAuthentication": false, + "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:5107/", - "sslPort": 44305 + "applicationUrl": "http://localhost:17930", + "sslPort": 44394 } }, "profiles": { @@ -18,15 +18,10 @@ "WebRazorPages": { "commandName": "Project", "launchBrowser": true, + "applicationUrl": "https://localhost:5001;http://localhost:5000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "http://localhost:5107/" - }, - "Docker": { - "commandName": "Docker", - "launchBrowser": true, - "launchUrl": "{Scheme}://localhost:{ServicePort}" + } } } } \ No newline at end of file diff --git a/src/WebRazorPages/Startup.cs b/src/WebRazorPages/Startup.cs index fc3ac8b..6f0c160 100644 --- a/src/WebRazorPages/Startup.cs +++ b/src/WebRazorPages/Startup.cs @@ -1,14 +1,16 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.UI; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; using Microsoft.eShopWeb.ApplicationCore.Interfaces; using Microsoft.eShopWeb.ApplicationCore.Services; using Microsoft.eShopWeb.Infrastructure.Data; using Microsoft.eShopWeb.Infrastructure.Identity; using Microsoft.eShopWeb.Infrastructure.Logging; using Microsoft.eShopWeb.Infrastructure.Services; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Identity; -using Microsoft.EntityFrameworkCore; using Microsoft.eShopWeb.RazorPages.Interfaces; using Microsoft.eShopWeb.RazorPages.Services; using Microsoft.Extensions.Configuration; @@ -74,20 +76,17 @@ namespace Microsoft.eShopWeb.RazorPages ConfigureServices(services); } + + // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + ConfigureCookieOptions(services); + services.AddIdentity() + .AddDefaultUI(UIFramework.Bootstrap4) .AddEntityFrameworkStores() .AddDefaultTokenProviders(); - services.ConfigureApplicationCookie(options => - { - options.Cookie.HttpOnly = true; - options.ExpireTimeSpan = TimeSpan.FromHours(1); - options.LoginPath = "/Account/Signin"; - options.LogoutPath = "/Account/Signout"; - }); - services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>)); services.AddScoped(typeof(IAsyncRepository<>), typeof(EfRepository<>)); @@ -106,8 +105,9 @@ namespace Microsoft.eShopWeb.RazorPages // Add memory cache services services.AddMemoryCache(); + services.AddMvc() - .SetCompatibilityVersion(AspNetCore.Mvc.CompatibilityVersion.Version_2_1) + .SetCompatibilityVersion(CompatibilityVersion.Version_2_2) .AddRazorPagesOptions(options => { options.Conventions.AuthorizeFolder("/Order"); @@ -117,9 +117,25 @@ namespace Microsoft.eShopWeb.RazorPages _services = services; } + private static void ConfigureCookieOptions(IServiceCollection services) + { + services.Configure(options => + { + // This lambda determines whether user consent for non-essential cookies is needed for a given request. + options.CheckConsentNeeded = context => true; + options.MinimumSameSitePolicy = SameSiteMode.None; + }); + services.ConfigureApplicationCookie(options => + { + options.Cookie.HttpOnly = true; + options.ExpireTimeSpan = TimeSpan.FromHours(1); + options.LoginPath = "/Account/Signin"; + options.LogoutPath = "/Account/Signout"; + }); + } + // 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, IHostingEnvironment env) { if (env.IsDevelopment()) { @@ -129,12 +145,15 @@ namespace Microsoft.eShopWeb.RazorPages } else { - app.UseExceptionHandler("/Catalog/Error"); + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); + app.UseCookiePolicy(); + app.UseAuthentication(); app.UseMvc(); @@ -161,5 +180,6 @@ namespace Microsoft.eShopWeb.RazorPages await context.Response.WriteAsync(sb.ToString()); })); } + } } diff --git a/src/WebRazorPages/WebRazorPages.csproj b/src/WebRazorPages/WebRazorPages.csproj index c3d61ff..ec17601 100644 --- a/src/WebRazorPages/WebRazorPages.csproj +++ b/src/WebRazorPages/WebRazorPages.csproj @@ -1,16 +1,27 @@  - - netcoreapp2.1 - Microsoft.eShopWeb.RazorPages - Microsoft.eShopWeb.RazorPages - Linux - 231ddc1b-6787-4704-a0c0-18df6a022660 - - - - - - - - + + + netcoreapp2.2 + Microsoft.eShopWeb.RazorPages + Microsoft.eShopWeb.RazorPages + Linux + aspnet-WebRazorPages-6B1EFE4D-B682-4543-93F5-69EE95000B1D + InProcess + + + + + + + + + + + + + + PreserveNewest + + + diff --git a/src/WebRazorPages/appsettings.Development.json b/src/WebRazorPages/appsettings.Development.json index fa8ce71..e203e94 100644 --- a/src/WebRazorPages/appsettings.Development.json +++ b/src/WebRazorPages/appsettings.Development.json @@ -1,6 +1,5 @@ -{ +{ "Logging": { - "IncludeScopes": false, "LogLevel": { "Default": "Debug", "System": "Information", diff --git a/src/WebRazorPages/appsettings.json b/src/WebRazorPages/appsettings.json index 5fff67b..d4d3578 100644 --- a/src/WebRazorPages/appsettings.json +++ b/src/WebRazorPages/appsettings.json @@ -1,8 +1,11 @@ -{ +{ + "ConnectionStrings": { + "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-WebRazorPages-53bc9b9d-9d6a-45d4-8429-2a2761773502;Trusted_Connection=True;MultipleActiveResultSets=true" + }, "Logging": { - "IncludeScopes": false, "LogLevel": { "Default": "Warning" } - } + }, + "AllowedHosts": "*" } diff --git a/tests/FunctionalTests/FunctionalTests.csproj b/tests/FunctionalTests/FunctionalTests.csproj index 2023879..056258c 100644 --- a/tests/FunctionalTests/FunctionalTests.csproj +++ b/tests/FunctionalTests/FunctionalTests.csproj @@ -1,26 +1,32 @@  - - netcoreapp2.1 - Microsoft.eShopWeb.FunctionalTests - + + netcoreapp2.2 + Microsoft.eShopWeb.FunctionalTests + false + - - - - - - - + + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + - - - - - + + + + + - - - + + + diff --git a/tests/FunctionalTests/Web/Controllers/CustomWebApplicationFactory.cs b/tests/FunctionalTests/Web/Controllers/CustomWebApplicationFactory.cs index aeb116c..ea52d80 100644 --- a/tests/FunctionalTests/Web/Controllers/CustomWebApplicationFactory.cs +++ b/tests/FunctionalTests/Web/Controllers/CustomWebApplicationFactory.cs @@ -1,12 +1,12 @@ -using Microsoft.eShopWeb.Infrastructure.Data; -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.EntityFrameworkCore; +using Microsoft.eShopWeb.Infrastructure.Data; +using Microsoft.eShopWeb.Infrastructure.Identity; using Microsoft.eShopWeb.Web; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.eShopWeb.Infrastructure.Identity; namespace Microsoft.eShopWeb.FunctionalTests.Web.Controllers { diff --git a/tests/FunctionalTests/Web/Controllers/OrderControllerIndex.cs b/tests/FunctionalTests/Web/Controllers/OrderControllerIndex.cs index 2b20b58..8f6e085 100644 --- a/tests/FunctionalTests/Web/Controllers/OrderControllerIndex.cs +++ b/tests/FunctionalTests/Web/Controllers/OrderControllerIndex.cs @@ -26,7 +26,7 @@ namespace Microsoft.eShopWeb.FunctionalTests.Web.Controllers var redirectLocation = response.Headers.Location.OriginalString; Assert.Equal(HttpStatusCode.Redirect, response.StatusCode); - Assert.Contains("Account/Signin", redirectLocation); + Assert.Contains("Account/Login", redirectLocation); } } } diff --git a/tests/FunctionalTests/WebRazorPages/CustomWebRazorPagesApplicationFactory.cs b/tests/FunctionalTests/WebRazorPages/CustomWebRazorPagesApplicationFactory.cs index b9bce7d..9f0126d 100644 --- a/tests/FunctionalTests/WebRazorPages/CustomWebRazorPagesApplicationFactory.cs +++ b/tests/FunctionalTests/WebRazorPages/CustomWebRazorPagesApplicationFactory.cs @@ -1,12 +1,12 @@ -using Microsoft.eShopWeb.Infrastructure.Data; -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Testing; -using Microsoft.eShopWeb.Web; +using Microsoft.EntityFrameworkCore; +using Microsoft.eShopWeb.Infrastructure.Data; +using Microsoft.eShopWeb.Infrastructure.Identity; +using Microsoft.eShopWeb.RazorPages; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.eShopWeb.Infrastructure.Identity; namespace Microsoft.eShopWeb.FunctionalTests.WebRazorPages { diff --git a/tests/FunctionalTests/WebRazorPages/OrderIndexOnGet.cs b/tests/FunctionalTests/WebRazorPages/OrderIndexOnGet.cs index e5a1959..4f1d41f 100644 --- a/tests/FunctionalTests/WebRazorPages/OrderIndexOnGet.cs +++ b/tests/FunctionalTests/WebRazorPages/OrderIndexOnGet.cs @@ -1,5 +1,5 @@ using Microsoft.AspNetCore.Mvc.Testing; -using Microsoft.eShopWeb.Web; +using Microsoft.eShopWeb.RazorPages; using System.Net; using System.Net.Http; using System.Threading.Tasks; @@ -26,7 +26,7 @@ namespace Microsoft.eShopWeb.FunctionalTests.WebRazorPages var redirectLocation = response.Headers.Location.OriginalString; Assert.Equal(HttpStatusCode.Redirect, response.StatusCode); - Assert.Contains("Account/Signin", redirectLocation); + Assert.Contains("Account/Login", redirectLocation); } } } diff --git a/tests/IntegrationTests/IntegrationTests.csproj b/tests/IntegrationTests/IntegrationTests.csproj index 39240bb..2cbbf59 100644 --- a/tests/IntegrationTests/IntegrationTests.csproj +++ b/tests/IntegrationTests/IntegrationTests.csproj @@ -1,25 +1,29 @@  - - netcoreapp2.1 - Microsoft.eShopWeb.IntegrationTests - + + netcoreapp2.2 + Microsoft.eShopWeb.IntegrationTests + false + - - - - - + + + + + + + all + runtime; build; native; contentfiles; analyzers + + - + + + + - - - - - - - - + + + diff --git a/tests/UnitTests/UnitTests.csproj b/tests/UnitTests/UnitTests.csproj index 0b81218..9917fe0 100644 --- a/tests/UnitTests/UnitTests.csproj +++ b/tests/UnitTests/UnitTests.csproj @@ -1,26 +1,32 @@  - - netcoreapp2.1 - Microsoft.eShopWeb.UnitTests - + + netcoreapp2.2 + Microsoft.eShopWeb.UnitTests + false + - - - - - - - - + + + + + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + - - - - + + + - - - + + + diff --git a/tests/XUnitTestProject1/UnitTest1.cs b/tests/XUnitTestProject1/UnitTest1.cs new file mode 100644 index 0000000..ded6b0c --- /dev/null +++ b/tests/XUnitTestProject1/UnitTest1.cs @@ -0,0 +1,14 @@ +using System; +using Xunit; + +namespace XUnitTestProject1 +{ + public class UnitTest1 + { + [Fact] + public void Test1() + { + + } + } +} diff --git a/tests/XUnitTestProject1/XUnitTestProject1.csproj b/tests/XUnitTestProject1/XUnitTestProject1.csproj new file mode 100644 index 0000000..3e02510 --- /dev/null +++ b/tests/XUnitTestProject1/XUnitTestProject1.csproj @@ -0,0 +1,15 @@ + + + + netcoreapp2.2 + + false + + + + + + + + +