Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
290 commits
Select commit Hold shift + click to select a range
d3572e7
delete
yaochangyu Apr 7, 2021
9d39385
delete
yaochangyu Apr 7, 2021
f6c0619
delete
yaochangyu Apr 7, 2021
e749e1f
Merge remote-tracking branch 'origin/master'
yaochangyu Apr 7, 2021
801bea6
add miss file
yaochangyu Apr 7, 2021
4fd70b0
add batch file
yaochangyu Apr 7, 2021
ea8c40b
add batch file
yaochangyu Apr 7, 2021
aba89a3
add batch file
yaochangyu Apr 7, 2021
18be3d0
add batch file
yaochangyu Apr 7, 2021
d50a334
add batch file
yaochangyu Apr 7, 2021
7221b37
refactor
yaochangyu Apr 8, 2021
7195b7e
refactor
yaochangyu Apr 8, 2021
e2c2f43
add Topshelf.Extensions.Configuration
yaochangyu Apr 8, 2021
ad476db
add user secret test
yaochangyu Apr 9, 2021
0234723
Merge remote-tracking branch 'origin/master'
yaochangyu Apr 9, 2021
985ba5f
調整架構
yaochangyu Apr 9, 2021
d3651c7
調整架構
yaochangyu Apr 10, 2021
7f3e111
refactor
yaochangyu Apr 11, 2021
bd5cec8
add
yaochangyu Apr 12, 2021
aacd852
Merge remote-tracking branch 'origin/master'
yaochangyu Apr 12, 2021
98cf02c
refactor
yaochangyu Apr 12, 2021
69c6b41
refactor
yaochangyu Apr 12, 2021
c8b846c
refactory
yaochangyu Apr 12, 2021
154ba5d
refactor
yaochangyu Apr 12, 2021
d35db10
refactor
yaochangyu Apr 14, 2021
2123ba5
refactor
yaochangyu Apr 14, 2021
7b055dc
refactor
yaochangyu Apr 15, 2021
6fa0e35
refactor
yaochangyu Apr 15, 2021
56a8c7b
refactor
yaochangyu Apr 15, 2021
2f3bf4b
refactor
yaochangyu Apr 15, 2021
a531fee
refactor
yaochangyu Apr 15, 2021
4a88ffa
refactor
yaochangyu Apr 15, 2021
eb494be
refactor
yaochangyu Apr 15, 2021
e8d9477
re
yaochangyu Apr 15, 2021
8aafabc
refactor
yaochangyu Apr 15, 2021
cd9d27f
refactor
yaochangyu Apr 15, 2021
1ef21fc
fix bug
yaochangyu Apr 15, 2021
19ef31f
first add
yaochangyu Apr 15, 2021
a5eab5a
Merge remote-tracking branch 'origin/master'
yaochangyu Apr 15, 2021
35f7904
refactor
yaochangyu Apr 16, 2021
69e4aac
Merge remote-tracking branch 'origin/master'
yaochangyu Apr 16, 2021
3be7ed3
refactor
yaochangyu Apr 16, 2021
4ed7925
refactor
yaochangyu Apr 16, 2021
168afe7
refactor
yaochangyu Apr 16, 2021
51632f9
refactor
yaochangyu Apr 16, 2021
ab8fbbb
add web api project
yaochangyu Apr 16, 2021
97a892c
add sqlite project
yaochangyu Apr 16, 2021
c7924a5
Merge remote-tracking branch 'origin/master'
yaochangyu Apr 16, 2021
59ad406
refactor
yaochangyu Apr 16, 2021
060119b
refactor
yaochangyu Apr 16, 2021
4efc03f
refactor
yaochangyu Apr 16, 2021
bc69418
refactor
yaochangyu Apr 17, 2021
b4a96a4
add sample
yaochangyu Apr 17, 2021
278dc59
add tes case
yaochangyu Apr 17, 2021
d7fd4be
refactor
yaochangyu Apr 18, 2021
6a362db
refactor
yaochangyu Apr 18, 2021
d0b2392
remove reference package
yaochangyu Apr 30, 2021
74e63a0
fix: DefaultDependencyResolver.Dispose() 不會調用物件的 Dispose()
yaochangyu May 10, 2021
16c77af
refactor: 觀察 mvc5 專案的 DI 有沒有正常的呼叫 IMessage.Dispose
yaochangyu May 10, 2021
596eb7e
refactor: 觀察 asp.net core 專案的 DI 有沒有正常的呼叫 IMessage.Dispose
yaochangyu May 10, 2021
1d90cf8
feat: 完成 func name 注入
yaochangyu May 20, 2021
76a30ca
refactor: test case name
yaochangyu May 20, 2021
69c21ed
feat: 增加 Unity 注入
yaochangyu May 20, 2021
31cf8ce
feat: 新增 Autofac test test
yaochangyu May 21, 2021
b695060
fix
yaochangyu May 21, 2021
3735188
add NET5.TestProject.csproj
yaochangyu May 21, 2021
d89c69b
refactor
yaochangyu May 21, 2021
ff8e202
new manual di register
yaochangyu May 21, 2021
8c4950c
refactor
yaochangyu May 21, 2021
a9cb5c6
refactor
yaochangyu May 21, 2021
3b090d0
refactor
yaochangyu May 21, 2021
fe65354
refactor
yaochangyu May 21, 2021
a8b2f4f
refactor
yaochangyu May 21, 2021
ae91f87
refactor
yaochangyu May 21, 2021
d1f9081
refactor
yaochangyu May 21, 2021
eb4d022
add project
yaochangyu Jul 15, 2021
b038c53
refactor: use sockethandler
yaochangyu Jul 15, 2021
62210f0
refactor
yaochangyu Jul 15, 2021
f6e34d7
refactor
yaochangyu Jul 15, 2021
8720295
add test case
yaochangyu Jul 15, 2021
fb14022
add test case
yaochangyu Jul 15, 2021
8c1c30d
refactory
yaochangyu Aug 19, 2021
0abe656
ss
yaochangyu Aug 19, 2021
a003ff2
Delete DI directory
yaochangyu Aug 19, 2021
b364db7
add project
yaochangyu Aug 19, 2021
ef896a7
add
yaochangyu Aug 19, 2021
0c60abb
add project
yaochangyu Oct 23, 2021
ab9dffc
refactor
yaochangyu Oct 23, 2021
f331ac5
first add
yaochangyu Nov 29, 2021
637a997
feat: add project
yaochangyu Dec 8, 2021
03084c5
refactor
yaochangyu Dec 8, 2021
ee8f6fa
feat: add specflow project
yaochangyu Jan 3, 2022
bf39937
refactor
yaochangyu Jan 3, 2022
d15093d
feat: 增加 NUnit
yaochangyu Jan 4, 2022
8f2ab08
feat: add new ef core 6 project
yaochangyu Jan 5, 2022
f676365
feat: add test case
yaochangyu Jan 6, 2022
2340a89
feat: add test case
yaochangyu Jan 9, 2022
39f3b07
feat: add test case
yaochangyu Jan 9, 2022
df03033
feat: add mimiprofiler project
yaochangyu Jan 16, 2022
4238a4c
add files
yaochangyu Jan 16, 2022
3c5627a
feat: 修正方案結構
yaochangyu Jan 16, 2022
4ccffec
add get/post action
yaochangyu Jan 16, 2022
41fa6a0
feat: add 大象資料庫
yaochangyu Jan 16, 2022
7084f4b
add db type
yaochangyu Jan 16, 2022
657348f
feat: add asp.net core 6
yaochangyu Jan 16, 2022
47bb47e
MiniProfiler 整合 Swagger
yaochangyu Jan 16, 2022
036dfd3
remove file
yaochangyu Jan 17, 2022
720e9f2
feat: add new project
yaochangyu Jan 18, 2022
a497b26
rename
yaochangyu Jan 19, 2022
f0d8f6d
add taskfile to sln
yaochangyu Jan 19, 2022
df4980f
feat:字典集合綁定
yaochangyu Jan 19, 2022
8630ea1
refactor
yaochangyu Jan 19, 2022
965ce4b
fix bug
yaochangyu Jan 19, 2022
d01f344
fix bug
yaochangyu Jan 19, 2022
ca4bb98
refactor
yaochangyu Jan 19, 2022
fee8ced
add test case
yaochangyu Jan 19, 2022
23bd21a
feat: Env File Config
yaochangyu Jan 19, 2022
9a0ea0c
refactor
yaochangyu Jan 20, 2022
c1dd221
refactor
yaochangyu Jan 20, 2022
da6e29d
add project
yaochangyu Feb 13, 2022
0b0745f
feat: add project
yaochangyu Feb 13, 2022
78fbb9e
Repo 實作 track 更新
yaochangyu Feb 16, 2022
15aea80
feat: 追蹤異動
yaochangyu Feb 17, 2022
e54e01e
異動複雜型別-失敗
yaochangyu Feb 17, 2022
fc62271
add complex type
yaochangyu Feb 18, 2022
ea069a2
add collection trackable
yaochangyu Feb 19, 2022
38cd599
class=>record
yaochangyu Feb 19, 2022
0305f3a
refactor
yaochangyu Feb 19, 2022
66ca512
refactor
yaochangyu Feb 19, 2022
98a592e
refactor
yaochangyu Feb 19, 2022
f955806
add bddpipe project
yaochangyu Feb 19, 2022
c65d353
add first project
yaochangyu Feb 27, 2022
066023b
feat: 完成異動案例
yaochangyu Mar 1, 2022
0573c8c
refactor: add accessContext
yaochangyu Mar 3, 2022
e621dd2
add profile data
yaochangyu Mar 3, 2022
3ca9bd0
feat: 實作 change track
yaochangyu Mar 5, 2022
62be34a
feat: 狀態追蹤套用 EF Core
yaochangyu Mar 5, 2022
246e223
fix: 修正無法存檔
yaochangyu Mar 6, 2022
1c79552
refactor
yaochangyu Mar 6, 2022
3374833
refactor
yaochangyu Mar 6, 2022
af1f134
feat: 新增一筆後存檔
yaochangyu Mar 6, 2022
200f218
feat: 編輯、刪除
yaochangyu Mar 6, 2022
c9d8b65
案例開始前後刪除資料
yaochangyu Mar 6, 2022
165a9c2
refactor
yaochangyu Mar 6, 2022
6117d95
refactor
yaochangyu Mar 7, 2022
6f54bd2
refactor
yaochangyu Mar 7, 2022
6a94eb0
add swagger doc project
yaochangyu Mar 12, 2022
b763c2b
refactor
yaochangyu Mar 12, 2022
f7c6739
add api info
yaochangyu Mar 12, 2022
19ebd71
add example
yaochangyu Mar 12, 2022
5c627f5
add JsonStringEnumMemberConverter
yaochangyu Mar 12, 2022
db68b24
enum to string
yaochangyu Mar 12, 2022
655b2fd
feat: add initial project
yaochangyu Mar 13, 2022
78ac76b
feat: set UrlSegmentApiVersionReader
yaochangyu Mar 13, 2022
84cbfe2
feat: Swagger UI 套用多版本
yaochangyu Mar 13, 2022
5d9e8a4
first project
yaochangyu Mar 22, 2022
394e993
feat: add DictionaryStringObjectJsonConverter project
yaochangyu Mar 27, 2022
8d6902f
feat: add JsonNodeExtensions
yaochangyu Mar 27, 2022
4452fc4
add project
yaochangyu Mar 28, 2022
9ff043b
feat: add DictionaryStringObjectJsonConverter
yaochangyu Mar 28, 2022
092d356
refactor
yaochangyu Mar 29, 2022
34de843
add raw sql
yaochangyu Mar 29, 2022
9d6e437
feat: raw sql query
yaochangyu Mar 30, 2022
10aeb3d
add project
yaochangyu Apr 9, 2022
5280afc
add RequireFieldValidator
yaochangyu Apr 9, 2022
c869ca9
feat: NameFieldValidator
yaochangyu Apr 10, 2022
507b407
feat: BirthdayFieldValidator
yaochangyu Apr 10, 2022
9187478
feat GenderFieldValidator
yaochangyu Apr 10, 2022
60093ac
refactor
yaochangyu Apr 10, 2022
5d5ff13
Merge pull request #11 from yaochangyu/Dictionary_Validate
yaochangyu Apr 10, 2022
1716a51
remove file
yaochangyu Apr 10, 2022
dfc5d6e
remove file
yaochangyu Apr 10, 2022
875783f
refactor
yaochangyu Apr 10, 2022
0dc48ba
refactor
yaochangyu Apr 11, 2022
a26eb70
refactor
yaochangyu Apr 11, 2022
94322d1
feat: add DictionaryStringObjectJsonConverter2
yaochangyu Apr 15, 2022
e939140
feat: add test case
yaochangyu Apr 16, 2022
b8b14ed
Merge pull request #12
yaochangyu Apr 16, 2022
6082108
fea: 新增 System.Text.Json.JsonDiffPatch 測試案例
yaochangyu May 14, 2022
2c9f5f2
build(deps): bump CefSharp.WinForms in /CEF/Lab.Startup/WinFormNet48
dependabot[bot] May 14, 2022
7f7396a
build(deps): bump CefSharp.WinForms in /CEF/Lab.Startup/WinFormCore30
dependabot[bot] May 14, 2022
585697a
feat: add NewtonsoftJsonDiffPathTests
yaochangyu May 14, 2022
c136d92
refactor
yaochangyu May 14, 2022
d0895a8
add json patch test case
yaochangyu May 14, 2022
07b74a6
feat: add project
yaochangyu May 22, 2022
b67c3af
feat: add test case
yaochangyu May 22, 2022
99627a3
feat: 訪問不需要授權的服務
yaochangyu May 22, 2022
4724568
refactor
yaochangyu May 22, 2022
15c3376
refactor
yaochangyu May 22, 2022
25a093e
refactor
yaochangyu May 22, 2022
57534f3
feat: add project
yaochangyu Jun 16, 2022
aee7db6
refactor
yaochangyu Jun 16, 2022
ad7760d
add test client test case
yaochangyu Jun 16, 2022
179f1a5
refactor
yaochangyu Jun 17, 2022
544f24a
Merge pull request #19 from yaochangyu/aspnet_core_middleware_test
yaochangyu Jun 17, 2022
9e6ac8e
Merge pull request #17 from yaochangyu/dependabot/nuget/CEF/Lab.Start…
yaochangyu Jun 17, 2022
1feb60f
Merge pull request #18 from yaochangyu/dependabot/nuget/CEF/Lab.Start…
yaochangyu Jun 17, 2022
1edfd77
feat: add unit test
yaochangyu Jun 18, 2022
f090952
refactor
yaochangyu Jun 19, 2022
95c4cbc
add BasicAuthenticationHandler單元測試
yaochangyu Jun 19, 2022
54673a6
refactor
yaochangyu Jun 19, 2022
ef9ae0b
Merge pull request #20
yaochangyu Jun 19, 2022
512503b
fix
yaochangyu Jun 20, 2022
64603ba
Merge pull request #21
yaochangyu Jun 20, 2022
80b3c9a
fix
yaochangyu Jun 20, 2022
1520fad
Merge pull request #22
yaochangyu Jun 20, 2022
24323d8
feat: 實作授權
yaochangyu Jun 21, 2022
1ae0420
refactor
yaochangyu Jun 21, 2022
248237f
Merge pull request #23
yaochangyu Jun 21, 2022
3499b66
feat: 套用範本
yaochangyu Jun 26, 2022
fc0ee3f
Merge pull request #30
yaochangyu Jun 26, 2022
bc3728a
feat: add other temp
yaochangyu Jun 26, 2022
5e786ca
refactor
yaochangyu Jun 26, 2022
8fb4fd9
Merge pull request #41
yaochangyu Jun 26, 2022
4f88718
add minio s3 sample
yaochangyu Jul 8, 2022
b1f55a1
feat: add yaml and web project
yaochangyu Jul 14, 2022
4c277b6
add task
yaochangyu Jul 16, 2022
51428f4
refactor
yaochangyu Jul 16, 2022
6547907
Merge pull request #46
yaochangyu Jul 16, 2022
57391bd
remove folder
yaochangyu Jul 16, 2022
d06f4bb
impl controlle
yaochangyu Jul 16, 2022
87721cc
from fork lab.specfirst
yaochangyu Jul 18, 2022
e9f6b44
feat: extra schema module
yaochangyu Jul 19, 2022
a857da0
feat: merge file
yaochangyu Jul 19, 2022
65158ec
modify task
yaochangyu Jul 20, 2022
85f9f3b
regen
yaochangyu Jul 20, 2022
1e35d1d
from fork lab.specfirst
yaochangyu Jul 18, 2022
df670f1
feat: extra schema module
yaochangyu Jul 19, 2022
5396074
feat: merge file
yaochangyu Jul 19, 2022
be5121c
modify task
yaochangyu Jul 20, 2022
bcb1a92
regen
yaochangyu Jul 20, 2022
f2c4780
feat: 範例完成
yaochangyu Aug 16, 2022
8359230
Merge pull request #48
yaochangyu Aug 16, 2022
2070c3a
feat: add test
yaochangyu Aug 20, 2022
3249bc1
refactor: add test case
yaochangyu Aug 20, 2022
5818b9e
refactor
yaochangyu Aug 20, 2022
ab9d435
refactor: 使用必要套件
yaochangyu Aug 20, 2022
840b4c5
refactor
yaochangyu Aug 20, 2022
4a10191
Merge pull request #49
yaochangyu Aug 20, 2022
2fdf8d5
add project
yaochangyu Aug 26, 2022
af30d60
切換設定
yaochangyu Aug 26, 2022
38e7cb0
add file
yaochangyu Aug 28, 2022
7d3e8ca
add file
yaochangyu Aug 28, 2022
dc9d588
增加 webapi task
yaochangyu Aug 28, 2022
6b9b3b1
add console app
yaochangyu Aug 28, 2022
b032e40
Merge pull request #53
yaochangyu Aug 28, 2022
07a1e4b
add file
yaochangyu Aug 29, 2022
776be87
app project
yaochangyu Aug 29, 2022
78c5f31
set serilog config
yaochangyu Sep 4, 2022
8224057
build(deps): bump Microsoft.Owin
dependabot[bot] Sep 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
19 changes: 19 additions & 0 deletions AWS/Lab.AwsS3/Lab.Aws.S3.MinIOS3/Lab.Aws.S3.MinIOS3.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.S3" Version="3.7.9.21" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>

</Project>
86 changes: 86 additions & 0 deletions AWS/Lab.AwsS3/Lab.Aws.S3.MinIOS3/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System.Collections.Concurrent;
using System.Reflection;
using Amazon;
using Amazon.S3;
using Amazon.S3.Model;

namespace Lab.Aws.S3.MinIOS3;

public class FieldTypeAssistant
{
private static ConcurrentDictionary<Type, Dictionary<string, string>> s_fieldTypeList = new();

public static Dictionary<string, string> GetStaticFieldValues<T>()
{
var type = typeof(T);
var fieldTypeList = s_fieldTypeList;
if (fieldTypeList.TryGetValue(type, out var results))
{
return results;
}

var bindingFlags = BindingFlags.Public
| BindingFlags.Static
;
results = new Dictionary<string, string>();
var fieldInfosInfos = type.GetFields(bindingFlags);
foreach (var fieldInfo in fieldInfosInfos)
{
var key = fieldInfo.Name;
var value = fieldInfo.GetValue(null);

results.Add(value.ToString(), key);
}

fieldTypeList.TryAdd(type, results);
return results;
}
}

public class ProfileFieldNames
{
public const string BB1Name = "BB1";

public const string BB2Name = "BB2";

private static readonly Lazy<IReadOnlyDictionary<string, string>> s_valueDictionary =
new(FieldTypeAssistant.GetStaticFieldValues<ProfileFieldNames>());

public static IReadOnlyDictionary<string, string> GetValues()
{
return s_valueDictionary.Value;
}

public static string GetValue(string key)
{
s_valueDictionary.Value.TryGetValue(key, out var value);
return value;
}
}

[TestClass]
public class UnitTest1
{
[TestMethod]
public void test()
{
var actual = ProfileFieldNames.GetValue("BB1");
Assert.AreEqual("BB1Name", actual);
}

[TestMethod]
public async Task 新增一個儲存桶()
{
var s3Config = new AmazonS3Config()
{
RegionEndpoint = RegionEndpoint.USEast1,
ServiceURL = "http://localhost:9000",
ForcePathStyle = true
};
var s3Client = new AmazonS3Client(s3Config);
var response = await s3Client.PutBucketAsync(new PutBucketRequest
{
BucketName = "test-bucket",
});
}
}
1 change: 1 addition & 0 deletions AWS/Lab.AwsS3/Lab.Aws.S3.MinIOS3/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Microsoft.VisualStudio.TestTools.UnitTesting;
21 changes: 21 additions & 0 deletions AWS/Lab.AwsS3/Lab.AwsS3.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab.Aws.S3.MinIOS3", "Lab.Aws.S3.MinIOS3\Lab.Aws.S3.MinIOS3.csproj", "{0FF96B3C-2410-4444-A113-FB2B80E4D940}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "global", "global", "{17F77AC4-5953-4CD1-917D-28A4746AB759}"
ProjectSection(SolutionItems) = preProject
docker-compose.yaml = docker-compose.yaml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0FF96B3C-2410-4444-A113-FB2B80E4D940}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0FF96B3C-2410-4444-A113-FB2B80E4D940}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0FF96B3C-2410-4444-A113-FB2B80E4D940}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0FF96B3C-2410-4444-A113-FB2B80E4D940}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
17 changes: 17 additions & 0 deletions AWS/Lab.AwsS3/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "3.8"

services:
s3-minio:
container_name: "s3-minio"
hostname: "minio"
image: minio/minio:latest
volumes:
- ./minio/data:/data
ports:
- "9000:9000"
- "9001:9001"
environment:
# 這裡的 key 要跟 .aws/credentials 裡的 key 名稱一樣,aws cli 才能正常的運作
MINIO_ROOT_USER: "AKIAIOSFODNN7EXAMPLE"
MINIO_ROOT_PASSWORD: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
command: server --console-address :9001 /data
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.8"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0"/>
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8"/>
<PackageReference Include="MSTest.TestFramework" Version="2.2.8"/>
<PackageReference Include="coverlet.collector" Version="3.1.2"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Lib.Middleware.OverrideResponse\Lib.Middleware.OverrideResponse.csproj"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.Unicode;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace Lib.Middleware.OverrideResponse.UnitTest;

[TestClass]
public class OverrideResponseHandlerMiddlewareUnitTest
{
[TestMethod]
public async Task 不模糊訊息()
{
var expected = @"{""code"":""9527""}";

var serviceProvider = CreateServiceProvider();
var jsonSerializerOptions = serviceProvider.GetService<JsonSerializerOptions>();
var logger = serviceProvider.GetService<ILogger<OverrideResponseHandlerMiddleware>>();
var target = new OverrideResponseHandlerMiddleware(nextContext =>
CreateFakeNextContext(nextContext, new { Code = "9527" }, StatusCodes.Status200OK));

var httpContext = new DefaultHttpContext
{
Response = { Body = new MemoryStream() }
};

await target.InvokeAsync(httpContext, logger, jsonSerializerOptions);
var response = httpContext.Response;
var stream = response.Body;
if (stream.CanSeek)
{
stream.Seek(0, SeekOrigin.Begin);
}

var actual = await new StreamReader(stream).ReadToEndAsync();
Assert.AreEqual(expected, actual);
}

[TestMethod]
public async Task 模糊化未授權訊息()
{
var expected = @"{""errorCode"":""NoAuthorization"",""errorMessage"":""Please contact your administrator""}";
var httpContext = new DefaultHttpContext
{
Response = { Body = new MemoryStream() }
};
var serviceProvider = CreateServiceProvider();
var jsonSerializerOptions = serviceProvider.GetService<JsonSerializerOptions>();
var logger = serviceProvider.GetService<ILogger<OverrideResponseHandlerMiddleware>>();

var target = new OverrideResponseHandlerMiddleware(nextContext =>
CreateFakeNextContext(nextContext, new
{
ErrorCode = "NoAuthorization",
ErrorMessage = "No permission"
}, StatusCodes.Status403Forbidden));

await target.InvokeAsync(httpContext, logger, jsonSerializerOptions);

var response = httpContext.Response;
var stream = response.Body;
if (stream.CanSeek)
{
stream.Seek(0, SeekOrigin.Begin);
}

var actual = await new StreamReader(stream).ReadToEndAsync();
Assert.AreEqual(expected, actual);
}

[TestMethod]
public async Task 模糊化未驗證訊息()
{
var expected = @"{""errorCode"":""NoAuthentication"",""errorMessage"":""Please contact your administrator""}";
var httpContext = new DefaultHttpContext
{
Response = { Body = new MemoryStream() }
};
var serviceProvider = CreateServiceProvider();
var jsonSerializerOptions = serviceProvider.GetService<JsonSerializerOptions>();
var logger = serviceProvider.GetService<ILogger<OverrideResponseHandlerMiddleware>>();

var target = new OverrideResponseHandlerMiddleware(nextContext =>
CreateFakeNextContext(nextContext, new
{
ErrorCode = "NoAuthentication",
ErrorMessage = "Invalid userid or password"
}, StatusCodes.Status401Unauthorized));

await target.InvokeAsync(httpContext, logger, jsonSerializerOptions);

var response = httpContext.Response;
var stream = response.Body;
if (stream.CanSeek)
{
stream.Seek(0, SeekOrigin.Begin);
}

var actual = await new StreamReader(stream).ReadToEndAsync();
Assert.AreEqual(expected, actual);
}

private static Task CreateFakeNextContext(HttpContext context, object detailFailure, int statusCode)
{
context.Response.StatusCode = statusCode;
context.Response.WriteAsJsonAsync(detailFailure);
return Task.CompletedTask;
}

private static JsonSerializerOptions CreateJsonSerializerOptions()
{
return new JsonSerializerOptions
{
Encoder = JavaScriptEncoder.Create(UnicodeRanges.BasicLatin,
UnicodeRanges.CjkUnifiedIdeographs),
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DictionaryKeyPolicy = JsonNamingPolicy.CamelCase,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};
}

private static IServiceProvider CreateServiceProvider()
{
var services = new ServiceCollection();
services.AddSingleton(p => CreateJsonSerializerOptions());
services.AddSingleton(p => LoggerFactory.Create(builder => { builder.AddConsole(); }));
services.AddSingleton(p => p.GetService<ILoggerFactory>().CreateLogger<OverrideResponseHandlerMiddleware>());
return services.BuildServiceProvider();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Microsoft.VisualStudio.TestTools.UnitTesting;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lib.Middleware.OverrideResponse", "Lib.Middleware.OverrideResponse\Lib.Middleware.OverrideResponse.csproj", "{F696FEA1-4126-42F0-8D2F-6F7BE99DF418}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lib.Middleware.OverrideResponse.UnitTest", "Lib.Middleware.OverrideResponse.UnitTest\Lib.Middleware.OverrideResponse.UnitTest.csproj", "{F5FD889F-037A-476E-B1F2-A01769A34674}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F696FEA1-4126-42F0-8D2F-6F7BE99DF418}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F696FEA1-4126-42F0-8D2F-6F7BE99DF418}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F696FEA1-4126-42F0-8D2F-6F7BE99DF418}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F696FEA1-4126-42F0-8D2F-6F7BE99DF418}.Release|Any CPU.Build.0 = Release|Any CPU
{F5FD889F-037A-476E-B1F2-A01769A34674}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F5FD889F-037A-476E-B1F2-A01769A34674}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F5FD889F-037A-476E-B1F2-A01769A34674}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F5FD889F-037A-476E-B1F2-A01769A34674}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0"/>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1"/>
<!-- <PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0"/>-->
<!-- <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.0"/>-->
<!-- <PackageReference Include="Microsoft.AspNetCore.HttpOverrides" Version="2.2.0" />-->
</ItemGroup>

</Project>
Loading