diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index af03345..7a96b4e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -22,7 +22,9 @@ build1: nonreg: stage: test script: - - ASPNETCORE_ENVIRONMENT=Development dotnet test + - | + cd test/nuget.host.tests + ASPNETCORE_ENVIRONMENT=Development dotnet test test2: stage: test diff --git a/.vscode/tasks.json b/.vscode/tasks.json index cd12d2f..a183bdb 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -19,7 +19,6 @@ "type": "process", "args": [ "build", - "src/nuget-host", "/p:Configuration=Debug", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary", @@ -73,7 +72,7 @@ "command": "dotnet", "type": "process", "args": [ - "${workspaceFolder}/bin/Debug/netcoreapp2.0/nuget-host.dll" + "${workspaceFolder}/bin/Debug/netcoreapp2.1/nuget-host.dll" ], "problemMatcher": "$msCompile" }, @@ -82,7 +81,7 @@ "command": "dotnet", "type": "process", "args": [ - "bin/Debug/netcoreapp2.0/nuget-host.dll", + "bin/Debug/netcoreapp2.1/nuget-host.dll", "/property:GenerateFullPaths=true", "/restore" ], diff --git a/test/nuget.host.tests/UnitTestWebHost.cs b/test/nuget.host.tests/UnitTestWebHost.cs index 5c7f151..d763130 100644 --- a/test/nuget.host.tests/UnitTestWebHost.cs +++ b/test/nuget.host.tests/UnitTestWebHost.cs @@ -7,38 +7,49 @@ using nuget_host.Data; using Microsoft.Extensions.Options; using nuget_host.Entities; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using System.Diagnostics; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; namespace nuget.host.tests { public class UnitTestWebHost { - const string testingUrl = "http://localhost:5003"; + const string testingUrl = "http://localhost:5000"; + + [Fact] public async Task TestHaveTestDbContext() - { - IWebHost webhost = BuildWebHost( new string[] { "--urls", testingUrl}); - Assert.NotNull(webhost); - webhost.Start(); - await webhost.StopAsync(); - } - - [Fact] - public async Task TestHaveConfig() { string envVar = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); Assert.Equal("Development", envVar); - IWebHost webhost = BuildWebHost( new string[] { "--urls", testingUrl }); - Assert.NotNull(webhost); - webhost.Start(); - - await webhost.StopAsync(); + IWebHost webhost = BuildWebHost(new string[] { "--urls", testingUrl }); + + using (var serviceScope = webhost.Services.CreateScope()) + { + var services = serviceScope.ServiceProvider; + + try + { + var myDependency = services.GetRequiredService(); + myDependency.Database.Migrate(); + } + catch (Exception ex) + { + var logger = services.GetRequiredService>(); + logger.LogError(ex, "An error occurred."); + } + } + } + public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup() .Build(); - + } }