using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; using Speckle.Sdk.Api; using Speckle.Sdk.Host; using Speckle.Sdk.Models; using Speckle.Sdk.Serialisation; using Speckle.Sdk.Tests.Unit.Host; namespace Speckle.Sdk.Tests.Unit.Serialisation; /// /// Test fixture that documents what property typing changes break backwards/cross/forwards compatibility, and are "breaking" changes. /// This doesn't guarantee things work this way for SpecklePy /// Nor does it encompass other tricks (like deserialize callback, or computed json ignored properties) /// [TestFixture] [Description( "For certain types, changing property from one type to another is a breaking change, and not backwards/forwards compatible" )] public class SerializerBreakingChanges : PrimitiveTestFixture { private IOperations _operations; [SetUp] public void Setup() { TypeLoader.Reset(); TypeLoader.Initialize(typeof(Base).Assembly, typeof(Point).Assembly); var serviceProvider = TestServiceSetup.GetServiceProvider(); _operations = serviceProvider.GetRequiredService(); } [Test] public void StringToInt_ShouldThrow() { var from = new StringValueMock { value = "testValue" }; Assert.ThrowsAsync( async () => await from.SerializeAsTAndDeserialize(_operations) ); } [Test, TestCaseSource(nameof(MyEnums))] public void StringToEnum_ShouldThrow(MyEnum testCase) { var from = new StringValueMock { value = testCase.ToString() }; Assert.ThrowsAsync(async () => { var res = await from.SerializeAsTAndDeserialize(_operations); }); } [ Test, Description("Deserialization of a JTokenType.Float to a .NET short/int/long should throw exception"), TestCaseSource(nameof(Float64TestCases)), TestCase(1e+30) ] public void DoubleToInt_ShouldThrow(double testCase) { var from = new DoubleValueMock { value = testCase }; Assert.ThrowsAsync( async () => await from.SerializeAsTAndDeserialize(_operations) ); } }