Skip to content

Commit e3a4178

Browse files
committed
test: adds more tests
1 parent 5ceb823 commit e3a4178

21 files changed

+257
-58
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=Cnblogs_002EDashScope_002EAI_002EUnitTests_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean>
23
<s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=Cnblogs_002EDashScope_002ESample_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean>
34
<s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=Cnblogs_002EDashScope_002ESdk_002ESnapshotGenerator_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean>
45
<s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=Cnblogs_002EDashScope_002ESdk_002EUnitTests_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean>
6+
<s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=Cnblogs_002EDashScope_002ETests_002EShared_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean>
57
<s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=Cnblogs_002EDashScope_002EWebSample_002EClient_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean>
68
<s:Boolean x:Key="/Default/Environment/Filtering/ExcludeCoverageFilters/=Cnblogs_002EDashScope_002EWebSample_003B_002A_003B_002A_003B_002A/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

src/Cnblogs.DashScope.AI/Cnblogs.DashScope.AI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="JsonSchema.Net.Generation" Version="5.0.2" />
14+
<PackageReference Include="JsonSchema.Net.Generation" Version="5.0.3" />
1515
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.5.0" />
1616
</ItemGroup>
1717

src/Cnblogs.DashScope.AspNetCore/DashScopeClientAspNetCore.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,16 @@ namespace Cnblogs.DashScope.AspNetCore;
55
/// <summary>
66
/// The <see cref="DashScopeClientCore"/> with DI and options pattern support.
77
/// </summary>
8-
public class DashScopeClientAspNetCore(IHttpClientFactory factory, DashScopeClientWebSocketPool pool)
9-
: DashScopeClientCore(factory.CreateClient(DashScopeAspNetCoreDefaults.DefaultHttpClientName), pool);
8+
public class DashScopeClientAspNetCore
9+
: DashScopeClientCore
10+
{
11+
/// <summary>
12+
/// The <see cref="DashScopeClientCore"/> with DI and options pattern support.
13+
/// </summary>
14+
/// <param name="factory">The factory to create <see cref="HttpClient"/>.</param>
15+
/// <param name="pool">The socket pool for WebSocket API calls.</param>
16+
public DashScopeClientAspNetCore(IHttpClientFactory factory, DashScopeClientWebSocketPool pool)
17+
: base(factory.CreateClient(DashScopeAspNetCoreDefaults.DefaultHttpClientName), pool)
18+
{
19+
}
20+
}

src/Cnblogs.DashScope.Core/DashScopeClientWebSocketPool.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@ namespace Cnblogs.DashScope.Core;
55
/// <summary>
66
/// Socket pool for DashScope API.
77
/// </summary>
8-
/// <param name="options"></param>
9-
public sealed class DashScopeClientWebSocketPool(DashScopeOptions options) : IDisposable
8+
public sealed class DashScopeClientWebSocketPool : IDisposable
109
{
1110
private readonly ConcurrentBag<DashScopeClientWebSocket> _available = new();
1211
private readonly ConcurrentBag<DashScopeClientWebSocket> _active = new();
12+
private readonly DashScopeOptions _options;
13+
14+
/// <summary>
15+
/// Socket pool for DashScope API.
16+
/// </summary>
17+
/// <param name="options">Options for DashScope sdk.</param>
18+
public DashScopeClientWebSocketPool(DashScopeOptions options)
19+
{
20+
_options = options;
21+
}
1322

1423
internal void ReturnSocketAsync(DashScopeClientWebSocket socket)
1524
{
@@ -49,7 +58,7 @@ public async Task<DashScopeClientWebSocketWrapper> RentSocketAsync<TOutput>(
4958
}
5059
else
5160
{
52-
socket = await InitializeNewSocketAsync<TOutput>(options.BaseWebsocketAddress, cancellationToken);
61+
socket = await InitializeNewSocketAsync<TOutput>(_options.BaseWebsocketAddress, cancellationToken);
5362
found = true;
5463
}
5564
}
@@ -68,12 +77,12 @@ private async Task<DashScopeClientWebSocket> InitializeNewSocketAsync<TOutput>(
6877
CancellationToken cancellationToken = default)
6978
where TOutput : class
7079
{
71-
if (_available.Count + _active.Count >= options.SocketPoolSize)
80+
if (_available.Count + _active.Count >= _options.SocketPoolSize)
7281
{
7382
throw new InvalidOperationException("[DashScopeSDK] Socket pool is full");
7483
}
7584

76-
var socket = new DashScopeClientWebSocket(options.ApiKey, options.WorkspaceId);
85+
var socket = new DashScopeClientWebSocket(_options.ApiKey, _options.WorkspaceId);
7786
await socket.ConnectAsync<TOutput>(new Uri(url), cancellationToken);
7887
return socket;
7988
}

src/Cnblogs.DashScope.Core/DashScopeWebSocketRequest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ public class DashScopeWebSocketRequest<TInput, TParameter>
1212
/// <summary>
1313
/// Metadata of the request.
1414
/// </summary>
15-
public required DashScopeWebSocketRequestHeader Header { get; set; }
15+
public DashScopeWebSocketRequestHeader Header { get; set; } = new();
1616

1717
/// <summary>
1818
/// Payload of the request.
1919
/// </summary>
20-
public required DashScopeWebSocketRequestPayload<TInput, TParameter> Payload { get; set; }
20+
public DashScopeWebSocketRequestPayload<TInput, TParameter> Payload { get; set; } = new();
2121
}

src/Cnblogs.DashScope.Core/DashScopeWebSocketRequestHeader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ public class DashScopeWebSocketRequestHeader
88
/// <summary>
99
/// Action name.
1010
/// </summary>
11-
public required string Action { get; set; }
11+
public string Action { get; set; } = string.Empty;
1212

1313
/// <summary>
1414
/// UUID for task.
1515
/// </summary>
16-
public required string TaskId { get; set; }
16+
public string TaskId { get; set; } = string.Empty;
1717

1818
/// <summary>
1919
/// Streaming type.

src/Cnblogs.DashScope.Core/DashScopeWebSocketRequestPayload.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ public class DashScopeWebSocketRequestPayload<TInput, TParameter>
3737
/// <summary>
3838
/// The input of the request.
3939
/// </summary>
40-
public required TInput Input { get; set; }
40+
public TInput Input { get; set; } = null!;
4141
}

src/Cnblogs.DashScope.Core/Internals/ClientWebSocketWrapper.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,46 @@
22

33
namespace Cnblogs.DashScope.Core.Internals;
44

5-
internal sealed class ClientWebSocketWrapper(ClientWebSocket socket) : IClientWebSocket
5+
internal sealed class ClientWebSocketWrapper : IClientWebSocket
66
{
7+
private readonly ClientWebSocket _socket;
8+
9+
public ClientWebSocketWrapper(ClientWebSocket socket)
10+
{
11+
_socket = socket;
12+
}
13+
714
/// <inheritdoc />
815
public void Dispose()
916
{
10-
socket.Dispose();
17+
_socket.Dispose();
1118
}
1219

1320
/// <inheritdoc />
14-
public ClientWebSocketOptions Options => socket.Options;
21+
public ClientWebSocketOptions Options => _socket.Options;
1522

1623
/// <inheritdoc />
17-
public WebSocketCloseStatus? CloseStatus => socket.CloseStatus;
24+
public WebSocketCloseStatus? CloseStatus => _socket.CloseStatus;
1825

1926
/// <inheritdoc />
20-
public Task ConnectAsync(Uri uri, CancellationToken cancellation) => socket.ConnectAsync(uri, cancellation);
27+
public Task ConnectAsync(Uri uri, CancellationToken cancellation) => _socket.ConnectAsync(uri, cancellation);
2128

2229
/// <inheritdoc />
2330
public Task SendAsync(
2431
ArraySegment<byte> buffer,
2532
WebSocketMessageType messageType,
2633
bool endOfMessage,
2734
CancellationToken cancellationToken)
28-
=> socket.SendAsync(buffer, messageType, endOfMessage, cancellationToken);
35+
=> _socket.SendAsync(buffer, messageType, endOfMessage, cancellationToken);
2936

3037
/// <inheritdoc />
3138
public Task<WebSocketReceiveResult> ReceiveAsync(ArraySegment<byte> buffer, CancellationToken cancellationToken)
32-
=> socket.ReceiveAsync(buffer, cancellationToken);
39+
=> _socket.ReceiveAsync(buffer, cancellationToken);
3340

3441
/// <inheritdoc />
3542
public Task CloseAsync(
3643
WebSocketCloseStatus closeStatus,
3744
string? statusDescription,
3845
CancellationToken cancellationToken)
39-
=> socket.CloseAsync(closeStatus, statusDescription, cancellationToken);
46+
=> _socket.CloseAsync(closeStatus, statusDescription, cancellationToken);
4047
}

src/Cnblogs.DashScope.Core/Internals/DashScopeDefaults.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ public static class DashScopeDefaults
2525
new()
2626
{
2727
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
28-
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
28+
PropertyNamingPolicy = JsonSnakeCaseLowerNamingPolicy.SnakeCaseLower,
2929
};
3030
}

src/Cnblogs.DashScope.Core/SpeechSynthesizerParameters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class SpeechSynthesizerParameters
1313
/// <summary>
1414
/// The voice to use.
1515
/// </summary>
16-
public required string Voice { get; set; }
16+
public string Voice { get; set; } = string.Empty;
1717

1818
/// <summary>
1919
/// Output file format, can be pcm, wav or mp3.

0 commit comments

Comments
 (0)