|
@@ -0,0 +1,157 @@
|
|
1
|
+using System;
|
|
2
|
+using Unibase.Data.Sql;
|
|
3
|
+using Unibase.Dependency;
|
|
4
|
+using Unibase.Platform.Data;
|
|
5
|
+using Unibase.Security.Principal;
|
|
6
|
+using Microsoft.Extensions.Hosting;
|
|
7
|
+using Microsoft.Extensions.Configuration;
|
|
8
|
+using Unibase.Data;
|
|
9
|
+using System.Dynamic;
|
|
10
|
+using Unibase.Platform.Managers;
|
|
11
|
+
|
|
12
|
+namespace UnitTests.Core
|
|
13
|
+{
|
|
14
|
+ public abstract class BaseUnitTest
|
|
15
|
+ {
|
|
16
|
+ private static AppIdentity _salesPersonIdentity = null;
|
|
17
|
+ private static AppIdentity _adminIdentity = null;
|
|
18
|
+ private static AppIdentity _hrIdentity = null;
|
|
19
|
+ private static AppIdentity _Identity = null;
|
|
20
|
+ private static bool _initialize = false;
|
|
21
|
+ // private static AppIdentity _Identity = null;
|
|
22
|
+ public AppIdentity GetAdminIdentity(string sessionid)
|
|
23
|
+ {
|
|
24
|
+
|
|
25
|
+ return _adminIdentity == null ? BuildAdminIdentity(sessionid) : _adminIdentity;
|
|
26
|
+ }
|
|
27
|
+ public AppIdentity GetIdentity(string sessionid)
|
|
28
|
+ {
|
|
29
|
+
|
|
30
|
+ return _Identity == null ? BuildIdentity(sessionid) : _Identity;
|
|
31
|
+ }
|
|
32
|
+ public AppIdentity GetSalesPersonIdentity(string sessionid)
|
|
33
|
+ {
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+ return _adminIdentity == null ? BuildSalesPersonIdentity(sessionid) : _adminIdentity;
|
|
37
|
+ }
|
|
38
|
+
|
|
39
|
+ public AppIdentity GetHrExecutiveIdentity()
|
|
40
|
+ {
|
|
41
|
+ return _adminIdentity == null ? BuildHrExecutiveIdentity() : _hrIdentity;
|
|
42
|
+ }
|
|
43
|
+
|
|
44
|
+ AppIdentity BuildAdminIdentity(string sessionid)
|
|
45
|
+ {
|
|
46
|
+ // _adminIdentity = new AppIdentity() { };
|
|
47
|
+ // DependencyConfig.Register(Unibase.Dependency.Enums.DIType.ServiceCollection);
|
|
48
|
+ // SqlDialect.Default(new Data.DbProviders.PgSqlDbProvider.DbContext().Dialect);
|
|
49
|
+ if (_initialize == false)
|
|
50
|
+ {
|
|
51
|
+ Initialize();
|
|
52
|
+ }
|
|
53
|
+ var identity = new Unibase.Security.Principal.AppIdentity("", 0);
|
|
54
|
+ var request = new SelectRequest(null)
|
|
55
|
+ {
|
|
56
|
+ Identity = identity
|
|
57
|
+ };
|
|
58
|
+ if (sessionid == null)
|
|
59
|
+ {
|
|
60
|
+ sessionid = "9e5af21ec1a24c0293fc3dda352cdd93 ";
|
|
61
|
+ }
|
|
62
|
+ //var _usermanger = DependencyConfig.Resolve<Unibase.Platform.Common.Managers.IUserManager>();
|
|
63
|
+ //var response = _usermanger.SignIn(request, "anji@gmail.com", "123456", true, false);
|
|
64
|
+ var response = Unibase.Platform.Membership.IdentityRegistry.GetIdentityByStaticSessionandTenantid(sessionid, 2);
|
|
65
|
+ return response;
|
|
66
|
+ }
|
|
67
|
+ AppIdentity BuildIdentity(string sessionid)
|
|
68
|
+ {
|
|
69
|
+ // _adminIdentity = new AppIdentity() { };
|
|
70
|
+ // DependencyConfig.Register(Unibase.Dependency.Enums.DIType.ServiceCollection);
|
|
71
|
+ // SqlDialect.Default(new Data.DbProviders.PgSqlDbProvider.DbContext().Dialect);
|
|
72
|
+ if (_initialize == false)
|
|
73
|
+ {
|
|
74
|
+ Initialize();
|
|
75
|
+ }
|
|
76
|
+ var identity = new Unibase.Security.Principal.AppIdentity("", 0);
|
|
77
|
+ var request = new SelectRequest(null)
|
|
78
|
+ {
|
|
79
|
+ Identity = identity
|
|
80
|
+ };
|
|
81
|
+ if (sessionid == null)
|
|
82
|
+ {
|
|
83
|
+ sessionid = "9e5af21ec1a24c0293fc3dda352cdd93";
|
|
84
|
+ }
|
|
85
|
+ //var _usermanger = DependencyConfig.Resolve<Unibase.Platform.Common.Managers.IUserManager>();
|
|
86
|
+ //var response = _usermanger.SignIn(request, "anji@gmail.com", "123456", true, false);
|
|
87
|
+ var response = Unibase.Platform.Membership.IdentityRegistry.GetIdentityByStaticSessionandTenantid(sessionid, 2);
|
|
88
|
+ return response;
|
|
89
|
+ }
|
|
90
|
+ AppIdentity BuildSalesPersonIdentity(string sessionid)
|
|
91
|
+ {
|
|
92
|
+ _salesPersonIdentity = new AppIdentity() { };
|
|
93
|
+ return _salesPersonIdentity;
|
|
94
|
+ }
|
|
95
|
+ AppIdentity BuildHrExecutiveIdentity()
|
|
96
|
+ {
|
|
97
|
+ _salesPersonIdentity = new AppIdentity() { };
|
|
98
|
+ return _salesPersonIdentity;
|
|
99
|
+ }
|
|
100
|
+ Boolean Initialize()
|
|
101
|
+ {
|
|
102
|
+ string commondbid = "0";
|
|
103
|
+ string tenantdbid = "1";
|
|
104
|
+ string connectionstring = "server=localhost;port=5432;Database=unittest_common;User id=postgres;Password=Bizgaze@123";
|
|
105
|
+ string tenantconnectionstring = "server=localhost;port=5432;Database=unittest_tenant;User id=postgres;Password=Bizgaze@123";
|
|
106
|
+ //Unibase.Web.Server.Startup(IConfiguration configuration);
|
|
107
|
+ // DependencyConfig.Register(Unibase.Dependency.Enums.DIType.ServiceCollection);
|
|
108
|
+ var container = DependencyConfig.GetContainer();
|
|
109
|
+ container.RegisterType<IRepository, Unibase.Platform.Data.NsDbRepository>("NsDbRepository");
|
|
110
|
+ container.RegisterType<IRepository, Unibase.Platform.Data.Repository>();
|
|
111
|
+ // DependencyConfig.Register(Unibase.Dependency.Enums.DIType.ServiceCollection);
|
|
112
|
+ SqlDialect.Default(new Unibase.Data.DbProviders.PgSqlDbProvider.DbContext().Dialect);
|
|
113
|
+ container.RegisterType<IDbContext, Unibase.Data.DbProviders.PgSqlDbProvider.DbContext>();
|
|
114
|
+ DbRegistry.RegisterDatabase(commondbid, connectionstring);
|
|
115
|
+ DbRegistry.RegisterDatabase(tenantdbid, tenantconnectionstring);
|
|
116
|
+ Unibase.Dependency.DependencyConfig.Resolve<IDbContext>();
|
|
117
|
+ _initialize = true;
|
|
118
|
+ return _initialize;
|
|
119
|
+ }
|
|
120
|
+ public ActionResponse Set( ActionRequest request ,string formuniqueid, ExpandoObject options)
|
|
121
|
+ {
|
|
122
|
+ //var request = new ActionRequest();
|
|
123
|
+
|
|
124
|
+ //if (request.Identity == null)
|
|
125
|
+ //{
|
|
126
|
+ // request.Identity = GetAdminIdentity();
|
|
127
|
+ //}
|
|
128
|
+ SelectRequest srequest = SelectRequest.FromRequest(request);
|
|
129
|
+ request.DisableEventLog = true;
|
|
130
|
+ // var _dataapimanger = DependencyConfig.Resolve<Unibase.Platform.DataSources.Managers.IDataApiManager>();
|
|
131
|
+ //var data = _dataapimanger.Set(request, options);
|
|
132
|
+ var _formmanager = DependencyConfig.Resolve<Unibase.Platform.Forms.Managers.IFormManager>();
|
|
133
|
+ if (!String.IsNullOrEmpty(formuniqueid))
|
|
134
|
+ {
|
|
135
|
+ var forminfo = _formmanager.GetForm(srequest, formuniqueid).Result;
|
|
136
|
+ if (forminfo != null)
|
|
137
|
+ {
|
|
138
|
+ var response = _formmanager.SaveDynForm(request, forminfo.FormId, options);
|
|
139
|
+ if (response.Status == ResponseStatus.Error)
|
|
140
|
+ {
|
|
141
|
+ return ActionResponse.CreateErrorResponse("error", response.Message);
|
|
142
|
+ }
|
|
143
|
+ }
|
|
144
|
+ }
|
|
145
|
+ return ActionResponse.CreateSuccessResponse("UnitTest Success");
|
|
146
|
+
|
|
147
|
+ }
|
|
148
|
+ public Unibase.Platform.Data.Enums.PermissionLevel CheckPermission(ActionRequest request)
|
|
149
|
+ {
|
|
150
|
+ SelectRequest srequest= SelectRequest.FromRequest(request);
|
|
151
|
+ BaseUnitTestManager _baseunittestmanager = new BaseUnitTestManager();
|
|
152
|
+ var permissionlevel = _baseunittestmanager.CheckPermission(srequest);
|
|
153
|
+ return permissionlevel;
|
|
154
|
+ }
|
|
155
|
+ }
|
|
156
|
+}
|
|
157
|
+
|