This commit is contained in:
Paul Schneider
2021-05-09 13:45:55 +01:00
parent 93394b3e82
commit 6a59f776d5
223 changed files with 75 additions and 8 deletions

View File

@ -0,0 +1,47 @@
using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore;
using nuget_host;
using Xunit;
using nuget_host.Data;
using Microsoft.Extensions.Options;
using nuget_host.Entities;
namespace nuget.host.tests
{
public class UnitTestWebHost
{
[Fact]
public void TestHaveTestDbContext()
{
IWebHost webhost = BuildWebHost( new string[] { "--urls", "localhost:5003" });
Assert.NotNull(webhost);
ApplicationDbContext dbcontext = (ApplicationDbContext) webhost.Services.GetService(typeof(ApplicationDbContext));
Assert.NotNull(dbcontext);
dbcontext.Database.EnsureCreated();
}
[Fact]
public void TestHaveConfig()
{
string envVar = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
Assert.Equal("Testing", envVar);
IWebHost webhost = BuildWebHost( new string[] { "--urls", "localhost:5003" });
Assert.NotNull(webhost);
IOptions<NugetSettings> configOptions = (IOptions<NugetSettings>) webhost.Services.GetService(typeof(IOptions<NugetSettings>));
NugetSettings nugetConfig = configOptions.Value;
Assert.NotNull(nugetConfig.ProtectionTitle);
Assert.NotNull(nugetConfig.PackagesRootDir);
Assert.True(nugetConfig.MaxUserKeyCount>0);
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}

View File

@ -0,0 +1,22 @@
<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.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<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/nuget-host/nuget-host.csproj" />
</ItemGroup>
</Project>