0b1de566df
* Use Concurrent Dictionaries and ignore case on them to avoid ToLower * remove single array allocation * allocate GetClosures differently * Use JsonReader for closures * add comment * use isdefined * more readonly with less allocations * sorts * fmt * use element type when making an array * first pass * Fix reading for object and array * serialization works? * Fix closure parsing * things are way faster * Deserialize is async * fmt * renames * remove deserialize threads * fmt * faster to use ordinal compare * serialization looks okay * fix closure writing * fixes * use possibly different values for compute id * use closure parser on download * memory test for blobs * decompose serialization * fmt * fmt * for decomposing, values should be used instead of original * set id after computing it * redo more closure parsing * fix memory test * don't throw on try get deserialized * fmt * fix integration tests * fix tests * disable memory blob storage by default * put back ? * merge fixes and delete worker threads * fmt * serialization of old floats pass * serialization of old floats pass * rename class * Use async/await on GetObject * await deserialization * fmt * uncomment and fix tests * don't allow things to exist in the closure table that doesn't exist * detach blob tests * rename serializer * async more correct * revert * fix merge * fix blob tests again * more fixes * Fix building * async fixes * more async fixes * fix tests? * rename GetId to GetIdAsync * clean up * more cleanup * fmt * fix test * fix analyzer errors * use ConcurrentDictionary to be thread safe
80 lines
2.7 KiB
C#
80 lines
2.7 KiB
C#
using System.Reflection;
|
|
using NUnit.Framework;
|
|
using Shouldly;
|
|
using Speckle.Newtonsoft.Json.Linq;
|
|
using Speckle.Objects.BuiltElements;
|
|
using Speckle.Sdk.Common;
|
|
using Speckle.Sdk.Host;
|
|
using Speckle.Sdk.Models;
|
|
using Speckle.Sdk.Serialisation;
|
|
|
|
namespace Speckle.Sdk.Serialization.Tests;
|
|
|
|
[TestFixture]
|
|
[Description("For certain types, changing property from one type to another should be implicitly backwards compatible")]
|
|
public class SerializationTests
|
|
{
|
|
private readonly Assembly _assembly = Assembly.GetExecutingAssembly();
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
TypeLoader.Reset();
|
|
TypeLoader.Initialize(typeof(Base).Assembly, typeof(Wall).Assembly, _assembly);
|
|
}
|
|
|
|
private async Task<string> ReadJson(string fullName)
|
|
{
|
|
await using var stream = _assembly.GetManifestResourceStream(fullName).NotNull();
|
|
using var reader = new StreamReader(stream);
|
|
return await reader.ReadToEndAsync();
|
|
}
|
|
|
|
private async Task<Dictionary<string, string>> ReadAsObjects(string fullName)
|
|
{
|
|
var jsonObjects = new Dictionary<string, string>();
|
|
var json = await ReadJson(fullName);
|
|
var array = JArray.Parse(json);
|
|
foreach (var obj in array)
|
|
{
|
|
if (obj is JObject jobj)
|
|
{
|
|
jsonObjects.Add(jobj["id"].NotNull().Value<string>().NotNull(), jobj.ToString());
|
|
}
|
|
}
|
|
return jsonObjects;
|
|
}
|
|
|
|
[Test]
|
|
[TestCase("RevitObject.json")]
|
|
public async Task Basic_Namespace_Validation(string fileName)
|
|
{
|
|
var fullName = _assembly.GetManifestResourceNames().Single(x => x.EndsWith(fileName));
|
|
var closure = await ReadAsObjects(fullName);
|
|
var deserializer = new SpeckleObjectDeserializer
|
|
{
|
|
ReadTransport = new TestTransport(closure),
|
|
CancellationToken = default
|
|
};
|
|
foreach (var (id, objJson) in closure)
|
|
{
|
|
var jObject = JObject.Parse(objJson);
|
|
var oldSpeckleType = jObject["speckle_type"].NotNull().Value<string>().NotNull();
|
|
var starts = oldSpeckleType.StartsWith("Speckle.Core.") || oldSpeckleType.StartsWith("Objects.");
|
|
starts.ShouldBeTrue($"{oldSpeckleType} isn't expected");
|
|
|
|
var baseType = await deserializer.DeserializeJsonAsync(objJson);
|
|
baseType.id.ShouldBe(id);
|
|
|
|
starts = baseType.speckle_type.StartsWith("Speckle.Core.") || baseType.speckle_type.StartsWith("Objects.");
|
|
starts.ShouldBeTrue($"{baseType.speckle_type} isn't expected");
|
|
|
|
var type = TypeLoader.GetAtomicType(baseType.speckle_type);
|
|
type.ShouldNotBeNull();
|
|
var name = TypeLoader.GetTypeString(type) ?? throw new ArgumentNullException();
|
|
starts = name.StartsWith("Speckle.Core") || name.StartsWith("Objects");
|
|
starts.ShouldBeTrue($"{name} isn't expected");
|
|
}
|
|
}
|
|
}
|