bug rename seance
This commit is contained in:
@ -1,26 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.Dnx.Compilation.CSharp;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace test
|
||||
{
|
||||
public class BaseTestContext {
|
||||
|
||||
protected IApplicationEnvironment applicationEnvironment = null;
|
||||
protected IServiceProvider serviceProvider = null;
|
||||
protected IConfigurationRoot configurationRoot;
|
||||
protected BeforeCompileContext beforeCompileContext;
|
||||
protected IServiceProvider provider;
|
||||
protected IConfigurationRoot configuration;
|
||||
protected readonly ITestOutputHelper _output;
|
||||
protected ServerSideFixture _serverFixture;
|
||||
|
||||
public BaseTestContext(ITestOutputHelper output, ServerSideFixture serverFixture)
|
||||
{
|
||||
this._output = output;
|
||||
this._serverFixture = serverFixture;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
CONFIGURATION=Debug
|
||||
BINTARGET=bin/$(CONFIGURATION)/dnx451/test.dll
|
||||
|
||||
all: test
|
||||
|
||||
project.lock.json: project.json
|
||||
dnu restore
|
||||
|
||||
../Yavsc/bin/$(CONFIGURATION)/dnx451/Yavsc.dll:
|
||||
make -C ../Yavsc
|
||||
|
||||
../Yavsc.Abstract/bin/$(CONFIGURATION)/dnx451/Yavsc.Abstract.dll:
|
||||
make -C ../Yavsc.Abstract
|
||||
|
||||
../Yavsc.Server/bin/$(CONFIGURATION)/dnx451/Yavsc.Server.dll:
|
||||
make -C ../Yavsc.Server
|
||||
|
||||
$(BINTARGET): project.lock.json ../Yavsc/bin/$(CONFIGURATION)/dnx451/Yavsc.dll ../Yavsc.Abstract/bin/$(CONFIGURATION)/dnx451/Yavsc.Abstract.dll ../Yavsc.Server/bin/$(CONFIGURATION)/dnx451/Yavsc.Server.dll
|
||||
dnu build --configuration $(CONFIGURATION)
|
||||
|
||||
breaking:
|
||||
dnx test -trait regres=yes
|
||||
|
||||
testdev: $(BINTARGET)
|
||||
ASPNET_ENV=Development dnx test -maxthreads 1 -trait dev=wip
|
||||
|
||||
|
||||
test: $(BINTARGET)
|
||||
ASPNET_ENV=Development dnx test -maxthreads 1 -trait regres=no
|
||||
|
||||
clean:
|
||||
rm -rf bin obj testingrepo
|
||||
|
||||
.PHONY: test
|
||||
|
@ -1,35 +0,0 @@
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace test.Mandatory
|
||||
{
|
||||
[Collection("EMaillingTeststCollection")]
|
||||
[Trait("regres", "no")]
|
||||
[Trait("dev", "wip")]
|
||||
public class Database: IClassFixture<ServerSideFixture>
|
||||
{
|
||||
ServerSideFixture _serverFixture;
|
||||
ITestOutputHelper output;
|
||||
public Database(ServerSideFixture serverFixture, ITestOutputHelper output)
|
||||
{
|
||||
this.output = output;
|
||||
_serverFixture = serverFixture;
|
||||
|
||||
output.WriteLine($"Startup.TestDbSettings.Database was {Startup.TestDbSettings.Database}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Assuming we're using an account that may create databases,
|
||||
/// Install all our migrations in a fresh new database.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void InstallFromScratchUsingPoweredNpgsqlUser()
|
||||
{
|
||||
if (_serverFixture.DbCreated)
|
||||
_serverFixture.DropTestDb();
|
||||
|
||||
_serverFixture.CreateTestDb();
|
||||
_serverFixture.UpgradeDb();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using Yavsc.Abstract.Manage;
|
||||
|
||||
namespace test
|
||||
{
|
||||
|
||||
[Collection("EMaillingTeststCollection")]
|
||||
[Trait("regres", "no")]
|
||||
public class EMaillingTests : IClassFixture<ServerSideFixture>
|
||||
|
||||
{
|
||||
ServerSideFixture _serverFixture;
|
||||
ITestOutputHelper output;
|
||||
ILogger _logger;
|
||||
public EMaillingTests(ServerSideFixture serverFixture, ITestOutputHelper output)
|
||||
{
|
||||
this.output = output;
|
||||
_serverFixture = serverFixture;
|
||||
_logger = serverFixture.Logger;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SendEMailSynchrone()
|
||||
{
|
||||
|
||||
AssertAsync.CompletesIn(2, () =>
|
||||
{
|
||||
output.WriteLine("SendEMailSynchrone ...");
|
||||
EmailSentViewModel mailSentInfo = _serverFixture.MailSender.SendEmailAsync
|
||||
(_serverFixture.SiteSetup.Owner.Name, _serverFixture.SiteSetup.Owner.EMail, $"monthly email", "test boby monthly email").Result;
|
||||
if (mailSentInfo==null)
|
||||
_logger.LogError("No info on sending");
|
||||
else if (!mailSentInfo.Sent)
|
||||
_logger.LogError($"{mailSentInfo.ErrorMessage}");
|
||||
else
|
||||
_logger.LogInformation($"mailId:{mailSentInfo.MessageId} \nto:{_serverFixture.SiteSetup.Owner.Name}");
|
||||
Assert.NotNull(mailSentInfo);
|
||||
output.WriteLine($">>done with {mailSentInfo.EMail} {mailSentInfo.Sent} {mailSentInfo.MessageId} {mailSentInfo.ErrorMessage}");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace test
|
||||
{
|
||||
|
||||
[Trait("regres", "no")]
|
||||
public class NodeTests
|
||||
{
|
||||
[Fact]
|
||||
void TestNodeJsForAnsitohtml ()
|
||||
{
|
||||
var procStart = new ProcessStartInfo("node", "node_modules/ansi-to-html/bin/ansi-to-html");
|
||||
procStart.UseShellExecute = false;
|
||||
procStart.RedirectStandardInput = true;
|
||||
procStart.RedirectStandardOutput = true;
|
||||
procStart.RedirectStandardError = true;
|
||||
var proc = Process.Start(procStart);
|
||||
proc.StandardInput.WriteLine("\x001b[30mblack\x1b[37mwhite");
|
||||
proc.StandardInput.Close();
|
||||
while (!proc.StandardOutput.EndOfStream)
|
||||
{
|
||||
Console.Write(proc.StandardOutput.ReadToEnd());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
void AnsiToHtml()
|
||||
{
|
||||
var procStart = new ProcessStartInfo("ls", "-l --color=always");
|
||||
procStart.UseShellExecute = false;
|
||||
procStart.RedirectStandardInput = false;
|
||||
procStart.RedirectStandardOutput = true;
|
||||
var proc = Process.Start(procStart);
|
||||
var encoded = GetStream(proc.StandardOutput);
|
||||
var reader = new StreamReader(encoded);
|
||||
var txt = reader.ReadToEnd();
|
||||
|
||||
Console.WriteLine(txt);
|
||||
}
|
||||
|
||||
public static Stream GetStream(StreamReader reader)
|
||||
{
|
||||
var procStart = new ProcessStartInfo("node", "node_modules/ansi-to-html/bin/ansi-to-html");
|
||||
procStart.UseShellExecute = false;
|
||||
procStart.RedirectStandardInput = true;
|
||||
procStart.RedirectStandardOutput = true;
|
||||
procStart.RedirectStandardError = true;
|
||||
var mem = new MemoryStream();
|
||||
StreamWriter writer = new StreamWriter(mem);
|
||||
var proc = Process.Start(procStart);
|
||||
var text = reader.ReadToEnd();
|
||||
proc.StandardInput.WriteLine(text);
|
||||
proc.StandardInput.Close();
|
||||
return proc.StandardOutput.BaseStream;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,167 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.AspNet.Hosting.Internal;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.OptionsModel;
|
||||
using Yavsc.Lib;
|
||||
using Yavsc.Services;
|
||||
using Yavsc;
|
||||
using Xunit;
|
||||
using Npgsql;
|
||||
|
||||
namespace test
|
||||
{
|
||||
[Trait("regres", "no")]
|
||||
public class ServerSideFixture : IDisposable {
|
||||
SiteSettings _siteSetup;
|
||||
ILogger _logger;
|
||||
IApplication _app;
|
||||
EMailer _mailer;
|
||||
ILoggerFactory _loggerFactory;
|
||||
IEmailSender _mailSender;
|
||||
public static string ApiKey => "53f4d5da-93a9-4584-82f9-b8fdf243b002" ;
|
||||
|
||||
public SiteSettings SiteSetup
|
||||
{
|
||||
get
|
||||
{
|
||||
return _siteSetup;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_siteSetup = value;
|
||||
}
|
||||
}
|
||||
|
||||
public IEmailSender MailSender
|
||||
{
|
||||
get
|
||||
{
|
||||
return _mailSender;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_mailSender = value;
|
||||
}
|
||||
}
|
||||
|
||||
public IApplication App
|
||||
{
|
||||
get
|
||||
{
|
||||
return _app;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_app = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal void UpgradeDb()
|
||||
{
|
||||
Microsoft.Data.Entity.Commands.Program.Main(
|
||||
new string [] { "database", "update" });
|
||||
}
|
||||
|
||||
public ILogger Logger
|
||||
{
|
||||
get
|
||||
{
|
||||
return _logger;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_logger = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool DbCreated { get; private set; }
|
||||
|
||||
//
|
||||
public ServerSideFixture()
|
||||
{
|
||||
InitTestHost();
|
||||
Logger.LogInformation("ServerSideFixture created.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
void InitTestHost()
|
||||
{
|
||||
|
||||
var host = new WebHostBuilder();
|
||||
|
||||
var hostengnine = host
|
||||
.UseEnvironment("Development")
|
||||
.UseServer("test")
|
||||
.UseStartup<test.Startup>()
|
||||
.Build();
|
||||
|
||||
App = hostengnine.Start();
|
||||
_mailer = App.Services.GetService(typeof(EMailer)) as EMailer;
|
||||
_loggerFactory = App.Services.GetService(typeof(ILoggerFactory)) as ILoggerFactory;
|
||||
|
||||
Logger = _loggerFactory.CreateLogger<ServerSideFixture> ();
|
||||
var siteSetup = App.Services.GetService(typeof(IOptions<SiteSettings>)) as IOptions<SiteSettings>;
|
||||
SiteSetup = siteSetup.Value;
|
||||
MailSender = App.Services.GetService(typeof(IEmailSender)) as IEmailSender;
|
||||
CheckDbExistence();
|
||||
if (!DbCreated)
|
||||
CreateTestDb();
|
||||
}
|
||||
|
||||
public void CreateTestDb()
|
||||
{
|
||||
if (!DbCreated)
|
||||
using (
|
||||
NpgsqlConnection cx = new NpgsqlConnection(Startup.DevDbSettings.ConnectionString))
|
||||
{
|
||||
cx.Open();
|
||||
var command = cx.CreateCommand();
|
||||
command.CommandText = $"create database \"{Startup.TestDbSettings.Database}\";";
|
||||
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))
|
||||
{
|
||||
cx.Open();
|
||||
var command = cx.CreateCommand();
|
||||
command.CommandText = $"drop database \"{Startup.TestDbSettings.Database}\";";
|
||||
command.ExecuteNonQuery();
|
||||
_logger.LogInformation($"database dropped");
|
||||
cx.Close();
|
||||
}
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
Logger.LogInformation("Disposing");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,220 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Builder.Internal;
|
||||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
using Xunit;
|
||||
using Yavsc;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Services;
|
||||
using System.Runtime.Versioning;
|
||||
using Microsoft.AspNet.Mvc.Razor;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Dnx.Compilation.CSharp;
|
||||
using Microsoft.Extensions.OptionsModel;
|
||||
using Yavsc.Helpers;
|
||||
using Microsoft.Data.Entity;
|
||||
using Xunit.Abstractions;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Yavsc.Server.Models.IT.SourceCode;
|
||||
|
||||
namespace test
|
||||
{
|
||||
|
||||
|
||||
[Collection("Yavsc mandatory success story")]
|
||||
[Trait("regres", "no")]
|
||||
public class YavscMandatory: BaseTestContext, IClassFixture<ServerSideFixture>
|
||||
{
|
||||
|
||||
public YavscMandatory(ITestOutputHelper output, ServerSideFixture fixture) : base (output, fixture)
|
||||
{
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void GitClone()
|
||||
{
|
||||
|
||||
var dbc = _serverFixture.App.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
|
||||
|
||||
var firstProject = dbc.Projects.Include(p=>p.Repository).FirstOrDefault();
|
||||
Assert.NotNull (firstProject);
|
||||
|
||||
var clone = new GitClone(_serverFixture.SiteSetup.GitRepository);
|
||||
clone.Launch(firstProject);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
void AnsiToHtml()
|
||||
{
|
||||
var procStart = new ProcessStartInfo("ls", "-l --color=always");
|
||||
procStart.UseShellExecute = false;
|
||||
procStart.RedirectStandardInput = false;
|
||||
procStart.RedirectStandardOutput = true;
|
||||
var proc = Process.Start(procStart);
|
||||
var encoded = AnsiToHtmlEncoder.GetStream(proc.StandardOutput);
|
||||
using (var reader = new StreamReader(encoded))
|
||||
{
|
||||
var txt = reader.ReadToEnd();
|
||||
_output.WriteLine(txt);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplicationDbContextExists()
|
||||
{
|
||||
var dbc = new ApplicationDbContext();
|
||||
Assert.NotNull(dbc.GCMDevices);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MvcRazorHostAndParser()
|
||||
{
|
||||
string cache = System.IO.Directory.GetCurrentDirectory();
|
||||
MvcRazorHost host = new MvcRazorHost(cache);
|
||||
var parser = host.CreateMarkupParser();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
void HaveDependecyInjection()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
void HaveHost()
|
||||
{
|
||||
beforeCompileContext = CreateYavscCompilationContext();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AConfigurationRoot()
|
||||
{
|
||||
var builder = new ConfigurationBuilder();
|
||||
builder.AddJsonFile( "appsettings.json", false);
|
||||
builder.AddJsonFile( "appsettings.Development.json", true);
|
||||
configurationRoot = builder.Build();
|
||||
}
|
||||
|
||||
internal static BeforeCompileContext CreateYavscCompilationContext()
|
||||
{
|
||||
var projectContext = new ProjectContext();
|
||||
projectContext.Name = "Yavsc";
|
||||
projectContext.ProjectDirectory = "/home/paul/workspace/yavsc/Yavsc";
|
||||
projectContext.ProjectFilePath = "/home/paul/workspace/yavsc/Yavsc/project.json";
|
||||
projectContext.TargetFramework = new FrameworkName("DNX", new Version(4, 5, 1));
|
||||
projectContext.Configuration = "Development";
|
||||
|
||||
return new BeforeCompileContext(
|
||||
null, projectContext, () => null, () => null, () => null);
|
||||
}
|
||||
|
||||
internal static IConfigurationRoot CreateConfiguration(string prjDir)
|
||||
{
|
||||
var builder = new ConfigurationBuilder();
|
||||
|
||||
builder.AddJsonFile(Path.Combine(prjDir, "appsettings.json"), true);
|
||||
builder.AddJsonFile(Path.Combine(prjDir, "appsettings.Development.json"), true);
|
||||
return builder.Build();
|
||||
}
|
||||
|
||||
internal static void ConfigureServices
|
||||
(ServiceCollection serviceCollection,
|
||||
string prjDir,
|
||||
out IConfigurationRoot configuration,
|
||||
out IServiceProvider provider)
|
||||
{
|
||||
configuration = CreateConfiguration(prjDir);
|
||||
|
||||
serviceCollection.AddOptions();
|
||||
var siteSettingsconf = configuration.GetSection("Site");
|
||||
serviceCollection.Configure<SiteSettings>(siteSettingsconf);
|
||||
var smtpSettingsconf = configuration.GetSection("Smtp");
|
||||
serviceCollection.Configure<SmtpSettings>(smtpSettingsconf);
|
||||
var locOptions = configuration.GetSection("Localization");
|
||||
serviceCollection.Configure<LocalizationOptions>(locOptions);
|
||||
|
||||
serviceCollection.AddSingleton(typeof(ILoggerFactory), typeof(LoggerFactory));
|
||||
serviceCollection.AddTransient(typeof(IEmailSender), typeof(MailSender));
|
||||
serviceCollection.AddTransient(typeof(RazorEngineHost));
|
||||
serviceCollection.AddTransient((s) => new RazorTemplateEngine(s.GetService<RazorEngineHost>()));
|
||||
serviceCollection.AddLogging();
|
||||
serviceCollection.AddMvcCore();
|
||||
serviceCollection.AddLocalization(options =>
|
||||
{
|
||||
options.ResourcesPath = "Resources";
|
||||
});
|
||||
var connectionString = configuration["Data:DefaultConnection:ConnectionString"];
|
||||
AppDomain.CurrentDomain.SetData("YAVSC_DB_CONNECTION", connectionString);
|
||||
serviceCollection.AddEntityFramework()
|
||||
.AddNpgsql()
|
||||
.AddDbContext<ApplicationDbContext>(
|
||||
db => db.UseNpgsql(connectionString)
|
||||
);
|
||||
provider = serviceCollection.BuildServiceProvider();
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void ARequestAppDelegate()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
|
||||
services.AddTransient<IRuntimeEnvironment>(
|
||||
svs => PlatformServices.Default.Runtime
|
||||
);
|
||||
|
||||
HaveHost();
|
||||
var prjDir = this.beforeCompileContext.ProjectContext.ProjectDirectory;
|
||||
ConfigureServices(services, prjDir, out configurationRoot, out serviceProvider);
|
||||
|
||||
IApplicationBuilder app = new ApplicationBuilder(serviceProvider);
|
||||
var rtd = app.Build();
|
||||
|
||||
}
|
||||
|
||||
|
||||
[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>(
|
||||
svs => PlatformServices.Default.Runtime
|
||||
);
|
||||
beforeCompileContext = YavscMandatory.CreateYavscCompilationContext();
|
||||
var prjDir = beforeCompileContext.ProjectContext.ProjectDirectory;
|
||||
YavscMandatory.ConfigureServices(services, prjDir, out configuration, out provider);
|
||||
|
||||
IApplicationBuilder app = new ApplicationBuilder(provider);
|
||||
app.UseMvc();
|
||||
var rtd = app.Build();
|
||||
IOptions<LocalizationOptions> localOptions = ActivatorUtilities.GetServiceOrCreateInstance<IOptions<LocalizationOptions>>(provider); ;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
namespace test.Settings
|
||||
{
|
||||
public abstract 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 class DevConnectionSettings : DbConnectionSettings
|
||||
{
|
||||
|
||||
}
|
||||
public class TestConnectionSettings : DbConnectionSettings
|
||||
{
|
||||
|
||||
}
|
||||
}
|
103
test/Startup.cs
103
test/Startup.cs
@ -1,103 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.OptionsModel;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
using Yavsc;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Services;
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.Extensions.WebEncoders;
|
||||
using Yavsc.Lib;
|
||||
using test.Settings;
|
||||
|
||||
namespace test
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
|
||||
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; }
|
||||
|
||||
ILogger logger;
|
||||
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
|
||||
{
|
||||
var devtag = env.IsDevelopment()?"D":"";
|
||||
var prodtag = env.IsProduction()?"P":"";
|
||||
var stagetag = env.IsStaging()?"S":"";
|
||||
|
||||
HostingFullName = $"{appEnv.RuntimeFramework.FullName} [{env.EnvironmentName}:{prodtag}{devtag}{stagetag}]";
|
||||
// Set up configuration sources.
|
||||
|
||||
var builder = new ConfigurationBuilder()
|
||||
.AddEnvironmentVariables()
|
||||
.AddJsonFile("appsettings.json")
|
||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
|
||||
Configuration = builder.Build();
|
||||
}
|
||||
|
||||
public void ConfigureServices (IServiceCollection services)
|
||||
{
|
||||
services.AddOptions();
|
||||
var siteSettingsconf = Configuration.GetSection("Site");
|
||||
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);
|
||||
|
||||
|
||||
services.AddInstance(typeof(ILoggerFactory), new LoggerFactory());
|
||||
services.AddTransient(typeof(IEmailSender), typeof(MailSender));
|
||||
services.AddEntityFramework().AddNpgsql().AddDbContext<ApplicationDbContext>();
|
||||
services.AddTransient((s) => new RazorTemplateEngine(s.GetService<RazorEngineHost>()));
|
||||
services.AddLogging();
|
||||
services.AddTransient<EMailer>();
|
||||
services.AddLocalization(options =>
|
||||
{
|
||||
options.ResourcesPath = "Resources";
|
||||
});
|
||||
|
||||
services.AddEntityFramework()
|
||||
.AddNpgsql()
|
||||
.AddDbContext<ApplicationDbContext>(
|
||||
db => db.UseNpgsql(Startup.TestDbSettings.ConnectionString)
|
||||
);
|
||||
|
||||
services.AddTransient<Microsoft.Extensions.WebEncoders.UrlEncoder, UrlEncoder>();
|
||||
|
||||
}
|
||||
|
||||
public void Configure (IApplicationBuilder app, IHostingEnvironment env,
|
||||
IOptions<SiteSettings> siteSettings,
|
||||
IOptions<TestConnectionSettings> testCxOptions,
|
||||
IOptions<DevConnectionSettings> devCxOptions,
|
||||
ILoggerFactory loggerFactory)
|
||||
{
|
||||
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
||||
loggerFactory.AddDebug();
|
||||
logger = loggerFactory.CreateLogger<Startup>();
|
||||
logger.LogInformation(env.EnvironmentName);
|
||||
|
||||
TestDbSettings = testCxOptions.Value;
|
||||
DevDbSettings = devCxOptions.Value;
|
||||
logger.LogInformation($"test db : {TestDbSettings.ConnectionString}");
|
||||
AppDomain.CurrentDomain.SetData("YAVSC_CONNECTION", TestDbSettings.ConnectionString);
|
||||
|
||||
var authConf = Configuration.GetSection("Authentication").GetSection("Yavsc");
|
||||
var clientId = authConf.GetSection("ClientId").Value;
|
||||
var clientSecret = authConf.GetSection("ClientSecret").Value;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace test {
|
||||
|
||||
public static class AssertAsync {
|
||||
|
||||
public static void CompletesIn(int timeout, Action action)
|
||||
{
|
||||
var task = Task.Run(action);
|
||||
var completedInTime = Task.WaitAll(new[] { task }, TimeSpan.FromSeconds(timeout));
|
||||
|
||||
if (task.Exception != null)
|
||||
{
|
||||
if (task.Exception.InnerExceptions.Count == 1)
|
||||
{
|
||||
throw task.Exception.InnerExceptions[0];
|
||||
}
|
||||
|
||||
throw task.Exception;
|
||||
}
|
||||
|
||||
if (!completedInTime)
|
||||
{
|
||||
throw new TimeoutException($"Task did not complete in {timeout} seconds.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,47 +0,0 @@
|
||||
// // NotWorking.cs
|
||||
// /*
|
||||
// paul 21/06/2018 10:16 20182018 6 21
|
||||
// */
|
||||
using System;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.OptionsModel;
|
||||
using Xunit;
|
||||
using Yavsc;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.Dnx.TestHost.TestAdapter;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace test
|
||||
{
|
||||
[Collection("Yavsc dropped intents")]
|
||||
[Trait("regres", "yes")]
|
||||
public class NotWorking : BaseTestContext
|
||||
{
|
||||
SourceInformationProvider _sourceInfoProvider;
|
||||
IOptions<LocalizationOptions> _localizationOptions;
|
||||
public NotWorking( IHostingEnvironment env , IOptions<SiteSettings> siteSettings,
|
||||
SourceInformationProvider sourceInfoProvider,
|
||||
IOptions<LocalizationOptions> localizationOptions,
|
||||
ServerSideFixture serverFixture, ITestOutputHelper output
|
||||
) : base (output, serverFixture) {
|
||||
_sourceInfoProvider = sourceInfoProvider;
|
||||
_localizationOptions = localizationOptions;
|
||||
}
|
||||
|
||||
public void StringLocalizer()
|
||||
{
|
||||
// TODO build applicationEnvironment
|
||||
ResourceManagerStringLocalizerFactory strFact = new ResourceManagerStringLocalizerFactory
|
||||
(applicationEnvironment, _localizationOptions);
|
||||
IStringLocalizer stringLocalizer = strFact.Create(typeof(NotWorking));
|
||||
}
|
||||
|
||||
public void NoDnxEnv()
|
||||
{
|
||||
|
||||
IOptions<LocalizationOptions> localOptions = Activator.CreateInstance<IOptions<LocalizationOptions>>();
|
||||
ResourceManagerStringLocalizerFactory strFact = new ResourceManagerStringLocalizerFactory(applicationEnvironment, localOptions);
|
||||
IStringLocalizer stringLocalizer = strFact.Create(typeof(NotWorking));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,121 +0,0 @@
|
||||
// // YavscWorkInProgress.cs
|
||||
// /*
|
||||
// paul 21/06/2018 10:11 20182018 6 21
|
||||
// */
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using Yavsc.Authentication;
|
||||
using static OAuth.AspNet.AuthServer.Constants;
|
||||
|
||||
namespace test
|
||||
{
|
||||
[Collection("Yavsc Work In Progress")]
|
||||
[Trait("regres", "yes")]
|
||||
public class YavscWorkInProgress : BaseTestContext, IClassFixture<ServerSideFixture>
|
||||
{
|
||||
public YavscWorkInProgress(ServerSideFixture serverFixture, ITestOutputHelper output)
|
||||
: base(output, serverFixture)
|
||||
{
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetLoginIntentData), parameters: 1)]
|
||||
public async Task TestUserMayLogin
|
||||
(
|
||||
string clientId,
|
||||
string clientSecret,
|
||||
string scope,
|
||||
string authorizeUrl,
|
||||
string redirectUrl,
|
||||
string accessTokenUrl,
|
||||
string login,
|
||||
string pass
|
||||
)
|
||||
{
|
||||
try
|
||||
{
|
||||
var oauthor = new OAuthenticator(clientId, clientSecret, scope,
|
||||
new Uri(authorizeUrl), new Uri(redirectUrl), new Uri(accessTokenUrl));
|
||||
var query = new Dictionary<string, string>();
|
||||
query[Parameters.Username] = login;
|
||||
query[Parameters.Password] = pass;
|
||||
query[Parameters.GrantType] = GrantTypes.Password;
|
||||
var result = await oauthor.RequestAccessTokenAsync(query);
|
||||
Console.WriteLine(">> Got an output");
|
||||
Console.WriteLine(Parameters.AccessToken + ": " + result[Parameters.AccessToken]);
|
||||
Console.WriteLine(Parameters.TokenType + ": " + result[Parameters.TokenType]);
|
||||
Console.WriteLine(Parameters.ExpiresIn + ": " + result[Parameters.ExpiresIn]);
|
||||
Console.WriteLine(Parameters.RefreshToken + ": " + result[Parameters.RefreshToken]);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var webex = ex as WebException;
|
||||
if (webex != null && webex.Status == (WebExceptionStatus)400)
|
||||
{
|
||||
if (login == "joe")
|
||||
{
|
||||
Console.WriteLine("Bad pass joe!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public static string GetPassword()
|
||||
{
|
||||
var pwd = new StringBuilder();
|
||||
while (true)
|
||||
{
|
||||
var len = pwd.ToString().Length;
|
||||
ConsoleKeyInfo i = Console.ReadKey(true);
|
||||
if (i.Key == ConsoleKey.Enter)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (i.Key == ConsoleKey.Backspace)
|
||||
{
|
||||
if (pwd.Length > 0)
|
||||
{
|
||||
pwd.Remove(len - 1, 1);
|
||||
Console.Write("\b \b");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pwd.Append(i.KeyChar);
|
||||
Console.Write("*");
|
||||
}
|
||||
}
|
||||
return pwd.ToString();
|
||||
}
|
||||
public static IEnumerable<object[]> GetLoginIntentData(int numTests)
|
||||
{
|
||||
|
||||
var allData = new List<object[]>();
|
||||
Console.WriteLine($"Please, enter {numTests}:");
|
||||
|
||||
for (int iTest=0; iTest<numTests; iTest++)
|
||||
{
|
||||
Console.Write("Please, enter a login:");
|
||||
var login = Console.ReadLine();
|
||||
Console.Write("Please, enter a pass:");
|
||||
var pass = GetPassword();
|
||||
|
||||
allData.Add(new object[] { ServerSideFixture.ApiKey, "blouh", "profile",
|
||||
"http://localhost:5000/authorize", "http://localhost:5000/oauth/success",
|
||||
"http://localhost:5000/token",login, pass });
|
||||
}
|
||||
return allData.Take(numTests);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Hosting.Server;
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Yavsc.Server
|
||||
{
|
||||
public class cliServerFactory : IServerFactory
|
||||
{
|
||||
public IFeatureCollection Initialize(IConfiguration configuration)
|
||||
{
|
||||
FeatureCollection featureCollection = new FeatureCollection();
|
||||
return featureCollection;
|
||||
}
|
||||
|
||||
public IDisposable Start(IFeatureCollection serverFeatures, Func<IFeatureCollection, Task> application)
|
||||
{
|
||||
var task = application(serverFeatures);
|
||||
return task;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
{
|
||||
"Site": {
|
||||
"Authority": "dev.pschneider.fr",
|
||||
"Title": "Yavsc dev",
|
||||
"Slogan": "Yavsc : WIP.",
|
||||
"Banner": "/images/yavsc.png",
|
||||
"HomeViewName": "Home",
|
||||
"FavIcon": "/favicon.ico",
|
||||
"Icon": "/images/yavsc.png",
|
||||
"GitRepository": "testingrepo",
|
||||
"Owner": {
|
||||
"Name": "Site Owner Name",
|
||||
"EMail": "your@email",
|
||||
"PostalAddress": {
|
||||
"Street1": "Your Address",
|
||||
"Street2": "your street",
|
||||
"PostalCode": "543 21~3",
|
||||
"City": "",
|
||||
"State": "",
|
||||
"Province": null
|
||||
}
|
||||
},
|
||||
"Admin": {
|
||||
"Name": "Administrator name",
|
||||
"EMail": "daAdmin@e.mail"
|
||||
}
|
||||
},
|
||||
"Smtp": {
|
||||
"Host": "localhost",
|
||||
"Port": 25,
|
||||
"EnableSSL": false
|
||||
},
|
||||
"Logging": {
|
||||
"IncludeScopes": true,
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"System": "Warning",
|
||||
"Microsoft": "Warning"
|
||||
}
|
||||
},
|
||||
"Data": {
|
||||
"DevConnection": {
|
||||
"Database":"postgres",
|
||||
"Server": "[NpgsqlHostName]",
|
||||
"Port": 5432,
|
||||
"Username": "[devUserName]",
|
||||
"Password": "[DevPassword]"
|
||||
},
|
||||
"TestConnection": {
|
||||
"Database":"[TestDbName]",
|
||||
"Server": "[TestNpgsqlHostName]",
|
||||
"Port": 5432,
|
||||
"Username": "[TestUserName]",
|
||||
"Password": "[TestPassword]"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
0 info it worked if it ends with ok
|
||||
1 verbose cli [ 'C:\\Programs\\nodejs\\node.exe',
|
||||
1 verbose cli 'C:\\Programs\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
|
||||
1 verbose cli 'install' ]
|
||||
2 info using npm@1.4.9
|
||||
3 info using node@v8.11.3
|
||||
4 error install Couldn't read dependencies
|
||||
5 error package.json ENOENT: no such file or directory, open 'C:\Users\paul\Documents\GitHub\yavsc\test\package.json'
|
||||
5 error package.json This is most likely not a problem with npm itself.
|
||||
5 error package.json npm can't find a package.json file in your current directory.
|
||||
6 error System Windows_NT 6.1.7601
|
||||
7 error command "C:\\Programs\\nodejs\\node.exe" "C:\\Programs\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
|
||||
8 error cwd C:\Users\paul\Documents\GitHub\yavsc\test
|
||||
9 error node -v v8.11.3
|
||||
10 error npm -v 1.4.9
|
||||
11 error path C:\Users\paul\Documents\GitHub\yavsc\test\package.json
|
||||
12 error syscall open
|
||||
13 error code ENOPACKAGEJSON
|
||||
14 error errno -4058
|
||||
15 verbose exit [ -4058, true ]
|
@ -1,64 +0,0 @@
|
||||
{
|
||||
"version": "1.0.5-*",
|
||||
"title": "Yavsc - les tests",
|
||||
"description": "Yavsc xUnit testing",
|
||||
"authors": [
|
||||
"Paul Schneider <paul@pschneider.fr>"
|
||||
],
|
||||
"packOptions": {
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/pazof/yavsc"
|
||||
},
|
||||
"licenseUrl": "https://github.com/pazof/yavsc/blob/vnext/LICENSE",
|
||||
"requireLicenseAcceptance": true,
|
||||
"owners": [
|
||||
"Paul Schneider <paul@pschneider.fr>"
|
||||
],
|
||||
"summary": "Yet another very small company",
|
||||
"projectUrl": "http://yavsc.pschneider.fr",
|
||||
"tags": [
|
||||
"Blog",
|
||||
"Blog",
|
||||
"PoS",
|
||||
"Chat"
|
||||
]
|
||||
},
|
||||
"exclude": [
|
||||
"bin",
|
||||
"wwwroot",
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"contrib",
|
||||
"testingrepo"
|
||||
],
|
||||
"tooling": {
|
||||
"defaultNamespace": "test"
|
||||
},
|
||||
"dependencies": {
|
||||
"EntityFramework.Commands": "7.0.0-rc1-final",
|
||||
"EntityFramework7.Npgsql": "3.1.0-rc1-3",
|
||||
"EntityFramework7.Npgsql.Design": "3.1.0-rc1-5",
|
||||
"Newtonsoft.Json": "9.0.1",
|
||||
"xunit": "2.1.0",
|
||||
"xunit.analyzers": "0.9.0",
|
||||
"xunit.assert": "2.1.0",
|
||||
"xunit.runner.console": "2.4.0-rc.2.build4045",
|
||||
"Microsoft.Dnx.TestHost": "1.0.0-rc1-final",
|
||||
"Microsoft.Dnx.Runtime": "1.0.0-rc1-final",
|
||||
"xunit.runner.dnx": "2.1.0-rc1-build204",
|
||||
"Yavsc.Server": {
|
||||
"target": "project"
|
||||
},
|
||||
"Yavsc": {
|
||||
"target": "project"
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": {}
|
||||
},
|
||||
"commands": {
|
||||
"test": "xunit.runner.dnx"
|
||||
},
|
||||
"userSecretsId": "aspnet5-YavscWeb-a0dadd21-2ced-43d3-96f9-7e504345102f"
|
||||
}
|
Reference in New Issue
Block a user