diff --git a/src/Web/Startup.cs b/src/Web/Startup.cs
index 1ca717b..edd33e2 100644
--- a/src/Web/Startup.cs
+++ b/src/Web/Startup.cs
@@ -61,9 +61,9 @@ namespace Microsoft.eShopWeb
// https://www.microsoft.com/en-us/download/details.aspx?id=54284
c.UseSqlServer(Configuration.GetConnectionString("CatalogConnection"));
}
- catch (System.Exception ex)
+ catch (Exception ex)
{
- var message = ex.Message;
+ //TODO: log the exception details
}
});
diff --git a/tests/FunctionalTests/FunctionalTests.csproj b/tests/FunctionalTests/FunctionalTests.csproj
index 72aaccb..7b5df4f 100644
--- a/tests/FunctionalTests/FunctionalTests.csproj
+++ b/tests/FunctionalTests/FunctionalTests.csproj
@@ -5,11 +5,11 @@
+
-
-
-
-
+
+
+
diff --git a/tests/FunctionalTests/Web/Controllers/CatalogControllerIndex.cs b/tests/FunctionalTests/Web/Controllers/CatalogControllerIndex.cs
new file mode 100644
index 0000000..42963dd
--- /dev/null
+++ b/tests/FunctionalTests/Web/Controllers/CatalogControllerIndex.cs
@@ -0,0 +1,70 @@
+using Infrastructure.Data;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Mvc.Testing;
+using Microsoft.eShopWeb;
+using System.Linq;
+using System.Net.Http;
+using System.Threading.Tasks;
+using Xunit;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using Infrastructure.Identity;
+using Microsoft.AspNetCore.Identity;
+using System;
+
+namespace FunctionalTests.Web.Controllers
+{
+public class CatalogControllerIndex : IClassFixture>
+{
+public CatalogControllerIndex(WebApplicationFactory fixture)
+{
+ var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder);
+ Client = factory.CreateClient();
+ var host = factory.Server?.Host;
+ SeedData(host);
+}
+
+private void SeedData(IWebHost host)
+{
+ if(host == null) { throw new ArgumentNullException("host"); }
+ using (var scope = host.Services.CreateScope())
+ {
+ var services = scope.ServiceProvider;
+ var loggerFactory = services.GetRequiredService();
+ try
+ {
+ var catalogContext = services.GetRequiredService();
+ CatalogContextSeed.SeedAsync(catalogContext, loggerFactory)
+ .Wait();
+
+ var userManager = services.GetRequiredService>();
+ AppIdentityDbContextSeed.SeedAsync(userManager).Wait();
+ }
+ catch (Exception ex)
+ {
+ var logger = loggerFactory.CreateLogger();
+ logger.LogError(ex, "An error occurred seeding the DB.");
+ }
+ }
+}
+
+private static void ConfigureWebHostBuilder(IWebHostBuilder builder)
+{
+ builder.UseEnvironment("Testing");
+}
+
+public HttpClient Client { get; }
+
+ [Fact]
+ public async Task ReturnsHomePageWithProductListing()
+ {
+ // Arrange & Act
+ var response = await Client.GetAsync("/");
+ response.EnsureSuccessStatusCode();
+ var stringResponse = await response.Content.ReadAsStringAsync();
+
+ // Assert
+ Assert.Contains(".NET Bot Black Sweatshirt", stringResponse);
+ }
+ }
+}