This commit is contained in:
Paul Schneider
2021-07-05 12:55:52 +01:00
parent 5de53a3cba
commit 476d35ae8a
270 changed files with 476 additions and 400 deletions

View 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();
}
}

View File

@ -0,0 +1,12 @@
{
"Nuget": {
"PackagesRootDir" : "packages",
"MaxUserKeyCount": 5
},
"Smtp": {
"Server": "localhost",
"Port": 25,
"SenderName": "Paul Schneider",
"SenderEmail": "paul@pschneider.fr"
}
}

View 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>