refactor: Projektdateien migriert. Cloud-NuGet-Pakete durch lokale NuGet-Projekte ersetzt.

This commit is contained in:
Developer 02
2024-08-01 18:44:39 +02:00
parent 0d82f7af6f
commit 62ddd4873f
206 changed files with 10927 additions and 1 deletions

View File

@@ -0,0 +1,25 @@
[Fact]
public async Task Check_Get_entity_Controller()
{
Shared_Test_Config.Init_Webapi_Context();
try
{
int entityId = 1;
_entity_Repository repository = new _entity_Repository();
_entity_Controller controller = new _entity_Controller(repository);
dynamic result = await controller.GetEntityAsync(entityId);
Assert.NotNull(result);
Assert.Equal(StatusCodes.Status200OK, result.Result.StatusCode);
var entity = result.Result.Value;
Assert.NotNull(entity);
if (entityId > 0) Assert.Equal(entityId, entity._entity_Id);
}
catch (Exception ex)
{
throw ex;
}
}

View File

@@ -0,0 +1,27 @@
[Fact]
public async Task Check_Get_entity_FilteredListController()
{
Shared_Test_Config.Init_Webapi_Context();
try
{
_filter_Filter filter = new _filter_Filter();
filter.Name = "";
_entity_Repository repository = new _entity_Repository();
_entity_Controller controller = new _entity_Controller(repository);
dynamic result = await controller.Get_entity_ListAsync(filter);
Assert.NotNull(result);
Assert.Equal(StatusCodes.Status200OK, result.StatusCode);
var entity = result.Value;
Assert.NotNull(entity);
Assert.NotEqual(entity.Count, 0);
}
catch (Exception ex)
{
throw ex;
}
}

View File

@@ -0,0 +1,54 @@
setlocal disableDelayedExpansion
:Variables
set InputFile=%2
set OutputFile=%InputFile%#
set entity=%1
set "_strFind=Check_Dynamic_EntityControllers"
set _strInsert1=[InlineData("%entity%")]
set "_strInsert1= %_strInsert1%"
rem if already inserted, do nothing
:Check
for /F "delims=" %%L in ('findstr /n "^" "%InputFile%"') do (
set "line=%%L"
setlocal EnableDelayedExpansion
set "line=!line:*:=!"
if "!line!" neq "" (
set "_line=!line:%_strInsert1%=!"
) else (
set _line=!line!
)
if "!_line!" neq "!line!" goto finish
endlocal
)
@echo off
:Replace
>"%OutputFile%" (
for /F "delims=" %%L in ('findstr /n "^" "%InputFile%"') do (
set "line=%%L"
setlocal EnableDelayedExpansion
set "line=!line:*:=!"
if "!line!" neq "" (
set "_line=!line:%_strFind%=!"
) else (
set _line=!line!
)
if "!_line!" neq "!line!" (
echo !_strInsert1!
)
echo.!line!
endlocal
)
)
del %InputFile%>nul
copy %OutputFile% %InputFile%>nul
del %OutputFile%>nul
:finish

View File

@@ -0,0 +1,61 @@
@echo off
setlocal disableDelayedExpansion
:Variables
set InputFile=%2
set OutputFile=%InputFile%#
set entity=%1
set "_strFind=ConfigureRepositoryWrapper(this IServiceCollection services)"
set "_strInsert1= services.AddScoped(typeof(IBaseRepository<%entity%>), typeof(%entity%Repository));"
set doreplace=0
rem if already inserted, do nothing
:Check
for /F "delims=" %%L in ('findstr /n "^" "%InputFile%"') do (
set "line=%%L"
setlocal EnableDelayedExpansion
set "line=!line:*:=!"
if "!line!" neq "" (
set "_line=!line:%_strInsert1%=!"
) else (
set _line=!line!
)
if "!_line!" neq "!line!" goto finish
endlocal
)
:Replace
>"%OutputFile%" (
for /F "delims=" %%L in ('findstr /n "^" "%InputFile%"') do (
set "line=%%L"
setlocal EnableDelayedExpansion
set "line=!line:*:=!"
if "!line!" neq "" (
set "_line=!line:%_strFind%=!"
) else (
set _line=!line!
)
if "!_line!" neq "!line!" (
echo.!line!
endlocal
set doreplace=1
) else (
echo.!line!
if !doreplace!==1 (
echo !_strInsert1!
)
endlocal
set doreplace=0
)
)
)
del %InputFile%
copy %OutputFile% %InputFile%>nul
del %OutputFile%
:finish

View File

@@ -0,0 +1,69 @@
@echo off
setlocal disableDelayedExpansion
:Variables
set InputFile=%2
set OutputFile=%InputFile%#
set entity=%1
set "_strFind=OnModelCreating(ModelBuilder modelBuilder)"
set "_strInsert1= public virtual DbSet<%entity%> %entity%Set { get; set; }"
set "_strInsert2= modelBuilder.Entity<%entity%>(entity =>"
set "_strInsert3= {"
set "_strInsert4= entity.ToView("%entity%", "webapi");"
set "_strInsert5= });"
set doreplace=0
rem if already inserted, do nothing
:Check
for /F "delims=" %%L in ('findstr /n "^" "%InputFile%"') do (
set "line=%%L"
setlocal EnableDelayedExpansion
set "line=!line:*:=!"
if "!line!" neq "" (
set "_line=!line:%_strInsert1%=!"
) else (
set _line=!line!
)
if "!_line!" neq "!line!" goto finish
endlocal
)
:Replace
>"%OutputFile%" (
for /F "delims=" %%L in ('findstr /n "^" "%InputFile%"') do (
set "line=%%L"
setlocal EnableDelayedExpansion
set "line=!line:*:=!"
if "!line!" neq "" (
set "_line=!line:%_strFind%=!"
) else (
set _line=!line!
)
if "!_line!" neq "!line!" (
echo !_strInsert1!
echo.!line!
endlocal
set doreplace=1
) else (
echo.!line!
if !doreplace!==1 (
echo !_strInsert2!
echo !_strInsert3!
echo !_strInsert4!
echo !_strInsert5!
echo.
)
endlocal
set doreplace=0
)
)
)
del %InputFile%
copy %OutputFile% %InputFile%>nul
del %OutputFile%
:finish

View File

@@ -0,0 +1,15 @@
@echo using HRD.LDAPService.JWT;
@echo using HRD.WebApi.Controllers;
@echo using HRD.WebApi.Repositories;
@echo using DAL.Models.Entities;
@echo.
@echo namespace %2Server.Controllers
@echo {
@echo [JWTAuthorize]
@echo public class %1Controller : BaseController^<%1^>
@echo {
@echo public %1Controller(IBaseRepository^<%1^> repositoryBase) : base(repositoryBase)
@echo {
@echo }
@echo }
@echo }

View File

@@ -0,0 +1,36 @@
@echo using System;
@echo using System.Threading.Tasks;
@echo using Microsoft.AspNetCore.Mvc;
@echo using Microsoft.AspNetCore.Http;
@echo using HRD.LDAPService.JWT;
@echo using HRD.WebApi.Controllers;
@echo using HRD.WebApi.Repositories;
@echo using DAL.Repositories;
@echo using DAL.Models.Entities;
@echo using DAL.Models.Filters;
@echo.
@echo namespace %2Server.Controllers
@echo {
@echo [JWTAuthorize]
@echo public class %1Controller : BaseController^<%1^>
@echo {
@echo public %1Controller(IBaseRepository^<%1^> repositoryBase) : base(repositoryBase)
@echo {
@echo }
@echo.
@echo [HttpPost("%3Filter")]
@echo public async Task^<IActionResult^> Get%1ListAsync([FromBody] %3Filter filter)
@echo {
@echo try
@echo {
@echo var list = await ((%1Repository)EntityRepository).GetListByFilterAsync(filter);
@echo return new OkObjectResult(list);
@echo }
@echo catch (Exception ex)
@echo {
@echo this.WriteLogException(ex);
@echo return StatusCode(StatusCodes.Status400BadRequest, $"Cann't get the filtered list of {typeof(%1).Name}");
@echo }
@echo }
@echo }
@echo }

View File

@@ -0,0 +1,23 @@
@echo using HRD.WebApi.DAL;
@echo using System;
@echo using System.ComponentModel.DataAnnotations.Schema;
@echo.
@echo namespace DAL.Models.Entities
@echo {
@echo public partial class %1 : BaseEntity
@echo {
@echo public int %1Id { get; set; }
@echo public string Name { get; set; }
@echo public string %1Shortname { get; set; }
@echo.
@echo // [NotMapped]
@echo // [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
@echo.
@echo //generic Id
@echo public override int GetEntityId() =^> %1Id;
@echo //generic ToString()
@echo public override string ToString() =^> $"%1Id: {GetEntityId()}; Name: {Name}";
@echo //generic EntityInfo()
@echo public override string EntityInfo() =^> base.EntityInfo();
@echo }
@echo }

View File

@@ -0,0 +1,11 @@
@echo using HRD.WebApi.DAL;
@echo.
@echo namespace DAL.Models.Filters
@echo {
@echo public partial class %1Filter : BaseFilter
@echo {
@echo public int? %1Id { get; set; }
@echo public string Name { get; set; }
@echo public int[] ListIds { get; set; }
@echo }
@echo }

View File

@@ -0,0 +1,12 @@
@echo using HRD.WebApi.Repositories;
@echo using DAL.Models.Entities;
@echo.
@echo namespace DAL.Repositories
@echo {
@echo public class %1Repository : BaseRepository^<%1^>
@echo {
@echo public %1Repository() : base(new WebApiContext())
@echo {
@echo }
@echo }
@echo }

View File

@@ -0,0 +1,51 @@
@echo using System.Collections.Generic;
@echo using System.Linq;
@echo using System.Threading.Tasks;
@echo using Microsoft.EntityFrameworkCore;
@echo using HRD.WebApi.Repositories;
@echo using DAL.Models.Entities;
@echo using DAL.Models.Filters;
@echo.
@echo namespace DAL.Repositories
@echo {
@echo public class %1Repository: BaseRepository^<%1^>
@echo {
@echo public %1Repository() : base(new WebApiContext())
@echo {
@echo }
@echo.
@echo public async Task^<List^<%1^>^> GetListByFilterAsync(%2Filter filter, bool asNoTracking = true)
@echo {
@echo var items = this.RepositoryContext.Set^<%1^>().AsQueryable();
@echo.
@echo if (filter.%2Id != null ^&^& filter.%2Id != 0)
@echo {
@echo items = items.Where(x =^> x.%1Id == filter.%2Id);
@echo return asNoTracking ? await items.ToListAsync() : await items.ToListAsync();
@echo }
@echo.
@echo /*
@echo // gets entity x if x.FirstName or x.LastName contains filter.Name, case independent
@echo if (!string.IsNullOrEmpty(filter.Name))
@echo {
@echo items = items.Where(x =^> EF.Functions.Like(x.FirstName.ToLower()+' '+ x.LastName.ToLower(), $"%%{filter.Name.ToLower()}%%"));
@echo }
@echo.
@echo // N:N - filter: gets entity x where one of Id in x.IdList (comma separated list of ids) is infilter.ListIds (array of Ids from Hensel-Selection multiselect Component)
@echo if (filter.ListIds != null ^&^& filter.ListIds.Length ^> 0)
@echo {
@echo IQueryable^<%1^> itemsTmp = null;
@echo for (int i = 0; i^< filter.ListIds.Length; i++)
@echo {
@echo var inx = filter.ListIds[i];
@echo var items_ = items.Where(x =^> EF.Functions.Like("," + x.IdList.Replace(" ", "") + ",", $"%%,{inx},%%"));
@echo itemsTmp = (itemsTmp != null) ? itemsTmp.Concat(items_) : items_;
@echo }
@echo items = itemsTmp;
@echo }
@echo */
@echo.
@echo return asNoTracking ? await items.AsNoTracking().ToListAsync() : await items.ToListAsync();
@echo }
@echo }
@echo }

View File

@@ -0,0 +1,20 @@
@echo off
echo ^<Project Sdk="Microsoft.NET.Sdk"^>
echo.
echo ^<PropertyGroup^>
echo ^<TargetFramework^>netcoreapp3.1^</TargetFramework^>
echo.
echo ^<IsPackable^>false^</IsPackable^>
echo ^</PropertyGroup^>
echo.
echo ^<ItemGroup^>
echo ^<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /^>
echo ^<PackageReference Include="xunit" Version="2.4.0" /^>
echo ^<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" /^>
echo ^<PackageReference Include="coverlet.collector" Version="1.2.0" /^>
echo ^</ItemGroup^>
echo.
echo ^<ItemGroup^>
echo ^<ProjectReference Include="..\%1Server\%1Server.csproj" /^>
echo ^</ItemGroup^>
echo ^</Project^>

View File

@@ -0,0 +1,65 @@
@echo off
setlocal disableDelayedExpansion
:Variables
set InputFile=%2
set OutputFile=%InputFile%#
set entity=%1
set filtername=%4
set "_strFind=//----Check_GetEntity%3"
set "_strInsert1= public async Task Check_Get%entity%%3()"
set "scripts_path=%~dp0..\Core"
set templatefile_path=%scripts_path%\Entity%3_test.tmpl
rem if already inserted, do nothing
:Check
for /F "delims=" %%L in ('findstr /n "^" "%InputFile%"') do (
set "line=%%L"
setlocal EnableDelayedExpansion
set "line=!line:*:=!"
if "!line!" neq "" (
set "_line=!line:%_strInsert1%=!"
) else (
set _line=!line!
)
if "!_line!" neq "!line!" goto finish
endlocal
)
call %scripts_path%\replaceinfile.bat %templatefile_path% _entity_ %entity% dontdelete>nul
if "%filtername%" neq "" (
call %scripts_path%\replaceinfile.bat %templatefile_path%# _filter_ %filtername% dontdelete>nul
del %templatefile_path%# >nul
copy %templatefile_path%## %templatefile_path%# >nul
del %templatefile_path%## >nul
)
:Replace
>"%OutputFile%" (
for /F "delims=" %%L in ('findstr /n "^" "%InputFile%"') do (
set "line=%%L"
setlocal EnableDelayedExpansion
set "line=!line:*:=!"
if "!line!" neq "" (
set "_line=!line:%_strFind%=!"
) else (
set _line=!line!
)
echo.!line!
if "!_line!" neq "!line!" (
type %templatefile_path%#
)
endlocal
)
)
del %templatefile_path%# >nul
del %InputFile% >nul
copy %OutputFile% %InputFile% >nul
del %OutputFile% >nul
:finish

View File

@@ -0,0 +1,33 @@
@echo off
setlocal disableDelayedExpansion
:Variables
set InputFile=%1
set OutputFile=%InputFile%#
set "_strFind=%2"
set "_strInsert=%3"
set "_withoutdelete=%4"
:Replace
>"%OutputFile%" (
for /F "delims=" %%L in ('findstr /n "^" "%InputFile%"') do (
set "line=%%L"
setlocal EnableDelayedExpansion
set "line=!line:*:=!"
if "!line!" neq "" (
set "_line=!line:%_strFind%=%_strInsert%!"
) else (
set _line=!line!
)
echo.!_line!
endlocal
)
)
if "%_withoutdelete%"=="" (
del %InputFile%
copy %OutputFile% %InputFile%>nul
del %OutputFile%
)

View File

@@ -0,0 +1,10 @@
@echo set Project=%1
@echo set NewEntity=1
@echo set Entityname=
@echo set Filter4Entity=
@echo @@if "%%NewEntity%%"=="" exit
@echo call ..\Core\start_add_entity_to_project.bat %%Project%% %%EntityName%% %%Filter4Entity%%

View File

@@ -0,0 +1,45 @@
@echo off
set project_name=%1
set entity=%2
set filter_name=%3
set "project_path=%~dp0..\.."
set "scripts_path=%~dp0..\Core"
set entity_path=%project_path%\DAL\Models\Entities
set filter_path=%project_path%\DAL\Models\Filters
set repository_path=%project_path%\DAL\Repositories
set controller_path=%project_path%\%project_name%Server\Controllers
set webapicontext_path=%project_path%\DAL\WebApiContext.cs
set serviceExtensions_path=%project_path%\%project_name%Server\Extends\ServiceExtensions4BaseRepository.cs
set controllertestgeneric_path=%project_path%\XUnitDAL.Test\_Shared\Shared_Test_Controller_Generic.cs
set controllertestentity_path=%project_path%\XUnitDAL.Test\Test_Controller_Entity.cs
set controllertestfilter_path=%project_path%\XUnitDAL.Test\Test_Controller_Filter.cs
if not exist "%entity_path%" mkdir "%entity_path%"
if not exist "%filter_path%" mkdir "%filter_path%"
if not exist "%repository_path%" mkdir "%repository_path%"
if not exist "%controller_path%" mkdir "%controller_path%"
IF "%filter_name%"=="" (
call %scripts_path%\add_repository.bat %entity% >"%repository_path%"\%entity%Repository.cs
call %scripts_path%\add_controller.bat %entity% %project_name% >"%controller_path%"\%entity%Controller.cs
) ELSE (
if not exist "%filter_path%"\%filter_name%Filter.cs call %scripts_path%\add_filter.bat %filter_name% >"%filter_path%"\%filter_name%Filter.cs
call %scripts_path%\add_repository_filter.bat %entity% %filter_name% >"%repository_path%"\%entity%Repository.cs
call %scripts_path%\add_controller_filter.bat %entity% %project_name% %filter_name% >"%controller_path%"\%entity%Controller.cs
)
call %scripts_path%\add_entity.bat %entity% >"%entity_path%"\%entity%.cs
call %scripts_path%\add_WebApiContext.bat %entity% "%webapicontext_path%"
call %scripts_path%\add_serviceExtensions.bat %entity% "%ServiceExtensions_path%"
if exist "%controllertestgeneric_path%" call %scripts_path%\add_CommonTestController.bat %entity% %controllertestgeneric_path%
if exist "%controllertestentity_path%" call %scripts_path%\add_tests_generic.bat %entity% %controllertestentity_path% Controller
if exist "%controllertestfilter_path%" (
IF "%filter_name%" neq "" call %scripts_path%\add_tests_generic.bat %entity% %controllertestfilter_path% FilteredListController %filter_name%
)
echo --finished: %2