48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
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();
|
|
|
|
}
|
|
}
|