From ee6ca137e4e3c7790604589312a1c2b02e8ee003 Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Mon, 27 Nov 2023 00:22:01 +0330 Subject: [PATCH 1/2] Refactor test cases use ClassFixture --- .../AuthorizationRolePermissionsTests.cs | 29 +--- .../AuthorizationTests.cs | 17 +- .../BasicTests.cs | 45 ++--- .../Fixtures/AuthorizationFixture.cs | 20 +++ .../AuthorizationRolePermissionsFixture.cs | 37 ++++ .../Fixtures/BaseFixture.cs | 36 ++++ .../Fixtures/NormalFixture.cs | 15 ++ .../NormalTests.cs | 8 + .../Program.cs | 4 +- .../Startup.cs | 4 +- .../Authorizations/AspCoreAuthorization.cs | 5 - .../Managers/WhiteLabelManager.cs | 160 ++++++++++-------- .../StartUpExtensions.cs | 3 +- .../UnitOfWork.cs | 7 +- .../Interfaces/IUniqueIdentityManager.cs | 3 +- .../Logics/DatabaseLogicInfrastructure.cs | 23 ++- .../Managers/DefaultUniqueIdentityManager.cs | 12 +- .../LongIdMappedDatabaseLogicBaseTest.cs | 4 +- .../EasyMicroservices.Cores.Tests.csproj | 3 +- .../Fixtures/ServiceProviderFixture.cs | 5 +- .../Fixtures/WhiteLabelLaboratoryFixture.cs | 98 +++++------ 21 files changed, 306 insertions(+), 232 deletions(-) create mode 100644 src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Fixtures/AuthorizationFixture.cs create mode 100644 src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Fixtures/AuthorizationRolePermissionsFixture.cs create mode 100644 src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Fixtures/BaseFixture.cs create mode 100644 src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Fixtures/NormalFixture.cs create mode 100644 src/CSharp/EasyMicroservices.Cores.AspCore.Tests/NormalTests.cs diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/AuthorizationRolePermissionsTests.cs b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/AuthorizationRolePermissionsTests.cs index 968864d..0ab1f31 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/AuthorizationRolePermissionsTests.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/AuthorizationRolePermissionsTests.cs @@ -1,5 +1,6 @@ using EasyMicroservices.AuthenticationsMicroservice.VirtualServerForTests; using EasyMicroservices.AuthenticationsMicroservice.VirtualServerForTests.TestResources; +using EasyMicroservices.Cores.AspCore.Tests.Fixtures; using EasyMicroservices.Cores.AspCoreApi.Authorizations; using EasyMicroservices.Cores.AspCoreApi.Interfaces; using EasyMicroservices.Cores.AspEntityFrameworkCoreApi.Interfaces; @@ -11,34 +12,12 @@ namespace EasyMicroservices.Cores.AspCore.Tests { - public abstract class AuthorizationRolePermissionsTests : BasicTests + public class AuthorizationRolePermissionsTests : BasicTests,IClassFixture { public override int AppPort => 4566; public AuthorizationRolePermissionsTests() : base() { } - protected override void InitializeTestHost(bool isUseAuthorization, Action serviceCollection) - { - serviceCollection = (services) => - { - services.AddScoped(); - services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => - { - options.TokenValidationParameters = new TokenValidationParameters - { - ValidateIssuer = true, - ValidateAudience = true, - ValidateLifetime = true, - ValidateIssuerSigningKey = true, - ValidIssuer = "https://github.com/easymicroservices", - ValidAudience = "easymicroservices", - IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("VGhpc0lzQVNlY3JldEtleUZvckp3dEF1dGhlbnRpY2F0aW9u=")) - }; - }); - }; - base.InitializeTestHost(true, serviceCollection); - } - protected override void AssertTrue(MessageContract messageContract) { Assert.False(messageContract.IsSuccess); @@ -66,7 +45,7 @@ protected override void AuthorizeAssert(MessageContract messageContract) public async Task WriterRoleTest(string microserviceName, string roleName, string serviceName, string methodName, bool result) { int portNumber = 1045; - AspCoreAuthorization.AuthenticationRouteAddress = $"http://{localhost}:{portNumber}"; + AspCoreAuthorization.AuthenticationRouteAddress = $"http://localhost:{portNumber}"; await AuthenticationVirtualTestManager.OnInitialize(portNumber); var resources = AuthenticationResource.GetResources(microserviceName, new Dictionary>() { @@ -110,7 +89,7 @@ public async Task WriterRoleTest(string microserviceName, string roleName, strin public async Task ReaderRoleTest(string microserviceName, string roleName, string serviceName) { int portNumber = 1045; - AspCoreAuthorization.AuthenticationRouteAddress = $"http://{localhost}:{portNumber}"; + AspCoreAuthorization.AuthenticationRouteAddress = $"http://localhost:{portNumber}"; await AuthenticationVirtualTestManager.OnInitialize(portNumber); var resources = AuthenticationResource.GetResources(microserviceName, new Dictionary>() { diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/AuthorizationTests.cs b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/AuthorizationTests.cs index bcafdfb..5ed26ff 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/AuthorizationTests.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/AuthorizationTests.cs @@ -1,22 +1,11 @@ -using EasyMicroservices.Cores.AspCoreApi.Interfaces; +using EasyMicroservices.Cores.AspCore.Tests.Fixtures; using EasyMicroservices.ServiceContracts; namespace EasyMicroservices.Cores.AspCore.Tests { - public abstract class AuthorizationTests : BasicTests + public class AuthorizationTests : BasicTests, IClassFixture { - public override int AppPort => 4565; - public AuthorizationTests() : base() - { } - - protected override void InitializeTestHost(bool isUseAuthorization, Action serviceCollection) - { - serviceCollection = (services) => - { - services.AddScoped(); - }; - base.InitializeTestHost(true, serviceCollection); - } + public override int AppPort { get; } = 4565; protected override void AssertTrue(MessageContract messageContract) { diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs index b88c479..b017ccf 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs @@ -1,4 +1,5 @@ -using EasyMicroservices.Cores.Database.Managers; +using EasyMicroservices.Cores.AspCore.Tests.Fixtures; +using EasyMicroservices.Cores.Database.Managers; using EasyMicroservices.Cores.Tests.Contracts.Common; using EasyMicroservices.Cores.Tests.Fixtures; using EasyMicroservices.ServiceContracts; @@ -6,43 +7,15 @@ namespace EasyMicroservices.Cores.AspCore.Tests { - public abstract class BasicTests : WhiteLabelLaboratoryFixture + public abstract class BasicTests : IClassFixture { - public BasicTests() - { - InitializeTestHost(false, null); - } - public virtual int AppPort { get; } = 4564; - protected virtual void InitializeTestHost(bool isUseAuthorization, Action serviceCollection) - { - Exception exception = default; - TaskCompletionSource taskCompletionSource = new TaskCompletionSource(); - Thread thread = new Thread(async () => - { - try - { - await Startup.Run(AppPort, serviceCollection, null); - } - catch (Exception ex) - { - exception = ex; - } - finally - { - taskCompletionSource.SetResult(); - } - }); - thread.Start(); - taskCompletionSource.Task.GetAwaiter().GetResult(); - if (exception != default) - throw new Exception("see inner", exception); - } - + protected static HttpClient HttpClient { get; set; } = new HttpClient(); + public abstract int AppPort { get; } string RouteAddress { get { - return $"http://{localhost}:{AppPort}"; + return $"http://localhost:{AppPort}"; } } @@ -86,13 +59,15 @@ public async Task AddUser() UserName = "Ali", UniqueIdentity = "1-2" }); - var result = JsonConvert.DeserializeObject(await data.Content.ReadAsStringAsync()); + var jsondata = await data.Content.ReadAsStringAsync(); + var result = JsonConvert.DeserializeObject(jsondata); AssertTrue(result); var getAllRespone = await Get_EndpointsReturnSuccessAndCorrectContentType(); var users = JsonConvert.DeserializeObject>(getAllRespone); AssertTrue(users); if (users.IsSuccess) - AssertTrue(users.Result.All(x => DefaultUniqueIdentityManager.DecodeUniqueIdentity(x.UniqueIdentity).Length > 2)); + Assert.True(users.Result.All(x => DefaultUniqueIdentityManager.DecodeUniqueIdentity(x.UniqueIdentity).Length > 2), + JsonConvert.SerializeObject(users.Result)); } protected virtual void AuthorizeAssert(MessageContract messageContract) diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Fixtures/AuthorizationFixture.cs b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Fixtures/AuthorizationFixture.cs new file mode 100644 index 0000000..e04582d --- /dev/null +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Fixtures/AuthorizationFixture.cs @@ -0,0 +1,20 @@ +using EasyMicroservices.Cores.AspCoreApi.Interfaces; + +namespace EasyMicroservices.Cores.AspCore.Tests.Fixtures; + +public class AuthorizationFixture : IAsyncLifetime +{ + public IServiceProvider ServiceProvider { get; private set; } + public Task InitializeAsync() + { + return BaseFixture.Init(4565, (sc) => + { + sc.AddScoped(); + }); + } + + public Task DisposeAsync() + { + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Fixtures/AuthorizationRolePermissionsFixture.cs b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Fixtures/AuthorizationRolePermissionsFixture.cs new file mode 100644 index 0000000..052bb3d --- /dev/null +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Fixtures/AuthorizationRolePermissionsFixture.cs @@ -0,0 +1,37 @@ +using EasyMicroservices.Cores.AspCoreApi.Authorizations; +using EasyMicroservices.Cores.AspCoreApi.Interfaces; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.IdentityModel.Tokens; +using System.Text; + +namespace EasyMicroservices.Cores.AspCore.Tests.Fixtures; + +public class AuthorizationRolePermissionsFixture : IAsyncLifetime +{ + public IServiceProvider ServiceProvider { get; private set; } + public Task InitializeAsync() + { + return BaseFixture.Init(4566, (services) => + { + services.AddScoped(); + services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => + { + options.TokenValidationParameters = new TokenValidationParameters + { + ValidateIssuer = true, + ValidateAudience = true, + ValidateLifetime = true, + ValidateIssuerSigningKey = true, + ValidIssuer = "https://github.com/easymicroservices", + ValidAudience = "easymicroservices", + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("VGhpc0lzQVNlY3JldEtleUZvckp3dEF1dGhlbnRpY2F0aW9u=")) + }; + }); + }); + } + + public Task DisposeAsync() + { + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Fixtures/BaseFixture.cs b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Fixtures/BaseFixture.cs new file mode 100644 index 0000000..f3ecf18 --- /dev/null +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Fixtures/BaseFixture.cs @@ -0,0 +1,36 @@ +using EasyMicroservices.Cores.AspCore.Tests.Controllers; +using EasyMicroservices.Cores.AspCoreApi.Managers; +using EasyMicroservices.Cores.AspEntityFrameworkCoreApi; +using EasyMicroservices.Cores.AspEntityFrameworkCoreApi.Interfaces; +using EasyMicroservices.Cores.Database.Interfaces; +using EasyMicroservices.Cores.Database.Managers; +using EasyMicroservices.Cores.Relational.EntityFrameworkCore.Intrerfaces; +using EasyMicroservices.Cores.Tests.DatabaseLogics.Database.Contexts; + +namespace EasyMicroservices.Cores.AspCore.Tests.Fixtures; + +public class BaseFixture +{ + public static async Task Init(long port, Action changeCollection = null) + { + string microserviceName = "TestExample"; + WebApplicationBuilder app = StartUpExtensions.Create(null); + app.Services.Builder(); + app.Services.AddTransient((serviceProvider) => new UnitOfWork(serviceProvider)); + app.Services.AddTransient(serviceProvider => new MyTestContext(serviceProvider.GetService())); + app.Services.AddTransient(); + app.Services.AddSingleton(service => new WhiteLabelManager(service)); + app.Services.AddSingleton((provider) => + { + return new DefaultUniqueIdentityManager(provider.GetService().CurrentWhiteLabel); + }); + changeCollection?.Invoke(app.Services); + StartUpExtensions.AddWhiteLabelRoute(microserviceName, $"http://localhost:6041"); + app.Services.AddControllers().AddApplicationPart(typeof(UserController).Assembly); + app.WebHost.UseUrls($"http://localhost:{port}"); + var build = await app.Build(true); + build.MapControllers(); + _ = build.RunAsync(); + return build.Services; + } +} diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Fixtures/NormalFixture.cs b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Fixtures/NormalFixture.cs new file mode 100644 index 0000000..17648c6 --- /dev/null +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Fixtures/NormalFixture.cs @@ -0,0 +1,15 @@ +namespace EasyMicroservices.Cores.AspCore.Tests.Fixtures; + +public class NormalFixture : IAsyncLifetime +{ + public IServiceProvider ServiceProvider { get; private set; } + public Task InitializeAsync() + { + return BaseFixture.Init(4564); + } + + public Task DisposeAsync() + { + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/NormalTests.cs b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/NormalTests.cs new file mode 100644 index 0000000..8c3f09b --- /dev/null +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/NormalTests.cs @@ -0,0 +1,8 @@ +using EasyMicroservices.Cores.AspCore.Tests.Fixtures; + +namespace EasyMicroservices.Cores.AspCore.Tests; + +public class NormalTests : BasicTests, IClassFixture +{ + public override int AppPort { get; } = 4564; +} diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs index 2e7c9cf..a201bb2 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs @@ -6,7 +6,6 @@ using EasyMicroservices.Cores.Tests.DatabaseLogics.Database.Contexts; using EasyMicroservices.Cores.Tests.DatabaseLogics.Database.Entities; using Microsoft.EntityFrameworkCore; -using System.Text; namespace EasyMicroservices.Cores.AspCore.Tests { @@ -20,9 +19,10 @@ public static async Task Main(string[] args) app.Services.AddScoped((serviceProvider) => new UnitOfWork(serviceProvider).GetLongContractLogic()); app.Services.AddTransient(serviceProvider => new MyTestContext(serviceProvider.GetService())); app.Services.AddScoped(serviceProvider => new DatabaseBuilder()); + app.Services.AddSingleton(service => new WhiteLabelManager(service)); app.Services.AddSingleton((provider) => { - return new DefaultUniqueIdentityManager(WhiteLabelManager.CurrentWhiteLabel); + return new DefaultUniqueIdentityManager(provider.GetService().CurrentWhiteLabel); }); StartUpExtensions.AddWhiteLabel(microserviceName, "RootAddresses:WhiteLabel"); var build = await app.Build(); diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Startup.cs b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Startup.cs index 5f72ad7..7c99314 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Startup.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Startup.cs @@ -8,7 +8,6 @@ using EasyMicroservices.Cores.Relational.EntityFrameworkCore.Intrerfaces; using EasyMicroservices.Cores.Tests.DatabaseLogics.Database.Contexts; using EasyMicroservices.ServiceContracts; -using System.Text; namespace EasyMicroservices.Cores.AspCore.Tests { @@ -22,9 +21,10 @@ static WebApplicationBuilder CreateBuilder(long port) app.Services.AddTransient((serviceProvider) => new UnitOfWork(serviceProvider)); app.Services.AddTransient(serviceProvider => new MyTestContext(serviceProvider.GetService())); app.Services.AddTransient(); + app.Services.AddSingleton(service => new WhiteLabelManager(service)); app.Services.AddSingleton((provider) => { - return new DefaultUniqueIdentityManager(WhiteLabelManager.CurrentWhiteLabel); + return new DefaultUniqueIdentityManager(provider.GetService().CurrentWhiteLabel); }); StartUpExtensions.AddWhiteLabelRoute(microserviceName, $"http://localhost:6041"); app.Services.AddControllers().AddApplicationPart(typeof(UserController).Assembly); diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Authorizations/AspCoreAuthorization.cs b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Authorizations/AspCoreAuthorization.cs index c3f8739..fa1025a 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Authorizations/AspCoreAuthorization.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/Authorizations/AspCoreAuthorization.cs @@ -28,7 +28,6 @@ public class AspCoreAuthorization : IAuthorization public AspCoreAuthorization(IBaseUnitOfWork baseUnitOfWork) { BaseUnitOfWork = baseUnitOfWork; - UniqueIdentityManager = baseUnitOfWork.GetUniqueIdentityManager(); } /// @@ -38,10 +37,6 @@ public AspCoreAuthorization(IBaseUnitOfWork baseUnitOfWork) /// /// /// - public IUniqueIdentityManager UniqueIdentityManager { get; } - /// - /// - /// public static string AuthenticationRouteAddress { get; set; } /// /// diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/Managers/WhiteLabelManager.cs b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/Managers/WhiteLabelManager.cs index 70ebc31..b19a82e 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/Managers/WhiteLabelManager.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/Managers/WhiteLabelManager.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; using System.Net.Http; +using System.Threading; using System.Threading.Tasks; using WhiteLables.GeneratedServices; @@ -17,7 +18,11 @@ namespace EasyMicroservices.Cores.AspCoreApi.Managers /// public class WhiteLabelManager { - internal WhiteLabelManager(IServiceProvider serviceProvider) + /// + /// + /// + /// + public WhiteLabelManager(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; } @@ -30,19 +35,13 @@ internal WhiteLabelManager(IServiceProvider serviceProvider) /// /// /// - public static bool IsInitialized - { - get - { - return _CurrentWhiteLabel is not null; - } - } + public bool IsInitialized { get; set; } - static WhiteLabelInfo _CurrentWhiteLabel; + WhiteLabelInfo _CurrentWhiteLabel; /// /// /// - public static WhiteLabelInfo CurrentWhiteLabel + public WhiteLabelInfo CurrentWhiteLabel { get { @@ -66,6 +65,7 @@ string GetDefaultUniqueIdentity(ICollection whiteLables, lon return $"{DefaultUniqueIdentityManager.GenerateUniqueIdentity(found.Id)}-{GetDefaultUniqueIdentity(whiteLables, found.Id)}".Trim('-'); } + static SemaphoreSlim SemaphoreSlim { get; set; } = new SemaphoreSlim(1); /// /// /// @@ -75,88 +75,98 @@ string GetDefaultUniqueIdentity(ICollection whiteLables, lon /// public async Task Initialize(string microserviceName, string whiteLableRoute, params Type[] dbContextTypes) { - if (IsInitialized) - return CurrentWhiteLabel; - microserviceName.ThrowIfNullOrEmpty(nameof(microserviceName)); - microserviceName.ThrowIfNullOrEmpty(nameof(whiteLableRoute)); - Console.WriteLine($"WhiteLabelManager Initialize! {microserviceName} {whiteLableRoute}"); - if (dbContextTypes.IsEmpty()) - return CurrentWhiteLabel; - var whiteLabelClient = new WhiteLables.GeneratedServices.WhiteLabelClient(whiteLableRoute, HttpClient); - var whiteLabels = await whiteLabelClient.GetAllAsync().AsCheckedResult(x => x.Result).ConfigureAwait(false); - var defaultUniqueIdentity = GetDefaultUniqueIdentity(whiteLabels, null); - - var microserviceClient = new WhiteLables.GeneratedServices.MicroserviceClient(whiteLableRoute, HttpClient); - var microservices = await microserviceClient.GetAllAsync().ConfigureAwait(false); - var foundMicroservice = microservices.Result.FirstOrDefault(x => x.Name.Equals(microserviceName, StringComparison.OrdinalIgnoreCase)); - if (foundMicroservice == null) + try { - foundMicroservice = new WhiteLables.GeneratedServices.MicroserviceContract() + await SemaphoreSlim.WaitAsync(); + if (IsInitialized) + return CurrentWhiteLabel; + microserviceName.ThrowIfNullOrEmpty(nameof(microserviceName)); + microserviceName.ThrowIfNullOrEmpty(nameof(whiteLableRoute)); + Console.WriteLine($"WhiteLabelManager Initialize! {microserviceName} {whiteLableRoute}"); + if (dbContextTypes.IsEmpty()) + return CurrentWhiteLabel; + var whiteLabelClient = new WhiteLables.GeneratedServices.WhiteLabelClient(whiteLableRoute, HttpClient); + var whiteLabels = await whiteLabelClient.GetAllAsync().AsCheckedResult(x => x.Result).ConfigureAwait(false); + var defaultUniqueIdentity = GetDefaultUniqueIdentity(whiteLabels, null); + + var microserviceClient = new WhiteLables.GeneratedServices.MicroserviceClient(whiteLableRoute, HttpClient); + var microservices = await microserviceClient.GetAllAsync().ConfigureAwait(false); + var foundMicroservice = microservices.Result.FirstOrDefault(x => x.Name.Equals(microserviceName, StringComparison.OrdinalIgnoreCase)); + if (foundMicroservice == null) + { + foundMicroservice = new WhiteLables.GeneratedServices.MicroserviceContract() + { + InstanceIndex = 1, + Name = microserviceName, + Description = "Automatically added" + }; + var addMicroservice = await microserviceClient.AddAsync(foundMicroservice).ConfigureAwait(false); + foundMicroservice.Id = addMicroservice.Result; + } + + CurrentWhiteLabel = new WhiteLabelInfo() { - InstanceIndex = 1, - Name = microserviceName, - Description = "Automatically added" + MicroserviceId = foundMicroservice.Id, + MicroserviceName = microserviceName, + StartUniqueIdentity = defaultUniqueIdentity }; - var addMicroservice = await microserviceClient.AddAsync(foundMicroservice).ConfigureAwait(false); - foundMicroservice.Id = addMicroservice.Result; - } - CurrentWhiteLabel = new WhiteLabelInfo() - { - MicroserviceId = foundMicroservice.Id, - MicroserviceName = microserviceName, - StartUniqueIdentity = defaultUniqueIdentity - }; - var uniqueIdentityManager = new UnitOfWork(_serviceProvider).GetUniqueIdentityManager() as DefaultUniqueIdentityManager; + var uniqueIdentityManager = new UnitOfWork(_serviceProvider).GetUniqueIdentityManager() as DefaultUniqueIdentityManager; - var microserviceContextTableClient = new WhiteLables.GeneratedServices.MicroserviceContextTableClient(whiteLableRoute, HttpClient); - var microserviceContextTables = await microserviceContextTableClient.GetAllAsync().ConfigureAwait(false); + var microserviceContextTableClient = new WhiteLables.GeneratedServices.MicroserviceContextTableClient(whiteLableRoute, HttpClient); + var microserviceContextTables = await microserviceContextTableClient.GetAllAsync().ConfigureAwait(false); - HashSet addedInWhitLabels = new HashSet(); - foreach (var contextTableContract in microserviceContextTables.Result) - { - uniqueIdentityManager.InitializeTables(contextTableContract.MicroserviceId, contextTableContract.ContextName, contextTableContract.TableName, contextTableContract.ContextTableId); - addedInWhitLabels.Add(uniqueIdentityManager.GetContextTableName(contextTableContract.MicroserviceId, contextTableContract.ContextName, contextTableContract.TableName)); - } + HashSet addedInWhitLabels = new HashSet(); + foreach (var contextTableContract in microserviceContextTables.Result) + { + uniqueIdentityManager.InitializeTables(contextTableContract.MicroserviceId, contextTableContract.ContextName, contextTableContract.TableName, contextTableContract.ContextTableId); + addedInWhitLabels.Add(uniqueIdentityManager.GetContextTableName(contextTableContract.MicroserviceId, contextTableContract.ContextName, contextTableContract.TableName)); + } - foreach (var contextType in dbContextTypes) - { - var contextTableClient = new WhiteLables.GeneratedServices.ContextTableClient(whiteLableRoute, HttpClient); - var contextTables = await contextTableClient.GetAllAsync().ConfigureAwait(false); - using var instanceOfContext = _serviceProvider.GetService(contextType) as DbContext; - string contextName = uniqueIdentityManager.GetContextName(contextType); - foreach (var entityType in instanceOfContext.Model.GetEntityTypes()) + foreach (var contextType in dbContextTypes) { - string tableName = entityType.ServiceOnlyConstructorBinding.RuntimeType.Name; - var tableFullName = uniqueIdentityManager.GetContextTableName(foundMicroservice.Id, contextType.Name, tableName); - if (!addedInWhitLabels.Contains(tableFullName)) + var contextTableClient = new WhiteLables.GeneratedServices.ContextTableClient(whiteLableRoute, HttpClient); + var contextTables = await contextTableClient.GetAllAsync().ConfigureAwait(false); + using var instanceOfContext = _serviceProvider.GetService(contextType) as DbContext; + string contextName = uniqueIdentityManager.GetContextName(contextType); + foreach (var entityType in instanceOfContext.Model.GetEntityTypes()) { - if (microserviceContextTables.Result.Any(x => x.ContextName == contextName && x.TableName == tableName && x.MicroserviceId == foundMicroservice.Id)) - continue; - var contextTable = contextTables.Result.FirstOrDefault(x => x.ContextName == contextName && x.TableName == tableName); - if (contextTable == null) + string tableName = entityType.ServiceOnlyConstructorBinding.RuntimeType.Name; + var tableFullName = uniqueIdentityManager.GetContextTableName(foundMicroservice.Id, contextType.Name, tableName); + if (!addedInWhitLabels.Contains(tableFullName)) { - contextTable = new WhiteLables.GeneratedServices.ContextTableContract() + if (microserviceContextTables.Result.Any(x => x.ContextName == contextName && x.TableName == tableName && x.MicroserviceId == foundMicroservice.Id)) + continue; + var contextTable = contextTables.Result.FirstOrDefault(x => x.ContextName == contextName && x.TableName == tableName); + if (contextTable == null) + { + contextTable = new WhiteLables.GeneratedServices.ContextTableContract() + { + ContextName = contextName, + TableName = tableName, + }; + var contextTableResult = await contextTableClient.AddAsync(contextTable).ConfigureAwait(false); + contextTable.Id = contextTableResult.Result; + } + var addedMicroserviceContextTable = await microserviceContextTableClient.AddAsync(new WhiteLables.GeneratedServices.MicroserviceContextTableContract() { ContextName = contextName, TableName = tableName, - }; - var contextTableResult = await contextTableClient.AddAsync(contextTable).ConfigureAwait(false); - contextTable.Id = contextTableResult.Result; + MicroserviceName = microserviceName, + MicroserviceId = foundMicroservice.Id, + ContextTableId = contextTable.Id + }).ConfigureAwait(false); + uniqueIdentityManager.InitializeTables(foundMicroservice.Id, contextName, tableName, contextTable.Id); } - var addedMicroserviceContextTable = await microserviceContextTableClient.AddAsync(new WhiteLables.GeneratedServices.MicroserviceContextTableContract() - { - ContextName = contextName, - TableName = tableName, - MicroserviceName = microserviceName, - MicroserviceId = foundMicroservice.Id, - ContextTableId = contextTable.Id - }).ConfigureAwait(false); - uniqueIdentityManager.InitializeTables(foundMicroservice.Id, contextName, tableName, contextTable.Id); } } + IsInitialized = true; + return CurrentWhiteLabel; + } + finally + { + SemaphoreSlim.Release(); } - return CurrentWhiteLabel; } } } diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/StartUpExtensions.cs b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/StartUpExtensions.cs index cb26595..0fd91b1 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/StartUpExtensions.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/StartUpExtensions.cs @@ -65,9 +65,10 @@ public static IServiceCollection Builder(this IServiceCollection servi services.AddHttpContextAccessor(); services.AddScoped(service => new UnitOfWork(service)); services.AddScoped(); + services.AddSingleton(service => new WhiteLabelManager(service)); services.AddSingleton((provider) => { - return new DefaultUniqueIdentityManager(WhiteLabelManager.CurrentWhiteLabel); + return new DefaultUniqueIdentityManager(provider.GetService().CurrentWhiteLabel); }); services.AddScoped(service => new UnitOfWork(service).GetMapper()); services.AddTransient(serviceProvider => serviceProvider.GetService()); diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs index 2d822dd..02e94c2 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs @@ -364,9 +364,10 @@ public virtual Task InitializeWhiteLabel(string microserviceName, string whiteLa throw new ObjectDisposedException(nameof(ServiceProvider)); _InitializeWhiteLabel = async (serviceProvider) => { - if (!WhiteLabelManager.IsInitialized) - return await new WhiteLabelManager(serviceProvider).Initialize(microserviceName, whiteLableRoute, dbContextTypes); - return WhiteLabelManager.CurrentWhiteLabel; + var whiteLabelManager = serviceProvider.GetService(); + if (!whiteLabelManager.IsInitialized) + return await whiteLabelManager.Initialize(microserviceName, whiteLableRoute, dbContextTypes); + return whiteLabelManager.CurrentWhiteLabel; }; return Task.CompletedTask; } diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IUniqueIdentityManager.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IUniqueIdentityManager.cs index 532aa5b..347055b 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IUniqueIdentityManager.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IUniqueIdentityManager.cs @@ -15,11 +15,10 @@ public interface IUniqueIdentityManager /// update unique identity /// /// - /// /// /// /// is need update database - Task UpdateUniqueIdentity(IBaseUnitOfWork baseUnitOfWork, IContext context, TEntity entity); + bool UpdateUniqueIdentity(IContext context, TEntity entity); /// /// /// diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs index 0e78edb..7b24758 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs @@ -27,7 +27,6 @@ public class DatabaseLogicInfrastructure : IDisposable /// /// internal protected readonly IMapperProvider MapperProvider; - readonly IUniqueIdentityManager _uniqueIdentityManager; readonly IBaseUnitOfWork _baseUnitOfWork; /// /// @@ -37,9 +36,12 @@ public DatabaseLogicInfrastructure(IBaseUnitOfWork baseUnitOfWork) { _baseUnitOfWork = baseUnitOfWork; MapperProvider = baseUnitOfWork.GetMapper(); - _uniqueIdentityManager = baseUnitOfWork.GetUniqueIdentityManager(); } - + async Task GetIUniqueIdentityManager() + { + await _baseUnitOfWork.InitializeWhiteLabel(); + return _baseUnitOfWork.GetUniqueIdentityManager(); + } /// /// /// @@ -55,15 +57,16 @@ protected virtual void ValidateMappedResult(ref T value) private IEasyReadableQueryableAsync UniqueIdentityQueryMaker(IEasyReadableQueryableAsync easyReadableQueryable, string uniqueIdentity, GetUniqueIdentityType type) where TEntity : class { + var uniqueIdentityManager = _baseUnitOfWork.GetUniqueIdentityManager(); IEasyReadableQueryableAsync queryable = easyReadableQueryable; - if (!_uniqueIdentityManager.IsUniqueIdentityForThisTable(easyReadableQueryable.Context, uniqueIdentity)) + if (!uniqueIdentityManager.IsUniqueIdentityForThisTable(easyReadableQueryable.Context, uniqueIdentity)) uniqueIdentity += "-"; bool isEndWithDash = uniqueIdentity.EndsWith("-"); bool doEqual = false; if (type == GetUniqueIdentityType.OnlyParent) { - var tableUniqueIdentity = _uniqueIdentityManager.GetTableUniqueIdentity(easyReadableQueryable.Context); - var lastTableUniqueIdentity = _uniqueIdentityManager.GetLastTableUniqueIdentity(uniqueIdentity); + var tableUniqueIdentity = uniqueIdentityManager.GetTableUniqueIdentity(easyReadableQueryable.Context); + var lastTableUniqueIdentity = uniqueIdentityManager.GetLastTableUniqueIdentity(uniqueIdentity); doEqual = tableUniqueIdentity.Equals(lastTableUniqueIdentity); if (!isEndWithDash && !doEqual) @@ -75,7 +78,7 @@ private IEasyReadableQueryableAsync UniqueIdentityQueryMaker(I { if (!isEndWithDash) uniqueIdentity += "-"; - uniqueIdentity += _uniqueIdentityManager.GetLastTableUniqueIdentity(uniqueIdentity) + "-"; + uniqueIdentity += uniqueIdentityManager.GetLastTableUniqueIdentity(uniqueIdentity) + "-"; } if (doEqual) queryable = queryable.ConvertToReadable(queryable.Where(x => (x as IUniqueIdentitySchema).UniqueIdentity.Equals(uniqueIdentity))); @@ -734,7 +737,8 @@ public async Task> Add(IEasyWritableQueryableA } } await easyWritableQueryable.SaveChangesAsync(); - if (await _uniqueIdentityManager.UpdateUniqueIdentity(_baseUnitOfWork, easyWritableQueryable.Context, result.Entity)) + var uniqueIdentityManager = await GetIUniqueIdentityManager(); + if (uniqueIdentityManager.UpdateUniqueIdentity(easyWritableQueryable.Context, result.Entity)) { await InternalUpdate(easyWritableQueryable, result.Entity, false, true, true, cancellationToken); await easyWritableQueryable.SaveChangesAsync(); @@ -765,9 +769,10 @@ public async Task AddBulk(IEasyWritableQueryableAsync< } await easyWritableQueryable.SaveChangesAsync(); bool anyUpdate = false; + var uniqueIdentityManager = await GetIUniqueIdentityManager(); foreach (var item in result) { - if (await _uniqueIdentityManager.UpdateUniqueIdentity(_baseUnitOfWork, easyWritableQueryable.Context, item.Entity)) + if (uniqueIdentityManager.UpdateUniqueIdentity(easyWritableQueryable.Context, item.Entity)) { anyUpdate = true; } diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Managers/DefaultUniqueIdentityManager.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Managers/DefaultUniqueIdentityManager.cs index 1937d4d..54d1ad6 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Managers/DefaultUniqueIdentityManager.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Managers/DefaultUniqueIdentityManager.cs @@ -29,20 +29,18 @@ public DefaultUniqueIdentityManager(WhiteLabelInfo whiteLabelInfo) /// /// /// - /// /// /// /// /// - public async Task UpdateUniqueIdentity(IBaseUnitOfWork baseUnitOfWork, IContext context, TEntity entity) + public bool UpdateUniqueIdentity(IContext context, TEntity entity) { if (entity is IUniqueIdentitySchema uniqueIdentitySchema) { - var whiteLabel = await baseUnitOfWork.InitializeWhiteLabel(); if (uniqueIdentitySchema.UniqueIdentity.IsNullOrEmpty()) - uniqueIdentitySchema.UniqueIdentity = whiteLabel.StartUniqueIdentity; + uniqueIdentitySchema.UniqueIdentity = _whiteLabelInfo.StartUniqueIdentity; var ids = uniqueIdentitySchema.UniqueIdentity.IsNullOrEmpty() ? null : DecodeUniqueIdentity(uniqueIdentitySchema.UniqueIdentity); - if (TableIds.TryGetValue(GetContextTableName(context.ContextType, whiteLabel.MicroserviceId), out long tableId)) + if (TableIds.TryGetValue(GetContextTableName(context.ContextType, _whiteLabelInfo.MicroserviceId), out long tableId)) { if (entity is IIdSchema longIdSchema) { @@ -52,6 +50,10 @@ public async Task UpdateUniqueIdentity(IBaseUnitOfWork baseUnitOf { uniqueIdentitySchema.UniqueIdentity = ids.IsEmpty() ? GenerateUniqueIdentity(tableId, intIdSchema.Id) : GenerateUniqueIdentity(ids, tableId, intIdSchema.Id); } + } + else + { + } return true; } diff --git a/src/CSharp/EasyMicroservices.Cores.Tests/DatabaseLogics/LongIdMappedDatabaseLogicBaseTest.cs b/src/CSharp/EasyMicroservices.Cores.Tests/DatabaseLogics/LongIdMappedDatabaseLogicBaseTest.cs index 8efaf43..84ddcfd 100644 --- a/src/CSharp/EasyMicroservices.Cores.Tests/DatabaseLogics/LongIdMappedDatabaseLogicBaseTest.cs +++ b/src/CSharp/EasyMicroservices.Cores.Tests/DatabaseLogics/LongIdMappedDatabaseLogicBaseTest.cs @@ -26,7 +26,7 @@ public void OnConfiguring(DbContextOptionsBuilder optionsBuilder) } } - public abstract class LongIdMappedDatabaseLogicBaseTest : IClassFixture, IClassFixture + public class LongIdMappedDatabaseLogicBaseTest : IClassFixture, IClassFixture { private readonly IServiceProvider _serviceProvider; public LongIdMappedDatabaseLogicBaseTest(ServiceProviderFixture fixture) @@ -74,7 +74,7 @@ public virtual IDatabase GetDatabase() return new EntityFrameworkCoreDatabaseProvider(new MyTestContext(new DatabaseBuilder())); } - const long TableContextId = 150; + const long TableContextId = 9; const long ProfileTableContextId = 151; const long CategoryTableContextId = 152; const long SubjectTableContextId = 153; diff --git a/src/CSharp/EasyMicroservices.Cores.Tests/EasyMicroservices.Cores.Tests.csproj b/src/CSharp/EasyMicroservices.Cores.Tests/EasyMicroservices.Cores.Tests.csproj index 2f9f8e2..39f6cd8 100644 --- a/src/CSharp/EasyMicroservices.Cores.Tests/EasyMicroservices.Cores.Tests.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Tests/EasyMicroservices.Cores.Tests.csproj @@ -19,7 +19,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - + @@ -33,6 +33,7 @@ + diff --git a/src/CSharp/EasyMicroservices.Cores.Tests/Fixtures/ServiceProviderFixture.cs b/src/CSharp/EasyMicroservices.Cores.Tests/Fixtures/ServiceProviderFixture.cs index 11ac15a..588bf58 100644 --- a/src/CSharp/EasyMicroservices.Cores.Tests/Fixtures/ServiceProviderFixture.cs +++ b/src/CSharp/EasyMicroservices.Cores.Tests/Fixtures/ServiceProviderFixture.cs @@ -9,7 +9,6 @@ using EasyMicroservices.Cores.Tests.Database; using EasyMicroservices.Cores.Tests.DatabaseLogics.Database.Contexts; using Microsoft.Extensions.DependencyInjection; -using System.Text; namespace EasyMicroservices.Cores.Tests.Fixtures { @@ -21,6 +20,7 @@ public ServiceProviderFixture() { } + public async Task InitializeAsync() { var serviceCollection = new ServiceCollection(); @@ -28,9 +28,10 @@ public async Task InitializeAsync() serviceCollection.AddTransient(); serviceCollection.AddTransient(serviceProvider => new MyTestContext(serviceProvider.GetService())); serviceCollection.AddTransient(); + serviceCollection.AddSingleton(service => new WhiteLabelManager(service)); serviceCollection.AddSingleton((provider) => { - return new DefaultUniqueIdentityManager(WhiteLabelManager.CurrentWhiteLabel); + return new DefaultUniqueIdentityManager(provider.GetService().CurrentWhiteLabel); }); StartUpExtensions.AddWhiteLabelRoute(microserviceName, $"http://localhost:6041"); serviceCollection.AddTransient(); diff --git a/src/CSharp/EasyMicroservices.Cores.Tests/Fixtures/WhiteLabelLaboratoryFixture.cs b/src/CSharp/EasyMicroservices.Cores.Tests/Fixtures/WhiteLabelLaboratoryFixture.cs index c71b38d..6c0e6ea 100644 --- a/src/CSharp/EasyMicroservices.Cores.Tests/Fixtures/WhiteLabelLaboratoryFixture.cs +++ b/src/CSharp/EasyMicroservices.Cores.Tests/Fixtures/WhiteLabelLaboratoryFixture.cs @@ -1,12 +1,12 @@ using EasyMicroservices.Cores.Tests.Database; using EasyMicroservices.Cores.Tests.DatabaseLogics.Database.Contexts; -using EasyMicroservices.Payments.VirtualServerForTests.TestResources; using EasyMicroservices.WhiteLabelsMicroservice.VirtualServerForTests; +using EasyMicroservices.WhiteLabelsMicroservice.VirtualServerForTests.TestResources; using System.Text; namespace EasyMicroservices.Cores.Tests.Fixtures { - public class WhiteLabelLaboratoryFixture : IAsyncLifetime, IClassFixture + public class WhiteLabelLaboratoryFixture : IAsyncLifetime { public const string localhost = "127.0.0.1"; protected int Port = 6041; @@ -44,58 +44,58 @@ protected async Task OnInitialize() } } - //[Fact] - //public async Task WhiteLabelGetAllTest() - //{ - // var whiteLabelClient = new WhiteLables.GeneratedServices.WhiteLabelClient(_routeAddress, HttpClient); - // var all = await whiteLabelClient.GetAllAsync(); - // Assert.True(all.IsSuccess); - // Assert.True(all.Result.Count == 2); - // Assert.True(all.Result.All(x => x.Name.HasValue())); - //} + [Fact] + public async Task WhiteLabelGetAllTest() + { + var whiteLabelClient = new WhiteLables.GeneratedServices.WhiteLabelClient(_routeAddress, HttpClient); + var all = await whiteLabelClient.GetAllAsync(); + Assert.True(all.IsSuccess); + Assert.True(all.Result.Count == 2); + Assert.True(all.Result.All(x => x.Name.HasValue())); + } - //[Fact] - //public async Task MicroserviceGetAllTest() - //{ - // var client = new WhiteLables.GeneratedServices.MicroserviceClient(_routeAddress, HttpClient); - // var all = await client.GetAllAsync(); - // Assert.True(all.IsSuccess); - // Assert.True(all.Result.Count == 1); - // Assert.True(all.Result.All(x => x.Name == "TextExample")); - //} + [Fact] + public async Task MicroserviceGetAllTest() + { + var client = new WhiteLables.GeneratedServices.MicroserviceClient(_routeAddress, HttpClient); + var all = await client.GetAllAsync(); + Assert.True(all.IsSuccess); + Assert.True(all.Result.Count == 1); + Assert.True(all.Result.All(x => x.Name == "TextExample")); + } - //[Fact] - //public async Task MicroserviceAddTest() - //{ - // var client = new WhiteLables.GeneratedServices.MicroserviceClient(_routeAddress, HttpClient); - // var added = await client.AddAsync(new WhiteLables.GeneratedServices.MicroserviceContract() - // { - // Name = "TextExample", - // Description = "Automatically added" - // }); - // Assert.True(added.IsSuccess); - // Assert.True(added.Result == 1); - //} + [Fact] + public async Task MicroserviceAddTest() + { + var client = new WhiteLables.GeneratedServices.MicroserviceClient(_routeAddress, HttpClient); + var added = await client.AddAsync(new WhiteLables.GeneratedServices.MicroserviceContract() + { + Name = "TextExample", + Description = "Automatically added" + }); + Assert.True(added.IsSuccess); + Assert.True(added.Result == 1); + } - //[Fact] - //public async Task MicroserviceContextTableGetAllTest() - //{ - // var client = new WhiteLables.GeneratedServices.MicroserviceContextTableClient(_routeAddress, HttpClient); - // var all = await client.GetAllAsync(); - // Assert.True(all.IsSuccess); - // Assert.True(all.Result.Count >= 5); - // Assert.True(all.Result.All(x => x.MicroserviceName == "TextExample")); - //} + [Fact] + public async Task MicroserviceContextTableGetAllTest() + { + var client = new WhiteLables.GeneratedServices.MicroserviceContextTableClient(_routeAddress, HttpClient); + var all = await client.GetAllAsync(); + Assert.True(all.IsSuccess); + Assert.True(all.Result.Count >= 5); + Assert.True(all.Result.All(x => x.MicroserviceName == "TextExample")); + } - //[Fact] - //public async Task ContextTableGetAllTest() - //{ - // var client = new WhiteLables.GeneratedServices.ContextTableClient(_routeAddress, HttpClient); - // var all = await client.GetAllAsync(); - // Assert.True(all.IsSuccess); - // Assert.True(all.Result.Count >= 5); - //} + [Fact] + public async Task ContextTableGetAllTest() + { + var client = new WhiteLables.GeneratedServices.ContextTableClient(_routeAddress, HttpClient); + var all = await client.GetAllAsync(); + Assert.True(all.IsSuccess); + Assert.True(all.Result.Count >= 5); + } public async Task InitializeAsync() { From ffa74ad0c1ab778e0ca26b3c56fc2bed311b44c3 Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Mon, 27 Nov 2023 00:22:23 +0330 Subject: [PATCH 2/2] Add version --- .../EasyMicroservices.Cores.AspCoreApi.csproj | 2 +- .../EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj | 2 +- .../EasyMicroservices.Cores.Clients.csproj | 2 +- .../EasyMicroservices.Cores.Contracts.csproj | 2 +- .../EasyMicroservices.Cores.Database.csproj | 2 +- .../EasyMicroservices.Cores.EntityFrameworkCore.csproj | 2 +- ...asyMicroservices.Cores.Relational.EntityFrameworkCore.csproj | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj index ab38b5c..b7f1d66 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj @@ -4,7 +4,7 @@ net6.0;net7.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.0.54 + 0.0.0.55 asp core servces. EasyMicroservices@gmail.com core,cores,base,database,services,asp,aspnet diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj index 49a07c6..a705432 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj @@ -4,7 +4,7 @@ net6.0;net7.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.0.54 + 0.0.0.55 asp core servces. EasyMicroservices@gmail.com core,cores,base,database,services,asp,aspnet,aspcore,efcore diff --git a/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj b/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj index 48da6d2..f45c5ea 100644 --- a/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj @@ -4,7 +4,7 @@ netstandard2.0;netstandard2.1;net6.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.0.54 + 0.0.0.55 core of database. EasyMicroservices@gmail.com core,cores,base,client,clients diff --git a/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj b/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj index ad5925b..bf198dd 100644 --- a/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj @@ -4,7 +4,7 @@ netstandard2.0;netstandard2.1;net45;net6.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.0.54 + 0.0.0.55 core contracts. EasyMicroservices@gmail.com core,cores,base,contract,contracts,dto,dtos diff --git a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj index 2f0f5c7..4783e27 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj @@ -4,7 +4,7 @@ netstandard2.0;netstandard2.1;net45;net6.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.0.54 + 0.0.0.55 core of database. EasyMicroservices@gmail.com core,cores,base,database diff --git a/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj b/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj index 04d77d1..35e1217 100644 --- a/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj +++ b/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj @@ -4,7 +4,7 @@ net6.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.0.54 + 0.0.0.55 ef core of database. EasyMicroservices@gmail.com core,cores,base,database,ef,efcore diff --git a/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj index affdd7f..5ede0e8 100644 --- a/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj @@ -4,7 +4,7 @@ net6.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.0.54 + 0.0.0.55 ef core of Relational database. EasyMicroservices@gmail.com core,cores,base,database,ef,efcore,Relational