-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
332 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using NUnit.Framework; | ||
using LangSmith; | ||
using System.Threading.Tasks; | ||
using System.Collections.Generic; | ||
using Moq.Protected; // Needed for mocking HttpMessageHandler | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Net; | ||
using System.Text.Json; | ||
using Moq; | ||
|
||
[TestFixture] | ||
public class ClientTest | ||
{ | ||
private Client _client; | ||
private ClientConfig _config; | ||
private Mock<HttpMessageHandler> _handlerMock; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
_config = new ClientConfig | ||
{ | ||
ApiUrl = "https://api.smith.langchain.com", | ||
ApiKey = "test-api-key", | ||
AutoBatchTracing = true, | ||
TimeoutMs = 12000, | ||
PendingAutoBatchedRunLimit = 100 | ||
}; | ||
|
||
_handlerMock = new Mock<HttpMessageHandler>(); | ||
var httpClient = new HttpClient(_handlerMock.Object) | ||
{ | ||
BaseAddress = new System.Uri(_config.ApiUrl), | ||
}; | ||
|
||
_client = new Client(_config, httpClient); // Adjust Client constructor to accept HttpClient for testing | ||
} | ||
|
||
[Test] | ||
public async Task CreateRunAsync_WithValidParamsAndAutoBatchTracingEnabled_ReturnsQueuedRunResult() | ||
{ | ||
// Arrange | ||
var runParams = new CreateRunParams { Name = "Test Run", Id = "test-id" }; | ||
_config.AutoBatchTracing = true; | ||
|
||
// Simulate queued response without actual HTTP call | ||
_handlerMock | ||
.Protected() | ||
.Setup<Task<HttpResponseMessage>>( | ||
"SendAsync", | ||
ItExpr.IsAny<HttpRequestMessage>(), | ||
ItExpr.IsAny<CancellationToken>() | ||
) | ||
.ReturnsAsync(new HttpResponseMessage | ||
{ | ||
StatusCode = HttpStatusCode.OK, | ||
Content = new StringContent(JsonSerializer.Serialize(new RunResult { Success = true, Message = "Run creation queued" })) | ||
}); | ||
|
||
// Act | ||
var result = await _client.CreateRunAsync(runParams); | ||
|
||
// Assert | ||
Assert.IsTrue(result.Success); | ||
Assert.AreEqual("Run creation queued", result.Message); | ||
} | ||
|
||
[Test] | ||
public async Task CreateRunAsync_WithValidParamsAndAutoBatchTracingDisabled_ReturnsRunResultFromPostAsync() | ||
{ | ||
// Arrange | ||
var runParams = new CreateRunParams(); | ||
_configMock.Setup(c => c.AutoBatchTracing).Returns(false); | ||
var expectedPath = "/runs"; | ||
var expectedRunResult = new RunResult { Success = true, Message = "Test Run Result" }; | ||
_client.PostAsync<CreateRunParams, RunResult>(expectedPath, runParams).Returns(expectedRunResult); | ||
|
||
// Act | ||
var result = await _client.CreateRunAsync(runParams); | ||
|
||
// Assert | ||
Assert.AreEqual(expectedRunResult, result); | ||
_configMock.Verify(c => c.AutoBatchTracing, Times.Once); | ||
_client.Verify(c => c.PostAsync<CreateRunParams, RunResult>(expectedPath, runParams), Times.Once); | ||
} | ||
|
||
[Test] | ||
public void CreateRunAsync_WithNullParams_ThrowsArgumentNullException() | ||
{ | ||
// Arrange | ||
CreateRunParams runParams = null; | ||
|
||
// Act & Assert | ||
Assert.ThrowsAsync<ArgumentNullException>(() => _client.CreateRunAsync(runParams)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
dotnet/LangSmith/obj/Debug/net8.0/LangSmith.AssemblyInfoInputs.cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3b84794afe51ab4e4a7e81e9ba93bc891d9b74009cf7304dc48a131cdc3a82d0 | ||
7fdc29b12e858a4f995d7fdf5a3519db6e6303b14ca260055580c106d48d5992 |
Binary file not shown.
Binary file added
BIN
+2.06 KB
dotnet/LangSmith/obj/Debug/net8.0/LangSmith.csproj.AssemblyReference.cache
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.