Files
speckle-sharp-sdk/tests/Speckle.Sdk.Tests.Unit/Serialisation/SerializerBreakingChanges.cs
T
Adam Hathcock 6f5f044095 Adam/cxpla 6 kill remaining kit code in core (#59)
* compiles with relevant deletions

* Test fixes

* fix type loading

* type load for tests

* speckle objects renamespace

* rename Core to Sdk

* Fix test references

* tests renaming

* rename logging

* fmt

* start of adding an attribute to all base types

* convert all types and do basic test

* Fix most tests

* fix more tests

* fmt

* Build fix

* add changes and more tests

* Fix tests

* Fix integration tests
2024-08-08 10:52:19 +01:00

48 lines
1.6 KiB
C#

using NUnit.Framework;
using Speckle.Sdk.Serialisation;
namespace Speckle.Sdk.Tests.Unit.Serialisation;
/// <summary>
/// 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)
/// </summary>
[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
{
[Test]
public void StringToInt_ShouldThrow()
{
var from = new StringValueMock { value = "testValue" };
Assert.Throws<SpeckleDeserializeException>(() => from.SerializeAsTAndDeserialize<IntValueMock>());
}
[Test, TestCaseSource(nameof(MyEnums))]
public void StringToEnum_ShouldThrow(MyEnum testCase)
{
var from = new StringValueMock { value = testCase.ToString() };
Assert.Throws<SpeckleDeserializeException>(() =>
{
var res = from.SerializeAsTAndDeserialize<EnumValueMock>();
});
}
[
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.Throws<SpeckleDeserializeException>(() => from.SerializeAsTAndDeserialize<IntValueMock>());
}
}