Relocate test project: test/yavscTests -> src/Yavsc.Org.Tests
Move the integration test project from the top-level test/ directory into src/ alongside the projects it tests. Rename the project (and folder) to Yavsc.Org.Tests to match .NET conventions and reflect that it tests the Org runtime primarily. Path changes: - test/yavscTests/yavscTests.csproj -> src/Yavsc.Org.Tests/Yavsc.Org.Tests.csproj - All .cs / .json / .resx files moved to their new location - PostItViewModelTests moved out to the dedicated src/PostIt.Tests project (it was unrelated to Org testing) Build adjustments: - <ProjectReference> paths shortened (..\..\src\X -> ..\X) - PostIt project reference removed (covered by its own test project) - <OutputType>exe added (required by xunit.v3) - xunit.v3.common and xunit.v3.extensibility.core added to package versions Solution + sln: - yavsc.sln Project Name updated to 'Yavsc.Org.Tests' and path updated - GUID preserved so existing build configs stay valid Static web assets: - The CopyStaticWebAssetsManifest target was hard-coding the destination filename to 'testhost.staticwebassets.endpoints.json', which worked when the assembly was named 'yavscTests'. Now that the assembly name is 'Yavsc.Org.Tests', ASP.NET Core's MapStaticAssets() looks for 'Yavsc.Org.Tests.staticwebassets.endpoints.json' (entry-assembly-based resolution). Use $(MSBuildProjectName) so the copy target stays correct under any future rename.
This commit is contained in:
parent
ad19ccbcfa
commit
22b397ce7e
18 changed files with 16 additions and 22 deletions
67
src/Yavsc.Org.Tests/Mandatory/BatchTests.cs
Normal file
67
src/Yavsc.Org.Tests/Mandatory/BatchTests.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Server.Models.IT.SourceCode;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
using yavscTests.ServerFixtures;
|
||||
using Yavsc.Server.Models.IT;
|
||||
|
||||
namespace yavscTests
|
||||
{
|
||||
[Collection("Yavsc Server")]
|
||||
[Trait("regression", "oui")]
|
||||
public class BaseTestContext: IClassFixture<WebServerFixture>, IDisposable
|
||||
{
|
||||
public readonly WebServerFixture _serverFixture;
|
||||
private readonly ITestOutputHelper _output;
|
||||
|
||||
public BaseTestContext(ITestOutputHelper output, WebServerFixture fixture)
|
||||
{
|
||||
this._serverFixture = fixture;
|
||||
this._output = output;
|
||||
}
|
||||
|
||||
// FIXME write a scenario from an empty database [Fact]
|
||||
public void GitClone()
|
||||
{
|
||||
using var scope = _serverFixture.Services.CreateScope();
|
||||
var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
||||
Assert.NotNull(dbContext.Project);
|
||||
Project yavsc = new Project
|
||||
{
|
||||
Name = "Yavsc"
|
||||
};
|
||||
dbContext.Project.Add(yavsc);
|
||||
dbContext.SaveChanges();
|
||||
var firstProject = dbContext.Project.Include(p => p.Repository).FirstOrDefault(
|
||||
p => p.Name == "Yavsc"
|
||||
);
|
||||
Assert.NotNull (firstProject);
|
||||
var di = new DirectoryInfo(_serverFixture.SiteSettings.GitRepository);
|
||||
if (!di.Exists) di.Create();
|
||||
|
||||
var clone = new GitClone(_serverFixture.SiteSettings.GitRepository);
|
||||
clone.Launch(firstProject);
|
||||
gitRepo = di.FullName;
|
||||
}
|
||||
string gitRepo=null;
|
||||
private IConfigurationRoot configurationRoot;
|
||||
|
||||
|
||||
[Fact]
|
||||
public void HaveConfigurationRoot()
|
||||
{
|
||||
var builder = new ConfigurationBuilder();
|
||||
configurationRoot = builder.Build();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (gitRepo!=null)
|
||||
{
|
||||
Directory.Delete(Path.Combine(gitRepo,"yavsc"), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
100
src/Yavsc.Org.Tests/Mandatory/Remoting.cs
Normal file
100
src/Yavsc.Org.Tests/Mandatory/Remoting.cs
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Net.Security;
|
||||
using yavscTests.ServerFixtures;
|
||||
using IdentityModel.Client;
|
||||
|
||||
namespace yavscTests
|
||||
{
|
||||
[Collection("Yavsc Server")]
|
||||
[Trait("regression", "oui")]
|
||||
public class Remoting : BaseTestContext, IClassFixture<WebServerFixture>
|
||||
{
|
||||
public Remoting(WebServerFixture serverFixture, ITestOutputHelper output)
|
||||
: base(output, serverFixture)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task ObtainServiceToken()
|
||||
{
|
||||
var serverUrl = _serverFixture.Addresses.FirstOrDefault(u => u.StartsWith("https:"));
|
||||
if (string.IsNullOrEmpty(serverUrl))
|
||||
throw new InvalidOperationException("No HTTPS server address found");
|
||||
|
||||
HttpClient client = NewHttpClient();
|
||||
var disco = await client.GetDiscoveryDocumentAsync(serverUrl);
|
||||
if (disco.IsError) throw new Exception(disco.Error);
|
||||
|
||||
var response = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
|
||||
{
|
||||
Address = disco.TokenEndpoint,
|
||||
ClientId = _serverFixture.TestClientId,
|
||||
ClientSecret = _serverFixture.TestClientSecret,
|
||||
Scope = "test",
|
||||
GrantType = "client_credentials"
|
||||
});
|
||||
if (response.IsError) throw new Exception(response.Error);
|
||||
}
|
||||
|
||||
private static HttpClient NewHttpClient()
|
||||
{
|
||||
return new HttpClient(new BypassSslValidationHandler());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ObtainResourceOwnerPasswordToken()
|
||||
{
|
||||
var serverUrl = _serverFixture.Addresses.FirstOrDefault(u => u.StartsWith("https:"));
|
||||
if (string.IsNullOrEmpty(serverUrl))
|
||||
throw new InvalidOperationException("No HTTPS server address found");
|
||||
|
||||
var client = NewHttpClient();
|
||||
var disco = await client.GetDiscoveryDocumentAsync(serverUrl);
|
||||
if (disco.IsError) throw new Exception(disco.Error);
|
||||
|
||||
var response = await client.RequestPasswordTokenAsync(new PasswordTokenRequest
|
||||
{
|
||||
Address = disco.TokenEndpoint,
|
||||
ClientId = _serverFixture.TestClientId,
|
||||
ClientSecret = _serverFixture.TestClientSecret,
|
||||
UserName = _serverFixture.TestingUserName,
|
||||
Password = _serverFixture.TestingUserPassword,
|
||||
Scope = "test",
|
||||
Parameters =
|
||||
{
|
||||
{ "acr_values", "tenant:custom_account_store1 foo bar quux" }
|
||||
}
|
||||
});
|
||||
|
||||
if (response.IsError) throw new Exception(response.Error);
|
||||
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> GetLoginIntentData()
|
||||
{
|
||||
return new object[][] { new object[] { "testuser", "test" } };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal class BypassSslValidationHandler : HttpClientHandler
|
||||
{
|
||||
public BypassSslValidationHandler()
|
||||
{
|
||||
// Override validation for this handler only
|
||||
ServerCertificateCustomValidationCallback = ValidateCertificate;
|
||||
}
|
||||
|
||||
private bool ValidateCertificate(
|
||||
HttpRequestMessage request,
|
||||
X509Certificate2? certificate,
|
||||
X509Chain? chain,
|
||||
SslPolicyErrors errors)
|
||||
{
|
||||
// Accept all certificates (bypass validation)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
22
src/Yavsc.Org.Tests/Mandatory/Resources.cs
Normal file
22
src/Yavsc.Org.Tests/Mandatory/Resources.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
namespace yavscTests {
|
||||
public class ResxResources {
|
||||
const string resPath = "Resources/Test.TestResources.resx";
|
||||
public void HaveAResxLoader()
|
||||
{
|
||||
System.Resources.ResourceReader loader = new System.Resources.ResourceReader(resPath);
|
||||
// IDictionary
|
||||
var etor = loader.GetEnumerator();
|
||||
while (etor.Current !=null)
|
||||
{
|
||||
byte[] data;
|
||||
string stringdata;
|
||||
string resName = etor.Key.ToString();
|
||||
|
||||
loader.GetResourceData(resName, out stringdata, out data);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
15
src/Yavsc.Org.Tests/Mandatory/Services.cs
Normal file
15
src/Yavsc.Org.Tests/Mandatory/Services.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
using yavscTests.ServerFixtures;
|
||||
|
||||
|
||||
namespace yavscTests.Mandatory;
|
||||
|
||||
[Collection("Yavsc Server")]
|
||||
[Trait("regression", "oui")]
|
||||
public class Services : BaseTestContext, IClassFixture<WebServerFixture>
|
||||
{
|
||||
public Services(ITestOutputHelper output, WebServerFixture fixture) : base(output, fixture)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue