添加项目

main
wanggaofeng 4 months ago
parent c3936cddc8
commit 7d3ced04b0

@ -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);
}
}
}

@ -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;

@ -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>

@ -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();
}
}
}

@ -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
Loading…
Cancel
Save