diff --git a/src/Speckle.Sdk/Api/GraphQL/Serializer/ConstantCaseEnumConverter.cs b/src/Speckle.Sdk/Api/GraphQL/Serializer/ConstantCaseEnumConverter.cs index 0abc3614..3d7eb29c 100644 --- a/src/Speckle.Sdk/Api/GraphQL/Serializer/ConstantCaseEnumConverter.cs +++ b/src/Speckle.Sdk/Api/GraphQL/Serializer/ConstantCaseEnumConverter.cs @@ -1,5 +1,3 @@ -#nullable disable - using System.Reflection; using GraphQL.Client.Abstractions.Utilities; using Speckle.Newtonsoft.Json; @@ -9,7 +7,7 @@ namespace Speckle.Sdk.Api.GraphQL.Serializer; internal class ConstantCaseEnumConverter : StringEnumConverter { - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) { if (value == null) { @@ -18,7 +16,7 @@ internal class ConstantCaseEnumConverter : StringEnumConverter else { var enumString = ((Enum)value).ToString("G"); - var memberName = value + string? memberName = value .GetType() .GetMember(enumString, BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public) .FirstOrDefault() @@ -34,7 +32,9 @@ internal class ConstantCaseEnumConverter : StringEnumConverter } else { +#pragma warning disable CS8604 // Possible null reference argument. //never null? writer.WriteValue(memberName.ToConstantCase()); +#pragma warning restore CS8604 // Possible null reference argument. } } } diff --git a/src/Speckle.Sdk/Api/GraphQL/Serializer/MapConverter.cs b/src/Speckle.Sdk/Api/GraphQL/Serializer/MapConverter.cs index cf095cf3..c552f1bf 100644 --- a/src/Speckle.Sdk/Api/GraphQL/Serializer/MapConverter.cs +++ b/src/Speckle.Sdk/Api/GraphQL/Serializer/MapConverter.cs @@ -1,4 +1,3 @@ -#nullable disable using System.Diagnostics.CodeAnalysis; using GraphQL; using Speckle.Newtonsoft.Json; @@ -8,7 +7,7 @@ namespace Speckle.Sdk.Api.GraphQL.Serializer; internal sealed class MapConverter : JsonConverter { - public override void WriteJson(JsonWriter writer, Map value, JsonSerializer serializer) + public override void WriteJson(JsonWriter writer, Map? value, JsonSerializer serializer) { throw new NotImplementedException( "This converter currently is only intended to be used to read a JSON object into a strongly-typed representation." @@ -18,7 +17,7 @@ internal sealed class MapConverter : JsonConverter public override Map ReadJson( JsonReader reader, Type objectType, - Map existingValue, + Map? existingValue, bool hasExistingValue, JsonSerializer serializer ) @@ -39,16 +38,23 @@ internal sealed class MapConverter : JsonConverter )] private object ReadToken(JToken token) { - return token switch + switch (token) { - JObject jObject => ReadDictionary(jObject, new Dictionary()), - JArray jArray => ReadArray(jArray).ToList(), - JValue jValue => jValue.Value, - JConstructor => throw new ArgumentOutOfRangeException(nameof(token), "cannot deserialize a JSON constructor"), - JProperty => throw new ArgumentOutOfRangeException(nameof(token), "cannot deserialize a JSON property"), - JContainer => throw new ArgumentOutOfRangeException(nameof(token), "cannot deserialize a JSON comment"), - _ => throw new ArgumentOutOfRangeException(nameof(token), $"Invalid token type {token?.Type}"), - }; + case JObject jObject: + return ReadDictionary(jObject, new Dictionary()); + case JArray jArray: + return ReadArray(jArray).ToList(); + case JValue jValue: + return jValue.Value ?? string.Empty; + case JConstructor: + throw new ArgumentOutOfRangeException(nameof(token), "cannot deserialize a JSON constructor"); + case JProperty: + throw new ArgumentOutOfRangeException(nameof(token), "cannot deserialize a JSON property"); + case JContainer: + throw new ArgumentOutOfRangeException(nameof(token), "cannot deserialize a JSON comment"); + default: + throw new ArgumentOutOfRangeException(nameof(token), $"Invalid token type {token?.Type}"); + } } private Dictionary ReadDictionary(JToken element, Dictionary to) diff --git a/src/Speckle.Sdk/Api/GraphQL/Serializer/NewtonsoftJsonSerializer.cs b/src/Speckle.Sdk/Api/GraphQL/Serializer/NewtonsoftJsonSerializer.cs index c7c0d51c..80239e9d 100644 --- a/src/Speckle.Sdk/Api/GraphQL/Serializer/NewtonsoftJsonSerializer.cs +++ b/src/Speckle.Sdk/Api/GraphQL/Serializer/NewtonsoftJsonSerializer.cs @@ -1,10 +1,10 @@ -#nullable disable using System.Text; using GraphQL; using GraphQL.Client.Abstractions; using GraphQL.Client.Abstractions.Websocket; using Speckle.Newtonsoft.Json; using Speckle.Newtonsoft.Json.Serialization; +using Speckle.Sdk.Common; using Speckle.Sdk.Serialisation; namespace Speckle.Sdk.Api.GraphQL.Serializer; @@ -51,10 +51,9 @@ internal sealed class NewtonsoftJsonSerializer : IGraphQLWebsocketJsonSerializer public GraphQLWebSocketResponse DeserializeToWebsocketResponse(byte[] bytes) { - return JsonConvert.DeserializeObject>( - Encoding.UTF8.GetString(bytes), - JsonSerializerSettings - ); + return JsonConvert + .DeserializeObject>(Encoding.UTF8.GetString(bytes), JsonSerializerSettings) + .NotNull(); } public Task> DeserializeFromUtf8StreamAsync( @@ -79,6 +78,6 @@ internal sealed class NewtonsoftJsonSerializer : IGraphQLWebsocketJsonSerializer using var sr = new StreamReader(stream); using JsonReader reader = SpeckleObjectSerializerPool.Instance.GetJsonTextReader(sr); var serializer = JsonSerializer.Create(serializerSettings); - return Task.FromResult(serializer.Deserialize(reader)); + return Task.FromResult(serializer.Deserialize(reader) ?? throw new ArgumentException("Serialized data is null")); } } diff --git a/src/Speckle.Sdk/Credentials/Account.cs b/src/Speckle.Sdk/Credentials/Account.cs index f1a529b8..b58b9c21 100644 --- a/src/Speckle.Sdk/Credentials/Account.cs +++ b/src/Speckle.Sdk/Credentials/Account.cs @@ -1,4 +1,3 @@ -#nullable disable using System.Runtime.InteropServices; using Speckle.Sdk.Api.GraphQL.Models; using Speckle.Sdk.Helpers; @@ -48,7 +47,7 @@ public class Account : IEquatable private static string CleanURL(string server) { - if (Uri.TryCreate(server, UriKind.Absolute, out Uri newUri)) + if (Uri.TryCreate(server, UriKind.Absolute, out Uri? newUri)) { server = newUri.Authority; } @@ -77,12 +76,12 @@ public class Account : IEquatable return $"Account ({userInfo.email} | {serverInfo.url})"; } - public bool Equals(Account other) + public bool Equals(Account? other) { return other is not null && other.userInfo.email == userInfo.email && other.serverInfo.url == serverInfo.url; } - public override bool Equals(object obj) + public override bool Equals(object? obj) { return obj is Account acc && Equals(acc); } diff --git a/src/Speckle.Sdk/Credentials/AccountManager.cs b/src/Speckle.Sdk/Credentials/AccountManager.cs index 1bf7c3af..e8784ee1 100644 --- a/src/Speckle.Sdk/Credentials/AccountManager.cs +++ b/src/Speckle.Sdk/Credentials/AccountManager.cs @@ -248,7 +248,7 @@ public class AccountManager( account.serverInfo.frontend2 = true; // setting the id to null will force it to be recreated - account.id = null; + account.id = null!; //TODO this is gross so remove when id is nullable RemoveAccount(id); _accountStorage.SaveObject(account.id.NotNull(), JsonConvert.SerializeObject(account)); diff --git a/src/Speckle.Sdk/Host/Attributes.cs b/src/Speckle.Sdk/Host/Attributes.cs index c5e94a77..5887f6af 100644 --- a/src/Speckle.Sdk/Host/Attributes.cs +++ b/src/Speckle.Sdk/Host/Attributes.cs @@ -1,4 +1,3 @@ -#nullable disable namespace Speckle.Sdk.Host; [AttributeUsage(AttributeTargets.Constructor)] @@ -7,7 +6,7 @@ public sealed class SchemaInfoAttribute : Attribute public SchemaInfoAttribute(string name, string description) : this(name, description, null, null) { } - public SchemaInfoAttribute(string name, string description, string category, string subcategory) + public SchemaInfoAttribute(string name, string description, string? category, string? subcategory) { Name = name; Description = description; @@ -15,9 +14,9 @@ public sealed class SchemaInfoAttribute : Attribute Subcategory = subcategory; } - public string Subcategory { get; } + public string? Subcategory { get; } - public string Category { get; } + public string? Category { get; } public string Description { get; } diff --git a/src/Speckle.Sdk/Models/Base.cs b/src/Speckle.Sdk/Models/Base.cs index d68e31e7..45b8efed 100644 --- a/src/Speckle.Sdk/Models/Base.cs +++ b/src/Speckle.Sdk/Models/Base.cs @@ -1,4 +1,3 @@ -#nullable disable using System.Collections; using System.Diagnostics.CodeAnalysis; using System.Reflection; @@ -24,15 +23,13 @@ namespace Speckle.Sdk.Models; [SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Serialized property names are camelCase by design")] public class Base : DynamicBase, ISpeckleObject { - private string _type; + private string? _type; /// /// A speckle object's id is an unique hash based on its properties. NOTE: this field will be null unless the object was deserialised from a source. Use the function to get it. /// [SchemaIgnore] - public virtual string id { get; set; } - -#nullable enable //Starting nullability syntax here so that `id` null oblivious, + public virtual string? id { get; set; } /// /// Secondary, ideally host application driven, object identifier. diff --git a/src/Speckle.Sdk/Models/Blob.cs b/src/Speckle.Sdk/Models/Blob.cs index ad6706b8..540d1ca0 100644 --- a/src/Speckle.Sdk/Models/Blob.cs +++ b/src/Speckle.Sdk/Models/Blob.cs @@ -1,5 +1,4 @@ -#nullable disable -using System.Runtime.Serialization; +using System.Runtime.Serialization; using Speckle.Newtonsoft.Json; namespace Speckle.Sdk.Models; @@ -38,13 +37,13 @@ public class Blob : Base /// /// For blobs, the id is the same as the file hash. Please note, when deserialising, the id will be set from the original hash generated on sending. /// - public override string id + public override string? id { get => GetFileHash(); set => base.id = value; } - public string GetFileHash() + public string? GetFileHash() { if ((_isHashExpired || _hash == null) && filePath != null) { @@ -63,6 +62,7 @@ public class Blob : Base public string GetLocalDestinationPath(string blobStorageFolder) { var fileName = Path.GetFileName(filePath); - return Path.Combine(blobStorageFolder, $"{id[..10]}-{fileName}"); + var x = id ?? throw new ArgumentException("id is empty"); + return Path.Combine(blobStorageFolder, $"{x[..10]}-{fileName}"); } } diff --git a/src/Speckle.Sdk/Models/Extensions/BaseExtensions.cs b/src/Speckle.Sdk/Models/Extensions/BaseExtensions.cs index 6721650c..009c67a8 100644 --- a/src/Speckle.Sdk/Models/Extensions/BaseExtensions.cs +++ b/src/Speckle.Sdk/Models/Extensions/BaseExtensions.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Diagnostics.Contracts; +using Speckle.Sdk.Common; using Speckle.Sdk.Models.Collections; namespace Speckle.Sdk.Models.Extensions; @@ -31,7 +32,7 @@ public static class BaseExtensions root, b => { - if (!cache.Add(b.id)) + if (!cache.Add(b.id.NotNull())) { return true; } @@ -42,7 +43,7 @@ public static class BaseExtensions foreach (var b in traversal) { - if (!cache.Contains(b.id)) + if (!cache.Contains(b.id.NotNull())) { yield return b; } diff --git a/src/Speckle.Sdk/Models/ISpeckleObject.cs b/src/Speckle.Sdk/Models/ISpeckleObject.cs index 5516c367..55a7e74d 100644 --- a/src/Speckle.Sdk/Models/ISpeckleObject.cs +++ b/src/Speckle.Sdk/Models/ISpeckleObject.cs @@ -2,10 +2,7 @@ public interface ISpeckleObject { -#nullable disable - public string id { get; } - -#nullable enable //Starting nullability syntax here so that `id` null oblivious, + public string? id { get; } public string? applicationId { get; } diff --git a/src/Speckle.Sdk/Serialisation/SpeckleObjectSerializer.cs b/src/Speckle.Sdk/Serialisation/SpeckleObjectSerializer.cs index 2ed4a1a6..618f7e6f 100644 --- a/src/Speckle.Sdk/Serialisation/SpeckleObjectSerializer.cs +++ b/src/Speckle.Sdk/Serialisation/SpeckleObjectSerializer.cs @@ -362,7 +362,7 @@ public class SpeckleObjectSerializer } else { - id = new Id(((Blob)baseObj).id); + id = new Id(((Blob)baseObj).id.NotNull()); } writer.WritePropertyName("id"); writer.WriteValue(id.Value); diff --git a/src/Speckle.Sdk/Serialisation/V2/Send/ObjectSerializer.cs b/src/Speckle.Sdk/Serialisation/V2/Send/ObjectSerializer.cs index b427094e..c5f1a377 100644 --- a/src/Speckle.Sdk/Serialisation/V2/Send/ObjectSerializer.cs +++ b/src/Speckle.Sdk/Serialisation/V2/Send/ObjectSerializer.cs @@ -20,7 +20,6 @@ public class ObjectSerializer : IObjectSerializer { private HashSet _parentObjects = new(); private readonly Dictionary _currentClosures = new(); - private readonly IDictionary _baseCache; private readonly bool _trackDetachedChildren; private readonly IBasePropertyGatherer _propertyGatherer; @@ -41,12 +40,10 @@ public class ObjectSerializer : IObjectSerializer /// public ObjectSerializer( IBasePropertyGatherer propertyGatherer, - IDictionary baseCache, bool trackDetachedChildren = false, CancellationToken cancellationToken = default ) { - _baseCache = baseCache; _propertyGatherer = propertyGatherer; _cancellationToken = cancellationToken; _trackDetachedChildren = trackDetachedChildren; @@ -69,7 +66,6 @@ public class ObjectSerializer : IObjectSerializer { throw new SpeckleSerializeException($"Failed to extract (pre-serialize) properties from the {baseObj}", ex); } - _baseCache[baseObj] = new(item.Item2, _currentClosures); yield return (item.Item1, item.Item2); foreach (var chunk in _chunks) { @@ -232,26 +228,13 @@ public class ObjectSerializer : IObjectSerializer return null; } - Closures childClosures; - Id id; - Json json; - if (_baseCache.TryGetValue(baseObj, out var info)) - { - id = new Id(baseObj.id); - childClosures = info.Closures; - json = info.Json; - MergeClosures(_currentClosures, childClosures); - } - else - { - childClosures = isRoot || inheritedDetachInfo.IsDetachable ? _currentClosures : []; - var sb = Pools.StringBuilders.Get(); - using var writer = new StringWriter(sb); - using var jsonWriter = SpeckleObjectSerializerPool.Instance.GetJsonTextWriter(writer); - id = SerializeBaseObject(baseObj, jsonWriter, childClosures); - json = new Json(writer.ToString()); - Pools.StringBuilders.Return(sb); - } + var childClosures = isRoot || inheritedDetachInfo.IsDetachable ? _currentClosures : []; + var sb = Pools.StringBuilders.Get(); + using var writer = new StringWriter(sb); + using var jsonWriter = SpeckleObjectSerializerPool.Instance.GetJsonTextWriter(writer); + var id = SerializeBaseObject(baseObj, jsonWriter, childClosures); + var json = new Json(writer.ToString()); + Pools.StringBuilders.Return(sb); _parentObjects.Remove(baseObj); @@ -311,7 +294,7 @@ public class ObjectSerializer : IObjectSerializer } else { - id = new Id(((Blob)baseObj).id); + id = new Id(((Blob)baseObj).id.NotNull()); } writer.WritePropertyName("id"); writer.WriteValue(id.Value); diff --git a/src/Speckle.Sdk/Serialisation/V2/Send/ObjectSerializerFactory.cs b/src/Speckle.Sdk/Serialisation/V2/Send/ObjectSerializerFactory.cs index 2fa75d05..77f3b6f9 100644 --- a/src/Speckle.Sdk/Serialisation/V2/Send/ObjectSerializerFactory.cs +++ b/src/Speckle.Sdk/Serialisation/V2/Send/ObjectSerializerFactory.cs @@ -1,11 +1,10 @@ using Speckle.InterfaceGenerator; -using Speckle.Sdk.Models; namespace Speckle.Sdk.Serialisation.V2.Send; [GenerateAutoInterface] public class ObjectSerializerFactory(IBasePropertyGatherer propertyGatherer) : IObjectSerializerFactory { - public IObjectSerializer Create(IDictionary baseCache, CancellationToken cancellationToken) => - new ObjectSerializer(propertyGatherer, baseCache, true, cancellationToken); + public IObjectSerializer Create(CancellationToken cancellationToken) => + new ObjectSerializer(propertyGatherer, true, cancellationToken); } diff --git a/src/Speckle.Sdk/Serialisation/V2/Send/SerializeProcess.cs b/src/Speckle.Sdk/Serialisation/V2/Send/SerializeProcess.cs index 40186bea..534fbc1e 100644 --- a/src/Speckle.Sdk/Serialisation/V2/Send/SerializeProcess.cs +++ b/src/Speckle.Sdk/Serialisation/V2/Send/SerializeProcess.cs @@ -9,7 +9,7 @@ using Speckle.Sdk.Transports; namespace Speckle.Sdk.Serialisation.V2.Send; -public record SerializeProcessOptions(bool SkipCacheRead, bool SkipCacheWrite, bool SkipServer, bool CacheBases); +public record SerializeProcessOptions(bool SkipCacheRead, bool SkipCacheWrite, bool SkipServer); public readonly record struct SerializeProcessResults( string RootId, @@ -26,11 +26,8 @@ public class SerializeProcess( SerializeProcessOptions? options = null ) : ChannelSaver, ISerializeProcess { - private readonly SerializeProcessOptions _options = options ?? new(false, false, false, true); + private readonly SerializeProcessOptions _options = options ?? new(false, false, false); private readonly ConcurrentDictionary _jsonCache = new(); - - private readonly IDictionary _baseCache = - options?.CacheBases ?? true ? new ConcurrentDictionary() : new EmptyDictionary(); private readonly ConcurrentDictionary _objectReferences = new(); private long _totalFound; @@ -44,7 +41,7 @@ public class SerializeProcess( var channelTask = Start(cancellationToken); await Traverse(root, true, cancellationToken).ConfigureAwait(false); await channelTask.ConfigureAwait(false); - return new(root.id, _objectReferences.Freeze()); + return new(root.id.NotNull(), _objectReferences.Freeze()); } private async Task Traverse(Base obj, bool isEnd, CancellationToken cancellationToken) @@ -110,7 +107,7 @@ public class SerializeProcess( } if (id is null || !_jsonCache.TryGetValue(id.Value, out var json)) { - var serializer2 = objectSerializerFactory.Create(_baseCache, cancellationToken); + var serializer2 = objectSerializerFactory.Create(cancellationToken); var items = serializer2.Serialize(obj).ToList(); foreach (var kvp in serializer2.ObjectReferences) { diff --git a/tests/Speckle.Sdk.Serialization.Testing/Program.cs b/tests/Speckle.Sdk.Serialization.Testing/Program.cs index b807f795..5df2d34d 100644 --- a/tests/Speckle.Sdk.Serialization.Testing/Program.cs +++ b/tests/Speckle.Sdk.Serialization.Testing/Program.cs @@ -61,7 +61,7 @@ var process2 = factory.CreateSerializeProcess( streamId, token, progress, - new SerializeProcessOptions(skipCacheSendCheck, skipCacheSendSave, true, true) + new SerializeProcessOptions(skipCacheSendCheck, skipCacheSendSave, true) ); await process2.Serialize(@base, default).ConfigureAwait(false); Console.WriteLine("Detach"); diff --git a/tests/Speckle.Sdk.Serialization.Tests/DetachedTests.cs b/tests/Speckle.Sdk.Serialization.Tests/DetachedTests.cs index dabdda56..54316cd2 100644 --- a/tests/Speckle.Sdk.Serialization.Tests/DetachedTests.cs +++ b/tests/Speckle.Sdk.Serialization.Tests/DetachedTests.cs @@ -26,9 +26,7 @@ public class DetachedTests } [Test(Description = "Checks that all typed properties (including obsolete ones) are returned")] - [TestCase(true)] - [TestCase(false)] - public async Task CanSerialize_New_Detached(bool cacheBases) + public async Task CanSerialize_New_Detached() { var expectedJson = """ { @@ -76,7 +74,7 @@ public class DetachedTests new DummyServerObjectManager(), new BaseChildFinder(new BasePropertyGatherer()), new ObjectSerializerFactory(new BasePropertyGatherer()), - new SerializeProcessOptions(false, false, true, cacheBases) + new SerializeProcessOptions(false, false, true) ); await process2.Serialize(@base, default).ConfigureAwait(false); @@ -193,9 +191,7 @@ public class DetachedTests } [Test(Description = "Checks that all typed properties (including obsolete ones) are returned")] - [TestCase(true)] - [TestCase(false)] - public async Task CanSerialize_New_Detached2(bool cacheBases) + public async Task CanSerialize_New_Detached2() { var root = """ @@ -270,7 +266,7 @@ public class DetachedTests new DummyServerObjectManager(), new BaseChildFinder(new BasePropertyGatherer()), new ObjectSerializerFactory(new BasePropertyGatherer()), - new SerializeProcessOptions(false, false, true, cacheBases) + new SerializeProcessOptions(false, false, true) ); var results = await process2.Serialize(@base, default).ConfigureAwait(false); diff --git a/tests/Speckle.Sdk.Serialization.Tests/ExternalIdTests.cs b/tests/Speckle.Sdk.Serialization.Tests/ExternalIdTests.cs index c9a110e3..cde6aac0 100644 --- a/tests/Speckle.Sdk.Serialization.Tests/ExternalIdTests.cs +++ b/tests/Speckle.Sdk.Serialization.Tests/ExternalIdTests.cs @@ -1,5 +1,4 @@ -using System.Collections.Concurrent; -using NUnit.Framework; +using NUnit.Framework; using Shouldly; using Speckle.Newtonsoft.Json.Linq; using Speckle.Objects.Geometry; @@ -27,11 +26,7 @@ public class ExternalIdTests public void ExternalIdTest_Detached(string lineId, string valueId) { var p = new Polyline() { units = "cm", value = [1, 2] }; - var serializer = new ObjectSerializer( - new BasePropertyGatherer(), - new ConcurrentDictionary(), - true - ); + var serializer = new ObjectSerializer(new BasePropertyGatherer(), true); var list = serializer.Serialize(p).ToDictionary(x => x.Item1, x => x.Item2); list.ContainsKey(new Id(lineId)).ShouldBeTrue(); var json = list[new Id(lineId)]; @@ -58,11 +53,7 @@ public class ExternalIdTests knots = [], weights = [], }; - var serializer = new ObjectSerializer( - new BasePropertyGatherer(), - new ConcurrentDictionary(), - true - ); + var serializer = new ObjectSerializer(new BasePropertyGatherer(), true); var list = serializer.Serialize(curve).ToDictionary(x => x.Item1, x => x.Item2); list.ContainsKey(new Id(lineId)).ShouldBeTrue(); var json = list[new Id(lineId)]; @@ -90,11 +81,7 @@ public class ExternalIdTests weights = [], }; var polycurve = new Polycurve() { segments = [curve], units = "cm" }; - var serializer = new ObjectSerializer( - new BasePropertyGatherer(), - new ConcurrentDictionary(), - true - ); + var serializer = new ObjectSerializer(new BasePropertyGatherer(), true); var list = serializer.Serialize(polycurve).ToDictionary(x => x.Item1, x => x.Item2); list.ContainsKey(new Id(lineId)).ShouldBeTrue(); var json = list[new Id(lineId)]; @@ -124,11 +111,7 @@ public class ExternalIdTests var polycurve = new Polycurve() { segments = [curve], units = "cm" }; var @base = new Base(); @base.SetDetachedProp("profile", polycurve); - var serializer = new ObjectSerializer( - new BasePropertyGatherer(), - new ConcurrentDictionary(), - true - ); + var serializer = new ObjectSerializer(new BasePropertyGatherer(), true); var list = serializer.Serialize(@base).ToDictionary(x => x.Item1, x => x.Item2); list.ContainsKey(new Id(lineId)).ShouldBeTrue(); var json = list[new Id(lineId)]; diff --git a/tests/Speckle.Sdk.Serialization.Tests/SerializationTests.cs b/tests/Speckle.Sdk.Serialization.Tests/SerializationTests.cs index 70cd8ba4..3ccf593a 100644 --- a/tests/Speckle.Sdk.Serialization.Tests/SerializationTests.cs +++ b/tests/Speckle.Sdk.Serialization.Tests/SerializationTests.cs @@ -228,7 +228,7 @@ public class SerializationTests var j = serializer.Serialize(base1); //j.ShouldBe(objJson); JToken.DeepEquals(JObject.Parse(j), JObject.Parse(objJson)); - newIds.Add(base1.id, j); + newIds.Add(base1.id.NotNull(), j); oldIds.Add(id, j); idToBase.Add(id, base1); } @@ -263,7 +263,7 @@ public class SerializationTests new DummySendServerObjectManager(newIdToJson), new BaseChildFinder(new BasePropertyGatherer()), new ObjectSerializerFactory(new BasePropertyGatherer()), - new SerializeProcessOptions(true, true, false, true) + new SerializeProcessOptions(true, true, false) ); var (rootId2, _) = await serializeProcess.Serialize(root, default); diff --git a/tests/Speckle.Sdk.Tests.Integration/Api/GraphQL/Resources/CommentResourceTests.cs b/tests/Speckle.Sdk.Tests.Integration/Api/GraphQL/Resources/CommentResourceTests.cs index 6e134d4a..a6b90605 100644 --- a/tests/Speckle.Sdk.Tests.Integration/Api/GraphQL/Resources/CommentResourceTests.cs +++ b/tests/Speckle.Sdk.Tests.Integration/Api/GraphQL/Resources/CommentResourceTests.cs @@ -2,6 +2,7 @@ using Speckle.Sdk.Api.GraphQL.Inputs; using Speckle.Sdk.Api.GraphQL.Models; using Speckle.Sdk.Api.GraphQL.Resources; +using Speckle.Sdk.Common; namespace Speckle.Sdk.Tests.Integration.API.GraphQL.Resources; @@ -76,7 +77,7 @@ public class CommentResourceTests public async Task Edit() { var blobs = await Fixtures.SendBlobData(_testUser.Account, _project.id); - var blobIds = blobs.Select(b => b.id).ToList(); + var blobIds = blobs.Select(b => b.id.NotNull()).ToList(); EditCommentInput input = new(new(blobIds, null), _comment.id, _project.id); var editedComment = await Sut.Edit(input); @@ -92,7 +93,7 @@ public class CommentResourceTests public async Task Reply() { var blobs = await Fixtures.SendBlobData(_testUser.Account, _project.id); - var blobIds = blobs.Select(b => b.id).ToList(); + var blobIds = blobs.Select(b => b.id.NotNull()).ToList(); CreateCommentReplyInput input = new(new(blobIds, null), _comment.id, _project.id); var editedComment = await Sut.Reply(input); diff --git a/tests/Speckle.Sdk.Tests.Integration/Api/GraphQL/Resources/ProjectResourceExceptionalTests.cs b/tests/Speckle.Sdk.Tests.Integration/Api/GraphQL/Resources/ProjectResourceExceptionalTests.cs index ffb294de..5a938fff 100644 --- a/tests/Speckle.Sdk.Tests.Integration/Api/GraphQL/Resources/ProjectResourceExceptionalTests.cs +++ b/tests/Speckle.Sdk.Tests.Integration/Api/GraphQL/Resources/ProjectResourceExceptionalTests.cs @@ -4,6 +4,7 @@ using Speckle.Sdk.Api.GraphQL.Enums; using Speckle.Sdk.Api.GraphQL.Inputs; using Speckle.Sdk.Api.GraphQL.Models; using Speckle.Sdk.Api.GraphQL.Resources; +using Speckle.Sdk.Common; namespace Speckle.Sdk.Tests.Integration.API.GraphQL.Resources; @@ -88,7 +89,7 @@ public class ProjectResourceExceptionalTests [TestCase(StreamRoles.REVOKE)] public void ProjectUpdateRole_NonExistentProject(string newRole) { - ProjectUpdateRoleInput input = new(_secondUser.Account.id, "NonExistentProject", newRole); + ProjectUpdateRoleInput input = new(_secondUser.Account.id.NotNull(), "NonExistentProject", newRole); var ex = Assert.ThrowsAsync(async () => _ = await Sut.UpdateRole(input)); Assert.That(ex?.InnerExceptions, Has.One.Items.And.All.TypeOf()); @@ -101,7 +102,7 @@ public class ProjectResourceExceptionalTests [TestCase(StreamRoles.REVOKE)] public void ProjectUpdateRole_NonAuth(string newRole) { - ProjectUpdateRoleInput input = new(_secondUser.Account.id, "NonExistentProject", newRole); + ProjectUpdateRoleInput input = new(_secondUser.Account.id.NotNull(), "NonExistentProject", newRole); var ex = Assert.ThrowsAsync(async () => _ = await _unauthedUser.Project.UpdateRole(input)); Assert.That(ex?.InnerExceptions, Has.One.Items.And.All.TypeOf()); diff --git a/tests/Speckle.Sdk.Tests.Integration/Fixtures.cs b/tests/Speckle.Sdk.Tests.Integration/Fixtures.cs index 9b8e293c..d57badd1 100644 --- a/tests/Speckle.Sdk.Tests.Integration/Fixtures.cs +++ b/tests/Speckle.Sdk.Tests.Integration/Fixtures.cs @@ -159,7 +159,7 @@ public static class Fixtures internal static async Task CreateComment(Client client, string projectId, string modelId, string versionId) { var blobs = await SendBlobData(client.Account, projectId); - var blobIds = blobs.Select(b => b.id).ToList(); + var blobIds = blobs.Select(b => b.id.NotNull()).ToList(); CreateCommentInput input = new(new(blobIds, null), projectId, $"{projectId},{modelId},{versionId}", null, null); return await client.Comment.Create(input); } diff --git a/tests/Speckle.Sdk.Tests.Unit/Fixtures.cs b/tests/Speckle.Sdk.Tests.Unit/Fixtures.cs index d5a018fe..88746a75 100644 --- a/tests/Speckle.Sdk.Tests.Unit/Fixtures.cs +++ b/tests/Speckle.Sdk.Tests.Unit/Fixtures.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using Speckle.Sdk.Common; using Speckle.Sdk.Credentials; using Speckle.Sdk.Logging; using Speckle.Sdk.Transports; @@ -16,7 +17,7 @@ public abstract class Fixtures public static void UpdateOrSaveAccount(Account account) { - DeleteLocalAccount(account.id); + DeleteLocalAccount(account.id.NotNull()); string serializedObject = JsonConvert.SerializeObject(account); s_accountStorage.SaveObjectSync(account.id, serializedObject); } diff --git a/tests/Speckle.Sdk.Tests.Unit/Models/TraversalTests.cs b/tests/Speckle.Sdk.Tests.Unit/Models/TraversalTests.cs index 2144f020..5c36f3e6 100644 --- a/tests/Speckle.Sdk.Tests.Unit/Models/TraversalTests.cs +++ b/tests/Speckle.Sdk.Tests.Unit/Models/TraversalTests.cs @@ -1,4 +1,5 @@ using NUnit.Framework; +using Speckle.Sdk.Common; using Speckle.Sdk.Models; using Speckle.Sdk.Models.Extensions; @@ -25,7 +26,7 @@ public class TraversalTests }, }; - static bool BreakRule(Base b) => b.id.Contains("break on me"); + static bool BreakRule(Base b) => b.id.NotNull().Contains("break on me"); //Flatten var ret = root.Flatten(BreakRule).ToList();