build cli
This commit is contained in:
30
test/yavscTests/FirstUIStript.cs
Normal file
30
test/yavscTests/FirstUIStript.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using OpenQA.Selenium;
|
||||
using OpenQA.Selenium.Chrome;
|
||||
|
||||
namespace SeleniumDocs.GettingStarted;
|
||||
|
||||
public static class FirstScript
|
||||
{
|
||||
public static void DoTestSeleniumWebSite()
|
||||
{
|
||||
IWebDriver driver = new ChromeDriver();
|
||||
|
||||
driver.Navigate().GoToUrl("https://www.selenium.dev/selenium/web/web-form.html");
|
||||
|
||||
var title = driver.Title;
|
||||
|
||||
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(500);
|
||||
|
||||
var textBox = driver.FindElement(By.Name("my-text"));
|
||||
var submitButton = driver.FindElement(By.TagName("button"));
|
||||
|
||||
textBox.SendKeys("Selenium");
|
||||
submitButton.Click();
|
||||
|
||||
var message = driver.FindElement(By.Id("message"));
|
||||
var value = message.Text;
|
||||
|
||||
driver.Quit();
|
||||
}
|
||||
}
|
@ -1,28 +1,15 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Xunit;
|
||||
using Yavsc;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Services;
|
||||
using System.Runtime.Versioning;
|
||||
using System.Diagnostics;
|
||||
using Yavsc.Helpers;
|
||||
using Xunit.Abstractions;
|
||||
using Yavsc.Server.Models.IT.SourceCode;
|
||||
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
|
||||
{
|
||||
[Collection("Yavsc mandatory success story")]
|
||||
[Collection("Yavsc Server")]
|
||||
[Trait("regression", "oui")]
|
||||
public class BaseTestContext: IClassFixture<WebServerFixture>, IDisposable
|
||||
{
|
||||
|
@ -6,11 +6,10 @@ using System.Net;
|
||||
using isnd.tests;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using Yavsc.Authentication;
|
||||
|
||||
namespace yavscTests
|
||||
{
|
||||
[Collection("Yavsc Work In Progress")]
|
||||
[Collection("Yavsc Server")]
|
||||
[Trait("regression", "oui")]
|
||||
public class Remoting : BaseTestContext, IClassFixture<WebServerFixture>
|
||||
{
|
||||
@ -21,7 +20,7 @@ namespace yavscTests
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetLoginIntentData), parameters: 1)]
|
||||
[MemberData(nameof(GetLoginIntentData))]
|
||||
public async Task TestUserMayLogin
|
||||
(
|
||||
string userName,
|
||||
@ -30,54 +29,42 @@ namespace yavscTests
|
||||
{
|
||||
try
|
||||
{
|
||||
var serverUrl = _serverFixture.Addresses.FirstOrDefault();
|
||||
var serverUrl = _serverFixture.Addresses.FirstOrDefault(
|
||||
u => u.StartsWith("https:")
|
||||
);
|
||||
|
||||
String auth = _serverFixture.SiteSettings.Authority;
|
||||
|
||||
var oauthor = new OAuthenticator(_serverFixture.TestClientId, _serverFixture.TestClientSecret,
|
||||
"profile",
|
||||
new Uri(serverUrl), new Uri(serverUrl), new Uri(serverUrl+"/connect/token"));
|
||||
|
||||
|
||||
var query = new Dictionary<string, string>
|
||||
{
|
||||
["Username"] = userName,
|
||||
["Password"] = password,
|
||||
["GrantType"] = "Password"
|
||||
["GrantType"] = "password"
|
||||
};
|
||||
|
||||
var result = await oauthor.RequestAccessTokenAsync(query);
|
||||
Console.WriteLine(">> Got an output");
|
||||
Console.WriteLine( "AccessToken " + result["AccessToken"]);
|
||||
Console.WriteLine("TokenType " + result["TokenType"]);
|
||||
Console.WriteLine("ExpiresIn " + result["ExpiresIn"]);
|
||||
Console.WriteLine("RefreshToken : " + result["RefreshToken"]);
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var webex = ex as WebException;
|
||||
if (webex != null && webex.Status == (WebExceptionStatus)400)
|
||||
if (webex != null)
|
||||
{
|
||||
if (_serverFixture?.TestingSetup?.ValidCreds.UserName == "lame-user")
|
||||
if (webex.Status == WebExceptionStatus.ProtocolError)
|
||||
{
|
||||
Console.WriteLine("Bad pass joe!");
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> GetLoginIntentData(int countFakes = 0)
|
||||
public static IEnumerable<object[]> GetLoginIntentData()
|
||||
{
|
||||
if (countFakes == 0)
|
||||
return new object[][] { new object[] { "testuser", "test" } };
|
||||
|
||||
var fakUsers = new List<String[]>();
|
||||
for (int i = 0; i < countFakes; i++)
|
||||
{
|
||||
fakUsers.Add(new String[] { "fakeTester" + i, "pass" + i });
|
||||
}
|
||||
return fakUsers;
|
||||
return new object[][] { new object[] { "testuser", "test" } };
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,12 @@
|
||||
using isnd.tests;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using Yavsc.Abstract.Manage;
|
||||
using Yavsc.Interface;
|
||||
using Yavsc.Models;
|
||||
|
||||
namespace yavscTests
|
||||
{
|
||||
@ -25,12 +29,18 @@ namespace yavscTests
|
||||
[Fact]
|
||||
public void SendEMailSynchrone()
|
||||
{
|
||||
|
||||
AssertAsync.CompletesIn(2, () =>
|
||||
AssertAsync.CompletesIn(2, () =>
|
||||
{
|
||||
using IServiceScope scope = _serverFixture.Services.CreateScope();
|
||||
ITrueEmailSender mailSender = scope.ServiceProvider.GetRequiredService<ITrueEmailSender>();
|
||||
|
||||
output.WriteLine("SendEMailSynchrone ...");
|
||||
_serverFixture.MailSender.SendEmailAsync
|
||||
(_serverFixture.SiteSettings.Owner.EMail, $"monthly email", "test boby monthly email").Wait();
|
||||
mailSender.SendEmailAsync
|
||||
(
|
||||
_serverFixture.SiteSettings.Owner.Name,
|
||||
_serverFixture.SiteSettings.Owner.EMail,
|
||||
$"monthly email",
|
||||
"test boby monthly email").Wait();
|
||||
|
||||
});
|
||||
}
|
||||
|
@ -1,66 +0,0 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace yavscTests
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Since node isn't any requirement by here,
|
||||
/// It may regress
|
||||
/// </summary>
|
||||
[Trait("regression", "allways")]
|
||||
public class NodeTests
|
||||
{
|
||||
void TestNodeJsForAnsitohtml ()
|
||||
{
|
||||
var procStart = new ProcessStartInfo("node", "node_modules/ansi-to-html/bin/ansi-to-html")
|
||||
{
|
||||
UseShellExecute = false,
|
||||
RedirectStandardInput = true,
|
||||
RedirectStandardOutput = true,
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
void AnsiToHtml()
|
||||
{
|
||||
var procStart = new ProcessStartInfo("ls", "-l --color=always")
|
||||
{
|
||||
UseShellExecute = false,
|
||||
RedirectStandardInput = false,
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -4,11 +4,15 @@ using System.Threading.Tasks;
|
||||
namespace yavscTests {
|
||||
|
||||
public static class AssertAsync {
|
||||
|
||||
public static void CompletesIn(int timeout, Action action)
|
||||
/// <summary>
|
||||
/// Completes In
|
||||
/// </summary>
|
||||
/// <param name="timeoutFromSecond"></param>
|
||||
/// <param name="action"></param>
|
||||
public static void CompletesIn(int timeoutFromSecond, Action action)
|
||||
{
|
||||
var task = Task.Run(action);
|
||||
var completedInTime = Task.WaitAll(new[] { task }, TimeSpan.FromSeconds(timeout));
|
||||
var completedInTime = Task.WaitAll(new[] { task }, TimeSpan.FromSeconds(timeoutFromSecond));
|
||||
|
||||
if (task.Exception != null)
|
||||
{
|
||||
@ -22,7 +26,7 @@ namespace yavscTests {
|
||||
|
||||
if (!completedInTime)
|
||||
{
|
||||
throw new TimeoutException($"Task did not complete in {timeout} seconds.");
|
||||
throw new TimeoutException($"Task did not complete in {timeoutFromSecond} seconds.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,6 @@ namespace isnd.tests
|
||||
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 string TestClientSecret { get; private set; } = "TestClientSecret";
|
||||
|
||||
@ -119,6 +118,15 @@ namespace isnd.tests
|
||||
dbContext.Client.Add(testClient);
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
testClient.DisplayName = "Testing Client";
|
||||
testClient.Secret = TestClientSecret;
|
||||
testClient.Active = true;
|
||||
testClient.Type = ApplicationTypes.NativeConfidential;
|
||||
testClient.AccessTokenLifetime = 900;
|
||||
testClient.RefreshTokenLifeTime = 1500;
|
||||
}
|
||||
}
|
||||
|
||||
public void EnsureUser(string testingUserName)
|
||||
|
@ -12,6 +12,7 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="Selenium.WebDriver" />
|
||||
<PackageReference Include="xunit" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Hosting" />
|
||||
|
Reference in New Issue
Block a user