Consolidate Web and WebRazorPages Projects (#192)
* Moved Privacy, Home page to Razor Pages * Migrating Basket from RazorPages to Web. * Removed BasketController; refactored viewmodels * Moved BasketComponent into Pages/Shared Added auth rules to Startup for Pages Added notes to controllers about Pages usage. * Fixed broken my orders test Consolidated Functional Tests * Fixed logo link to home page Fixed Order Detail Total $ format
This commit is contained in:
@@ -22,11 +22,14 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\ApplicationCore\ApplicationCore.csproj" />
|
||||
<ProjectReference Include="..\..\src\Web\Web.csproj" />
|
||||
<ProjectReference Include="..\..\src\WebRazorPages\WebRazorPages.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="WebRazorPages\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Microsoft.eShopWeb.FunctionalTests.Web.Controllers
|
||||
[Fact]
|
||||
public async Task ReturnsRedirectGivenAnonymousUser()
|
||||
{
|
||||
var response = await Client.GetAsync("/Order/Index");
|
||||
var response = await Client.GetAsync("/order/my-orders");
|
||||
var redirectLocation = response.Headers.Location.OriginalString;
|
||||
|
||||
Assert.Equal(HttpStatusCode.Redirect, response.StatusCode);
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
using Microsoft.eShopWeb.RazorPages;
|
||||
using Microsoft.eShopWeb.FunctionalTests.Web.Controllers;
|
||||
using Microsoft.eShopWeb.Web;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.eShopWeb.FunctionalTests.WebRazorPages
|
||||
{
|
||||
public class HomePageOnGet : IClassFixture<CustomWebRazorPagesApplicationFactory<Startup>>
|
||||
public class HomePageOnGet : IClassFixture<CustomWebApplicationFactory<Startup>>
|
||||
{
|
||||
public HomePageOnGet(CustomWebRazorPagesApplicationFactory<Startup> factory)
|
||||
public HomePageOnGet(CustomWebApplicationFactory<Startup> factory)
|
||||
{
|
||||
Client = factory.CreateClient();
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
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.RazorPages;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
|
||||
namespace Microsoft.eShopWeb.FunctionalTests.WebRazorPages
|
||||
{
|
||||
public class CustomWebRazorPagesApplicationFactory<TStartup>
|
||||
: WebApplicationFactory<Startup>
|
||||
{
|
||||
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||
{
|
||||
builder.ConfigureServices(services =>
|
||||
{
|
||||
// Create a new service provider.
|
||||
var serviceProvider = new ServiceCollection()
|
||||
.AddEntityFrameworkInMemoryDatabase()
|
||||
.BuildServiceProvider();
|
||||
|
||||
// Add a database context (ApplicationDbContext) using an in-memory
|
||||
// database for testing.
|
||||
services.AddDbContext<CatalogContext>(options =>
|
||||
{
|
||||
options.UseInMemoryDatabase("InMemoryDbForTesting");
|
||||
options.UseInternalServiceProvider(serviceProvider);
|
||||
});
|
||||
|
||||
services.AddDbContext<AppIdentityDbContext>(options =>
|
||||
{
|
||||
options.UseInMemoryDatabase("Identity");
|
||||
options.UseInternalServiceProvider(serviceProvider);
|
||||
});
|
||||
|
||||
// Build the service provider.
|
||||
var sp = services.BuildServiceProvider();
|
||||
|
||||
// Create a scope to obtain a reference to the database
|
||||
// context (ApplicationDbContext).
|
||||
using (var scope = sp.CreateScope())
|
||||
{
|
||||
var scopedServices = scope.ServiceProvider;
|
||||
var db = scopedServices.GetRequiredService<CatalogContext>();
|
||||
var loggerFactory = scopedServices.GetRequiredService<ILoggerFactory>();
|
||||
|
||||
var logger = scopedServices
|
||||
.GetRequiredService<ILogger<CustomWebRazorPagesApplicationFactory<TStartup>>>();
|
||||
|
||||
// Ensure the database is created.
|
||||
db.Database.EnsureCreated();
|
||||
|
||||
try
|
||||
{
|
||||
// Seed the database with test data.
|
||||
CatalogContextSeed.SeedAsync(db, loggerFactory).Wait();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"An error occurred seeding the " +
|
||||
"database with test messages. Error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.eShopWeb.RazorPages;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.eShopWeb.FunctionalTests.WebRazorPages
|
||||
{
|
||||
public class OrderIndexOnGet : IClassFixture<CustomWebRazorPagesApplicationFactory<Startup>>
|
||||
{
|
||||
public OrderIndexOnGet(CustomWebRazorPagesApplicationFactory<Startup> factory)
|
||||
{
|
||||
Client = factory.CreateClient(new WebApplicationFactoryClientOptions
|
||||
{
|
||||
AllowAutoRedirect = false
|
||||
});
|
||||
}
|
||||
|
||||
public HttpClient Client { get; }
|
||||
|
||||
[Fact]
|
||||
public async Task ReturnsRedirectGivenAnonymousUser()
|
||||
{
|
||||
var response = await Client.GetAsync("/Order/Index");
|
||||
var redirectLocation = response.Headers.Location.OriginalString;
|
||||
|
||||
Assert.Equal(HttpStatusCode.Redirect, response.StatusCode);
|
||||
Assert.Contains("Account/Login", redirectLocation);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user