fixes nonreg
This commit is contained in:
@ -15,7 +15,7 @@ namespace test.Mandatory
|
|||||||
this.output = output;
|
this.output = output;
|
||||||
_serverFixture = serverFixture;
|
_serverFixture = serverFixture;
|
||||||
|
|
||||||
output.WriteLine($"Startup.TestDbSettings.Database was {Startup.TestDbSettings.Database}");
|
output.WriteLine($"Startup.DbSettings.Testing is {Startup.DbSettings.Testing}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Data.Common;
|
||||||
using Microsoft.AspNet.Hosting;
|
using Microsoft.AspNet.Hosting;
|
||||||
using Microsoft.AspNet.Hosting.Internal;
|
using Microsoft.AspNet.Hosting.Internal;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
@ -6,6 +7,7 @@ using Microsoft.Extensions.OptionsModel;
|
|||||||
using Yavsc.Lib;
|
using Yavsc.Lib;
|
||||||
using Yavsc.Services;
|
using Yavsc.Services;
|
||||||
using Yavsc;
|
using Yavsc;
|
||||||
|
using Yavsc.Models;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Npgsql;
|
using Npgsql;
|
||||||
|
|
||||||
@ -22,6 +24,7 @@ namespace test
|
|||||||
|
|
||||||
public static string ApiKey => "53f4d5da-93a9-4584-82f9-b8fdf243b002" ;
|
public static string ApiKey => "53f4d5da-93a9-4584-82f9-b8fdf243b002" ;
|
||||||
|
|
||||||
|
public ApplicationDbContext DbContext { get; private set; }
|
||||||
public SiteSettings SiteSetup
|
public SiteSettings SiteSetup
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -109,50 +112,61 @@ namespace test
|
|||||||
var siteSetup = App.Services.GetService(typeof(IOptions<SiteSettings>)) as IOptions<SiteSettings>;
|
var siteSetup = App.Services.GetService(typeof(IOptions<SiteSettings>)) as IOptions<SiteSettings>;
|
||||||
SiteSetup = siteSetup.Value;
|
SiteSetup = siteSetup.Value;
|
||||||
MailSender = App.Services.GetService(typeof(IEmailSender)) as IEmailSender;
|
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();
|
CheckDbExistence();
|
||||||
if (!DbCreated)
|
if (!DbCreated)
|
||||||
CreateTestDb();
|
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()
|
public void CreateTestDb()
|
||||||
{
|
{
|
||||||
if (!DbCreated)
|
if (!DbCreated)
|
||||||
using (
|
using (
|
||||||
NpgsqlConnection cx = new NpgsqlConnection(Startup.DevDbSettings.ConnectionString))
|
NpgsqlConnection cx = new NpgsqlConnection(Startup.DbSettings.DatabaseCtor))
|
||||||
{
|
{
|
||||||
cx.Open();
|
cx.Open();
|
||||||
var command = cx.CreateCommand();
|
var command = cx.CreateCommand();
|
||||||
command.CommandText = $"create database \"{Startup.TestDbSettings.Database}\";";
|
command.CommandText = $"create database \"{TestingDatabase}\";";
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
|
|
||||||
_logger.LogInformation($"database created.");
|
_logger.LogInformation($"database created.");
|
||||||
cx.Close();
|
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()
|
public void DropTestDb()
|
||||||
{
|
{
|
||||||
if (DbCreated)
|
if (DbCreated)
|
||||||
using (
|
using (
|
||||||
NpgsqlConnection cx = new NpgsqlConnection(Startup.DevDbSettings.ConnectionString))
|
NpgsqlConnection cx = new NpgsqlConnection(Startup.DbSettings.DatabaseCtor))
|
||||||
{
|
{
|
||||||
cx.Open();
|
cx.Open();
|
||||||
var command = cx.CreateCommand();
|
var command = cx.CreateCommand();
|
||||||
command.CommandText = $"drop database \"{Startup.TestDbSettings.Database}\";";
|
command.CommandText = $"drop database \"{TestingDatabase}\"";
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
_logger.LogInformation($"database dropped");
|
_logger.LogInformation($"database dropped");
|
||||||
cx.Close();
|
cx.Close();
|
||||||
|
@ -32,18 +32,20 @@ namespace test
|
|||||||
public class YavscMandatory: BaseTestContext, IClassFixture<ServerSideFixture>
|
public class YavscMandatory: BaseTestContext, IClassFixture<ServerSideFixture>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ApplicationDbContext _dbContext;
|
||||||
|
|
||||||
public YavscMandatory(ITestOutputHelper output, ServerSideFixture fixture) : base (output, fixture)
|
public YavscMandatory(ITestOutputHelper output, ServerSideFixture fixture) : base (output, fixture)
|
||||||
{
|
{
|
||||||
|
_dbContext = fixture.DbContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void GitClone()
|
public void GitClone()
|
||||||
{
|
{
|
||||||
|
var firstProject = _dbContext.Projects.Include(p=>p.Repository).FirstOrDefault();
|
||||||
var dbc = _serverFixture.App.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
|
|
||||||
|
|
||||||
var firstProject = dbc.Projects.Include(p=>p.Repository).FirstOrDefault();
|
|
||||||
Assert.NotNull (firstProject);
|
Assert.NotNull (firstProject);
|
||||||
|
var di = new DirectoryInfo(_serverFixture.SiteSetup.GitRepository);
|
||||||
|
if (!di.Exists) di.Create();
|
||||||
|
|
||||||
var clone = new GitClone(_serverFixture.SiteSetup.GitRepository);
|
var clone = new GitClone(_serverFixture.SiteSetup.GitRepository);
|
||||||
clone.Launch(firstProject);
|
clone.Launch(firstProject);
|
||||||
@ -65,12 +67,6 @@ namespace test
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void ApplicationDbContextExists()
|
|
||||||
{
|
|
||||||
var dbc = new ApplicationDbContext();
|
|
||||||
Assert.NotNull(dbc.GCMDevices);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void MvcRazorHostAndParser()
|
public void MvcRazorHostAndParser()
|
||||||
@ -80,12 +76,6 @@ namespace test
|
|||||||
var parser = host.CreateMarkupParser();
|
var parser = host.CreateMarkupParser();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
void HaveDependecyInjection()
|
|
||||||
{
|
|
||||||
var services = new ServiceCollection();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
void HaveHost()
|
void HaveHost()
|
||||||
{
|
{
|
||||||
@ -149,7 +139,7 @@ namespace test
|
|||||||
{
|
{
|
||||||
options.ResourcesPath = "Resources";
|
options.ResourcesPath = "Resources";
|
||||||
});
|
});
|
||||||
var connectionString = configuration["Data:DefaultConnection:ConnectionString"];
|
var connectionString = configuration["ConnectionStrings:Default"];
|
||||||
AppDomain.CurrentDomain.SetData("YAVSC_DB_CONNECTION", connectionString);
|
AppDomain.CurrentDomain.SetData("YAVSC_DB_CONNECTION", connectionString);
|
||||||
serviceCollection.AddEntityFramework()
|
serviceCollection.AddEntityFramework()
|
||||||
.AddNpgsql()
|
.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]
|
[Fact]
|
||||||
public void InitApplicationBuilder()
|
public void InitApplicationBuilder()
|
||||||
{
|
{
|
||||||
|
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
|
|
||||||
services.AddTransient<IRuntimeEnvironment>(
|
services.AddTransient<IRuntimeEnvironment>(
|
||||||
|
@ -1,23 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
namespace test.Settings
|
namespace test.Settings
|
||||||
{
|
{
|
||||||
public abstract class DbConnectionSettings
|
public class DbConnectionSettings
|
||||||
{
|
{
|
||||||
public string Database { get; set; }
|
public string DatabaseCtor { get; set; }
|
||||||
public string Server { get; set; }
|
public string Default { get; set; }
|
||||||
public int Port { get; set; }
|
public string Testing { get; set; }
|
||||||
public string Username { get; set; }
|
|
||||||
|
|
||||||
public string ConnectionString => $"Database={Database};Server={Server};Port={Port};Username={Username};Password={Password};";
|
|
||||||
|
|
||||||
public string Password { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DevConnectionSettings : DbConnectionSettings
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
public class TestConnectionSettings : DbConnectionSettings
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -23,8 +23,7 @@ namespace test
|
|||||||
public static IConfiguration Configuration { get; set; }
|
public static IConfiguration Configuration { get; set; }
|
||||||
|
|
||||||
public static string HostingFullName { get; private set; }
|
public static string HostingFullName { get; private set; }
|
||||||
public static DbConnectionSettings DevDbSettings { get; private set; }
|
public static DbConnectionSettings DbSettings { get; private set; }
|
||||||
public static DbConnectionSettings TestDbSettings { get; private set; }
|
|
||||||
|
|
||||||
ILogger logger;
|
ILogger logger;
|
||||||
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
|
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
|
||||||
@ -50,11 +49,8 @@ namespace test
|
|||||||
services.Configure<SiteSettings>(siteSettingsconf);
|
services.Configure<SiteSettings>(siteSettingsconf);
|
||||||
var smtpSettingsconf = Configuration.GetSection("Smtp");
|
var smtpSettingsconf = Configuration.GetSection("Smtp");
|
||||||
services.Configure<SmtpSettings>(smtpSettingsconf);
|
services.Configure<SmtpSettings>(smtpSettingsconf);
|
||||||
var devCx = Configuration.GetSection("Data:DevConnection");
|
var dbSettingsconf = Configuration.GetSection("ConnectionStrings");
|
||||||
services.Configure<DevConnectionSettings>(devCx);
|
services.Configure<DbConnectionSettings>(dbSettingsconf);
|
||||||
var testCx = Configuration.GetSection("Data:TestConnection");
|
|
||||||
services.Configure<TestConnectionSettings>(testCx);
|
|
||||||
|
|
||||||
|
|
||||||
services.AddInstance(typeof(ILoggerFactory), new LoggerFactory());
|
services.AddInstance(typeof(ILoggerFactory), new LoggerFactory());
|
||||||
services.AddTransient(typeof(IEmailSender), typeof(MailSender));
|
services.AddTransient(typeof(IEmailSender), typeof(MailSender));
|
||||||
@ -70,7 +66,7 @@ namespace test
|
|||||||
services.AddEntityFramework()
|
services.AddEntityFramework()
|
||||||
.AddNpgsql()
|
.AddNpgsql()
|
||||||
.AddDbContext<ApplicationDbContext>(
|
.AddDbContext<ApplicationDbContext>(
|
||||||
db => db.UseNpgsql(Startup.TestDbSettings.ConnectionString)
|
db => db.UseNpgsql(Startup.DbSettings.Default)
|
||||||
);
|
);
|
||||||
|
|
||||||
services.AddTransient<Microsoft.Extensions.WebEncoders.UrlEncoder, UrlEncoder>();
|
services.AddTransient<Microsoft.Extensions.WebEncoders.UrlEncoder, UrlEncoder>();
|
||||||
@ -79,8 +75,7 @@ namespace test
|
|||||||
|
|
||||||
public void Configure (IApplicationBuilder app, IHostingEnvironment env,
|
public void Configure (IApplicationBuilder app, IHostingEnvironment env,
|
||||||
IOptions<SiteSettings> siteSettings,
|
IOptions<SiteSettings> siteSettings,
|
||||||
IOptions<TestConnectionSettings> testCxOptions,
|
IOptions<DbConnectionSettings> cxOptions,
|
||||||
IOptions<DevConnectionSettings> devCxOptions,
|
|
||||||
ILoggerFactory loggerFactory)
|
ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
||||||
@ -88,10 +83,10 @@ namespace test
|
|||||||
logger = loggerFactory.CreateLogger<Startup>();
|
logger = loggerFactory.CreateLogger<Startup>();
|
||||||
logger.LogInformation(env.EnvironmentName);
|
logger.LogInformation(env.EnvironmentName);
|
||||||
|
|
||||||
TestDbSettings = testCxOptions.Value;
|
DbSettings = cxOptions.Value;
|
||||||
DevDbSettings = devCxOptions.Value;
|
logger.LogInformation($"default db : {DbSettings.Default}");
|
||||||
logger.LogInformation($"test db : {TestDbSettings.ConnectionString}");
|
logger.LogInformation($"test db : {DbSettings.Testing}");
|
||||||
AppDomain.CurrentDomain.SetData("YAVSC_DB_CONNECTION", TestDbSettings.ConnectionString);
|
AppDomain.CurrentDomain.SetData("YAVSC_DB_CONNECTION", DbSettings.Default);
|
||||||
|
|
||||||
var authConf = Configuration.GetSection("Authentication").GetSection("Yavsc");
|
var authConf = Configuration.GetSection("Authentication").GetSection("Yavsc");
|
||||||
var clientId = authConf.GetSection("ClientId").Value;
|
var clientId = authConf.GetSection("ClientId").Value;
|
||||||
|
Reference in New Issue
Block a user