fixes nonreg
This commit is contained in:
@ -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>(
|
||||
|
@ -1,23 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace test.Settings
|
||||
{
|
||||
public abstract class DbConnectionSettings
|
||||
public class DbConnectionSettings
|
||||
{
|
||||
public string Database { get; set; }
|
||||
public string Server { get; set; }
|
||||
public int Port { 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 string DatabaseCtor { get; set; }
|
||||
public string Default { get; set; }
|
||||
public string Testing { get; set; }
|
||||
}
|
||||
|
||||
public class DevConnectionSettings : DbConnectionSettings
|
||||
{
|
||||
|
||||
}
|
||||
public class TestConnectionSettings : DbConnectionSettings
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,7 @@ namespace test
|
||||
public static IConfiguration Configuration { get; set; }
|
||||
|
||||
public static string HostingFullName { get; private set; }
|
||||
public static DbConnectionSettings DevDbSettings { get; private set; }
|
||||
public static DbConnectionSettings TestDbSettings { get; private set; }
|
||||
public static DbConnectionSettings DbSettings { get; private set; }
|
||||
|
||||
ILogger logger;
|
||||
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
|
||||
@ -50,11 +49,8 @@ namespace test
|
||||
services.Configure<SiteSettings>(siteSettingsconf);
|
||||
var smtpSettingsconf = Configuration.GetSection("Smtp");
|
||||
services.Configure<SmtpSettings>(smtpSettingsconf);
|
||||
var devCx = Configuration.GetSection("Data:DevConnection");
|
||||
services.Configure<DevConnectionSettings>(devCx);
|
||||
var testCx = Configuration.GetSection("Data:TestConnection");
|
||||
services.Configure<TestConnectionSettings>(testCx);
|
||||
|
||||
var dbSettingsconf = Configuration.GetSection("ConnectionStrings");
|
||||
services.Configure<DbConnectionSettings>(dbSettingsconf);
|
||||
|
||||
services.AddInstance(typeof(ILoggerFactory), new LoggerFactory());
|
||||
services.AddTransient(typeof(IEmailSender), typeof(MailSender));
|
||||
@ -70,7 +66,7 @@ namespace test
|
||||
services.AddEntityFramework()
|
||||
.AddNpgsql()
|
||||
.AddDbContext<ApplicationDbContext>(
|
||||
db => db.UseNpgsql(Startup.TestDbSettings.ConnectionString)
|
||||
db => db.UseNpgsql(Startup.DbSettings.Default)
|
||||
);
|
||||
|
||||
services.AddTransient<Microsoft.Extensions.WebEncoders.UrlEncoder, UrlEncoder>();
|
||||
@ -79,8 +75,7 @@ namespace test
|
||||
|
||||
public void Configure (IApplicationBuilder app, IHostingEnvironment env,
|
||||
IOptions<SiteSettings> siteSettings,
|
||||
IOptions<TestConnectionSettings> testCxOptions,
|
||||
IOptions<DevConnectionSettings> devCxOptions,
|
||||
IOptions<DbConnectionSettings> cxOptions,
|
||||
ILoggerFactory loggerFactory)
|
||||
{
|
||||
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
||||
@ -88,10 +83,10 @@ namespace test
|
||||
logger = loggerFactory.CreateLogger<Startup>();
|
||||
logger.LogInformation(env.EnvironmentName);
|
||||
|
||||
TestDbSettings = testCxOptions.Value;
|
||||
DevDbSettings = devCxOptions.Value;
|
||||
logger.LogInformation($"test db : {TestDbSettings.ConnectionString}");
|
||||
AppDomain.CurrentDomain.SetData("YAVSC_DB_CONNECTION", TestDbSettings.ConnectionString);
|
||||
DbSettings = cxOptions.Value;
|
||||
logger.LogInformation($"default db : {DbSettings.Default}");
|
||||
logger.LogInformation($"test db : {DbSettings.Testing}");
|
||||
AppDomain.CurrentDomain.SetData("YAVSC_DB_CONNECTION", DbSettings.Default);
|
||||
|
||||
var authConf = Configuration.GetSection("Authentication").GetSection("Yavsc");
|
||||
var clientId = authConf.GetSection("ClientId").Value;
|
||||
|
Reference in New Issue
Block a user