refactor: Projektdateien migriert. Cloud-NuGet-Pakete durch lokale NuGet-Projekte ersetzt.
This commit is contained in:
89
XUnitDAL.Test/_Shared/Shared_Test_Controller_Generic.cs
Normal file
89
XUnitDAL.Test/_Shared/Shared_Test_Controller_Generic.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Xunit;
|
||||
using XUnitWebApi.SharedConfig;
|
||||
using XUnitWebApi.SharedUtils;
|
||||
|
||||
namespace XUnitWebApi.SharedController
|
||||
{
|
||||
public class Shared_Test_Controller_Generic
|
||||
{
|
||||
[Theory()]
|
||||
[InlineData("")]
|
||||
[InlineData("AdWebAppToWebAppRole")]
|
||||
[InlineData("CostCentre")]
|
||||
[InlineData("Department")]
|
||||
[InlineData("DocumentArt")]
|
||||
[InlineData("EmployeeAttribute")]
|
||||
[InlineData("EmployeeStatus")]
|
||||
[InlineData("Project")]
|
||||
[InlineData("Rang")]
|
||||
[InlineData("WebApp")]
|
||||
[InlineData("WebAppRole")]
|
||||
[InlineData("DepartmentToWebAppToEmployeeForWindream")]
|
||||
[InlineData("DocumentArtToDepartment")]
|
||||
[InlineData("Employee")]
|
||||
[InlineData("EmployeeToAttribute")]
|
||||
[InlineData("EmployeeToDepartment")]
|
||||
[InlineData("EmployeeToWebApp")]
|
||||
[InlineData("WebAppAdditionalRole")]
|
||||
[InlineData("WebAppToDepartment")]
|
||||
[InlineData("WebAppToWebAppAdditionalRole")]
|
||||
[InlineData("WebAppToWebAppRole")]
|
||||
[InlineData("WindreamColumnsToDepartment")]
|
||||
[InlineData("WindreamIndex")]
|
||||
[InlineData("WindreamIndexToWindreamSearchToDepartment")]
|
||||
[InlineData("WindreamSearch")]
|
||||
[InlineData("WindreamSearchItem")]
|
||||
[InlineData("WindreamSearchItemToWindreamSearchToDepartment")]
|
||||
[InlineData("WindreamSearchToDepartment")]
|
||||
[InlineData("WindreamInputFolder")]
|
||||
[InlineData("Subsidiary")]
|
||||
public async Task Check_Dynamic_EntityControllers(string entityName = "", int entityId = 0)
|
||||
{
|
||||
Shared_Test_Config.Init_Webapi_Context();
|
||||
string actualEntity = "";
|
||||
List<string> ExceptionList = new List<string>();
|
||||
|
||||
var typeList = TestHelper.GetAllRepositories().Select(t => t.Name.Replace("Repository", ""));
|
||||
|
||||
foreach (var item in typeList)
|
||||
{
|
||||
try
|
||||
{
|
||||
actualEntity = item;
|
||||
if (entityName == "" || item == entityName)
|
||||
{
|
||||
dynamic repository = TestHelper.GetRepository_BasedOn_BaseRepository(item);
|
||||
if (repository == null) continue;
|
||||
dynamic controller = TestHelper.GetApiController_BasedOn_BaseController(item, repository);
|
||||
if (controller == null) continue;
|
||||
dynamic result;
|
||||
if (entityId > 0)
|
||||
{
|
||||
result = await controller.GetEntityAsync(entityId);
|
||||
result = result?.Result;
|
||||
}
|
||||
else result = await controller.GetAllAsync();
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(StatusCodes.Status200OK, result.StatusCode);
|
||||
|
||||
var entity = result.Value;
|
||||
Assert.NotNull(entity);
|
||||
|
||||
if (entityId > 0) Assert.Equal(entityId, entity.GetEntityId());
|
||||
else Assert.NotEqual(entity.Count, 0);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//throw new Exception(actualEntity, ex);
|
||||
Console.WriteLine(ex.Message);
|
||||
ExceptionList.Add($"Entity: {actualEntity} " + ex.Message + " " + ex.InnerException);
|
||||
}
|
||||
}
|
||||
var errList = "";
|
||||
foreach (var item in ExceptionList) errList += "\r\n -- " + item;
|
||||
if (ExceptionList.Count > 0) throw new Exception(errList);
|
||||
}
|
||||
}
|
||||
}
|
||||
88
XUnitDAL.Test/_Shared/Shared_Test_DAL.cs
Normal file
88
XUnitDAL.Test/_Shared/Shared_Test_DAL.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using DAL;
|
||||
using DAL._Shared.SharedRepositories;
|
||||
using HRD.WebApi;
|
||||
using System.Reflection;
|
||||
using Xunit;
|
||||
using XUnitWebApi.SharedConfig;
|
||||
using XUnitWebApi.SharedUtils;
|
||||
|
||||
namespace XUnitWebApi.SahredDAL
|
||||
{
|
||||
public class Shared_Test_DAL
|
||||
{
|
||||
[Fact]
|
||||
public async System.Threading.Tasks.Task Check_Repository_XXXAsync()
|
||||
{
|
||||
Shared_Test_Config.Init_Webapi_Context();
|
||||
WebAppUserRepository webAppUserRepository = new WebAppUserRepository();
|
||||
|
||||
var res = await webAppUserRepository.TakeListAsync(2);
|
||||
Assert.NotEmpty(res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Check_Repository_By_Name()
|
||||
{
|
||||
var res = Check_Repositories(0, true, "Case");
|
||||
Assert.True(res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Check_All_Repositories()
|
||||
{
|
||||
var res = Check_Repositories(0, true);
|
||||
Assert.True(res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Check_All_Repositories_With_Values()
|
||||
{
|
||||
var res = Check_Repositories(1, true);
|
||||
Assert.True(res);
|
||||
}
|
||||
|
||||
private bool Check_Repositories(int count = 0, bool raiseRepositoryExceptions = false, string repositoryName = "", string namespaceName = "DAL.Repositories")
|
||||
{
|
||||
Shared_Test_Config.Init_Webapi_Context();
|
||||
|
||||
WebApiConfig.RaiseRepositoryExceptions = raiseRepositoryExceptions;
|
||||
|
||||
string entityName = string.Empty;
|
||||
|
||||
List<string> ExceptionList = new List<string>();
|
||||
|
||||
using WebApiContext ctx = new WebApiContext();
|
||||
{
|
||||
Assert.True(ctx.Database.CanConnect());
|
||||
var typeList = TestHelper.GetAllRepositories(namespaceName);
|
||||
|
||||
foreach (var item in typeList)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (repositoryName == "" || item.Name.Contains(repositoryName))
|
||||
{
|
||||
Type type = item as Type;
|
||||
entityName = type.Name;
|
||||
object instance = Activator.CreateInstance(type);
|
||||
MethodInfo takeListMethod = type.GetMethod("TakeList");
|
||||
dynamic list = takeListMethod.Invoke(instance, new object[] { count, true });
|
||||
System.Diagnostics.Debug.WriteLine(entityName);
|
||||
Assert.NotNull(list);
|
||||
Assert.Equal(count, list.Count);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
ExceptionList.Add($"Entity: {entityName} " + ex.Message + " " + ex.InnerException);
|
||||
}
|
||||
}
|
||||
}
|
||||
var errList = "";
|
||||
foreach (var item in ExceptionList) errList += "\r\n -- " + item;
|
||||
if (ExceptionList.Count > 0) throw new Exception(errList);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
98
XUnitDAL.Test/_Shared/Shared_Test_LDAP.cs
Normal file
98
XUnitDAL.Test/_Shared/Shared_Test_LDAP.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using DAL._Shared.SharedModels;
|
||||
using DAL._Shared.SharedRepositories;
|
||||
using HRD.LDAPService;
|
||||
using HRD.LDAPService.JWT;
|
||||
using StaffDBServer.SharedControllers;
|
||||
using Xunit;
|
||||
using XUnitWebApi.SharedConfig;
|
||||
|
||||
namespace XUnitWebApi.SharedLDAP
|
||||
{
|
||||
public class Shared_Test_LDAP
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("user", "pwd")]
|
||||
[InlineData("user2", "pwd")]
|
||||
public async System.Threading.Tasks.Task Validate_Credentials_WebAppUser(string login, string passwort)
|
||||
{
|
||||
Shared_Test_Config.Init_Webapi_Context();
|
||||
|
||||
try
|
||||
{
|
||||
WebAppUser userFromClient = new WebAppUser(
|
||||
login,
|
||||
login,
|
||||
"User",
|
||||
login);
|
||||
userFromClient.Password = passwort;
|
||||
|
||||
WebAppEmployeeInfoRepository webAppEmployeeInfoRepository = new WebAppEmployeeInfoRepository();
|
||||
WebAppEmployeeInfo webAppEmployeeInfo = await webAppEmployeeInfoRepository.GetByAsync(x => x.LoginName == userFromClient.LoginName);
|
||||
Assert.NotNull(webAppEmployeeInfo);
|
||||
|
||||
WebAppUserHelper webAppUserHelper = new WebAppUserHelper();
|
||||
LdapUser ldapUserFromClient = new LdapUser(userFromClient.LoginName, webAppEmployeeInfo.EmployeeId, userFromClient.Password, webAppEmployeeInfo.DepartmentId, webAppEmployeeInfo.ExtendedDepartmentIdList);
|
||||
Assert.NotNull(ldapUserFromClient);
|
||||
|
||||
bool ldapUserOk = JwtManager.GenerateLdapUserWithJwtToken(ldapUserFromClient);
|
||||
Assert.True(ldapUserOk);
|
||||
|
||||
WebAppUser newUser = await webAppUserHelper.CheckLoginWithNameAndPasswordAsync(userFromClient);
|
||||
|
||||
Assert.NotNull(newUser);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Theory]
|
||||
[InlineData("visitoripad", "pwd")]
|
||||
public void Validate_Credentials_with_password(string login, string passwort)
|
||||
{
|
||||
try
|
||||
{
|
||||
LdapUser ldapUser = new LdapUser(login, 0, passwort);
|
||||
var result = LdapAuthenticationService.CheckAndUpdateIdentityWithPassword(ldapUser);
|
||||
|
||||
Assert.True(result);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetLdapUsers))]
|
||||
public void Validate_Credentials_with_password_Version2(LdapUser ldapUser)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = LdapAuthenticationService.CheckAndUpdateIdentityWithPassword(ldapUser);
|
||||
|
||||
Assert.True(result);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> GetLdapUsers()
|
||||
{
|
||||
LdapUser ldapUser = new LdapUser("user1", 0, "pwd");
|
||||
LdapUser ldapUser2 = new LdapUser("Error", 0, "pwd");
|
||||
|
||||
var allData = new List<object[]>
|
||||
{
|
||||
new object[] { ldapUser },
|
||||
new object[] { ldapUser2 }
|
||||
};
|
||||
|
||||
return allData;
|
||||
}
|
||||
}
|
||||
}
|
||||
46
XUnitDAL.Test/_Shared/Shared_Utils.cs
Normal file
46
XUnitDAL.Test/_Shared/Shared_Utils.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
namespace XUnitWebApi.SharedUtils
|
||||
{
|
||||
public static class TestHelper
|
||||
{
|
||||
public static IEnumerable<Type> GetAllRepositories(string namespaceName = "DAL.Repositories")
|
||||
{
|
||||
var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(t => t.GetTypes())
|
||||
.Where(t => t.IsClass && !t.Name.StartsWith("<")
|
||||
&& (t.Namespace == namespaceName || t.Namespace == "DAL.SharedRepositories")
|
||||
);
|
||||
return types;
|
||||
}
|
||||
|
||||
public static dynamic GetApiController_BasedOn_BaseController(string controllerName, dynamic repository)
|
||||
{
|
||||
var typeList = AppDomain.CurrentDomain.GetAssemblies().SelectMany(t => t.GetTypes())
|
||||
.Where(t => t.IsClass && !t.Name.StartsWith("<"))
|
||||
.Where(t => t.Name.Contains("Controller"))
|
||||
.Where(t => t.BaseType.Name.StartsWith("BaseController"))
|
||||
.Where(t => controllerName == "" || t.Name == controllerName + "Controller");
|
||||
//var entityTypes = typeList.ToList();
|
||||
//var entityType = entityTypes.Where(t => controllerName == "" || t.Name.Contains(controllerName)).FirstOrDefault();
|
||||
var entityType = typeList.FirstOrDefault();
|
||||
if (entityType == default) return default;
|
||||
Type type = entityType as Type;
|
||||
dynamic instance = Activator.CreateInstance(type, new object[] { repository });
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static dynamic GetRepository_BasedOn_BaseRepository(string repositoryName)
|
||||
{
|
||||
var typeList = AppDomain.CurrentDomain.GetAssemblies().SelectMany(t => t.GetTypes())
|
||||
.Where(t => t.IsClass && !t.Name.StartsWith("<"))
|
||||
.Where(t => repositoryName == "" || t.Name == repositoryName + "Repository")
|
||||
.Where(t => t.Name.Contains("Repository"))
|
||||
.Where(t => t.BaseType.Name.StartsWith("BaseRepository"));
|
||||
var entityType = typeList.FirstOrDefault();
|
||||
if (entityType == default) return default;
|
||||
Type type = entityType as Type;
|
||||
dynamic instance = Activator.CreateInstance(type);
|
||||
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
41
XUnitDAL.Test/_Shared/Shared_test_config.cs
Normal file
41
XUnitDAL.Test/_Shared/Shared_test_config.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using HRD.AppLogger;
|
||||
using HRD.LDAPService;
|
||||
using HRD.LDAPService.JWT;
|
||||
using HRD.WebApi;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace XUnitWebApi.SharedConfig
|
||||
{
|
||||
public static class Shared_Test_Config
|
||||
{
|
||||
public static void Init_Webapi_Context()
|
||||
{
|
||||
if (WebApiConfig.Connectionstring != default) return; //all test are running simultain using the same WebApiConfig, therefore it must be initialised only one time
|
||||
var app_path = Directory.GetCurrentDirectory();
|
||||
var pos = app_path.IndexOf("XUnitDAL.Test");
|
||||
if (pos >= 0) app_path = app_path.Remove(pos);
|
||||
app_path += "StaffDBServer\\appsettings.json";
|
||||
|
||||
IConfiguration configuration = new ConfigurationBuilder().AddJsonFile(app_path, true, true).Build();
|
||||
WebApiConfig.Init(configuration);
|
||||
|
||||
WebApiConfig.AssemblyName = "KabionlineServer_test";
|
||||
WebApiConfig.AssemblyVersion = "xxx.xx";
|
||||
//WebApiConfig.Connectionstring = Config_ConnectionString;
|
||||
//WebApiConfig.NlogConnectionstring = Config_ConnectionString;
|
||||
WebApiConfig.NlogDBLogLevel = EN_LoggingLevel.Error;
|
||||
WebApiConfig.NlogFileLogLevel = EN_LoggingLevel.Off;
|
||||
WebApiConfig.RaiseRepositoryExceptions = false;
|
||||
|
||||
//JWT#1
|
||||
var jwtRoleList = new List<JwtRole>();
|
||||
var ADGroupPrefix = WebApiConfig.IsLive ? "" : "__Test";
|
||||
//jwtRoleList.Add(new JwtRole(JwtGlobals.ROLE_USER, "GG_WebApp" + ADGroupPrefix + "_Kabionline_User")); //(RO) nur eigene
|
||||
//jwtRoleList.Add(new JwtRole(JwtGlobals.ROLE_MASTER, "GG_WebApp" + ADGroupPrefix + "_Kabionline_Master")); //RW ALLE Abteilungen
|
||||
//jwtRoleList.Add(new JwtRole(JwtGlobals.ROLE_DEPARTMENTUSER, "GG_WebApp" + ADGroupPrefix + "_Kabionline_DepartmentUser")); //(RW) auch andere aus eigener Abteilung
|
||||
//jwtRoleList.Add(new JwtRole(JwtGlobals.ROLE_DEPARTMENTMASTER, "GG_WebApp" + ADGroupPrefix + "_Kabionline_DepartmentMaster")); //(RW) auch andere aus eigener Abteilung
|
||||
|
||||
JwtTokenConfig.JwtRoleList = jwtRoleList;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user