Skip to content

Commit

Permalink
Merge pull request #85 from Ali-YousefiTelori/develop
Browse files Browse the repository at this point in the history
add delay
  • Loading branch information
Ali-YousefiTelori authored Nov 26, 2023
2 parents a29edfb + 18b6d5d commit b3a0c7b
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace EasyMicroservices.Cores.AspCore.Tests
{
public abstract class BasicTests : IClassFixture<WhiteLabelLaboratoryFixture>
public abstract class BasicTests
{
protected static HttpClient HttpClient { get; set; } = new HttpClient();
public abstract int AppPort { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class AuthorizationFixture : IAsyncLifetime
public IServiceProvider ServiceProvider { get; private set; }
public Task InitializeAsync()
{
return BaseFixture.Init(4565, (sc) =>
return BaseFixture.Init(4565, 6044, (sc) =>
{
sc.AddScoped<IAuthorization, AppAuthorization>();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class AuthorizationRolePermissionsFixture : IAsyncLifetime
public IServiceProvider ServiceProvider { get; private set; }
public Task InitializeAsync()
{
return BaseFixture.Init(4566, (services) =>
return BaseFixture.Init(4566,6043, (services) =>
{
services.AddScoped<IAuthorization, AspCoreAuthorization>();
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
using EasyMicroservices.Cores.Database.Managers;
using EasyMicroservices.Cores.Relational.EntityFrameworkCore.Intrerfaces;
using EasyMicroservices.Cores.Tests.DatabaseLogics.Database.Contexts;
using EasyMicroservices.Cores.Tests.Fixtures;

namespace EasyMicroservices.Cores.AspCore.Tests.Fixtures;

public class BaseFixture
{
public static async Task<IServiceProvider> Init(long port, Action<IServiceCollection> changeCollection = null)
public static async Task<IServiceProvider> Init(int port, int whiteLabelPort, Action<IServiceCollection> changeCollection = null)
{
string microserviceName = "TestExample";
WebApplicationBuilder app = StartUpExtensions.Create<MyTestContext>(null);
Expand All @@ -25,12 +26,14 @@ public static async Task<IServiceProvider> Init(long port, Action<IServiceCollec
return new DefaultUniqueIdentityManager(provider.GetService<WhiteLabelManager>().CurrentWhiteLabel);
});
changeCollection?.Invoke(app.Services);
StartUpExtensions.AddWhiteLabelRoute(microserviceName, $"http://localhost:6041");
await BaseWhiteLabelFixture.Run(whiteLabelPort);
StartUpExtensions.AddWhiteLabelRoute(microserviceName, $"http://localhost:{whiteLabelPort}");
app.Services.AddControllers().AddApplicationPart(typeof(UserController).Assembly);
app.WebHost.UseUrls($"http://localhost:{port}");
var build = await app.Build<MyTestContext>(true);
build.MapControllers();
_ = build.RunAsync();
//await Task.Delay(TimeSpan.FromSeconds(2));
return build.Services;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class NormalFixture : IAsyncLifetime
public IServiceProvider ServiceProvider { get; private set; }
public Task InitializeAsync()
{
return BaseFixture.Init(4564);
return BaseFixture.Init(4564,6042);
}

public Task DisposeAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="EasyMicroservices.WhiteLabelsMicroservice.VirtualServerForTests" Version="0.0.0.6" />
<PackageReference Include="EasyMicroservices.WhiteLabelsMicroservice.VirtualServerForTests" Version="0.0.0.7" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using EasyMicroservices.Cores.Tests.Database;
using EasyMicroservices.Cores.Tests.DatabaseLogics.Database.Contexts;
using EasyMicroservices.WhiteLabelsMicroservice.VirtualServerForTests;
using EasyMicroservices.WhiteLabelsMicroservice.VirtualServerForTests.TestResources;

namespace EasyMicroservices.Cores.Tests.Fixtures;
public class BaseWhiteLabelFixture
{
public static async Task Run(int port)
{
var whiteLabelVirtualTestManager = new WhiteLabelVirtualTestManager();

if (await whiteLabelVirtualTestManager.OnInitialize(port))
{
Console.WriteLine($"WhiteLabelVirtualTestManager Initialized! {port}");
foreach (var item in WhiteLabelResource.GetResources(new MyTestContext(new DatabaseBuilder()), "TextExample"))
{
whiteLabelVirtualTestManager.AppendService(port, item.Key, item.Value);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using EasyMicroservices.Cores.Tests.Database;
using EasyMicroservices.Cores.Tests.DatabaseLogics.Database.Contexts;
using EasyMicroservices.WhiteLabelsMicroservice.VirtualServerForTests;
using EasyMicroservices.WhiteLabelsMicroservice.VirtualServerForTests.TestResources;
using System.Text;
using System.Text;

namespace EasyMicroservices.Cores.Tests.Fixtures
{
Expand All @@ -17,33 +13,6 @@ public WhiteLabelLaboratoryFixture()
_routeAddress = $"http://{localhost}:{Port}";
}

protected static WhiteLabelVirtualTestManager WhiteLabelVirtualTestManager { get; set; } = new WhiteLabelVirtualTestManager();

static bool _isInitialized = false;
static SemaphoreSlim Semaphore = new SemaphoreSlim(1);
protected async Task OnInitialize()
{
try
{
await Semaphore.WaitAsync();
if (_isInitialized)
return;
if (await WhiteLabelVirtualTestManager.OnInitialize(Port))
{
Console.WriteLine($"WhiteLabelVirtualTestManager Initialized! {Port}");
foreach (var item in WhiteLabelResource.GetResources(new MyTestContext(new DatabaseBuilder()), "TextExample"))
{
WhiteLabelVirtualTestManager.AppendService(Port, item.Key, item.Value);
}
}
_isInitialized = true;
}
finally
{
Semaphore.Release();
}
}

[Fact]
public async Task WhiteLabelGetAllTest()
{
Expand Down Expand Up @@ -97,9 +66,9 @@ public async Task ContextTableGetAllTest()
Assert.True(all.Result.Count >= 5);
}

public async Task InitializeAsync()
public Task InitializeAsync()
{
await OnInitialize();
return BaseWhiteLabelFixture.Run(6041);
}

public Task DisposeAsync()
Expand Down

0 comments on commit b3a0c7b

Please sign in to comment.