From 7d3ced04b049805525aa127f4a83bcd0a3ded008 Mon Sep 17 00:00:00 2001
From: wanggaofeng <15601716045@163.com>
Date: Thu, 16 May 2024 09:58:34 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Id4Study.Test/Etx.cs               | 33 ++++++++++++++++++++++++
 Id4Study.Test/GlobalUsing.cs       | 16 ++++++++++++
 Id4Study.Test/Id4Study.Test.csproj | 30 ++++++++++++++++++++++
 Id4Study.Test/UnitTest1.cs         | 41 ++++++++++++++++++++++++++++++
 Id4Study.sln                       | 25 ++++++++++++++++++
 5 files changed, 145 insertions(+)
 create mode 100644 Id4Study.Test/Etx.cs
 create mode 100644 Id4Study.Test/GlobalUsing.cs
 create mode 100644 Id4Study.Test/Id4Study.Test.csproj
 create mode 100644 Id4Study.Test/UnitTest1.cs
 create mode 100644 Id4Study.sln

diff --git a/Id4Study.Test/Etx.cs b/Id4Study.Test/Etx.cs
new file mode 100644
index 0000000..913cd04
--- /dev/null
+++ b/Id4Study.Test/Etx.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Id4Study.Test
+{
+    public static class Id4Etx
+    {
+        /// <summary>
+        /// GetDiscoveryDocumentAsync 重载版
+        /// (不强制使用https)
+        /// </summary>
+        /// <param name="client"></param>
+        /// <param name="address"></param>
+        /// <param name="mustHttps"></param>
+        /// <param name="cancellationToken"></param>
+        /// <returns></returns>
+        public static async Task<DiscoveryDocumentResponse> GetDiscoveryDocumentAsync
+        (
+            this HttpClient client,
+            string? address = null, 
+            bool mustHttps=false, 
+            CancellationToken cancellationToken = default
+        )
+        {
+            var policy = new DiscoveryDocumentRequest { Address = address };
+            policy.Policy.RequireHttps = mustHttps;
+            return await client.GetDiscoveryDocumentAsync(policy, cancellationToken).ConfigureAwait(false);
+        }
+    }
+}
diff --git a/Id4Study.Test/GlobalUsing.cs b/Id4Study.Test/GlobalUsing.cs
new file mode 100644
index 0000000..e217011
--- /dev/null
+++ b/Id4Study.Test/GlobalUsing.cs
@@ -0,0 +1,16 @@
+global using System.Collections;
+global using System.Collections.Generic;
+
+global using System.Linq;
+global using System.Linq.Expressions;
+
+
+global using Xunit;
+global using Xunit.Sdk;
+global using Xunit.Extensions;
+global using Xunit.Abstractions;
+
+global using IdentityModel;
+global using IdentityModel.Client;
+global using IdentityModel.Jwk;
+global using IdentityModel.Internal;
\ No newline at end of file
diff --git a/Id4Study.Test/Id4Study.Test.csproj b/Id4Study.Test/Id4Study.Test.csproj
new file mode 100644
index 0000000..0db8281
--- /dev/null
+++ b/Id4Study.Test/Id4Study.Test.csproj
@@ -0,0 +1,30 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>net8.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+
+    <IsPackable>false</IsPackable>
+    <IsTestProject>true</IsTestProject>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="coverlet.collector" Version="6.0.2">
+      <PrivateAssets>all</PrivateAssets>
+      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+    </PackageReference>
+    <PackageReference Include="IdentityModel" Version="7.0.0" />
+    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
+    <PackageReference Include="xunit" Version="2.8.0" />
+    <PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
+      <PrivateAssets>all</PrivateAssets>
+      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+    </PackageReference>
+  </ItemGroup>
+
+  <ItemGroup>
+    <Using Include="Xunit" />
+  </ItemGroup>
+
+</Project>
diff --git a/Id4Study.Test/UnitTest1.cs b/Id4Study.Test/UnitTest1.cs
new file mode 100644
index 0000000..1de3d87
--- /dev/null
+++ b/Id4Study.Test/UnitTest1.cs
@@ -0,0 +1,41 @@
+
+namespace Id4Study.Test
+{
+    public class UnitTest1
+    {
+        [Fact]
+        public async Task Test1Async()
+        {
+            var client = new HttpClient();
+
+            //发现文档
+            var disco = await client.GetDiscoveryDocumentAsync("http://192.168.20.46:8017/",false, CancellationToken.None);
+            
+            Assert.False(disco.IsError);
+
+            // 请求令牌
+            var tokenResponse = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
+            {
+                Address = disco.TokenEndpoint,
+
+                ClientId = "edit_oa",
+                ClientSecret = "edit_oa",
+                Scope = "EDS.Editor.WebAPI.Plan EDS.Editor.WebAPI.Scene EDS.Editor.WebAPI.Member EDS.Editor.WebAPI.Common EDS.Editor.WebAPI.Resource EDS.Editor.WebAPI.Exam"
+            });
+
+            Assert.False(tokenResponse.IsError);
+
+            //访问WebAPI
+            //tokenResponse.AccessToken;
+
+            client.SetBearerToken(tokenResponse?.AccessToken ?? "");
+
+            HttpResponseMessage? res = await client.GetAsync(
+                "http://192.168.20.46:8016/api.exam/v1.0.0.0/Paper/GetPaperListByPage?companyId=1051&orgId=198&currentPageIndex=1&pageSize=50");
+
+            Assert.True(res.IsSuccessStatusCode);
+
+            var content = await res.Content.ReadAsStringAsync();
+        }
+    }
+}
\ No newline at end of file
diff --git a/Id4Study.sln b/Id4Study.sln
new file mode 100644
index 0000000..82b8f84
--- /dev/null
+++ b/Id4Study.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.10.34825.169
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Id4Study.Test", "Id4Study.Test\Id4Study.Test.csproj", "{BDD25B65-9F7C-4A5B-8E42-8ACA25369D23}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{BDD25B65-9F7C-4A5B-8E42-8ACA25369D23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{BDD25B65-9F7C-4A5B-8E42-8ACA25369D23}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{BDD25B65-9F7C-4A5B-8E42-8ACA25369D23}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{BDD25B65-9F7C-4A5B-8E42-8ACA25369D23}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {32B30A6D-76BF-4432-B62E-53F6DDE955B0}
+	EndGlobalSection
+EndGlobal