diff --git a/EI_TestProject/EI_APITest.cs b/EI_TestProject/EI_APITest.cs new file mode 100644 index 00000000..c7a263ea --- /dev/null +++ b/EI_TestProject/EI_APITest.cs @@ -0,0 +1,55 @@ +using System.Net; +using System.Text; +using System.Text.Json.Nodes; +using Azure.Core; +using EI_TestProject; +using IRaCIS.Application.Contracts; +using IRaCIS.Core.Infrastructure; +using IRaCIS.Core.Infrastructure.Extention; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Org.BouncyCastle.Asn1.Crmf; +using Org.BouncyCastle.Asn1.Ocsp; +using RestSharp; +using Xunit; +using Xunit.Abstractions; + +public class UserApiTests : IDisposable +{ + private RestClient _client; + + + public UserApiTests() + { + // 创建一个 RestClient 对象,并设置基本 URL + //client = new RestClient("http://localhost:6100"); + + _client = RestHelper.InitRestHelper("http://123.56.94.154:8090/api", "Admin", MD5Helper.Md5("WHxckj@2019")); + + } + + + + + + /// + /// 删除系统用户 + /// + [Fact] + public async void Test_DeleteUserById() + { + var userId = Guid.Parse("98430000-3e2c-0016-225f-08db7612c7ae"); + var url = $"/user/deleteUser/{userId}"; + //测试删除Api + var result = await RestHelper.DeleteRequestAsync>(url); + } + + + + + public void Dispose() + { + // 在测试结束后释放资源(例如关闭网络连接等) + _client?.Dispose(); + } +} \ No newline at end of file diff --git a/EI_TestProject/EI_TestProject.csproj b/EI_TestProject/EI_TestProject.csproj new file mode 100644 index 00000000..81db44b7 --- /dev/null +++ b/EI_TestProject/EI_TestProject.csproj @@ -0,0 +1,32 @@ +锘 + + + net6.0 + enable + enable + + false + true + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/EI_TestProject/RestHelper.cs b/EI_TestProject/RestHelper.cs new file mode 100644 index 00000000..99c3835d --- /dev/null +++ b/EI_TestProject/RestHelper.cs @@ -0,0 +1,111 @@ +using Azure.Core; +using IRaCIS.Core.Infrastructure.Extention; +using IRaCIS.Core.Infrastructure; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json; +using RestSharp; +using System.Net; +using IRaCIS.Application.Contracts; + +namespace EI_TestProject +{ + public static class RestHelper + { + private static RestClient _client { get; set; } + + private static string _token { get; set; } + + + + public static RestClient InitRestHelper(string baseUrl, string userName, string md5Pwd) + { + _client = new RestClient(baseUrl); + + _client.AddDefaultHeader("Content-Type", "application/json"); + + var result = (LoginAndGetAccessTokenAsync>(userName, md5Pwd)).Result; + + _token = result.Data.JWTStr; + + return _client; + } + + + + /// + /// 登录获取Token + /// + /// + /// + /// + /// + private static async Task LoginAndGetAccessTokenAsync(string userName, string md5Pwd) + { + var jsonBody = new JObject { + { "UserName", userName.Trim() }, + { "Password", md5Pwd } + }; + + var result = await Post_JsonBodyRequestAsync("/user/login", jsonBody, false); + return result; + } + + /// + /// json Post 请求 封装 + /// + /// + /// + /// + /// + /// + /// + public static async Task Post_JsonBodyRequestAsync(string url, JObject jsonBody, bool isAddToken = true) + { + var request = new RestRequest(url, Method.Post); + + if (isAddToken) + { + var accessToken = _token; + request.AddHeader("Authorization", "Bearer " + accessToken); + } + + request.AddParameter("application/json", jsonBody.ToString(), ParameterType.RequestBody); + + var response = await _client.ExecuteAsync(request); + if (response.StatusCode == HttpStatusCode.OK) + { + return JsonConvert.DeserializeObject(response.Content); + } + else + { + throw new Exception($"Error {response.StatusCode}: {response.StatusDescription}. {response.Content}"); + } + } + + /// + /// URL Delete 请求封装 + /// + /// + /// + /// + /// + public static async Task DeleteRequestAsync(string url) + { + var request = new RestRequest(url, Method.Delete); + var accessToken = _token; + request.AddHeader("Authorization", "Bearer " + accessToken); + + var response = await _client.ExecuteAsync(request); + if (response.StatusCode == HttpStatusCode.OK) + { + return JsonConvert.DeserializeObject(response.Content); + } + else + { + throw new Exception($"Error {response.StatusCode}: {response.StatusDescription}. {response.Content}"); + } + } + + + } +} \ No newline at end of file diff --git a/EI_TestProject/UnitTest1.cs b/EI_TestProject/UnitTest1.cs new file mode 100644 index 00000000..ffdcfd55 --- /dev/null +++ b/EI_TestProject/UnitTest1.cs @@ -0,0 +1,11 @@ +namespace EI_TestProject +{ + public class UnitTest1 + { + [Fact] + public void Test1() + { + + } + } +} \ No newline at end of file diff --git a/EI_TestProject/Usings.cs b/EI_TestProject/Usings.cs new file mode 100644 index 00000000..8c927eb7 --- /dev/null +++ b/EI_TestProject/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/IRaCIS.Core.API.sln b/IRaCIS.Core.API.sln index a077bf2b..1bc0f98f 100644 --- a/IRaCIS.Core.API.sln +++ b/IRaCIS.Core.API.sln @@ -27,6 +27,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EI_Image_Viewer_Activation" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PublishSite", "PublishSite\PublishSite.csproj", "{1CC3F0F8-8701-4F49-837B-DBFDAC2C19ED}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EI_TestProject", "EI_TestProject\EI_TestProject.csproj", "{47F99CA7-E55B-4A0E-A511-7EDF34C57A20}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -175,6 +177,18 @@ Global {1CC3F0F8-8701-4F49-837B-DBFDAC2C19ED}.Release|x64.Build.0 = Release|x64 {1CC3F0F8-8701-4F49-837B-DBFDAC2C19ED}.Release|x86.ActiveCfg = Release|Any CPU {1CC3F0F8-8701-4F49-837B-DBFDAC2C19ED}.Release|x86.Build.0 = Release|Any CPU + {47F99CA7-E55B-4A0E-A511-7EDF34C57A20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {47F99CA7-E55B-4A0E-A511-7EDF34C57A20}.Debug|Any CPU.Build.0 = Debug|Any CPU + {47F99CA7-E55B-4A0E-A511-7EDF34C57A20}.Debug|x64.ActiveCfg = Debug|Any CPU + {47F99CA7-E55B-4A0E-A511-7EDF34C57A20}.Debug|x64.Build.0 = Debug|Any CPU + {47F99CA7-E55B-4A0E-A511-7EDF34C57A20}.Debug|x86.ActiveCfg = Debug|Any CPU + {47F99CA7-E55B-4A0E-A511-7EDF34C57A20}.Debug|x86.Build.0 = Debug|Any CPU + {47F99CA7-E55B-4A0E-A511-7EDF34C57A20}.Release|Any CPU.ActiveCfg = Release|Any CPU + {47F99CA7-E55B-4A0E-A511-7EDF34C57A20}.Release|Any CPU.Build.0 = Release|Any CPU + {47F99CA7-E55B-4A0E-A511-7EDF34C57A20}.Release|x64.ActiveCfg = Release|Any CPU + {47F99CA7-E55B-4A0E-A511-7EDF34C57A20}.Release|x64.Build.0 = Release|Any CPU + {47F99CA7-E55B-4A0E-A511-7EDF34C57A20}.Release|x86.ActiveCfg = Release|Any CPU + {47F99CA7-E55B-4A0E-A511-7EDF34C57A20}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/IRaCIS.Core.Application/Service/Institution/HospitalService.cs b/IRaCIS.Core.Application/Service/Institution/HospitalService.cs index 393b5b57..485b7d6f 100644 --- a/IRaCIS.Core.Application/Service/Institution/HospitalService.cs +++ b/IRaCIS.Core.Application/Service/Institution/HospitalService.cs @@ -55,10 +55,7 @@ namespace IRaCIS.Application.Services { return ResponseOutput.NotOk("璇ュ尰闄笅宸茬粡娉ㄥ唽鏈夊尰鐢燂紝涓嶅彲浠ュ垹闄ゃ"); } - //if (_userRepository.Find().Any(t => t.OrganizationId == hospitalId)) - //{ - // return ResponseOutput.NotOk("璇ュ尰闄笅瀛樺湪鐢ㄦ埛锛屾殏鏃舵棤娉曞垹闄ゃ"); - //} + var success = await _hospitalRepository.BatchDeleteNoTrackingAsync(x => x.Id == hospitalId); diff --git a/IRaCIS.Core.Infrastructure/_IRaCIS/Output/ResponseOutput.cs b/IRaCIS.Core.Infrastructure/_IRaCIS/Output/ResponseOutput.cs index dd5e4009..6b344f2c 100644 --- a/IRaCIS.Core.Infrastructure/_IRaCIS/Output/ResponseOutput.cs +++ b/IRaCIS.Core.Infrastructure/_IRaCIS/Output/ResponseOutput.cs @@ -10,7 +10,7 @@ namespace IRaCIS.Core.Infrastructure.Extention /// /// 鏄惁鎴愬姛鏍囪 /// - public bool IsSuccess { get; private set; } + public bool IsSuccess { get; set; } public ApiResponseCodeEnum Code { get; set; } = ApiResponseCodeEnum.OK; @@ -19,13 +19,13 @@ namespace IRaCIS.Core.Infrastructure.Extention /// /// 娑堟伅 /// - public string ErrorMessage { get; private set; } + public string ErrorMessage { get; set; } /// /// 鏁版嵁 鍏奸【浠ュ墠 Json搴忓垪鍖栫殑鏃跺欒繑鍥炲睘鎬у悕涓衡淩esult鈥 /// [JsonProperty("Result")] - public T Data { get; private set; } + public T Data { get; set; }