refact
This commit is contained in:
55
test/isnd.tests/UnitTestWebHost.cs
Normal file
55
test/isnd.tests/UnitTestWebHost.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore;
|
||||
using isn;
|
||||
using Xunit;
|
||||
using isn.Data;
|
||||
using Microsoft.Extensions.Options;
|
||||
using isn.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:5000";
|
||||
|
||||
|
||||
[Fact]
|
||||
public void TestHaveTestDbContext()
|
||||
{
|
||||
string envVar = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
|
||||
Assert.Equal("Development", envVar);
|
||||
IWebHost webhost = BuildWebHost(new string[] { "--urls", testingUrl });
|
||||
|
||||
using (var serviceScope = webhost.Services.CreateScope())
|
||||
{
|
||||
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) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
|
||||
}
|
||||
}
|
12
test/isnd.tests/appsettings.Development.json
Normal file
12
test/isnd.tests/appsettings.Development.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"Nuget": {
|
||||
"PackagesRootDir" : "packages",
|
||||
"MaxUserKeyCount": 5
|
||||
},
|
||||
"Smtp": {
|
||||
"Server": "localhost",
|
||||
"Port": 25,
|
||||
"SenderName": "Paul Schneider",
|
||||
"SenderEmail": "paul@pschneider.fr"
|
||||
}
|
||||
}
|
23
test/isnd.tests/isnd.tests.csproj
Normal file
23
test/isnd.tests/isnd.tests.csproj
Normal file
@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<UserSecretsId>d7144e46-4e63-4391-ba86-64b61f6e7be4</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
|
||||
<PackageReference Include="coverlet.collector" Version="1.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\isnd\isnd.csproj" />
|
||||
<ProjectReference Include="..\..\src\isn\isn.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Reference in New Issue
Block a user