isn/test/nuget.host.tests/UnitTestWebHost.cs

44 lines
1.3 KiB
C#
Raw Normal View History

2021-05-09 13:45:55 +01:00
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;
using System.Threading.Tasks;
2021-05-09 13:45:55 +01:00
namespace nuget.host.tests
{
public class UnitTestWebHost
{
const string testingUrl = "http://localhost:5003";
2021-05-09 13:45:55 +01:00
[Fact]
public async Task TestHaveTestDbContext()
2021-05-09 13:45:55 +01:00
{
IWebHost webhost = BuildWebHost( new string[] { "--urls", testingUrl});
2021-05-09 13:45:55 +01:00
Assert.NotNull(webhost);
webhost.Start();
await webhost.StopAsync();
2021-05-09 13:45:55 +01:00
}
[Fact]
public async Task TestHaveConfig()
2021-05-09 13:45:55 +01:00
{
string envVar = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
Assert.Equal("Development", envVar);
IWebHost webhost = BuildWebHost( new string[] { "--urls", testingUrl });
2021-05-09 13:45:55 +01:00
Assert.NotNull(webhost);
webhost.Start();
await webhost.StopAsync();
2021-05-09 13:45:55 +01:00
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}