UnitTest.Core First Commit
This commit is contained in:
@@ -0,0 +1,157 @@
|
|||||||
|
using System;
|
||||||
|
using Unibase.Data.Sql;
|
||||||
|
using Unibase.Dependency;
|
||||||
|
using Unibase.Platform.Data;
|
||||||
|
using Unibase.Security.Principal;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Unibase.Data;
|
||||||
|
using System.Dynamic;
|
||||||
|
using Unibase.Platform.Managers;
|
||||||
|
|
||||||
|
namespace UnitTests.Core
|
||||||
|
{
|
||||||
|
public abstract class BaseUnitTest
|
||||||
|
{
|
||||||
|
private static AppIdentity _salesPersonIdentity = null;
|
||||||
|
private static AppIdentity _adminIdentity = null;
|
||||||
|
private static AppIdentity _hrIdentity = null;
|
||||||
|
private static AppIdentity _Identity = null;
|
||||||
|
private static bool _initialize = false;
|
||||||
|
// private static AppIdentity _Identity = null;
|
||||||
|
public AppIdentity GetAdminIdentity(string sessionid)
|
||||||
|
{
|
||||||
|
|
||||||
|
return _adminIdentity == null ? BuildAdminIdentity(sessionid) : _adminIdentity;
|
||||||
|
}
|
||||||
|
public AppIdentity GetIdentity(string sessionid)
|
||||||
|
{
|
||||||
|
|
||||||
|
return _Identity == null ? BuildIdentity(sessionid) : _Identity;
|
||||||
|
}
|
||||||
|
public AppIdentity GetSalesPersonIdentity(string sessionid)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
return _adminIdentity == null ? BuildSalesPersonIdentity(sessionid) : _adminIdentity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AppIdentity GetHrExecutiveIdentity()
|
||||||
|
{
|
||||||
|
return _adminIdentity == null ? BuildHrExecutiveIdentity() : _hrIdentity;
|
||||||
|
}
|
||||||
|
|
||||||
|
AppIdentity BuildAdminIdentity(string sessionid)
|
||||||
|
{
|
||||||
|
// _adminIdentity = new AppIdentity() { };
|
||||||
|
// DependencyConfig.Register(Unibase.Dependency.Enums.DIType.ServiceCollection);
|
||||||
|
// SqlDialect.Default(new Data.DbProviders.PgSqlDbProvider.DbContext().Dialect);
|
||||||
|
if (_initialize == false)
|
||||||
|
{
|
||||||
|
Initialize();
|
||||||
|
}
|
||||||
|
var identity = new Unibase.Security.Principal.AppIdentity("", 0);
|
||||||
|
var request = new SelectRequest(null)
|
||||||
|
{
|
||||||
|
Identity = identity
|
||||||
|
};
|
||||||
|
if (sessionid == null)
|
||||||
|
{
|
||||||
|
sessionid = "9e5af21ec1a24c0293fc3dda352cdd93 ";
|
||||||
|
}
|
||||||
|
//var _usermanger = DependencyConfig.Resolve<Unibase.Platform.Common.Managers.IUserManager>();
|
||||||
|
//var response = _usermanger.SignIn(request, "anji@gmail.com", "123456", true, false);
|
||||||
|
var response = Unibase.Platform.Membership.IdentityRegistry.GetIdentityByStaticSessionandTenantid(sessionid, 2);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
AppIdentity BuildIdentity(string sessionid)
|
||||||
|
{
|
||||||
|
// _adminIdentity = new AppIdentity() { };
|
||||||
|
// DependencyConfig.Register(Unibase.Dependency.Enums.DIType.ServiceCollection);
|
||||||
|
// SqlDialect.Default(new Data.DbProviders.PgSqlDbProvider.DbContext().Dialect);
|
||||||
|
if (_initialize == false)
|
||||||
|
{
|
||||||
|
Initialize();
|
||||||
|
}
|
||||||
|
var identity = new Unibase.Security.Principal.AppIdentity("", 0);
|
||||||
|
var request = new SelectRequest(null)
|
||||||
|
{
|
||||||
|
Identity = identity
|
||||||
|
};
|
||||||
|
if (sessionid == null)
|
||||||
|
{
|
||||||
|
sessionid = "9e5af21ec1a24c0293fc3dda352cdd93";
|
||||||
|
}
|
||||||
|
//var _usermanger = DependencyConfig.Resolve<Unibase.Platform.Common.Managers.IUserManager>();
|
||||||
|
//var response = _usermanger.SignIn(request, "anji@gmail.com", "123456", true, false);
|
||||||
|
var response = Unibase.Platform.Membership.IdentityRegistry.GetIdentityByStaticSessionandTenantid(sessionid, 2);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
AppIdentity BuildSalesPersonIdentity(string sessionid)
|
||||||
|
{
|
||||||
|
_salesPersonIdentity = new AppIdentity() { };
|
||||||
|
return _salesPersonIdentity;
|
||||||
|
}
|
||||||
|
AppIdentity BuildHrExecutiveIdentity()
|
||||||
|
{
|
||||||
|
_salesPersonIdentity = new AppIdentity() { };
|
||||||
|
return _salesPersonIdentity;
|
||||||
|
}
|
||||||
|
Boolean Initialize()
|
||||||
|
{
|
||||||
|
string commondbid = "0";
|
||||||
|
string tenantdbid = "1";
|
||||||
|
string connectionstring = "server=localhost;port=5432;Database=unittest_common;User id=postgres;Password=Bizgaze@123";
|
||||||
|
string tenantconnectionstring = "server=localhost;port=5432;Database=unittest_tenant;User id=postgres;Password=Bizgaze@123";
|
||||||
|
//Unibase.Web.Server.Startup(IConfiguration configuration);
|
||||||
|
// DependencyConfig.Register(Unibase.Dependency.Enums.DIType.ServiceCollection);
|
||||||
|
var container = DependencyConfig.GetContainer();
|
||||||
|
container.RegisterType<IRepository, Unibase.Platform.Data.NsDbRepository>("NsDbRepository");
|
||||||
|
container.RegisterType<IRepository, Unibase.Platform.Data.Repository>();
|
||||||
|
// DependencyConfig.Register(Unibase.Dependency.Enums.DIType.ServiceCollection);
|
||||||
|
SqlDialect.Default(new Unibase.Data.DbProviders.PgSqlDbProvider.DbContext().Dialect);
|
||||||
|
container.RegisterType<IDbContext, Unibase.Data.DbProviders.PgSqlDbProvider.DbContext>();
|
||||||
|
DbRegistry.RegisterDatabase(commondbid, connectionstring);
|
||||||
|
DbRegistry.RegisterDatabase(tenantdbid, tenantconnectionstring);
|
||||||
|
Unibase.Dependency.DependencyConfig.Resolve<IDbContext>();
|
||||||
|
_initialize = true;
|
||||||
|
return _initialize;
|
||||||
|
}
|
||||||
|
public ActionResponse Set( ActionRequest request ,string formuniqueid, ExpandoObject options)
|
||||||
|
{
|
||||||
|
//var request = new ActionRequest();
|
||||||
|
|
||||||
|
//if (request.Identity == null)
|
||||||
|
//{
|
||||||
|
// request.Identity = GetAdminIdentity();
|
||||||
|
//}
|
||||||
|
SelectRequest srequest = SelectRequest.FromRequest(request);
|
||||||
|
request.DisableEventLog = true;
|
||||||
|
// var _dataapimanger = DependencyConfig.Resolve<Unibase.Platform.DataSources.Managers.IDataApiManager>();
|
||||||
|
//var data = _dataapimanger.Set(request, options);
|
||||||
|
var _formmanager = DependencyConfig.Resolve<Unibase.Platform.Forms.Managers.IFormManager>();
|
||||||
|
if (!String.IsNullOrEmpty(formuniqueid))
|
||||||
|
{
|
||||||
|
var forminfo = _formmanager.GetForm(srequest, formuniqueid).Result;
|
||||||
|
if (forminfo != null)
|
||||||
|
{
|
||||||
|
var response = _formmanager.SaveDynForm(request, forminfo.FormId, options);
|
||||||
|
if (response.Status == ResponseStatus.Error)
|
||||||
|
{
|
||||||
|
return ActionResponse.CreateErrorResponse("error", response.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ActionResponse.CreateSuccessResponse("UnitTest Success");
|
||||||
|
|
||||||
|
}
|
||||||
|
public Unibase.Platform.Data.Enums.PermissionLevel CheckPermission(ActionRequest request)
|
||||||
|
{
|
||||||
|
SelectRequest srequest= SelectRequest.FromRequest(request);
|
||||||
|
BaseUnitTestManager _baseunittestmanager = new BaseUnitTestManager();
|
||||||
|
var permissionlevel = _baseunittestmanager.CheckPermission(srequest);
|
||||||
|
return permissionlevel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace UnitTests.Core
|
||||||
|
{
|
||||||
|
public class BaseUnitTestManager:Unibase.Platform.Managers.BaseManager
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Npgsql" Version="5.0.7" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\platform.common\Platform.Common\Platform.Common.csproj" />
|
||||||
|
<ProjectReference Include="..\..\platform\Platform.Objects\Platform.Objects.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Unibase.Core">
|
||||||
|
<HintPath>..\..\dlls_unibase\Unibase.Core.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Unibase.DbProviders.MongoDbProvider">
|
||||||
|
<HintPath>..\..\dlls_unibase\Unibase.DbProviders.MongoDbProvider.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Unibase.DbProviders.PgSqlDbProvider">
|
||||||
|
<HintPath>..\..\dlls_unibase\Unibase.DbProviders.PgSqlDbProvider.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Unibase.Platform.Apps">
|
||||||
|
<HintPath>..\..\dlls_unibase\Unibase.Platform.Apps.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Unibase.Platform.Core">
|
||||||
|
<HintPath>..\..\dlls_unibase\Unibase.Platform.Core.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Unibase.Platform.Membership">
|
||||||
|
<HintPath>..\..\dlls_unibase\Unibase.Platform.Membership.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
Reference in New Issue
Block a user