Files
Adam Hathcock d305fe59cb feat(sdk) clean up registration of sdk to not be connector specific (#274)
* First pass of ObjectSaver and better in-memory usage

* fix some tests

* add commit to match deserialize process

* correct more tests

* format

* make a deserialize factory

* fix tests? and format

* use distinct

* Fix mismerge

* Fix serialization issues with tests

* fix merges

* follow copilot suggestions

* remove disables

* change registration to take strings and TypeLoader isn't public

* remove unused transports

* more test fixes

* fmt

* add Application object back
2025-04-08 09:49:31 +00:00

74 lines
2.0 KiB
C#

using Microsoft.Data.Sqlite;
using Microsoft.Extensions.DependencyInjection;
using Speckle.Sdk.Api;
using Speckle.Sdk.Credentials;
using Speckle.Sdk.Models;
using Speckle.Sdk.Transports;
namespace Speckle.Sdk.Tests.Performance;
public sealed class TestDataHelper : IDisposable
{
private static readonly string s_basePath = $"./temp {Guid.NewGuid()}";
public SQLiteTransport Transport { get; private set; }
public static IServiceProvider ServiceProvider { get; set; }
public string ObjectId { get; private set; }
public TestDataHelper()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddSpeckleSdk(new("Tests", "test"), "v3");
ServiceProvider = serviceCollection.BuildServiceProvider();
}
public async Task SeedTransport(Account account, string streamId, string objectId, bool skipCache)
{
// Transport = new SQLiteTransport(s_basePath, APPLICATION_NAME);
Transport = new SQLiteTransport();
//seed SQLite transport with test data
ObjectId = await SeedTransport(account, streamId, objectId, Transport, skipCache).ConfigureAwait(false);
}
public async Task<string> SeedTransport(
Account account,
string streamId,
string objectId,
ITransport transport,
bool skipCache
)
{
if (!skipCache)
{
using ServerTransport remoteTransport = ServiceProvider
.GetRequiredService<IServerTransportFactory>()
.Create(account, streamId);
transport.BeginWrite();
await remoteTransport.CopyObjectAndChildren(objectId, transport).ConfigureAwait(false);
transport.EndWrite();
await transport.WriteComplete().ConfigureAwait(false);
}
return objectId;
}
public async Task<Base> DeserializeBase()
{
return await ServiceProvider
.GetRequiredService<IOperations>()
.Receive(ObjectId, null, Transport)
.ConfigureAwait(false);
}
public void Dispose()
{
Transport.Dispose();
SqliteConnection.ClearAllPools();
if (Directory.Exists(s_basePath))
{
Directory.Delete(s_basePath, true);
}
}
}