refact
This commit is contained in:
47
test/nuget.host.tests/UnitTestWebHost.cs
Normal file
47
test/nuget.host.tests/UnitTestWebHost.cs
Normal 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();
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user