Réussi! - échec : 0, réussite : 2, ignorée(s) : 0, total : 2, durée : 444 ms

This commit is contained in:
Paul Schneider
2021-05-09 14:56:32 +01:00
parent 6a59f776d5
commit ffb7cad00a
15 changed files with 181 additions and 33 deletions

View File

@ -6,35 +6,32 @@ using Xunit;
using nuget_host.Data;
using Microsoft.Extensions.Options;
using nuget_host.Entities;
using System.Threading.Tasks;
namespace nuget.host.tests
{
public class UnitTestWebHost
{
const string testingUrl = "http://localhost:5003";
[Fact]
public void TestHaveTestDbContext()
public async Task TestHaveTestDbContext()
{
IWebHost webhost = BuildWebHost( new string[] { "--urls", "localhost:5003" });
IWebHost webhost = BuildWebHost( new string[] { "--urls", testingUrl});
Assert.NotNull(webhost);
ApplicationDbContext dbcontext = (ApplicationDbContext) webhost.Services.GetService(typeof(ApplicationDbContext));
Assert.NotNull(dbcontext);
dbcontext.Database.EnsureCreated();
webhost.Start();
await webhost.StopAsync();
}
[Fact]
public void TestHaveConfig()
public async Task TestHaveConfig()
{
string envVar = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
Assert.Equal("Testing", envVar);
IWebHost webhost = BuildWebHost( new string[] { "--urls", "localhost:5003" });
Assert.Equal("Development", envVar);
IWebHost webhost = BuildWebHost( new string[] { "--urls", testingUrl });
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);
webhost.Start();
await webhost.StopAsync();
}