Files
speckle-sharp-sdk/tests/Speckle.Objects.Tests.Unit/ObjectBaseValidityTests.cs
T
Adam Hathcock d269ac73dd Disallow SpeckleType inheritance (#71)
* Disallow SpeckleType inheritance

* fmt

* more tests
2024-08-13 14:32:58 +00:00

45 lines
1.2 KiB
C#

using NUnit.Framework;
using Shouldly;
using Speckle.Objects.Geometry;
using Speckle.Objects.Geometry.Autocad;
using Speckle.Objects.Structural.GSA.Geometry;
using Speckle.Sdk.Host;
using Speckle.Sdk.Models;
namespace Objects.Tests.Unit;
public class ObjectBaseValidityTests
{
[Test]
public void TestThatTypeWithoutAttributeFails()
{
TypeLoader.Reset();
TypeLoader.Initialize(typeof(Base).Assembly, typeof(GSAAssembly).Assembly);
}
[Test]
public void InheritanceTest_Disallow()
{
var exception = Assert.Throws<InvalidOperationException>(() =>
{
TypeLoader.Reset();
TypeLoader.Initialize(typeof(Base).Assembly, typeof(GSAAssembly).Assembly, typeof(Test).Assembly);
});
exception.ShouldNotBeNull();
exception.Message.ShouldBe(
"Objects.Tests.Unit.ObjectBaseValidityTests+Test inherits from Base has no SpeckleTypeAttribute"
);
}
[Test]
public void InheritanceTest_Allow()
{
TypeLoader.Reset();
TypeLoader.Initialize(typeof(Base).Assembly, typeof(GSAAssembly).Assembly);
var fullTypeString = TypeLoader.GetFullTypeString(typeof(AutocadPolycurve));
fullTypeString.ShouldBe("Objects.Geometry.Polycurve:Objects.Geometry.Autocad.AutocadPolycurve");
}
public class Test : Polycurve;
}