refactoring
This commit is contained in:
parent
fb044dabcb
commit
e1b1347284
20 changed files with 153 additions and 132 deletions
42
test/Mandatory/EMailling.cs
Normal file
42
test/Mandatory/EMailling.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
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;
|
||||
public EMaillingTests(ServerSideFixture serverFixture, ITestOutputHelper output)
|
||||
{
|
||||
this.output = output;
|
||||
_serverFixture = serverFixture;
|
||||
}
|
||||
|
||||
[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)
|
||||
_serverFixture._logger.LogError("No info on sending");
|
||||
else if (!mailSentInfo.Sent)
|
||||
_serverFixture._logger.LogError($"{mailSentInfo.ErrorMessage}");
|
||||
else
|
||||
_serverFixture._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}");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
60
test/Mandatory/NodeTests.cs
Executable file
60
test/Mandatory/NodeTests.cs
Executable file
|
|
@ -0,0 +1,60 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
55
test/Mandatory/ServerSideFixture.cs
Normal file
55
test/Mandatory/ServerSideFixture.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
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;
|
||||
|
||||
namespace test
|
||||
{
|
||||
[Trait("regres", "no")]
|
||||
public class ServerSideFixture : IDisposable {
|
||||
public SiteSettings _siteSetup;
|
||||
public ILogger _logger;
|
||||
public IApplication _app;
|
||||
public EMailer _mailer;
|
||||
public ILoggerFactory _loggerFactory;
|
||||
public IEmailSender _mailSender;
|
||||
|
||||
public ServerSideFixture()
|
||||
{
|
||||
InitTestHost();
|
||||
_logger = _loggerFactory.CreateLogger<ServerSideFixture> ();
|
||||
_logger.LogInformation("ServerSideFixture");
|
||||
}
|
||||
|
||||
[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;
|
||||
var siteSetup = _app.Services.GetService(typeof(IOptions<SiteSettings>)) as IOptions<SiteSettings>;
|
||||
_siteSetup = siteSetup.Value;
|
||||
_mailSender = _app.Services.GetService(typeof(IEmailSender)) as IEmailSender;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_logger.LogInformation("Disposing");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
220
test/Mandatory/YavscMandatory.cs
Executable file
220
test/Mandatory/YavscMandatory.cs
Executable file
|
|
@ -0,0 +1,220 @@
|
|||
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 Yavsc.Lib;
|
||||
using System.Linq;
|
||||
|
||||
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); ;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue