fixes nonreg
This commit is contained in:
parent
f0e8451577
commit
f290074149
5 changed files with 54 additions and 87 deletions
|
|
@ -15,7 +15,7 @@ namespace test.Mandatory
|
|||
this.output = output;
|
||||
_serverFixture = serverFixture;
|
||||
|
||||
output.WriteLine($"Startup.TestDbSettings.Database was {Startup.TestDbSettings.Database}");
|
||||
output.WriteLine($"Startup.DbSettings.Testing is {Startup.DbSettings.Testing}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Data.Common;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.AspNet.Hosting.Internal;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
|
@ -6,6 +7,7 @@ using Microsoft.Extensions.OptionsModel;
|
|||
using Yavsc.Lib;
|
||||
using Yavsc.Services;
|
||||
using Yavsc;
|
||||
using Yavsc.Models;
|
||||
using Xunit;
|
||||
using Npgsql;
|
||||
|
||||
|
|
@ -22,6 +24,7 @@ namespace test
|
|||
|
||||
public static string ApiKey => "53f4d5da-93a9-4584-82f9-b8fdf243b002" ;
|
||||
|
||||
public ApplicationDbContext DbContext { get; private set; }
|
||||
public SiteSettings SiteSetup
|
||||
{
|
||||
get
|
||||
|
|
@ -109,55 +112,66 @@ namespace test
|
|||
var siteSetup = App.Services.GetService(typeof(IOptions<SiteSettings>)) as IOptions<SiteSettings>;
|
||||
SiteSetup = siteSetup.Value;
|
||||
MailSender = App.Services.GetService(typeof(IEmailSender)) as IEmailSender;
|
||||
|
||||
var builder = new DbConnectionStringBuilder();
|
||||
builder.ConnectionString = Startup.DbSettings.Testing;
|
||||
Logger.LogInformation("testing database:" +builder["Database"]);
|
||||
TestingDatabase = (string) builder["Database"];
|
||||
|
||||
CheckDbExistence();
|
||||
if (!DbCreated)
|
||||
CreateTestDb();
|
||||
DbContext = App.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
|
||||
|
||||
}
|
||||
|
||||
public string TestingDatabase { get; private set; }
|
||||
|
||||
public void CheckDbExistence()
|
||||
{
|
||||
using (
|
||||
NpgsqlConnection cx = new NpgsqlConnection(Startup.DbSettings.DatabaseCtor))
|
||||
{
|
||||
cx.Open();
|
||||
var command = cx.CreateCommand();
|
||||
command.CommandText = $"SELECT 1 FROM pg_database WHERE datname='{TestingDatabase}';";
|
||||
DbCreated = (command.ExecuteScalar()!=null);
|
||||
|
||||
_logger.LogInformation($"DbCreated:{DbCreated}");
|
||||
cx.Close();
|
||||
}
|
||||
}
|
||||
/* Needs a connection string parsing */
|
||||
|
||||
public void CreateTestDb()
|
||||
{
|
||||
if (!DbCreated)
|
||||
using (
|
||||
NpgsqlConnection cx = new NpgsqlConnection(Startup.DevDbSettings.ConnectionString))
|
||||
NpgsqlConnection cx = new NpgsqlConnection(Startup.DbSettings.DatabaseCtor))
|
||||
{
|
||||
cx.Open();
|
||||
var command = cx.CreateCommand();
|
||||
command.CommandText = $"create database \"{Startup.TestDbSettings.Database}\";";
|
||||
command.CommandText = $"create database \"{TestingDatabase}\";";
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
_logger.LogInformation($"database created.");
|
||||
cx.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckDbExistence()
|
||||
{
|
||||
using (
|
||||
NpgsqlConnection cx = new NpgsqlConnection(Startup.DevDbSettings.ConnectionString))
|
||||
{
|
||||
cx.Open();
|
||||
var command = cx.CreateCommand();
|
||||
command.CommandText = $"SELECT 1 FROM pg_database WHERE datname='{Startup.TestDbSettings.Database}';";
|
||||
DbCreated = (command.ExecuteScalar()!=null);
|
||||
|
||||
_logger.LogInformation($"DbCreated:{DbCreated}");
|
||||
cx.Close();
|
||||
}
|
||||
}
|
||||
public void DropTestDb()
|
||||
{
|
||||
if (DbCreated)
|
||||
using (
|
||||
NpgsqlConnection cx = new NpgsqlConnection(Startup.DevDbSettings.ConnectionString))
|
||||
NpgsqlConnection cx = new NpgsqlConnection(Startup.DbSettings.DatabaseCtor))
|
||||
{
|
||||
cx.Open();
|
||||
var command = cx.CreateCommand();
|
||||
command.CommandText = $"drop database \"{Startup.TestDbSettings.Database}\";";
|
||||
command.CommandText = $"drop database \"{TestingDatabase}\"";
|
||||
command.ExecuteNonQuery();
|
||||
_logger.LogInformation($"database dropped");
|
||||
cx.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
Logger.LogInformation("Disposing");
|
||||
|
|
|
|||
|
|
@ -31,19 +31,21 @@ namespace test
|
|||
[Trait("regres", "no")]
|
||||
public class YavscMandatory: BaseTestContext, IClassFixture<ServerSideFixture>
|
||||
{
|
||||
|
||||
|
||||
ApplicationDbContext _dbContext;
|
||||
|
||||
public YavscMandatory(ITestOutputHelper output, ServerSideFixture fixture) : base (output, fixture)
|
||||
{
|
||||
|
||||
_dbContext = fixture.DbContext;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GitClone()
|
||||
{
|
||||
|
||||
var dbc = _serverFixture.App.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
|
||||
|
||||
var firstProject = dbc.Projects.Include(p=>p.Repository).FirstOrDefault();
|
||||
var firstProject = _dbContext.Projects.Include(p=>p.Repository).FirstOrDefault();
|
||||
Assert.NotNull (firstProject);
|
||||
var di = new DirectoryInfo(_serverFixture.SiteSetup.GitRepository);
|
||||
if (!di.Exists) di.Create();
|
||||
|
||||
var clone = new GitClone(_serverFixture.SiteSetup.GitRepository);
|
||||
clone.Launch(firstProject);
|
||||
|
|
@ -65,12 +67,6 @@ namespace test
|
|||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplicationDbContextExists()
|
||||
{
|
||||
var dbc = new ApplicationDbContext();
|
||||
Assert.NotNull(dbc.GCMDevices);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MvcRazorHostAndParser()
|
||||
|
|
@ -80,12 +76,6 @@ namespace test
|
|||
var parser = host.CreateMarkupParser();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
void HaveDependecyInjection()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
void HaveHost()
|
||||
{
|
||||
|
|
@ -149,7 +139,7 @@ namespace test
|
|||
{
|
||||
options.ResourcesPath = "Resources";
|
||||
});
|
||||
var connectionString = configuration["Data:DefaultConnection:ConnectionString"];
|
||||
var connectionString = configuration["ConnectionStrings:Default"];
|
||||
AppDomain.CurrentDomain.SetData("YAVSC_DB_CONNECTION", connectionString);
|
||||
serviceCollection.AddEntityFramework()
|
||||
.AddNpgsql()
|
||||
|
|
@ -178,29 +168,9 @@ namespace test
|
|||
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void MessageSenderFromLib()
|
||||
{
|
||||
ARequestAppDelegate();
|
||||
ILoggerFactory factory = ActivatorUtilities.GetServiceOrCreateInstance<ILoggerFactory>(serviceProvider);
|
||||
var dbc = new ApplicationDbContext();
|
||||
|
||||
IOptions<SiteSettings> siteOptions =
|
||||
ActivatorUtilities.GetServiceOrCreateInstance<IOptions<SiteSettings>>(serviceProvider);
|
||||
;
|
||||
IOptions<SmtpSettings> smtpOptions = ActivatorUtilities.GetServiceOrCreateInstance<IOptions<SmtpSettings>>(serviceProvider);
|
||||
;
|
||||
IOptions<GoogleAuthSettings> googleOptions = ActivatorUtilities.GetServiceOrCreateInstance<IOptions<GoogleAuthSettings>>(serviceProvider);
|
||||
;
|
||||
IEmailSender eSender = new MailSender
|
||||
(factory, siteOptions, smtpOptions, googleOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InitApplicationBuilder()
|
||||
{
|
||||
|
||||
var services = new ServiceCollection();
|
||||
|
||||
services.AddTransient<IRuntimeEnvironment>(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue