Files
speckle-sharp-sdk/tests/Speckle.Sdk.Serialization.Tests/ExplicitInterfaceTests.cs
T
Adam Hathcock 1fe1a54dcf Custom task scheduler for serialization, fix batch size calc (#194)
* Add a custom task scheduler

* Better usage, don't wait to enqueue to save to channels

* Completely pre-cal batch size to avoid spinning issues

* Try to fix cache counting

* properly dispose things

* format

* clean up

* adjust count and save on current thread

* move batch it's own file

* update a few packages

* fix build and add batch tests
2025-01-03 12:26:19 +00:00

64 lines
1.9 KiB
C#

using NUnit.Framework;
using Shouldly;
using Speckle.Sdk.Host;
using Speckle.Sdk.Models;
using Speckle.Sdk.Serialisation.V2.Send;
namespace Speckle.Sdk.Serialization.Tests;
public class ExplicitInterfaceTests
{
[SetUp]
public void Setup()
{
TypeLoader.Reset();
TypeLoader.Initialize(typeof(Base).Assembly, typeof(TestClass).Assembly);
}
[Test]
public async Task Test_Json()
{
var testClass = new TestClass() { RegularProperty = "Hello" };
var objects = new Dictionary<string, string>();
using var process2 = new SerializeProcess(
null,
new DummySendCacheManager(objects),
new DummyServerObjectManager(),
new BaseChildFinder(new BasePropertyGatherer()),
new ObjectSerializerFactory(new BasePropertyGatherer()),
new SerializeProcessOptions(false, false, true, true)
);
await process2.Serialize(testClass, default).ConfigureAwait(false);
objects.Count.ShouldBe(1);
objects["daaa67cfd73a957247cf2d631b7ca4f3"]
.ShouldBe(
"{\"RegularProperty\":\"Hello\",\"applicationId\":null,\"speckle_type\":\"Speckle.Core.Serialisation.TestClass\",\"id\":\"daaa67cfd73a957247cf2d631b7ca4f3\"}"
);
}
[Test]
public void Test_ExtractAllProperties()
{
var testClass = new TestClass() { RegularProperty = "Hello" };
var gatherer = new BasePropertyGatherer();
var properties = gatherer.ExtractAllProperties(testClass).ToList();
properties.Count.ShouldBe(3);
properties.Select(x => x.Name).ShouldContain("RegularProperty");
properties.Select(x => x.Name).ShouldNotContain("TestProperty");
}
}
[SpeckleType("Speckle.Core.Serialisation.TestClass")]
public sealed class TestClass : Base, ITestInterface
{
public string RegularProperty { get; set; }
string ITestInterface.TestProperty => RegularProperty;
}
public interface ITestInterface
{
string TestProperty { get; }
}