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