build tests
This commit is contained in:
@ -16,6 +16,7 @@
|
|||||||
"Slogan": "Yavsc!",
|
"Slogan": "Yavsc!",
|
||||||
"StyleSheet": "/css/default.css",
|
"StyleSheet": "/css/default.css",
|
||||||
"Authority": "https://127.0.0.1:5001/",
|
"Authority": "https://127.0.0.1:5001/",
|
||||||
|
"Banner": "/images/arts/concert.jpg",
|
||||||
"Owner": {
|
"Owner": {
|
||||||
"Name": "[Site owner's name]",
|
"Name": "[Site owner's name]",
|
||||||
"EMail": "[Site owner's e-mail address]"
|
"EMail": "[Site owner's e-mail address]"
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
|
|
||||||
namespace yavscTests
|
|
||||||
{
|
|
||||||
public class BaseTestContext {
|
|
||||||
|
|
||||||
protected IServiceProvider serviceProvider = null;
|
|
||||||
protected IConfigurationRoot configurationRoot;
|
|
||||||
protected IServiceProvider provider;
|
|
||||||
protected IConfigurationRoot configuration;
|
|
||||||
protected ServerSideFixture _serverFixture;
|
|
||||||
|
|
||||||
public BaseTestContext( ServerSideFixture serverFixture)
|
|
||||||
{
|
|
||||||
this._serverFixture = serverFixture;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +1,40 @@
|
|||||||
using System;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Builder.Internal;
|
|
||||||
using Microsoft.AspNetCore.Razor;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Localization;
|
using Microsoft.Extensions.Localization;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Yavsc;
|
using Yavsc;
|
||||||
using Yavsc.Models;
|
using Yavsc.Models;
|
||||||
using Yavsc.Services;
|
using Yavsc.Services;
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
using Microsoft.AspNetCore.Mvc.Razor;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Microsoft.Dnx.Compilation.CSharp;
|
|
||||||
using Microsoft.Extensions.OptionsModel;
|
|
||||||
using Yavsc.Helpers;
|
using Yavsc.Helpers;
|
||||||
using Microsoft.Data.Entity;
|
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using Yavsc.Server.Models.IT.SourceCode;
|
using Yavsc.Server.Models.IT.SourceCode;
|
||||||
using yavscTests.Settings;
|
using yavscTests.Settings;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.DotNet.Scaffolding.Shared.ProjectModel;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Yavsc.Settings;
|
||||||
|
using Microsoft.AspNetCore.Razor.Language;
|
||||||
|
using isnd.tests;
|
||||||
|
|
||||||
namespace yavscTests
|
namespace yavscTests
|
||||||
{
|
{
|
||||||
[Collection("Yavsc mandatory success story")]
|
[Collection("Yavsc mandatory success story")]
|
||||||
[Trait("regression", "oui")]
|
[Trait("regression", "oui")]
|
||||||
public class BatchTests: BaseTestContext, IClassFixture<ServerSideFixture>, IDisposable
|
public class BaseTestContext: IClassFixture<WebServerFixture>, IDisposable
|
||||||
{
|
{
|
||||||
private TestingSetup _testingOptions;
|
public readonly WebServerFixture _serverFixture;
|
||||||
|
private readonly TestingSetup _testingOptions;
|
||||||
|
private readonly ITestOutputHelper _output;
|
||||||
|
|
||||||
public BatchTests(ITestOutputHelper output, ServerSideFixture fixture) : base (output, fixture)
|
public BaseTestContext(ITestOutputHelper output, WebServerFixture fixture)
|
||||||
{
|
{
|
||||||
_testingOptions = fixture.TestingSetup;
|
this._serverFixture = fixture;
|
||||||
|
_testingOptions = fixture.TestingSetup;
|
||||||
|
this._output = output;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -44,50 +44,21 @@ namespace yavscTests
|
|||||||
Assert.NotNull (_serverFixture.DbContext.Project);
|
Assert.NotNull (_serverFixture.DbContext.Project);
|
||||||
var firstProject = _serverFixture.DbContext.Project.Include(p=>p.Repository).FirstOrDefault();
|
var firstProject = _serverFixture.DbContext.Project.Include(p=>p.Repository).FirstOrDefault();
|
||||||
Assert.NotNull (firstProject);
|
Assert.NotNull (firstProject);
|
||||||
var di = new DirectoryInfo(_serverFixture.SiteSetup.GitRepository);
|
var di = new DirectoryInfo(_serverFixture.SiteSettings.GitRepository);
|
||||||
if (!di.Exists) di.Create();
|
if (!di.Exists) di.Create();
|
||||||
|
|
||||||
var clone = new GitClone(_serverFixture.SiteSetup.GitRepository);
|
var clone = new GitClone(_serverFixture.SiteSettings.GitRepository);
|
||||||
clone.Launch(firstProject);
|
clone.Launch(firstProject);
|
||||||
gitRepo = di.FullName;
|
gitRepo = di.FullName;
|
||||||
}
|
}
|
||||||
string gitRepo=null;
|
string gitRepo=null;
|
||||||
|
private IConfigurationRoot configurationRoot;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
void AnsiToHtml()
|
public void HaveConfigurationRoot()
|
||||||
{
|
|
||||||
var procStart = new ProcessStartInfo("ls", "-l --color=always")
|
|
||||||
{
|
|
||||||
UseShellExecute = false,
|
|
||||||
RedirectStandardInput = false,
|
|
||||||
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 MvcRazorHostAndParser()
|
|
||||||
{
|
|
||||||
string cache = System.IO.Directory.GetCurrentDirectory();
|
|
||||||
MvcRazorHost host = new MvcRazorHost(cache);
|
|
||||||
var parser = host.CreateMarkupParser();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
void HaveHost()
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void EnsureConfigurationRoot()
|
|
||||||
{
|
{
|
||||||
var builder = new ConfigurationBuilder();
|
var builder = new ConfigurationBuilder();
|
||||||
builder.AddJsonFile( "appsettings.json", false);
|
builder.AddJsonFile( "appsettings.json", false);
|
||||||
@ -95,33 +66,7 @@ namespace yavscTests
|
|||||||
configurationRoot = builder.Build();
|
configurationRoot = builder.Build();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal BeforeCompileContext CreateYavscCompilationContext()
|
|
||||||
{
|
|
||||||
BeforeCompileContext newBeforeCompileContext = null;
|
|
||||||
Assert.NotNull(_testingOptions);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var projectContext = new ProjectContext
|
|
||||||
{
|
|
||||||
Name = "Yavsc",
|
|
||||||
ProjectDirectory = _testingOptions.YavscWebPath,
|
|
||||||
ProjectFilePath = Path.Combine(_testingOptions.YavscWebPath, "project.json"),
|
|
||||||
TargetFramework = new FrameworkName("DNX", new Version(4, 5, 1)),
|
|
||||||
Configuration = Environment.GetEnvironmentVariable("ASPNET_ENV")
|
|
||||||
};
|
|
||||||
|
|
||||||
newBeforeCompileContext = new BeforeCompileContext(
|
|
||||||
null, projectContext, () => null, () => null, () => null);
|
|
||||||
|
|
||||||
}
|
|
||||||
catch(Exception ex)
|
|
||||||
{
|
|
||||||
_output.WriteLine(ex.Message);
|
|
||||||
_output.WriteLine(ex.StackTrace);
|
|
||||||
}
|
|
||||||
|
|
||||||
return newBeforeCompileContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static IConfigurationRoot CreateConfiguration(string prjDir)
|
internal static IConfigurationRoot CreateConfiguration(string prjDir)
|
||||||
{
|
{
|
||||||
@ -131,14 +76,14 @@ namespace yavscTests
|
|||||||
builder.AddJsonFile(Path.Combine(prjDir, "appsettings.Development.json"), true);
|
builder.AddJsonFile(Path.Combine(prjDir, "appsettings.Development.json"), true);
|
||||||
return builder.Build();
|
return builder.Build();
|
||||||
}
|
}
|
||||||
|
static IConfigurationRoot ConfigurationRoot;
|
||||||
internal static void ConfigureServices
|
internal static void ConfigureServices
|
||||||
(ServiceCollection serviceCollection,
|
(ServiceCollection serviceCollection,
|
||||||
string prjDir,
|
string prjDir,
|
||||||
out IConfigurationRoot configuration,
|
out IConfigurationRoot configuration,
|
||||||
out IServiceProvider provider)
|
out IServiceProvider provider)
|
||||||
{
|
{
|
||||||
configuration = CreateConfiguration(prjDir);
|
ConfigurationRoot = configuration = CreateConfiguration(prjDir);
|
||||||
|
|
||||||
serviceCollection.AddOptions();
|
serviceCollection.AddOptions();
|
||||||
var siteSettingsconf = configuration.GetSection("Site");
|
var siteSettingsconf = configuration.GetSection("Site");
|
||||||
@ -149,82 +94,20 @@ namespace yavscTests
|
|||||||
serviceCollection.Configure<LocalizationOptions>(locOptions);
|
serviceCollection.Configure<LocalizationOptions>(locOptions);
|
||||||
|
|
||||||
serviceCollection.AddSingleton(typeof(ILoggerFactory), typeof(LoggerFactory));
|
serviceCollection.AddSingleton(typeof(ILoggerFactory), typeof(LoggerFactory));
|
||||||
serviceCollection.AddTransient(typeof(IEmailSender), typeof(MailSender));
|
serviceCollection.AddTransient(typeof(IEmailSender<ApplicationUser>), typeof(MailSender));
|
||||||
serviceCollection.AddTransient(typeof(RazorEngineHost));
|
|
||||||
serviceCollection.AddTransient((s) => new RazorTemplateEngine(s.GetService<RazorEngineHost>()));
|
|
||||||
serviceCollection.AddLogging();
|
serviceCollection.AddLogging();
|
||||||
serviceCollection.AddMvcCore();
|
serviceCollection.AddMvcCore();
|
||||||
serviceCollection.AddLocalization(options =>
|
serviceCollection.AddLocalization(options =>
|
||||||
{
|
{
|
||||||
options.ResourcesPath = "Resources";
|
options.ResourcesPath = "Resources";
|
||||||
});
|
});
|
||||||
AppDomain.CurrentDomain.SetData("YAVSC_DB_CONNECTION", Startup.TestingSetup.ConnectionStrings.Default);
|
serviceCollection.AddDbContext<ApplicationDbContext>(options =>
|
||||||
serviceCollection.AddEntityFramework()
|
options.UseNpgsql(o => ConfigurationRoot.GetConnectionString("DefaultConnection")));
|
||||||
.AddNpgsql()
|
|
||||||
.AddDbContext<ApplicationDbContext>(
|
|
||||||
db => db.UseNpgsql(Startup.TestingSetup.ConnectionStrings.Default)
|
|
||||||
);
|
|
||||||
provider = serviceCollection.BuildServiceProvider();
|
provider = serviceCollection.BuildServiceProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
[Fact]
|
|
||||||
public void ARequestDelegate()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
var services = new ServiceCollection();
|
|
||||||
services.AddTransient<IRuntimeEnvironment>(
|
|
||||||
svs => PlatformServices.Default.Runtime
|
|
||||||
);
|
|
||||||
|
|
||||||
beforeCompileContext = CreateYavscCompilationContext();
|
|
||||||
var prjDir = this.beforeCompileContext.ProjectContext.ProjectDirectory;
|
|
||||||
ConfigureServices(services, prjDir, out configurationRoot, out serviceProvider);
|
|
||||||
|
|
||||||
IApplicationBuilder app = new ApplicationBuilder(serviceProvider);
|
|
||||||
var rtd = app.Build();
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_output.WriteLine(ex.Message);
|
|
||||||
_output.WriteLine(ex.StackTrace);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void InitApplicationBuilder()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
var services = new ServiceCollection();
|
|
||||||
|
|
||||||
services.AddTransient<IRuntimeEnvironment>(
|
|
||||||
svs => PlatformServices.Default.Runtime
|
|
||||||
);
|
|
||||||
beforeCompileContext = CreateYavscCompilationContext();
|
|
||||||
var prjDir = beforeCompileContext.ProjectContext.ProjectDirectory;
|
|
||||||
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); ;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_output.WriteLine(ex.Message);
|
|
||||||
_output.WriteLine(ex.StackTrace);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
if (gitRepo!=null)
|
if (gitRepo!=null)
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
// // YavscWorkInProgress.cs
|
|
||||||
// /*
|
|
||||||
// paul 21/06/2018 10:11 20182018 6 21
|
|
||||||
// */
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
|
||||||
using Xunit;
|
|
||||||
using Xunit.Abstractions;
|
|
||||||
using Yavsc.Authentication;
|
|
||||||
using static OAuth.AspNet.AuthServer.Constants;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
|
||||||
using Microsoft.AspNetCore.Mvc.Razor;
|
|
||||||
|
|
||||||
namespace yavscTests
|
|
||||||
{
|
|
||||||
[Collection("Yavsc Work In Progress")]
|
|
||||||
[Trait("regression", "oui")]
|
|
||||||
[Trait("module", "api")]
|
|
||||||
public class RegiserAPI : BaseTestContext, IClassFixture<ServerSideFixture>
|
|
||||||
{
|
|
||||||
public RegiserAPI(ServerSideFixture serverFixture, ITestOutputHelper output)
|
|
||||||
: base(output, serverFixture)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void EnsureWeb()
|
|
||||||
{
|
|
||||||
_serverFixture.EnsureWeb();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,33 +2,22 @@
|
|||||||
// /*
|
// /*
|
||||||
// paul 21/06/2018 10:11 20182018 6 21
|
// paul 21/06/2018 10:11 20182018 6 21
|
||||||
// */
|
// */
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text;
|
using isnd.tests;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.Extensions.OptionsModel;
|
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
using Yavsc.Authentication;
|
using Yavsc.Authentication;
|
||||||
using static OAuth.AspNet.AuthServer.Constants;
|
|
||||||
|
|
||||||
namespace yavscTests
|
namespace yavscTests
|
||||||
{
|
{
|
||||||
[Collection("Yavsc Work In Progress")]
|
[Collection("Yavsc Work In Progress")]
|
||||||
[Trait("regression", "oui")]
|
[Trait("regression", "oui")]
|
||||||
public class Remoting : BaseTestContext, IClassFixture<ServerSideFixture>
|
public class Remoting : BaseTestContext, IClassFixture<WebServerFixture>
|
||||||
{
|
{
|
||||||
readonly RegiserAPI r;
|
public Remoting(WebServerFixture serverFixture, ITestOutputHelper output)
|
||||||
public Remoting(ServerSideFixture serverFixture, ITestOutputHelper output)
|
|
||||||
: base(output, serverFixture)
|
: base(output, serverFixture)
|
||||||
{
|
{
|
||||||
|
|
||||||
r = new RegiserAPI(serverFixture, output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -45,23 +34,21 @@ namespace yavscTests
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
r.EnsureWeb();
|
|
||||||
|
|
||||||
var oauthor = new OAuthenticator(clientId, clientSecret, scope,
|
var oauthor = new OAuthenticator(clientId, clientSecret, scope,
|
||||||
new Uri(authorizeUrl), new Uri(redirectUrl), new Uri(accessTokenUrl));
|
new Uri(authorizeUrl), new Uri(redirectUrl), new Uri(accessTokenUrl));
|
||||||
var query = new Dictionary<string, string>
|
var query = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
[Parameters.Username] = Startup.TestingSetup.ValidCreds.UserName,
|
["Username"] = _serverFixture.TestingSetup.ValidCreds.UserName,
|
||||||
[Parameters.Password] = Startup.TestingSetup.ValidCreds.Password,
|
["Password"] = _serverFixture.TestingSetup.ValidCreds.Password,
|
||||||
[Parameters.GrantType] = GrantTypes.Password
|
["GrantType"] = "Password"
|
||||||
};
|
};
|
||||||
|
|
||||||
var result = await oauthor.RequestAccessTokenAsync(query);
|
var result = await oauthor.RequestAccessTokenAsync(query);
|
||||||
Console.WriteLine(">> Got an output");
|
Console.WriteLine(">> Got an output");
|
||||||
Console.WriteLine(Parameters.AccessToken + ": " + result[Parameters.AccessToken]);
|
Console.WriteLine( "AccessToken " + result["AccessToken"]);
|
||||||
Console.WriteLine(Parameters.TokenType + ": " + result[Parameters.TokenType]);
|
Console.WriteLine("TokenType " + result["TokenType"]);
|
||||||
Console.WriteLine(Parameters.ExpiresIn + ": " + result[Parameters.ExpiresIn]);
|
Console.WriteLine("ExpiresIn " + result["ExpiresIn"]);
|
||||||
Console.WriteLine(Parameters.RefreshToken + ": " + result[Parameters.RefreshToken]);
|
Console.WriteLine("RefreshToken : " + result["RefreshToken"]);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -69,7 +56,7 @@ namespace yavscTests
|
|||||||
var webex = ex as WebException;
|
var webex = ex as WebException;
|
||||||
if (webex != null && webex.Status == (WebExceptionStatus)400)
|
if (webex != null && webex.Status == (WebExceptionStatus)400)
|
||||||
{
|
{
|
||||||
if (Startup.TestingSetup.ValidCreds.UserName == "lame-user")
|
if (_serverFixture.TestingSetup.ValidCreds.UserName == "lame-user")
|
||||||
{
|
{
|
||||||
Console.WriteLine("Bad pass joe!");
|
Console.WriteLine("Bad pass joe!");
|
||||||
return;
|
return;
|
||||||
@ -79,5 +66,10 @@ namespace yavscTests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<object[]> GetLoginIntentData(int count)
|
||||||
|
{
|
||||||
|
return new object[][] {new object[]{ "", "", "", "", "", "" } };
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,268 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Data.Common;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Hosting.Internal;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.Extensions.OptionsModel;
|
|
||||||
using Yavsc.Lib;
|
|
||||||
using Yavsc.Services;
|
|
||||||
using Yavsc;
|
|
||||||
using Yavsc.Models;
|
|
||||||
using Xunit;
|
|
||||||
using Npgsql;
|
|
||||||
using Microsoft.Data.Entity;
|
|
||||||
using Microsoft.Data.Entity.Metadata.Conventions;
|
|
||||||
using yavscTests.Settings;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace yavscTests
|
|
||||||
{
|
|
||||||
[Trait("regression", "II")]
|
|
||||||
public class ServerSideFixture : IDisposable
|
|
||||||
{
|
|
||||||
SiteSettings _siteSetup;
|
|
||||||
ILogger _logger;
|
|
||||||
IApplication _app;
|
|
||||||
readonly EMailer _mailer;
|
|
||||||
readonly ILoggerFactory _loggerFactory;
|
|
||||||
IEmailSender _mailSender;
|
|
||||||
|
|
||||||
public string ApiKey { get; private set; }
|
|
||||||
|
|
||||||
public ApplicationDbContext DbContext { get; private set; }
|
|
||||||
public SiteSettings SiteSetup
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _siteSetup;
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_siteSetup = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// initialized by Init
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
public TestingSetup TestingSetup { get; private set; }
|
|
||||||
|
|
||||||
public IEmailSender MailSender
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _mailSender;
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_mailSender = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public IApplication App
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _app;
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_app = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
internal int UpgradeDb()
|
|
||||||
{
|
|
||||||
return Microsoft.Data.Entity.Commands.Program.Main(
|
|
||||||
new string[] { "database", "update" });
|
|
||||||
}
|
|
||||||
|
|
||||||
public ILogger Logger
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_logger = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bool dbCreated;
|
|
||||||
public WebHostBuilder Host { get; private set; }
|
|
||||||
private readonly IHostingEngine hostengnine;
|
|
||||||
|
|
||||||
|
|
||||||
void AssertNotNull(object obj, string msg)
|
|
||||||
{
|
|
||||||
if (obj == null)
|
|
||||||
throw new Exception(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
public ServerSideFixture()
|
|
||||||
{
|
|
||||||
Host = new WebHostBuilder();
|
|
||||||
AssertNotNull(Host, nameof(Host));
|
|
||||||
|
|
||||||
hostengnine = Host
|
|
||||||
.UseEnvironment("Testing")
|
|
||||||
.UseServer("yavscTests")
|
|
||||||
.UseStartup<Startup>()
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
AssertNotNull(hostengnine, nameof(hostengnine));
|
|
||||||
|
|
||||||
App = hostengnine.Start();
|
|
||||||
|
|
||||||
AssertNotNull(App, nameof(App));
|
|
||||||
|
|
||||||
// hostengnine.ApplicationServices
|
|
||||||
|
|
||||||
_mailer = App.Services.GetService(typeof(EMailer)) as EMailer;
|
|
||||||
AssertNotNull(_mailer, nameof(_mailer));
|
|
||||||
MailSender = App.Services.GetService(typeof(IEmailSender)) as IEmailSender;
|
|
||||||
AssertNotNull(MailSender, nameof(MailSender));
|
|
||||||
|
|
||||||
_loggerFactory = App.Services.GetService(typeof(ILoggerFactory)) as ILoggerFactory;
|
|
||||||
AssertNotNull(_loggerFactory, nameof(_loggerFactory));
|
|
||||||
|
|
||||||
var siteSetup = App.Services.GetService(typeof(IOptions<SiteSettings>)) as IOptions<SiteSettings>;
|
|
||||||
AssertNotNull(siteSetup, nameof(siteSetup));
|
|
||||||
|
|
||||||
var testingSetup = App.Services.GetService(typeof(IOptions<TestingSetup>)) as IOptions<TestingSetup>;
|
|
||||||
AssertNotNull(testingSetup, nameof(testingSetup));
|
|
||||||
|
|
||||||
DbContext = App.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
|
|
||||||
|
|
||||||
SiteSetup = siteSetup.Value;
|
|
||||||
AssertNotNull(SiteSetup, nameof(SiteSetup));
|
|
||||||
|
|
||||||
TestingSetup = testingSetup.Value;
|
|
||||||
AssertNotNull(TestingSetup, nameof(TestingSetup));
|
|
||||||
|
|
||||||
Logger = _loggerFactory.CreateLogger<ServerSideFixture>();
|
|
||||||
AssertNotNull(Logger, nameof(Logger));
|
|
||||||
|
|
||||||
var builder = new DbConnectionStringBuilder
|
|
||||||
{
|
|
||||||
ConnectionString = Startup.TestingSetup.ConnectionStrings.Default
|
|
||||||
};
|
|
||||||
ConventionSet conventions = new ConventionSet();
|
|
||||||
|
|
||||||
modelBuilder = new ModelBuilder(conventions);
|
|
||||||
ApplicationDbContext context = new ApplicationDbContext();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TestingDatabase = (string)builder["Database"];
|
|
||||||
AssertNotNull(TestingDatabase, nameof(TestingDatabase));
|
|
||||||
|
|
||||||
Logger.LogInformation("ServerSideFixture created.");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private readonly ModelBuilder modelBuilder;
|
|
||||||
|
|
||||||
public string TestingDatabase { get; private set; }
|
|
||||||
|
|
||||||
public void CheckDbExistence()
|
|
||||||
{
|
|
||||||
using (
|
|
||||||
NpgsqlConnection cx = new NpgsqlConnection(Startup.TestingSetup.ConnectionStrings.Default))
|
|
||||||
{
|
|
||||||
cx.Open();
|
|
||||||
_logger.LogInformation($"check db for TestingDatabase:{TestingDatabase}");
|
|
||||||
var command = cx.CreateCommand();
|
|
||||||
command.CommandText = $"SELECT 1 FROM pg_database WHERE datname='{TestingDatabase}';";
|
|
||||||
dbCreated = (command.ExecuteScalar()!=null);
|
|
||||||
_logger.LogInformation($"DbCreated:{dbCreated}");
|
|
||||||
cx.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool EnsureTestDb()
|
|
||||||
{
|
|
||||||
if (!DbCreated)
|
|
||||||
{
|
|
||||||
using (NpgsqlConnection cx =
|
|
||||||
new NpgsqlConnection(Startup.TestingSetup.ConnectionStrings.DatabaseCtor))
|
|
||||||
{
|
|
||||||
_logger.LogInformation($"create database for TestingDatabase : {TestingDatabase}");
|
|
||||||
|
|
||||||
cx.Open();
|
|
||||||
var command = cx.CreateCommand();
|
|
||||||
using (NpgsqlConnection ownercx = new NpgsqlConnection(Startup.TestingSetup.ConnectionStrings.Default))
|
|
||||||
command.CommandText = $"create database \"{TestingDatabase}\" OWNER \"{ownercx.UserName}\";";
|
|
||||||
|
|
||||||
_logger.LogInformation(command.CommandText);
|
|
||||||
command.ExecuteNonQuery();
|
|
||||||
cx.Close();
|
|
||||||
}
|
|
||||||
dbCreated = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
return dbCreated;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DropTestDb()
|
|
||||||
{
|
|
||||||
if (dbCreated)
|
|
||||||
DbContext.Database.EnsureDeleted();
|
|
||||||
dbCreated = false;
|
|
||||||
}
|
|
||||||
public bool EnsureWeb()
|
|
||||||
{
|
|
||||||
if (WebApp!=null) return true;
|
|
||||||
|
|
||||||
Task.Run(() => {
|
|
||||||
var di = new DirectoryInfo(Startup.TestingSetup.YavscWebPath);
|
|
||||||
Assert.True(di.Exists);
|
|
||||||
Environment.CurrentDirectory = di.FullName;
|
|
||||||
WebHostBuilder = new WebHostBuilder();
|
|
||||||
webhostengnine = WebHostBuilder
|
|
||||||
.UseEnvironment("Development")
|
|
||||||
.UseServer("yavscTests")
|
|
||||||
.UseStartup<Yavsc.Startup>()
|
|
||||||
.Build();
|
|
||||||
WebApp = webhostengnine.Start();
|
|
||||||
}).Wait();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
if (DbCreated) DropTestDb();
|
|
||||||
if (WebApp!=null) WebApp.Dispose();
|
|
||||||
if (Logger!=null) Logger.LogInformation("Disposing");
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool DbCreated { get {
|
|
||||||
try {
|
|
||||||
CheckDbExistence();
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex.Message);
|
|
||||||
_logger.LogError(ex.StackTrace);
|
|
||||||
}
|
|
||||||
return dbCreated; } }
|
|
||||||
|
|
||||||
public WebHostBuilder WebHostBuilder { get; private set; }
|
|
||||||
|
|
||||||
private IHostingEngine webhostengnine;
|
|
||||||
|
|
||||||
public IApplication WebApp { get; private set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -2,6 +2,7 @@ using System;
|
|||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
using Yavsc.Helpers;
|
using Yavsc.Helpers;
|
||||||
|
using Yavsc.Server.Helpers;
|
||||||
|
|
||||||
namespace yavscTests
|
namespace yavscTests
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using isnd.tests;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
@ -7,11 +8,11 @@ namespace yavscTests.Mandatory
|
|||||||
[Collection("Database")]
|
[Collection("Database")]
|
||||||
[Trait("regression", "II")]
|
[Trait("regression", "II")]
|
||||||
[Trait("dev", "wip")]
|
[Trait("dev", "wip")]
|
||||||
public class Database: IClassFixture<ServerSideFixture>, IDisposable
|
public class Database: IClassFixture<WebServerFixture>, IDisposable
|
||||||
{
|
{
|
||||||
readonly ServerSideFixture _serverFixture;
|
readonly WebServerFixture _serverFixture;
|
||||||
readonly ITestOutputHelper output;
|
readonly ITestOutputHelper output;
|
||||||
public Database(ServerSideFixture serverFixture, ITestOutputHelper output)
|
public Database(WebServerFixture serverFixture, ITestOutputHelper output)
|
||||||
{
|
{
|
||||||
this.output = output;
|
this.output = output;
|
||||||
_serverFixture = serverFixture;
|
_serverFixture = serverFixture;
|
||||||
@ -25,7 +26,7 @@ namespace yavscTests.Mandatory
|
|||||||
{
|
{
|
||||||
output.WriteLine("db not dropped");
|
output.WriteLine("db not dropped");
|
||||||
}
|
}
|
||||||
output.WriteLine($"Startup.Testing.ConnectionStrings.Default is {Startup.TestingSetup.ConnectionStrings.Default}");
|
output.WriteLine($"Startup.Testing.ConnectionStrings.Default is {_serverFixture.TestingSetup.ConnectionStrings.Default}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
using isnd.tests;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
@ -8,13 +9,13 @@ namespace yavscTests
|
|||||||
|
|
||||||
[Collection("EMaillingTeststCollection")]
|
[Collection("EMaillingTeststCollection")]
|
||||||
[Trait("regression", "II")]
|
[Trait("regression", "II")]
|
||||||
public class EMaillingTests : IClassFixture<ServerSideFixture>
|
public class EMaillingTests : IClassFixture<WebServerFixture>
|
||||||
|
|
||||||
{
|
{
|
||||||
readonly ServerSideFixture _serverFixture;
|
readonly WebServerFixture _serverFixture;
|
||||||
readonly ITestOutputHelper output;
|
readonly ITestOutputHelper output;
|
||||||
readonly ILogger _logger;
|
readonly ILogger _logger;
|
||||||
public EMaillingTests(ServerSideFixture serverFixture, ITestOutputHelper output)
|
public EMaillingTests(WebServerFixture serverFixture, ITestOutputHelper output)
|
||||||
{
|
{
|
||||||
this.output = output;
|
this.output = output;
|
||||||
_serverFixture = serverFixture;
|
_serverFixture = serverFixture;
|
||||||
@ -25,20 +26,13 @@ namespace yavscTests
|
|||||||
public void SendEMailSynchrone()
|
public void SendEMailSynchrone()
|
||||||
{
|
{
|
||||||
|
|
||||||
AssertAsync.CompletesIn(2, () =>
|
AssertAsync.CompletesIn(2, () =>
|
||||||
{
|
{
|
||||||
output.WriteLine("SendEMailSynchrone ...");
|
output.WriteLine("SendEMailSynchrone ...");
|
||||||
EmailSentViewModel mailSentInfo = _serverFixture.MailSender.SendEmailAsync
|
_serverFixture.MailSender.SendEmailAsync
|
||||||
(_serverFixture.SiteSetup.Owner.Name, _serverFixture.SiteSetup.Owner.EMail, $"monthly email", "test boby monthly email").Result;
|
(_serverFixture.SiteSettings.Owner.EMail, $"monthly email", "test boby monthly email").Wait();
|
||||||
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,459 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Razor;
|
|
||||||
using Yavsc;
|
|
||||||
using Yavsc.Models;
|
|
||||||
using Yavsc.Services;
|
|
||||||
using Microsoft.Extensions.WebEncoders;
|
|
||||||
using yavscTests.Settings;
|
|
||||||
using Microsoft.AspNetCore.Diagnostics;
|
|
||||||
using System.Net;
|
|
||||||
using Yavsc.Extensions;
|
|
||||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.AspNetCore.Authentication.OAuth;
|
|
||||||
using Yavsc.Helpers.Auth;
|
|
||||||
using Google.Apis.Util.Store;
|
|
||||||
using System.Security.Claims;
|
|
||||||
using Google.Apis.Auth.OAuth2.Responses;
|
|
||||||
using Constants = Yavsc.Constants;
|
|
||||||
using Yavsc.Models.Auth;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using System.Collections.Concurrent;
|
|
||||||
using System.Security.Principal;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
|
||||||
using Microsoft.AspNetCore.Mvc.Razor;
|
|
||||||
using Microsoft.AspNetCore.Authentication;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.Net.Http.Headers;
|
|
||||||
using static Yavsc.Startup;
|
|
||||||
using Microsoft.AspNetCore.DataProtection.Infrastructure;
|
|
||||||
using System.IO;
|
|
||||||
using Yavsc.Lib;
|
|
||||||
using Yavsc.Settings;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using Microsoft.AspNetCore.Mvc.Authorization;
|
|
||||||
|
|
||||||
namespace yavscTests
|
|
||||||
{
|
|
||||||
public class Startup
|
|
||||||
{
|
|
||||||
|
|
||||||
public static IConfiguration Configuration { get; set; }
|
|
||||||
|
|
||||||
public static string HostingFullName { get; private set; }
|
|
||||||
|
|
||||||
public ApplicationDbContext DbContext { get; private set; }
|
|
||||||
|
|
||||||
public static TestingSetup TestingSetup { get; private set; }
|
|
||||||
|
|
||||||
public static IConfigurationRoot GoogleWebClientConfiguration { get; set; }
|
|
||||||
|
|
||||||
public static CookieAuthenticationOptions ExternalCookieAppOptions { get; private set; }
|
|
||||||
private static ILogger logger;
|
|
||||||
|
|
||||||
public static string ApiKey { get; private set; }
|
|
||||||
|
|
||||||
|
|
||||||
public Startup(IHostingEnvironment env)
|
|
||||||
{
|
|
||||||
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()
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
|
|
||||||
.AddEnvironmentVariables();
|
|
||||||
if (env.IsDevelopment())
|
|
||||||
{
|
|
||||||
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
|
|
||||||
builder.AddUserSecrets();
|
|
||||||
}
|
|
||||||
Configuration = builder.Build();
|
|
||||||
|
|
||||||
var googleClientFile = Configuration["Authentication:Google:GoogleWebClientJson"];
|
|
||||||
var googleServiceAccountJsonFile = Configuration["Authentication:Google:GoogleServiceAccountJson"];
|
|
||||||
if (googleClientFile != null)
|
|
||||||
GoogleWebClientConfiguration = new ConfigurationBuilder().AddJsonFile(googleClientFile).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 dbSettingsconf = Configuration.GetSection("ConnectionStrings");
|
|
||||||
services.Configure<DbConnectionSettings>(dbSettingsconf);
|
|
||||||
var testingconf = Configuration.GetSection("Testing");
|
|
||||||
services.Configure<TestingSetup>(testingconf);
|
|
||||||
|
|
||||||
services.AddTransient(typeof(IEmailSender), typeof(MailSender));
|
|
||||||
services.AddEntityFramework().AddNpgsql().AddDbContext<ApplicationDbContext>();
|
|
||||||
services.AddLogging();
|
|
||||||
services.AddTransient<ServerSideFixture>();
|
|
||||||
services.AddTransient<MailSender>();
|
|
||||||
services.AddTransient<EMailer>();
|
|
||||||
|
|
||||||
services.AddLocalization(options =>
|
|
||||||
{
|
|
||||||
options.ResourcesPath = "Resources";
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add memory cache services
|
|
||||||
services.AddCaching();
|
|
||||||
|
|
||||||
// Add session related services.
|
|
||||||
services.AddSession();
|
|
||||||
|
|
||||||
// Add the system clock service
|
|
||||||
services.AddSingleton<ISystemClock, SystemClock>();
|
|
||||||
|
|
||||||
services.AddAuthorizationBuilder()
|
|
||||||
.AddPolicy("AdministratorOnly", policy =>
|
|
||||||
{
|
|
||||||
policy.RequireClaim(JwtClaimType.Role, Constants.AdminGroupName);
|
|
||||||
})
|
|
||||||
.AddPolicy("FrontOffice", policy => policy.RequireRole(Constants.FrontOfficeGroupName))
|
|
||||||
.AddPolicy("Bearer", new AuthorizationPolicyBuilder()
|
|
||||||
.AddAuthenticationSchemes("yavsc")
|
|
||||||
.RequireAuthenticatedUser().Build())
|
|
||||||
.AddPolicy("Authenticated", policy => policy.RequireAuthenticatedUser());
|
|
||||||
|
|
||||||
services.AddDataProtection();
|
|
||||||
services.ConfigureDataProtection(configure =>
|
|
||||||
{
|
|
||||||
configure.SetApplicationName(Configuration["Site:Title"]);
|
|
||||||
configure.SetDefaultKeyLifetime(TimeSpan.FromDays(45));
|
|
||||||
configure.PersistKeysToFileSystem(
|
|
||||||
new DirectoryInfo(Configuration["DataProtection:Keys:Dir"]));
|
|
||||||
});
|
|
||||||
|
|
||||||
services.Add(ServiceDescriptor.Singleton(typeof(IApplicationDiscriminator),
|
|
||||||
typeof(SystemWebApplicationDiscriminator)));
|
|
||||||
|
|
||||||
|
|
||||||
services.AddSingleton<IAuthorizationHandler, HasBadgeHandler>();
|
|
||||||
services.AddSingleton<IAuthorizationHandler, HasTemporaryPassHandler>();
|
|
||||||
services.AddSingleton<IAuthorizationHandler, BlogEditHandler>();
|
|
||||||
services.AddSingleton<IAuthorizationHandler, BlogViewHandler>();
|
|
||||||
services.AddSingleton<IAuthorizationHandler, BillEditHandler>();
|
|
||||||
services.AddSingleton<IAuthorizationHandler, BillViewHandler>();
|
|
||||||
services.AddSingleton<IAuthorizationHandler, PostUserFileHandler>();
|
|
||||||
services.AddSingleton<IAuthorizationHandler, ViewFileHandler>();
|
|
||||||
services.AddSingleton<IAuthorizationHandler, SendMessageHandler>();
|
|
||||||
services.AddSingleton<IConnexionManager, HubConnectionManager>();
|
|
||||||
services.AddSingleton<ILiveProcessor, LiveProcessor>();
|
|
||||||
services.AddSingleton<IFileSystemAuthManager, FileSystemAuthManager>();
|
|
||||||
services.AddSingleton<UserManager<ApplicationDbContext>>();
|
|
||||||
services.AddIdentity<ApplicationUser, IdentityRole>(
|
|
||||||
option =>
|
|
||||||
{
|
|
||||||
option.User.RequireUniqueEmail = true;
|
|
||||||
}
|
|
||||||
).AddEntityFrameworkStores<ApplicationDbContext>()
|
|
||||||
.AddTokenProvider<EmailTokenProvider<ApplicationUser>>(Constants.DefaultFactor)
|
|
||||||
// .AddTokenProvider<UserTokenProvider>(Constants.DefaultFactor)
|
|
||||||
// .AddTokenProvider<UserTokenProvider>(Constants.SMSFactor)
|
|
||||||
.AddTokenProvider<UserTokenProvider>(Constants.EMailFactor)
|
|
||||||
// .AddTokenProvider<UserTokenProvider>(Constants.AppFactor)
|
|
||||||
//
|
|
||||||
;
|
|
||||||
|
|
||||||
services.AddMvc(config =>
|
|
||||||
{
|
|
||||||
var policy = new AuthorizationPolicyBuilder()
|
|
||||||
.RequireAuthenticatedUser()
|
|
||||||
.Build();
|
|
||||||
config.Filters.Add(new AuthorizeFilter(policy));
|
|
||||||
config.Filters.Add(new ProducesAttribute("application/json"));
|
|
||||||
// config.ModelBinders.Insert(0,new MyDateTimeModelBinder());
|
|
||||||
// config.ModelBinders.Insert(0,new MyDecimalModelBinder());
|
|
||||||
config.OutputFormatters.Add(new PdfFormatter());
|
|
||||||
}).AddFormatterMappings(
|
|
||||||
config => config.SetMediaTypeMappingForFormat("text/pdf",
|
|
||||||
new MediaTypeHeaderValue("text/pdf"))
|
|
||||||
).AddFormatterMappings(
|
|
||||||
config => config.SetMediaTypeMappingForFormat("text/x-tex",
|
|
||||||
new MediaTypeHeaderValue("text/x-tex"))
|
|
||||||
)
|
|
||||||
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix,
|
|
||||||
options =>
|
|
||||||
{
|
|
||||||
options.ResourcesPath = "Resources";
|
|
||||||
}).AddDataAnnotationsLocalization();
|
|
||||||
|
|
||||||
// services.AddScoped<LanguageActionFilter>();
|
|
||||||
|
|
||||||
// Inject ticket formatting
|
|
||||||
services.AddTransient(typeof(ISecureDataFormat<>), typeof(SecureDataFormat<>));
|
|
||||||
services.AddTransient<ISecureDataFormat<AuthenticationTicket>, TicketDataFormat>();
|
|
||||||
|
|
||||||
// Add application services.
|
|
||||||
services.AddTransient<IEmailSender<ApplicationUser>, MailSender>();
|
|
||||||
services.AddTransient<IYavscMessageSender, YavscMessageSender>();
|
|
||||||
services.AddTransient<IBillingService, BillingService>();
|
|
||||||
services.AddTransient<IDataStore, FileDataStore>((sp) => new FileDataStore("googledatastore", false));
|
|
||||||
services.AddTransient<ICalendarManager, CalendarManager>();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Client GetApplication(string clientId)
|
|
||||||
{
|
|
||||||
if (DbContext == null)
|
|
||||||
{
|
|
||||||
logger.LogError("no db!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Client app = DbContext.Applications.FirstOrDefault(x => x.Id == clientId);
|
|
||||||
if (app == null) logger.LogError($"no app for <{clientId}>");
|
|
||||||
return app;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
UserManager<ApplicationUser> _usermanager;
|
|
||||||
|
|
||||||
public void Configure(
|
|
||||||
IApplicationBuilder app,
|
|
||||||
IHostingEnvironment env,
|
|
||||||
ApplicationDbContext dbContext,
|
|
||||||
IOptions<TestingSetup> testingSettings,
|
|
||||||
UserManager<ApplicationUser> usermanager,
|
|
||||||
ILoggerFactory loggerFactory
|
|
||||||
)
|
|
||||||
{
|
|
||||||
logger = loggerFactory.CreateLogger<Startup>();
|
|
||||||
logger.LogInformation(env.EnvironmentName);
|
|
||||||
this.DbContext = dbContext;
|
|
||||||
TestingSetup = testingSettings.Value;
|
|
||||||
|
|
||||||
_usermanager = usermanager;
|
|
||||||
|
|
||||||
if (TestingSetup.ConnectionStrings == null)
|
|
||||||
logger.LogInformation($" Testing.ConnectionStrings is null : ");
|
|
||||||
else
|
|
||||||
{
|
|
||||||
AppDomain.CurrentDomain.SetData("YAVSC_DB_CONNECTION", TestingSetup.ConnectionStrings.Default);
|
|
||||||
}
|
|
||||||
|
|
||||||
var authConf = Configuration.GetSection("Authentication").GetSection("Yavsc");
|
|
||||||
var clientId = authConf.GetSection("ClientId").Value;
|
|
||||||
var clientSecret = authConf.GetSection("ClientSecret").Value;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.UseDeveloperExceptionPage();
|
|
||||||
app.UseRuntimeInfoPage();
|
|
||||||
var epo = new ErrorPageOptions
|
|
||||||
{
|
|
||||||
SourceCodeLineCount = 20
|
|
||||||
};
|
|
||||||
app.UseDeveloperExceptionPage(epo);
|
|
||||||
app.UseDatabaseErrorPage(
|
|
||||||
x =>
|
|
||||||
{
|
|
||||||
x.EnableAll();
|
|
||||||
x.ShowExceptionDetails = true;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
app.UseWelcomePage("/welcome");
|
|
||||||
|
|
||||||
// before fixing the security protocol, let beleive our lib it's done with it.
|
|
||||||
//var cxmgr = PayPal.Manager.ConnectionManager.Instance;
|
|
||||||
// then, fix it.
|
|
||||||
// ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xC00; // Tls12, required by PayPal
|
|
||||||
|
|
||||||
app.UseIISPlatformHandler(options =>
|
|
||||||
{
|
|
||||||
options.AuthenticationDescriptions.Clear();
|
|
||||||
options.AutomaticAuthentication = false;
|
|
||||||
});
|
|
||||||
app.UseSession();
|
|
||||||
|
|
||||||
|
|
||||||
app.UseIdentity();
|
|
||||||
|
|
||||||
ProtectionProvider = new MonoDataProtectionProvider(Configuration["Site:Title"]); ;
|
|
||||||
|
|
||||||
app.UseWhen(context => context.Request.Path.StartsWithSegments("/api")
|
|
||||||
|| context.Request.Path.StartsWithSegments("/live"),
|
|
||||||
branchLiveOrApi =>
|
|
||||||
{
|
|
||||||
branchLiveOrApi.UseJwtBearerAuthentication(
|
|
||||||
|
|
||||||
options =>
|
|
||||||
{
|
|
||||||
options.AuthenticationScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
||||||
options.AutomaticAuthenticate = true;
|
|
||||||
options.SecurityTokenValidators.Clear();
|
|
||||||
var tickeDataProtector = new TicketDataFormatTokenValidator(
|
|
||||||
ProtectionProvider
|
|
||||||
);
|
|
||||||
options.SecurityTokenValidators.Add(tickeDataProtector);
|
|
||||||
options.Events = new JwtBearerEvents
|
|
||||||
{
|
|
||||||
OnReceivingToken = context =>
|
|
||||||
{
|
|
||||||
return Task.Run(() =>
|
|
||||||
{
|
|
||||||
var signalRTokenHeader = context.Request.Query["signalRTokenHeader"];
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(signalRTokenHeader) &&
|
|
||||||
(context.HttpContext.WebSockets.IsWebSocketRequest || context.Request.Headers["Accept"] == "text/event-stream"))
|
|
||||||
{
|
|
||||||
context.Token = context.Request.Query["signalRTokenHeader"];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
app.UseWhen(context => !context.Request.Path.StartsWithSegments("/api") && !context.Request.Path.StartsWithSegments("/live"),
|
|
||||||
branch =>
|
|
||||||
{
|
|
||||||
// External authentication shared cookie:
|
|
||||||
branch.UseCookieAuthentication(options =>
|
|
||||||
{
|
|
||||||
ExternalCookieAppOptions = options;
|
|
||||||
options.AuthenticationScheme = Yavsc.Constants.ExternalAuthenticationSheme;
|
|
||||||
options.AutomaticAuthenticate = true;
|
|
||||||
options.ExpireTimeSpan = TimeSpan.FromMinutes(5);
|
|
||||||
options.LoginPath = new PathString(Yavsc.Constants.LoginPath.Substring(1));
|
|
||||||
options.AccessDeniedPath = new PathString(Yavsc.Constants.LoginPath.Substring(1));
|
|
||||||
});
|
|
||||||
|
|
||||||
YavscGoogleAppOptions = new Yavsc.Auth.YavscGoogleOptions
|
|
||||||
{
|
|
||||||
ClientId = GoogleWebClientConfiguration["web:client_id"],
|
|
||||||
ClientSecret = GoogleWebClientConfiguration["web:client_secret"],
|
|
||||||
AccessType = "offline",
|
|
||||||
Scope = {
|
|
||||||
"profile",
|
|
||||||
"https://www.googleapis.com/auth/admin.directory.resource.calendar",
|
|
||||||
"https://www.googleapis.com/auth/calendar",
|
|
||||||
"https://www.googleapis.com/auth/calendar.events"
|
|
||||||
},
|
|
||||||
SaveTokensAsClaims = true,
|
|
||||||
UserInformationEndpoint = "https://www.googleapis.com/plus/v1/people/me",
|
|
||||||
Events = new OAuthEvents
|
|
||||||
{
|
|
||||||
OnCreatingTicket = async context =>
|
|
||||||
{
|
|
||||||
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>()
|
|
||||||
.CreateScope())
|
|
||||||
{
|
|
||||||
var gcontext = context as Yavsc.Auth.GoogleOAuthCreatingTicketContext;
|
|
||||||
context.Identity.AddClaim(new Claim(YavscClaimTypes.GoogleUserId, gcontext.GoogleUserId));
|
|
||||||
var DbContext = serviceScope.ServiceProvider.GetService<ApplicationDbContext>();
|
|
||||||
|
|
||||||
var store = serviceScope.ServiceProvider.GetService<IDataStore>();
|
|
||||||
await store.StoreAsync(gcontext.GoogleUserId, new TokenResponse
|
|
||||||
{
|
|
||||||
AccessToken = gcontext.TokenResponse.AccessToken,
|
|
||||||
RefreshToken = gcontext.TokenResponse.RefreshToken,
|
|
||||||
TokenType = gcontext.TokenResponse.TokenType,
|
|
||||||
ExpiresInSeconds = int.Parse(gcontext.TokenResponse.ExpiresIn),
|
|
||||||
IssuedUtc = DateTime.Now
|
|
||||||
});
|
|
||||||
await dbContext.StoreTokenAsync(gcontext.GoogleUserId,
|
|
||||||
gcontext.TokenResponse.Response,
|
|
||||||
gcontext.TokenResponse.AccessToken,
|
|
||||||
gcontext.TokenResponse.TokenType,
|
|
||||||
gcontext.TokenResponse.RefreshToken,
|
|
||||||
gcontext.TokenResponse.ExpiresIn);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
branch.UseMiddleware<Yavsc.Auth.GoogleMiddleware>(YavscGoogleAppOptions);
|
|
||||||
/* FIXME 403
|
|
||||||
|
|
||||||
branch.UseTwitterAuthentication(options=>
|
|
||||||
{
|
|
||||||
TwitterAppOptions = options;
|
|
||||||
options.ConsumerKey = Configuration["Authentication:Twitter:ClientId"];
|
|
||||||
options.ConsumerSecret = Configuration["Authentication:Twitter:ClientSecret"];
|
|
||||||
}); */
|
|
||||||
|
|
||||||
branch.UseOAuthAuthorizationServer(
|
|
||||||
|
|
||||||
options =>
|
|
||||||
{
|
|
||||||
OAuthServerAppOptions = options;
|
|
||||||
options.AuthorizeEndpointPath = new PathString(Constants.AuthorizePath.Substring(1));
|
|
||||||
options.TokenEndpointPath = new PathString(Constants.TokenPath.Substring(1));
|
|
||||||
options.ApplicationCanDisplayErrors = true;
|
|
||||||
options.AllowInsecureHttp = true;
|
|
||||||
options.AuthenticationScheme = OAuthDefaults.AuthenticationType;
|
|
||||||
options.TokenDataProtector = ProtectionProvider.CreateProtector("Bearer protection");
|
|
||||||
|
|
||||||
options.Provider = new OAuthAuthorizationServerProvider
|
|
||||||
{
|
|
||||||
OnValidateClientRedirectUri = ValidateClientRedirectUri,
|
|
||||||
OnValidateClientAuthentication = ValidateClientAuthentication,
|
|
||||||
OnGrantResourceOwnerCredentials = GrantResourceOwnerCredentials,
|
|
||||||
OnGrantClientCredentials = GrantClientCredetails
|
|
||||||
};
|
|
||||||
|
|
||||||
options.AuthorizationCodeProvider = new AuthenticationTokenProvider
|
|
||||||
{
|
|
||||||
OnCreate = CreateAuthenticationCode,
|
|
||||||
OnReceive = ReceiveAuthenticationCode,
|
|
||||||
};
|
|
||||||
|
|
||||||
options.RefreshTokenProvider = new AuthenticationTokenProvider
|
|
||||||
{
|
|
||||||
OnCreate = CreateRefreshToken,
|
|
||||||
OnReceive = ReceiveRefreshToken,
|
|
||||||
};
|
|
||||||
|
|
||||||
options.AutomaticAuthenticate = true;
|
|
||||||
options.AutomaticChallenge = true;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "google-secret.json");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ConfigureFileServerApp(app, SiteSetup, env, authorizationService);
|
|
||||||
|
|
||||||
app.UseRequestLocalization(localizationOptions.Value, (RequestCulture)new RequestCulture((string)"en-US"));
|
|
||||||
|
|
||||||
ConfigureWorkflow();
|
|
||||||
|
|
||||||
|
|
||||||
app.UseMvc(routes =>
|
|
||||||
{
|
|
||||||
routes.MapRoute(
|
|
||||||
name: "default",
|
|
||||||
template: "{controller=Home}/{action=Index}/{id?}");
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,48 +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.AspNetCore.Hosting;
|
|
||||||
using Microsoft.Dnx.TestHost.TestAdapter;
|
|
||||||
using Xunit.Abstractions;
|
|
||||||
|
|
||||||
namespace yavscTests
|
|
||||||
{
|
|
||||||
[Collection("Yavsc dropped intents")]
|
|
||||||
[Trait("regres", "yes")]
|
|
||||||
public class NotWorking : BaseTestContext
|
|
||||||
{
|
|
||||||
readonly SourceInformationProvider _sourceInfoProvider;
|
|
||||||
readonly IOptions<LocalizationOptions> _localizationOptions;
|
|
||||||
public NotWorking(
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
132
test/yavscTests/WebServerFixture.cs
Normal file
132
test/yavscTests/WebServerFixture.cs
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
using System.Net;
|
||||||
|
using Microsoft.AspNetCore;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.Hosting.Server;
|
||||||
|
using Microsoft.AspNetCore.Hosting.Server.Features;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using Xunit;
|
||||||
|
using Yavsc;
|
||||||
|
using Yavsc.Models;
|
||||||
|
using Yavsc.Services;
|
||||||
|
using yavscTests.Settings;
|
||||||
|
|
||||||
|
namespace isnd.tests
|
||||||
|
{
|
||||||
|
|
||||||
|
[CollectionDefinition("Web server collection")]
|
||||||
|
public class WebServerFixture : IDisposable
|
||||||
|
{
|
||||||
|
public IWebHost Host { get; private set;}
|
||||||
|
public List<string> Addresses { get; private set; } = new List<string>();
|
||||||
|
public Microsoft.Extensions.Logging.ILogger Logger { get; internal set; }
|
||||||
|
|
||||||
|
private SiteSettings siteSettings;
|
||||||
|
|
||||||
|
|
||||||
|
public string TestingUserName { get; private set; }
|
||||||
|
public string ProtectedTestingApiKey { get; internal set; }
|
||||||
|
public ApplicationUser TestingUser { get; private set; }
|
||||||
|
public bool DbCreated { get; internal set; }
|
||||||
|
public SiteSettings SiteSettings { get => siteSettings; set => siteSettings = value; }
|
||||||
|
public MailSender MailSender { get; internal set; }
|
||||||
|
public TestingSetup? TestingSetup { get; internal set; }
|
||||||
|
public ApplicationDbContext DbContext { get; internal set; }
|
||||||
|
|
||||||
|
public WebServerFixture()
|
||||||
|
{
|
||||||
|
SetupHost();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Host.StopAsync().Wait();
|
||||||
|
Host.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetupHost()
|
||||||
|
{
|
||||||
|
var builder = WebHost.CreateDefaultBuilder(new string[0]);
|
||||||
|
|
||||||
|
// .UseContentRoot("../../../../../src/isnd")
|
||||||
|
builder.UseStartup(typeof(Startup))
|
||||||
|
.ConfigureAppConfiguration((builderContext, config) =>
|
||||||
|
{
|
||||||
|
config.AddJsonFile("appsettings.json", true);
|
||||||
|
config.AddJsonFile("appsettings.Development.json", false);
|
||||||
|
});
|
||||||
|
|
||||||
|
Host = builder.Build();
|
||||||
|
|
||||||
|
var logFactory = Host.Services.GetRequiredService<ILoggerFactory>();
|
||||||
|
Logger = logFactory.CreateLogger<WebServerFixture>();
|
||||||
|
|
||||||
|
Host.Start(); //Starts listening on the configured addresses.
|
||||||
|
var server = Host.Services.GetRequiredService<IServer>();
|
||||||
|
|
||||||
|
var addressFeatures = server.Features.Get<IServerAddressesFeature>();
|
||||||
|
|
||||||
|
foreach (var address in addressFeatures.Addresses)
|
||||||
|
{
|
||||||
|
Addresses.Add(address);
|
||||||
|
}
|
||||||
|
SiteSettings = Host.Services.GetRequiredService<IOptions<SiteSettings>>().Value;
|
||||||
|
|
||||||
|
using IServiceScope scope = Host.Services.CreateScope();
|
||||||
|
ApplicationDbContext dbContext =
|
||||||
|
scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
||||||
|
|
||||||
|
|
||||||
|
TestingUserName = "Tester";
|
||||||
|
TestingUser = dbContext.Users.FirstOrDefault(u => u.UserName == TestingUserName);
|
||||||
|
EnsureUser(TestingUserName);
|
||||||
|
|
||||||
|
ServicePointManager.ServerCertificateValidationCallback =
|
||||||
|
(sender, cert, chain, sslPolicyErrors) => true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void EnsureUser(string testingUserName)
|
||||||
|
{
|
||||||
|
if (TestingUser == null)
|
||||||
|
{
|
||||||
|
using IServiceScope scope = Host.Services.CreateScope();
|
||||||
|
|
||||||
|
var userManager =
|
||||||
|
scope.ServiceProvider.GetRequiredService<UserManager<ApplicationUser>>();
|
||||||
|
|
||||||
|
|
||||||
|
TestingUser = new ApplicationUser
|
||||||
|
{
|
||||||
|
UserName = testingUserName
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = userManager.CreateAsync(TestingUser).Result;
|
||||||
|
|
||||||
|
Assert.True(result.Succeeded);
|
||||||
|
|
||||||
|
ApplicationDbContext dbContext =
|
||||||
|
scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
||||||
|
TestingUser = dbContext.Users.FirstOrDefault(u => u.UserName == testingUserName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void DropTestDb()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal bool EnsureTestDb()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal int UpgradeDb()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,16 +1,17 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.3.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.3.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.3" />
|
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.7" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.3" />
|
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.7" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.3" />
|
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.7" />
|
||||||
|
<PackageReference Include="Microsoft.Playwright" Version="1.53.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="xunit" Version="2.9.3" />
|
<PackageReference Include="xunit" Version="2.9.3" />
|
||||||
|
|
||||||
|
@ -17,6 +17,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sampleWebAsWebApiClient", "
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Api", "src\Api\Api.csproj", "{16CCC793-BF57-4E8B-9BB5-76283379BA3F}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Api", "src\Api\Api.csproj", "{16CCC793-BF57-4E8B-9BB5-76283379BA3F}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{27336229-4130-45CC-8284-7F3B54D16463}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "yavscTests", "test\yavscTests\yavscTests.csproj", "{D565C5C8-19A6-4134-A18B-FE71986FBA35}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -46,6 +50,10 @@ Global
|
|||||||
{16CCC793-BF57-4E8B-9BB5-76283379BA3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{16CCC793-BF57-4E8B-9BB5-76283379BA3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{16CCC793-BF57-4E8B-9BB5-76283379BA3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{16CCC793-BF57-4E8B-9BB5-76283379BA3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{16CCC793-BF57-4E8B-9BB5-76283379BA3F}.Release|Any CPU.Build.0 = Release|Any CPU
|
{16CCC793-BF57-4E8B-9BB5-76283379BA3F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{D565C5C8-19A6-4134-A18B-FE71986FBA35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{D565C5C8-19A6-4134-A18B-FE71986FBA35}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{D565C5C8-19A6-4134-A18B-FE71986FBA35}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{D565C5C8-19A6-4134-A18B-FE71986FBA35}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(NestedProjects) = preSolution
|
GlobalSection(NestedProjects) = preSolution
|
||||||
{5AFB6255-CF1B-4660-BB35-F24C8C75FECE} = {503DDD6B-BE10-4235-9EBD-E9B1FA6067DF}
|
{5AFB6255-CF1B-4660-BB35-F24C8C75FECE} = {503DDD6B-BE10-4235-9EBD-E9B1FA6067DF}
|
||||||
@ -53,5 +61,6 @@ Global
|
|||||||
{87DABC88-C38C-45DB-8F72-53B7C95ABC89} = {503DDD6B-BE10-4235-9EBD-E9B1FA6067DF}
|
{87DABC88-C38C-45DB-8F72-53B7C95ABC89} = {503DDD6B-BE10-4235-9EBD-E9B1FA6067DF}
|
||||||
{38AA74FE-3932-49C3-A382-338E7C861BB1} = {503DDD6B-BE10-4235-9EBD-E9B1FA6067DF}
|
{38AA74FE-3932-49C3-A382-338E7C861BB1} = {503DDD6B-BE10-4235-9EBD-E9B1FA6067DF}
|
||||||
{16CCC793-BF57-4E8B-9BB5-76283379BA3F} = {503DDD6B-BE10-4235-9EBD-E9B1FA6067DF}
|
{16CCC793-BF57-4E8B-9BB5-76283379BA3F} = {503DDD6B-BE10-4235-9EBD-E9B1FA6067DF}
|
||||||
|
{D565C5C8-19A6-4134-A18B-FE71986FBA35} = {27336229-4130-45CC-8284-7F3B54D16463}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
Reference in New Issue
Block a user