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