Skip to content

Commit

Permalink
some test deps
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw committed Feb 15, 2024
1 parent c14c9fb commit bcfdbea
Show file tree
Hide file tree
Showing 11 changed files with 332 additions and 9 deletions.
10 changes: 8 additions & 2 deletions dotnet/LangSmith/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ public class Client
private readonly HttpClient _httpClient;
private readonly ClientConfig _config;
private readonly ConcurrentQueue<BatchItem> _autoBatchQueue = new ConcurrentQueue<BatchItem>();
private IConfig @object;

public Client(ClientConfig config)
public Client(ClientConfig config, HttpClient httpClient)
{
_config = config ?? throw new ArgumentNullException(nameof(config));
_httpClient = new HttpClient
Expand All @@ -83,6 +84,11 @@ public Client(ClientConfig config)
}
}

public Client(IConfig @object)
{
this.@object = @object;
}

public async Task<RunResult> CreateRunAsync(CreateRunParams runParams)
{
if (runParams != null)
Expand Down Expand Up @@ -132,7 +138,7 @@ private void TriggerBatchProcessingIfNeeded()
{
if (_autoBatchQueue.Count >= _config.PendingAutoBatchedRunLimit)
{
Task.Run(async () => await ProcessAutoBatchQueueAsync());
Task.Run(ProcessAutoBatchQueueAsync);
}
}

Expand Down
97 changes: 97 additions & 0 deletions dotnet/LangSmith/ClientTest.cs
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));
}
}
5 changes: 5 additions & 0 deletions dotnet/LangSmith/LangSmith.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="moq" Version="4.20.70" />
<PackageReference Include="NUnit" Version="4.0.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[assembly: System.Reflection.AssemblyCompanyAttribute("LangSmith")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+d8b863758624f78ace060f4ab866f80d254aa5d7")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c14c9fb4b272f5d5998e8a2fcf7e53bfacde1111")]
[assembly: System.Reflection.AssemblyProductAttribute("LangSmith")]
[assembly: System.Reflection.AssemblyTitleAttribute("LangSmith")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3b84794afe51ab4e4a7e81e9ba93bc891d9b74009cf7304dc48a131cdc3a82d0
7fdc29b12e858a4f995d7fdf5a3519db6e6303b14ca260055580c106d48d5992
Binary file modified dotnet/LangSmith/obj/Debug/net8.0/LangSmith.assets.cache
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions dotnet/LangSmith/obj/LangSmith.csproj.nuget.dgspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"dependencies": {
"NUnit": {
"target": "Package",
"version": "[4.0.1, )"
},
"moq": {
"target": "Package",
"version": "[4.20.70, )"
}
},
"imports": [
"net461",
"net462",
Expand Down
3 changes: 3 additions & 0 deletions dotnet/LangSmith/obj/LangSmith.csproj.nuget.g.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="/Users/wfh/.nuget/packages/" />
</ItemGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)nunit/4.0.1/build/NUnit.props" Condition="Exists('$(NuGetPackageRoot)nunit/4.0.1/build/NUnit.props')" />
</ImportGroup>
</Project>
203 changes: 200 additions & 3 deletions dotnet/LangSmith/obj/project.assets.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,198 @@
{
"version": 3,
"targets": {
"net8.0": {}
"net8.0": {
"Castle.Core/5.1.1": {
"type": "package",
"dependencies": {
"System.Diagnostics.EventLog": "6.0.0"
},
"compile": {
"lib/net6.0/Castle.Core.dll": {
"related": ".xml"
}
},
"runtime": {
"lib/net6.0/Castle.Core.dll": {
"related": ".xml"
}
}
},
"Moq/4.20.70": {
"type": "package",
"dependencies": {
"Castle.Core": "5.1.1"
},
"compile": {
"lib/net6.0/Moq.dll": {
"related": ".xml"
}
},
"runtime": {
"lib/net6.0/Moq.dll": {
"related": ".xml"
}
}
},
"NUnit/4.0.1": {
"type": "package",
"compile": {
"lib/net6.0/nunit.framework.dll": {
"related": ".legacy.xml;.xml"
},
"lib/net6.0/nunit.framework.legacy.dll": {
"related": ".xml"
}
},
"runtime": {
"lib/net6.0/nunit.framework.dll": {
"related": ".legacy.xml;.xml"
},
"lib/net6.0/nunit.framework.legacy.dll": {
"related": ".xml"
}
},
"build": {
"build/NUnit.props": {}
}
},
"System.Diagnostics.EventLog/6.0.0": {
"type": "package",
"compile": {
"lib/net6.0/System.Diagnostics.EventLog.dll": {
"related": ".xml"
}
},
"runtime": {
"lib/net6.0/System.Diagnostics.EventLog.dll": {
"related": ".xml"
}
},
"build": {
"buildTransitive/netcoreapp3.1/_._": {}
},
"runtimeTargets": {
"runtimes/win/lib/net6.0/System.Diagnostics.EventLog.Messages.dll": {
"assetType": "runtime",
"rid": "win"
},
"runtimes/win/lib/net6.0/System.Diagnostics.EventLog.dll": {
"assetType": "runtime",
"rid": "win"
}
}
}
}
},
"libraries": {
"Castle.Core/5.1.1": {
"sha512": "rpYtIczkzGpf+EkZgDr9CClTdemhsrwA/W5hMoPjLkRFnXzH44zDLoovXeKtmxb1ykXK9aJVODSpiJml8CTw2g==",
"type": "package",
"path": "castle.core/5.1.1",
"files": [
".nupkg.metadata",
".signature.p7s",
"ASL - Apache Software Foundation License.txt",
"CHANGELOG.md",
"LICENSE",
"castle-logo.png",
"castle.core.5.1.1.nupkg.sha512",
"castle.core.nuspec",
"lib/net462/Castle.Core.dll",
"lib/net462/Castle.Core.xml",
"lib/net6.0/Castle.Core.dll",
"lib/net6.0/Castle.Core.xml",
"lib/netstandard2.0/Castle.Core.dll",
"lib/netstandard2.0/Castle.Core.xml",
"lib/netstandard2.1/Castle.Core.dll",
"lib/netstandard2.1/Castle.Core.xml",
"readme.txt"
]
},
"Moq/4.20.70": {
"sha512": "4rNnAwdpXJBuxqrOCzCyICXHSImOTRktCgCWXWykuF1qwoIsVvEnR7PjbMk/eLOxWvhmj5Kwt+kDV3RGUYcNwg==",
"type": "package",
"path": "moq/4.20.70",
"files": [
".nupkg.metadata",
".signature.p7s",
"icon.png",
"lib/net462/Moq.dll",
"lib/net462/Moq.xml",
"lib/net6.0/Moq.dll",
"lib/net6.0/Moq.xml",
"lib/netstandard2.0/Moq.dll",
"lib/netstandard2.0/Moq.xml",
"lib/netstandard2.1/Moq.dll",
"lib/netstandard2.1/Moq.xml",
"moq.4.20.70.nupkg.sha512",
"moq.nuspec",
"readme.md"
]
},
"NUnit/4.0.1": {
"sha512": "jNTHZ01hJsDNPDSBycoHpavFZUBf9vRVQLCyuo78LRrrFj6Ol/CeqK+NIeTk5d8Eycjk59KseWb7X5Ge6z7CgQ==",
"type": "package",
"path": "nunit/4.0.1",
"files": [
".nupkg.metadata",
".signature.p7s",
"CHANGES.md",
"LICENSE.txt",
"NOTICES.md",
"README.md",
"THIRD_PARTY_NOTICES.md",
"build/NUnit.props",
"icon.png",
"lib/net462/nunit.framework.dll",
"lib/net462/nunit.framework.legacy.dll",
"lib/net462/nunit.framework.legacy.xml",
"lib/net462/nunit.framework.xml",
"lib/net6.0/nunit.framework.dll",
"lib/net6.0/nunit.framework.legacy.dll",
"lib/net6.0/nunit.framework.legacy.xml",
"lib/net6.0/nunit.framework.xml",
"nunit.4.0.1.nupkg.sha512",
"nunit.nuspec"
]
},
"System.Diagnostics.EventLog/6.0.0": {
"sha512": "lcyUiXTsETK2ALsZrX+nWuHSIQeazhqPphLfaRxzdGaG93+0kELqpgEHtwWOlQe7+jSFnKwaCAgL4kjeZCQJnw==",
"type": "package",
"path": "system.diagnostics.eventlog/6.0.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"Icon.png",
"LICENSE.TXT",
"THIRD-PARTY-NOTICES.TXT",
"buildTransitive/netcoreapp2.0/System.Diagnostics.EventLog.targets",
"buildTransitive/netcoreapp3.1/_._",
"lib/net461/System.Diagnostics.EventLog.dll",
"lib/net461/System.Diagnostics.EventLog.xml",
"lib/net6.0/System.Diagnostics.EventLog.dll",
"lib/net6.0/System.Diagnostics.EventLog.xml",
"lib/netcoreapp3.1/System.Diagnostics.EventLog.dll",
"lib/netcoreapp3.1/System.Diagnostics.EventLog.xml",
"lib/netstandard2.0/System.Diagnostics.EventLog.dll",
"lib/netstandard2.0/System.Diagnostics.EventLog.xml",
"runtimes/win/lib/net6.0/System.Diagnostics.EventLog.Messages.dll",
"runtimes/win/lib/net6.0/System.Diagnostics.EventLog.dll",
"runtimes/win/lib/net6.0/System.Diagnostics.EventLog.xml",
"runtimes/win/lib/netcoreapp3.1/System.Diagnostics.EventLog.Messages.dll",
"runtimes/win/lib/netcoreapp3.1/System.Diagnostics.EventLog.dll",
"runtimes/win/lib/netcoreapp3.1/System.Diagnostics.EventLog.xml",
"system.diagnostics.eventlog.6.0.0.nupkg.sha512",
"system.diagnostics.eventlog.nuspec",
"useSharedDesignerContext.txt"
]
}
},
"libraries": {},
"projectFileDependencyGroups": {
"net8.0": []
"net8.0": [
"NUnit >= 4.0.1",
"moq >= 4.20.70"
]
},
"packageFolders": {
"/Users/wfh/.nuget/packages/": {}
Expand Down Expand Up @@ -43,6 +230,16 @@
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"dependencies": {
"NUnit": {
"target": "Package",
"version": "[4.0.1, )"
},
"moq": {
"target": "Package",
"version": "[4.20.70, )"
}
},
"imports": [
"net461",
"net462",
Expand Down
Loading

0 comments on commit bcfdbea

Please sign in to comment.