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();
|
||||
|
||||
}
|
||||
}
|
22
test/nuget.host.tests/nuget.host.tests.csproj
Normal file
22
test/nuget.host.tests/nuget.host.tests.csproj
Normal 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>
|
Reference in New Issue
Block a user