Skip to content

Commit 703e875

Browse files
author
Jicheng Lu
committed
Merge branch 'master' of https://github.com/SciSharp/BotSharp into features/integrate-response-api
2 parents ef4f1dd + c3b976e commit 703e875

26 files changed

Lines changed: 415 additions & 78 deletions
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>$(TargetFramework)</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<IsPackable>false</IsPackable>
8+
<RootNamespace>BotSharp.Core.UnitTests</RootNamespace>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" />
13+
<PackageReference Include="xunit" />
14+
<PackageReference Include="xunit.runner.visualstudio">
15+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
16+
<PrivateAssets>all</PrivateAssets>
17+
</PackageReference>
18+
<PackageReference Include="coverlet.collector">
19+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20+
<PrivateAssets>all</PrivateAssets>
21+
</PackageReference>
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<ProjectReference Include="..\src\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
26+
</ItemGroup>
27+
28+
</Project>
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using BotSharp.Core.Infrastructures;
2+
using Xunit;
3+
4+
namespace BotSharp.Core.UnitTests.Infrastructures;
5+
6+
public class SettingServiceTests
7+
{
8+
[Fact]
9+
public void Mask_null_or_empty_returns_empty()
10+
{
11+
Assert.Equal(string.Empty, SettingService.Mask(null!));
12+
Assert.Equal(string.Empty, SettingService.Mask(string.Empty));
13+
}
14+
15+
[Theory]
16+
[InlineData("a", "*")]
17+
[InlineData("ab", "**")]
18+
[InlineData("abc", "a**")]
19+
[InlineData("abcd", "a***")]
20+
[InlineData("0123456789", "0123******")]
21+
public void Mask_short_and_medium_inputs_matches_expected_masked_form(string input, string expected)
22+
{
23+
var actual = SettingService.Mask(input);
24+
Assert.Equal(expected, actual);
25+
}
26+
27+
[Fact]
28+
public void Mask_long_value_preserves_length_and_replaces_suffix_with_stars()
29+
{
30+
var input = new string('x', 64);
31+
var masked = SettingService.Mask(input);
32+
33+
Assert.Equal(64, masked.Length);
34+
Assert.NotEqual(input, masked);
35+
Assert.Contains('*', masked);
36+
Assert.StartsWith("x", masked, StringComparison.Ordinal);
37+
Assert.EndsWith("*", masked);
38+
}
39+
40+
[Theory]
41+
[InlineData("e", 1)]
42+
[InlineData("ef", 2)]
43+
[InlineData("efg", 3)]
44+
[InlineData("efgh", 4)]
45+
[InlineData("123456789012345", 15)]
46+
[InlineData("abcdefghijklmnopqrstuvwxyz", 26)]
47+
public void Mask_preserves_original_string_length(string input, int expectedLength)
48+
{
49+
var masked = SettingService.Mask(input);
50+
Assert.Equal(expectedLength, masked.Length);
51+
}
52+
53+
[Theory]
54+
[InlineData("a")]
55+
[InlineData("ab")]
56+
[InlineData("abc")]
57+
[InlineData("password123")]
58+
public void Mask_contains_at_least_one_asterisk(string input)
59+
{
60+
var masked = SettingService.Mask(input);
61+
Assert.Contains('*', masked);
62+
}
63+
64+
[Fact]
65+
public void Mask_very_long_string()
66+
{
67+
var input = new string('a', 1000);
68+
var masked = SettingService.Mask(input);
69+
70+
Assert.Equal(1000, masked.Length);
71+
Assert.Contains('*', masked);
72+
var keepLength = (1000 - 1) / 2;
73+
var asteriskCount = 1000 - keepLength;
74+
Assert.Equal(asteriskCount, masked.Count(c => c == '*'));
75+
}
76+
77+
[Fact]
78+
public void Mask_api_key_like_string()
79+
{
80+
var input = "sk_live_1234567890abcdef";
81+
var masked = SettingService.Mask(input);
82+
83+
Assert.Equal(input.Length, masked.Length);
84+
Assert.Contains('*', masked);
85+
Assert.StartsWith("sk_li", masked);
86+
}
87+
}

BotSharp.sln

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Core.A2A", "src\In
155155
EndProject
156156
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.MultiTenancy", "src\Plugins\BotSharp.Plugin.MultiTenancy\BotSharp.Plugin.MultiTenancy.csproj", "{562DD0C6-DAC8-02CC-C1DD-D43DF186CE76}"
157157
EndProject
158+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Core.UnitTests", "BotSharp.Core.UnitTests\BotSharp.Core.UnitTests.csproj", "{53E53E98-3C14-4AED-AC40-BD88170C5FE5}"
159+
EndProject
158160
Global
159161
GlobalSection(SolutionConfigurationPlatforms) = preSolution
160162
Debug|Any CPU = Debug|Any CPU
@@ -659,6 +661,14 @@ Global
659661
{562DD0C6-DAC8-02CC-C1DD-D43DF186CE76}.Release|Any CPU.Build.0 = Release|Any CPU
660662
{562DD0C6-DAC8-02CC-C1DD-D43DF186CE76}.Release|x64.ActiveCfg = Release|Any CPU
661663
{562DD0C6-DAC8-02CC-C1DD-D43DF186CE76}.Release|x64.Build.0 = Release|Any CPU
664+
{53E53E98-3C14-4AED-AC40-BD88170C5FE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
665+
{53E53E98-3C14-4AED-AC40-BD88170C5FE5}.Debug|Any CPU.Build.0 = Debug|Any CPU
666+
{53E53E98-3C14-4AED-AC40-BD88170C5FE5}.Debug|x64.ActiveCfg = Debug|Any CPU
667+
{53E53E98-3C14-4AED-AC40-BD88170C5FE5}.Debug|x64.Build.0 = Debug|Any CPU
668+
{53E53E98-3C14-4AED-AC40-BD88170C5FE5}.Release|Any CPU.ActiveCfg = Release|Any CPU
669+
{53E53E98-3C14-4AED-AC40-BD88170C5FE5}.Release|Any CPU.Build.0 = Release|Any CPU
670+
{53E53E98-3C14-4AED-AC40-BD88170C5FE5}.Release|x64.ActiveCfg = Release|Any CPU
671+
{53E53E98-3C14-4AED-AC40-BD88170C5FE5}.Release|x64.Build.0 = Release|Any CPU
662672
EndGlobalSection
663673
GlobalSection(SolutionProperties) = preSolution
664674
HideSolutionNode = FALSE
@@ -734,6 +744,7 @@ Global
734744
{13223C71-9EAC-9835-28ED-5A4833E6F915} = {53E7CD86-0D19-40D9-A0FA-AB4613837E89}
735745
{E8D01281-D52A-BFF4-33DB-E35D91754272} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
736746
{562DD0C6-DAC8-02CC-C1DD-D43DF186CE76} = {51AFE054-AE99-497D-A593-69BAEFB5106F}
747+
{53E53E98-3C14-4AED-AC40-BD88170C5FE5} = {32FAFFFE-A4CB-4FEE-BF7C-84518BBC6DCC}
737748
EndGlobalSection
738749
GlobalSection(ExtensibilityGlobals) = postSolution
739750
SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19}

src/Infrastructure/BotSharp.Abstraction/Graph/IGraphDb.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using BotSharp.Abstraction.Graph.Models;
22
using BotSharp.Abstraction.Graph.Options;
3+
using BotSharp.Abstraction.Graph.Requests;
34

45
namespace BotSharp.Abstraction.Graph;
56

@@ -9,4 +10,32 @@ public interface IGraphDb
910

1011
Task<GraphQueryResult> ExecuteQueryAsync(string query, GraphQueryExecuteOptions? options = null)
1112
=> throw new NotImplementedException();
13+
14+
#region Node
15+
Task<GraphNodeModel> GetNodeAsync(string graphId, string nodeId)
16+
=> throw new NotImplementedException();
17+
18+
Task<GraphNodeModel> CreateNodeAsync(string graphId, GraphNodeCreationRequest request)
19+
=> throw new NotImplementedException();
20+
21+
Task<GraphNodeModel> MergeNodeAsync(string graphId, string nodeId, GraphNodeUpdateRequest request)
22+
=> throw new NotImplementedException();
23+
24+
Task<bool> DeleteNodeAsync(string graphId, string nodeId)
25+
=> throw new NotImplementedException();
26+
#endregion
27+
28+
#region Edge
29+
Task<GraphEdgeModel> GetEdgeAsync(string graphId, string edgeId)
30+
=> throw new NotImplementedException();
31+
32+
Task<GraphEdgeModel> CreateEdgeAsync(string graphId, GraphEdgeCreationRequest request)
33+
=> throw new NotImplementedException();
34+
35+
Task<GraphEdgeModel> UpdateEdgeAsync(string graphId, string edgeId, GraphEdgeUpdateRequest request)
36+
=> throw new NotImplementedException();
37+
38+
Task<bool> DeleteEdgeAsync(string graphId, string edgeId)
39+
=> throw new NotImplementedException();
40+
#endregion
1241
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace BotSharp.Abstraction.Graph.Models;
2+
3+
public class GraphEdgeModel
4+
{
5+
public string Id { get; set; } = string.Empty;
6+
public string SourceNodeId { get; set; } = string.Empty;
7+
public string TargetNodeId { get; set; } = string.Empty;
8+
public string Type { get; set; } = string.Empty;
9+
public object? Properties { get; set; }
10+
public string? Direction { get; set; }
11+
public bool? Directed { get; set; }
12+
public float? Weight { get; set; }
13+
public DateTime? CreatedAt { get; set; }
14+
public DateTime? UpdatedAt { get; set; }
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace BotSharp.Abstraction.Graph.Models;
2+
3+
public class GraphNodeModel
4+
{
5+
public string Id { get; set; } = string.Empty;
6+
public List<string> Labels { get; set; } = new();
7+
public object Properties { get; set; } = new();
8+
public DateTime? Time { get; set; } = DateTime.UtcNow;
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace BotSharp.Abstraction.Graph.Requests;
2+
3+
public class GraphEdgeCreationRequest
4+
{
5+
public string? Id { get; set; }
6+
public string SourceNodeId { get; set; } = null!;
7+
public string TargetNodeId { get; set; } = null!;
8+
public string Type { get; set; } = null!;
9+
public bool Directed { get; set; } = true;
10+
public float? Weight { get; set; } = 1.0f;
11+
public Dictionary<string, object>? Properties { get; set; }
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace BotSharp.Abstraction.Graph.Requests;
2+
3+
public class GraphEdgeUpdateRequest
4+
{
5+
public string Id { get; set; } = null!;
6+
public Dictionary<string, object>? Properties { get; set; }
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace BotSharp.Abstraction.Graph.Requests;
2+
3+
public class GraphNodeCreationRequest
4+
{
5+
public string? Id { get; set; }
6+
public string[]? Labels { get; set; }
7+
public Dictionary<string, object>? Properties { get; set; }
8+
public DateTime? Time { get; set; }
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace BotSharp.Abstraction.Graph.Requests;
2+
3+
public class GraphNodeUpdateRequest
4+
{
5+
public string Id { get; set; } = null!;
6+
public string[]? Labels { get; set; }
7+
public Dictionary<string, object>? Properties { get; set; }
8+
public DateTime? Time { get; set; }
9+
}

0 commit comments

Comments
 (0)