From 3a492cd47825392a294b25116e3e42f62aaa8716 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 9 Jan 2025 16:59:32 +0000 Subject: [PATCH] Can send and pass to Verify --- .../Speckle.Connectors.Rhino8.csproj | 3 +- .../packages.lock.json | 119 ++++++++++++++++-- .../Tests/ArcToSpeckleConverterTests.cs | 1 - .../Tests/BasicConnectorBindingTests.cs | 1 - .../Tests/EllipseToSpeckleConverterTests.cs | 1 - .../Tests/RhinoCollection.cs | 1 - .../Tests/SelectionTests.cs | 1 - .../Tests/SendTests.cs | 51 ++------ .../Bindings/ConfigBinding.cs | 40 ++++-- .../Testing/ContainerRegistration.cs | 40 ------ Directory.Packages.props | 3 +- .../ServiceCollectionExtensions.cs | 87 ++++++++++++- 12 files changed, 233 insertions(+), 115 deletions(-) delete mode 100644 DUI3/Speckle.Connectors.DUI/Testing/ContainerRegistration.cs diff --git a/Connectors/Rhino/Speckle.Connectors.Rhino8/Speckle.Connectors.Rhino8.csproj b/Connectors/Rhino/Speckle.Connectors.Rhino8/Speckle.Connectors.Rhino8.csproj index 20424ebb6..a4ad780e8 100644 --- a/Connectors/Rhino/Speckle.Connectors.Rhino8/Speckle.Connectors.Rhino8.csproj +++ b/Connectors/Rhino/Speckle.Connectors.Rhino8/Speckle.Connectors.Rhino8.csproj @@ -1,4 +1,4 @@ - + net48 Debug;Release;Local @@ -16,6 +16,7 @@ + diff --git a/Connectors/Rhino/Speckle.Connectors.Rhino8/packages.lock.json b/Connectors/Rhino/Speckle.Connectors.Rhino8/packages.lock.json index 19568016b..9280b85bf 100644 --- a/Connectors/Rhino/Speckle.Connectors.Rhino8/packages.lock.json +++ b/Connectors/Rhino/Speckle.Connectors.Rhino8/packages.lock.json @@ -48,11 +48,55 @@ "resolved": "0.9.6", "contentHash": "HKH7tYrYYlCK1ct483hgxERAdVdMtl7gUKW9ijWXxA1UsYR4Z+TrRHYmzZ9qmpu1NnTycSrp005NYM78GDKV1w==" }, + "Verify.Xunit": { + "type": "Direct", + "requested": "[28.8.1, )", + "resolved": "28.8.1", + "contentHash": "s++6iCInd5xpv6e7cesd1/KplHaYNtXRMjOsDu+n+Z85fYeX64w+Wras+B1uAQK+Lg+0F4W5sc9jqmUkh8y8Lg==", + "dependencies": { + "Argon": "0.26.0", + "DiffEngine": "15.6.0", + "Microsoft.Bcl.AsyncInterfaces": "9.0.0", + "SimpleInfoName": "3.1.0", + "System.IO.Hashing": "9.0.0", + "System.Memory": "4.6.0", + "Verify": "28.8.1", + "xunit.abstractions": "2.0.3", + "xunit.extensibility.execution": "2.9.2" + } + }, + "Argon": { + "type": "Transitive", + "resolved": "0.26.0", + "contentHash": "n7btGXdtRyprGnpLMpBs6rLScxlvPtVWwmTR8h7CtJvpZXBGhGvibEdZxRjeTZNrwf403jJ0ZPpt35Pz/NaNsw==", + "dependencies": { + "System.Collections.Immutable": "8.0.0" + } + }, "Castle.Core": { "type": "Transitive", "resolved": "5.1.1", "contentHash": "rpYtIczkzGpf+EkZgDr9CClTdemhsrwA/W5hMoPjLkRFnXzH44zDLoovXeKtmxb1ykXK9aJVODSpiJml8CTw2g==" }, + "DiffEngine": { + "type": "Transitive", + "resolved": "15.6.0", + "contentHash": "q39O7vQknyZeKo2ipsNqoW2nH7+rntebNEOuYCbSu6rdp89om1VHOkWpERdKLYqQnIq3U20APYagcvvjoMiOlg==", + "dependencies": { + "EmptyFiles": "8.6.0", + "System.Collections.Immutable": "8.0.0", + "System.Management": "8.0.0" + } + }, + "EmptyFiles": { + "type": "Transitive", + "resolved": "8.6.0", + "contentHash": "7QuYKhc8DjllLRviZPeGXfDR5LEtTtBV8loBxfrQt7tFUiPhnHkqEe710yqpSxEebys/lKSJXhPoUX3xCeqkbQ==", + "dependencies": { + "System.Collections.Immutable": "8.0.0", + "System.Memory": "4.6.0" + } + }, "GraphQL.Client": { "type": "Transitive", "resolved": "6.0.0", @@ -87,8 +131,8 @@ }, "Microsoft.Bcl.AsyncInterfaces": { "type": "Transitive", - "resolved": "5.0.0", - "contentHash": "W8DPQjkMScOMTtJbPwmPyj9c3zYSFGawDW3jwlBOOsnY+EzZFLgNQ/UMkK35JmkNOVPdCyPr2Tw7Vv9N+KA3ZQ==", + "resolved": "9.0.0", + "contentHash": "owmu2Cr3IQ8yQiBleBHlGk8dSQ12oaF2e7TpzwJKEl4m84kkZJjEY1n33L67Y3zM5jPOjmmbdHjbfiL0RqcMRQ==", "dependencies": { "System.Threading.Tasks.Extensions": "4.5.4" } @@ -178,6 +222,11 @@ "resolved": "8.0.0", "contentHash": "dk9JPxTCIevS75HyEQ0E4OVAFhB2N+V9ShCXf8Q6FkUQZDkgLI12y679Nym1YqsiSysuQskT7Z+6nUf3yab6Vw==" }, + "SimpleInfoName": { + "type": "Transitive", + "resolved": "3.1.0", + "contentHash": "j+ENh86NhxrgDc6T1ueqIR2QOdDkSJY2dbTFyPN/JvIXifB4GHAunlMw/x7P6m7XaXEHr3s+SMZfKBlmnmkO6g==" + }, "Speckle.DoubleNumerics": { "type": "Transitive", "resolved": "4.0.1", @@ -220,22 +269,53 @@ }, "System.Buffers": { "type": "Transitive", - "resolved": "4.4.0", - "contentHash": "AwarXzzoDwX6BgrhjoJsk6tUezZEozOT5Y9QKF94Gl4JK91I4PIIBkBco9068Y9/Dra8Dkbie99kXB8+1BaYKw==" + "resolved": "4.6.0", + "contentHash": "lN6tZi7Q46zFzAbRYXTIvfXcyvQQgxnY7Xm6C6xQ9784dEL1amjM6S6Iw4ZpsvesAKnRVsM4scrDQaDqSClkjA==" + }, + "System.CodeDom": { + "type": "Transitive", + "resolved": "8.0.0", + "contentHash": "WTlRjL6KWIMr/pAaq3rYqh0TJlzpouaQ/W1eelssHgtlwHAH25jXTkUphTYx9HaIIf7XA6qs/0+YhtLEQRkJ+Q==" + }, + "System.Collections.Immutable": { + "type": "Transitive", + "resolved": "8.0.0", + "contentHash": "AurL6Y5BA1WotzlEvVaIDpqzpIPvYnnldxru8oXJU2yFxFUy3+pNXjXd1ymO+RA0rq0+590Q8gaz2l3Sr7fmqg==", + "dependencies": { + "System.Memory": "4.5.5", + "System.Runtime.CompilerServices.Unsafe": "6.0.0" + } }, "System.ComponentModel.Annotations": { "type": "Transitive", "resolved": "4.5.0", "contentHash": "UxYQ3FGUOtzJ7LfSdnYSFd7+oEv6M8NgUatatIN2HxNtDdlcvFAf+VIq4Of9cDMJEJC0aSRv/x898RYhB4Yppg==" }, + "System.IO.Hashing": { + "type": "Transitive", + "resolved": "9.0.0", + "contentHash": "seeO8icDfED/Qwl9PDFUx2Gf/7xv7dPsMnw5PnRwNZuz4EWMpy0wIVohC4MfCcTIoJgp+KUrWG4WH3NPSusQOA==", + "dependencies": { + "System.Buffers": "4.5.1", + "System.Memory": "4.5.5" + } + }, + "System.Management": { + "type": "Transitive", + "resolved": "8.0.0", + "contentHash": "jrK22i5LRzxZCfGb+tGmke2VH7oE0DvcDlJ1HAKYU8cPmD8XnpUT0bYn2Gy98GEhGjtfbR/sxKTVb+dE770pfA==", + "dependencies": { + "System.CodeDom": "8.0.0" + } + }, "System.Memory": { "type": "Transitive", - "resolved": "4.5.3", - "contentHash": "3oDzvc/zzetpTKWMShs1AADwZjQ/36HnsufHRPcOjyRAAMLDlu2iD33MBI2opxnezcVUtXyqDXXjoFMOU9c7SA==", + "resolved": "4.6.0", + "contentHash": "OEkbBQoklHngJ8UD8ez2AERSk2g+/qpAaSWWCBFbpH727HxDq5ydVkuncBaKcKfwRqXGWx64dS6G1SUScMsitg==", "dependencies": { - "System.Buffers": "4.4.0", - "System.Numerics.Vectors": "4.4.0", - "System.Runtime.CompilerServices.Unsafe": "4.5.2" + "System.Buffers": "4.6.0", + "System.Numerics.Vectors": "4.6.0", + "System.Runtime.CompilerServices.Unsafe": "6.1.0" } }, "System.Net.WebSockets.Client.Managed": { @@ -249,8 +329,8 @@ }, "System.Numerics.Vectors": { "type": "Transitive", - "resolved": "4.4.0", - "contentHash": "UiLzLW+Lw6HLed1Hcg+8jSRttrbuXv7DANVj0DkL9g6EnnzbL75EB7EWsw5uRbhxd/4YdG8li5XizGWepmG3PQ==" + "resolved": "4.6.0", + "contentHash": "t+SoieZsRuEyiw/J+qXUbolyO219tKQQI0+2/YI+Qv7YdGValA6WiuokrNKqjrTNsy5ABWU11bdKOzUdheteXg==" }, "System.Reactive": { "type": "Transitive", @@ -262,8 +342,8 @@ }, "System.Runtime.CompilerServices.Unsafe": { "type": "Transitive", - "resolved": "4.5.3", - "contentHash": "3TIsJhD1EiiT0w2CcDMN/iSSwnNnsrnbzeVHSKkaEgV85txMprmuO+Yq2AdSbeVGcg28pdNDTPK87tJhX7VFHw==" + "resolved": "6.1.0", + "contentHash": "5o/HZxx6RVqYlhKSq8/zronDkALJZUT2Vz0hx43f0gwe8mwlM0y2nYlqdBwLMzr262Bwvpikeb/yEwkAa5PADg==" }, "System.Threading.Tasks.Extensions": { "type": "Transitive", @@ -273,6 +353,19 @@ "System.Runtime.CompilerServices.Unsafe": "4.5.3" } }, + "Verify": { + "type": "Transitive", + "resolved": "28.8.1", + "contentHash": "lq4wiGgiTYOI6QR38qgY1H+SB4ejSrXReGiFFh5fjh7ZDdJtcEiVMbnReV3MF+4anw+SXmtIXWX6O3/cC4KIow==", + "dependencies": { + "Argon": "0.26.0", + "DiffEngine": "15.6.0", + "Microsoft.Bcl.AsyncInterfaces": "9.0.0", + "SimpleInfoName": "3.1.0", + "System.IO.Hashing": "9.0.0", + "System.Memory": "4.6.0" + } + }, "xunit.abstractions": { "type": "Transitive", "resolved": "2.0.3", diff --git a/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/ArcToSpeckleConverterTests.cs b/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/ArcToSpeckleConverterTests.cs index 31d73bfca..aaec60ef4 100644 --- a/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/ArcToSpeckleConverterTests.cs +++ b/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/ArcToSpeckleConverterTests.cs @@ -1,7 +1,6 @@ using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using Speckle.Converters.Common.Objects; -using Xunit; namespace Speckle.Connectors.Rhino; diff --git a/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/BasicConnectorBindingTests.cs b/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/BasicConnectorBindingTests.cs index e853c1ae3..098224638 100644 --- a/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/BasicConnectorBindingTests.cs +++ b/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/BasicConnectorBindingTests.cs @@ -2,7 +2,6 @@ using Speckle.Connectors.DUI.Bindings; using Speckle.Connectors.DUI.Testing; using Speckle.HostApps; -using Xunit; namespace Speckle.Connectors.Rhino; diff --git a/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/EllipseToSpeckleConverterTests.cs b/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/EllipseToSpeckleConverterTests.cs index 1ba5e0f57..d8884d17f 100644 --- a/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/EllipseToSpeckleConverterTests.cs +++ b/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/EllipseToSpeckleConverterTests.cs @@ -1,6 +1,5 @@ using Microsoft.Extensions.DependencyInjection; using Speckle.Converters.Common.Objects; -using Xunit; namespace Speckle.Connectors.Rhino; diff --git a/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/RhinoCollection.cs b/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/RhinoCollection.cs index a294a38fc..87802707e 100644 --- a/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/RhinoCollection.cs +++ b/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/RhinoCollection.cs @@ -1,7 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using Speckle.Converters.Common; using Speckle.Converters.Rhino; -using Xunit; namespace Speckle.Connectors.Rhino; diff --git a/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/SelectionTests.cs b/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/SelectionTests.cs index 391b402b8..3a83b9b0c 100644 --- a/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/SelectionTests.cs +++ b/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/SelectionTests.cs @@ -2,7 +2,6 @@ using Rhino; using Speckle.Connectors.DUI.Bindings; using Speckle.HostApps; -using Xunit; namespace Speckle.Connectors.Rhino; diff --git a/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/SendTests.cs b/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/SendTests.cs index 0757f84b7..d07109d61 100644 --- a/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/SendTests.cs +++ b/Connectors/Rhino/Speckle.Connectors.RhinoShared/Tests/SendTests.cs @@ -1,17 +1,13 @@ -using FluentAssertions; +using System.IO; +using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using Rhino; using Speckle.Connectors.DUI.Bindings; using Speckle.Connectors.DUI.Exceptions; using Speckle.Connectors.DUI.Models.Card; -using Speckle.Connectors.DUI.Testing; using Speckle.Connectors.Rhino.Filters; using Speckle.HostApps; -using Speckle.Sdk.Api; -using Speckle.Sdk.Models; -using Speckle.Sdk.Serialisation.V2.Send; -using Speckle.Sdk.Transports; -using Xunit; +using Speckle.Sdk.SQLite; namespace Speckle.Connectors.Rhino; @@ -66,45 +62,20 @@ public async Task Test_Send_Current() ModelId = "ModelId", }); - var testOperations = (TestOperations)serviceProvider.GetRequiredService(); - testOperations.WrappedOperations = new TestSender(); + var testFactory = (TestSqLiteJsonCacheManagerFactory)serviceProvider.GetRequiredService(); + var fileName = Path.GetTempFileName(); + testFactory.Initialize(fileName); var send = serviceProvider.GetBinding(); await send.Send(MODEL_CARD_ID); - } - - private sealed class TestSender : IOperations - { - public Task Receive2(Uri url, string streamId, string objectId, string? authorizationToken = null, - IProgress? onProgressAction = null, CancellationToken cancellationToken = new CancellationToken()) => - throw new NotImplementedException(); + var sqLiteJsonCacheManager = testFactory.CreateFromStream(string.Empty); + var all = sqLiteJsonCacheManager.GetAllObjects(); + await Verify(all); - public Task Receive(string objectId, ITransport? remoteTransport = null, ITransport? localTransport = null, - IProgress? onProgressAction = null, CancellationToken cancellationToken = new CancellationToken()) => - throw new NotImplementedException(); - - public Task Send2(Uri url, string streamId, string? authorizationToken, Base value, - IProgress? onProgressAction = null, - CancellationToken cancellationToken = new()) + if (File.Exists(fileName)) { - return Task.FromResult(new SerializeProcessResults()); + File.Delete(fileName); } - - public Task<(string rootObjId, IReadOnlyDictionary convertedReferences)> Send(Base value, IServerTransport transport, bool useDefaultCache, IProgress? onProgressAction = null, - CancellationToken cancellationToken = new CancellationToken()) => - throw new NotImplementedException(); - - public Task<(string rootObjId, IReadOnlyDictionary convertedReferences)> Send(Base value, ITransport transport, bool useDefaultCache, IProgress? onProgressAction = null, - CancellationToken cancellationToken = new CancellationToken()) => - throw new NotImplementedException(); - - public Task<(string rootObjId, IReadOnlyDictionary convertedReferences)> Send(Base value, IReadOnlyCollection transports, IProgress? onProgressAction = null, - CancellationToken cancellationToken = new CancellationToken()) => - throw new NotImplementedException(); - - public string Serialize(Base value, CancellationToken cancellationToken = new CancellationToken()) => throw new NotImplementedException(); - - public Task DeserializeAsync(string value, CancellationToken cancellationToken = new CancellationToken()) => throw new NotImplementedException(); } } diff --git a/DUI3/Speckle.Connectors.DUI/Bindings/ConfigBinding.cs b/DUI3/Speckle.Connectors.DUI/Bindings/ConfigBinding.cs index 9a537b61d..628f19a8d 100644 --- a/DUI3/Speckle.Connectors.DUI/Bindings/ConfigBinding.cs +++ b/DUI3/Speckle.Connectors.DUI/Bindings/ConfigBinding.cs @@ -1,11 +1,33 @@ using System.Runtime.Serialization; using Speckle.Connectors.DUI.Bridge; using Speckle.Connectors.DUI.Utils; +using Speckle.InterfaceGenerator; using Speckle.Sdk; using Speckle.Sdk.SQLite; namespace Speckle.Connectors.DUI.Bindings; +[GenerateAutoInterface] +public class ConfigStorage : IConfigStorage +{ + + private readonly ISqLiteJsonCacheManager _jsonCacheManager; + private readonly ISpeckleApplication _speckleApplication; + + public ConfigStorage(ISqLiteJsonCacheManagerFactory sqLiteJsonCacheManagerFactory, ISpeckleApplication speckleApplication) + { + _speckleApplication = speckleApplication; + _jsonCacheManager = sqLiteJsonCacheManagerFactory.CreateForUser("DUI3Config"); // POC: maybe inject? (if we ever want to use a different storage for configs later down the line) + } + + public string? GetConfig() => _jsonCacheManager.GetObject(_speckleApplication.HostApplication); + public void UpdateConfig(string config) => _jsonCacheManager.UpdateObject(_speckleApplication.HostApplication, config); + + + public string? GetAccounts() => _jsonCacheManager.GetObject("accounts"); + public void UpdateAccounts(string config) => _jsonCacheManager.UpdateObject("accounts", config); +} + /// /// POC: Simple config binding, as it was driving Dim nuts he couldn't swap to a dark theme. /// How does it store configs? In a sqlite db called 'DUI3Config', we create a row for each host application: @@ -17,20 +39,18 @@ public class ConfigBinding : IBinding { public string Name => "configBinding"; public IBrowserBridge Parent { get; } - private readonly ISqLiteJsonCacheManager _jsonCacheManager; - private readonly ISpeckleApplication _speckleApplication; + + private readonly IConfigStorage _configStorage; private readonly IJsonSerializer _serializer; public ConfigBinding( IJsonSerializer serializer, - ISpeckleApplication speckleApplication, IBrowserBridge bridge, - ISqLiteJsonCacheManagerFactory sqLiteJsonCacheManagerFactory + IConfigStorage configStorage ) { Parent = bridge; - _jsonCacheManager = sqLiteJsonCacheManagerFactory.CreateForUser("DUI3Config"); // POC: maybe inject? (if we ever want to use a different storage for configs later down the line) - _speckleApplication = speckleApplication; + _configStorage = configStorage; _serializer = serializer; } @@ -47,7 +67,7 @@ public bool GetIsDevMode() public ConnectorConfig GetConfig() { - var rawConfig = _jsonCacheManager.GetObject(_speckleApplication.HostApplication); + var rawConfig = _configStorage.GetConfig(); if (rawConfig is null) { return SeedConfig(); @@ -79,18 +99,18 @@ private ConnectorConfig SeedConfig() public void UpdateConfig(ConnectorConfig config) { var str = _serializer.Serialize(config); - _jsonCacheManager.UpdateObject(_speckleApplication.HostApplication, str); + _configStorage.UpdateConfig( str); } public void SetUserSelectedAccountId(string userSelectedAccountId) { var str = _serializer.Serialize(new AccountsConfig() { UserSelectedAccountId = userSelectedAccountId }); - _jsonCacheManager.UpdateObject("accounts", str); + _configStorage.UpdateAccounts(str); } public AccountsConfig? GetUserSelectedAccountId() { - var rawConfig = _jsonCacheManager.GetObject("accounts"); + var rawConfig = _configStorage.GetAccounts(); if (rawConfig is null) { return null; diff --git a/DUI3/Speckle.Connectors.DUI/Testing/ContainerRegistration.cs b/DUI3/Speckle.Connectors.DUI/Testing/ContainerRegistration.cs deleted file mode 100644 index d3e75525a..000000000 --- a/DUI3/Speckle.Connectors.DUI/Testing/ContainerRegistration.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Speckle.Sdk.Api; -using Speckle.Sdk.Common; -using Speckle.Sdk.Models; -using Speckle.Sdk.Serialisation.V2.Send; -using Speckle.Sdk.Transports; -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - -namespace Speckle.Connectors.DUI.Testing; - -public class TestOperations : IOperations -{ - public IOperations? WrappedOperations { get; set; } = null!; - public async Task Receive2(Uri url, string streamId, string objectId, string? authorizationToken = null, - IProgress? onProgressAction = null, CancellationToken cancellationToken = new CancellationToken()) => - throw new NotImplementedException(); - - public async Task Receive(string objectId, ITransport? remoteTransport = null, ITransport? localTransport = null, - IProgress? onProgressAction = null, CancellationToken cancellationToken = new CancellationToken()) => - throw new NotImplementedException(); - - public Task Send2(Uri url, string streamId, string? authorizationToken, Base value, IProgress? onProgressAction = null, - CancellationToken cancellationToken = new CancellationToken()) => - WrappedOperations.NotNull().Send2(url, streamId, authorizationToken, value, onProgressAction, cancellationToken); - - public async Task<(string rootObjId, IReadOnlyDictionary convertedReferences)> Send(Base value, IServerTransport transport, bool useDefaultCache, IProgress? onProgressAction = null, - CancellationToken cancellationToken = new CancellationToken()) => - throw new NotImplementedException(); - - public async Task<(string rootObjId, IReadOnlyDictionary convertedReferences)> Send(Base value, ITransport transport, bool useDefaultCache, IProgress? onProgressAction = null, - CancellationToken cancellationToken = new CancellationToken()) => - throw new NotImplementedException(); - - public async Task<(string rootObjId, IReadOnlyDictionary convertedReferences)> Send(Base value, IReadOnlyCollection transports, IProgress? onProgressAction = null, - CancellationToken cancellationToken = new CancellationToken()) => - throw new NotImplementedException(); - - public string Serialize(Base value, CancellationToken cancellationToken = new CancellationToken()) => throw new NotImplementedException(); - - public async Task DeserializeAsync(string value, CancellationToken cancellationToken = new CancellationToken()) => throw new NotImplementedException(); -} diff --git a/Directory.Packages.props b/Directory.Packages.props index bcf6a6686..ce619b079 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -49,8 +49,9 @@ + - + \ No newline at end of file diff --git a/Sdk/Speckle.HostApps/ServiceCollectionExtensions.cs b/Sdk/Speckle.HostApps/ServiceCollectionExtensions.cs index 6b5a5fa8e..0fd4e6c9a 100644 --- a/Sdk/Speckle.HostApps/ServiceCollectionExtensions.cs +++ b/Sdk/Speckle.HostApps/ServiceCollectionExtensions.cs @@ -10,12 +10,14 @@ using Speckle.Connectors.DUI.Testing; using Speckle.HostApps.Framework; using Speckle.Sdk; -using Speckle.Sdk.Api; using Speckle.Sdk.Credentials; using Speckle.Sdk.Models; using Speckle.Sdk.Serialisation; +using Speckle.Sdk.Serialisation.V2; +using Speckle.Sdk.Serialisation.V2.Receive; using Speckle.Sdk.Serialisation.V2.Send; using Speckle.Sdk.SQLite; +using Speckle.Sdk.Transports; namespace Speckle.HostApps; @@ -34,26 +36,101 @@ public static void UseHostAppTesting(this IServiceCollection serviceCollection) testServices.AddRange(serviceCollection); testServices.Replace(ServiceDescriptor.Singleton()); testServices.Replace(ServiceDescriptor.Singleton()); - testServices.Replace(ServiceDescriptor.Singleton()); testServices.Replace(ServiceDescriptor.Singleton()); testServices.Replace(ServiceDescriptor.Singleton()); testServices.Replace(ServiceDescriptor.Singleton()); testServices.Replace(ServiceDescriptor.Singleton()); + testServices.Replace(ServiceDescriptor.Singleton()); + testServices.Replace(ServiceDescriptor.Singleton()); var serviceProvider = testServices.BuildServiceProvider(); SpeckleXunitTestFramework.ServiceProvider = serviceProvider; } } +public sealed class TestSerializeProcessFactory ( + IBaseChildFinder baseChildFinder, + IObjectSerializerFactory objectSerializerFactory, + ISqLiteJsonCacheManagerFactory sqLiteJsonCacheManagerFactory, + IServerObjectManagerFactory serverObjectManagerFactory +) : ISerializeProcessFactory +{ + public ISerializeProcess CreateSerializeProcess( + Uri url, + string streamId, + string? authorizationToken, + IProgress? progress, + SerializeProcessOptions? options = null + ) + { + var sqLiteJsonCacheManager = sqLiteJsonCacheManagerFactory.CreateFromStream(streamId); + var serverObjectManager = serverObjectManagerFactory.Create(url, streamId, authorizationToken); + return new SerializeProcess( + progress, + sqLiteJsonCacheManager, + serverObjectManager, + baseChildFinder, + objectSerializerFactory, + new SerializeProcessOptions() + { + SkipServer = true, + SkipCacheRead = true, + SkipFindTotalObjects = true + } + ); + } + + public IDeserializeProcess CreateDeserializeProcess(Uri url, string streamId, string? authorizationToken, IProgress? progress, + DeserializeProcessOptions? options = null) => + throw new NotImplementedException(); +} + +public sealed class TestConfigStorage : IConfigStorage +{ + public string? GetConfig() => null; + + public void UpdateConfig(string config) { } + + public string? GetAccounts() => null; + + public void UpdateAccounts(string config) { } +} + +public sealed class TestSqLiteJsonCacheManager(ISqLiteJsonCacheManager wrapped) : ISqLiteJsonCacheManager +{ + public void Dispose() + { + // TODO release managed resources here + } + + public IReadOnlyCollection<(string Id, string Json)> GetAllObjects() => wrapped.GetAllObjects(); + + public void DeleteObject(string id) => wrapped.DeleteObject(id); + + public string? GetObject(string id) => wrapped.GetObject(id); + + public void SaveObject(string id, string json) => wrapped.SaveObject(id, json); + + public void UpdateObject(string id, string json) => wrapped.UpdateObject(id, json); + + public void SaveObjects(IEnumerable<(string id, string json)> items) => wrapped.SaveObjects(items); + + public bool HasObject(string objectId) => wrapped.HasObject(objectId); +} public sealed class TestSqLiteJsonCacheManagerFactory : ISqLiteJsonCacheManagerFactory, IDisposable { - private readonly SqLiteJsonCacheManager _sqLiteJsonCacheManager = new("Data Source=:memory;", 1); + private SqLiteJsonCacheManager _sqLiteJsonCacheManager = new ("Data Source=:memory:", 1); - public ISqLiteJsonCacheManager CreateForUser(string scope) => _sqLiteJsonCacheManager; + public ISqLiteJsonCacheManager CreateForUser(string scope) => new TestSqLiteJsonCacheManager(_sqLiteJsonCacheManager); - public ISqLiteJsonCacheManager CreateFromStream(string streamId) => _sqLiteJsonCacheManager; + public ISqLiteJsonCacheManager CreateFromStream(string streamId) => new TestSqLiteJsonCacheManager(_sqLiteJsonCacheManager); public void Dispose() => _sqLiteJsonCacheManager.Dispose(); + + public void Initialize(string path) + { + _sqLiteJsonCacheManager = new($"Data Source={path}", 1); + } } public class TestAccountService : IAccountService