Files
speckle-sharp-sdk/tests/Speckle.Sdk.Tests.Unit/Models/Extensions/BaseExtensionsTests.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

74 lines
2.3 KiB
C#

using NUnit.Framework;
using Speckle.Sdk.Host;
using Speckle.Sdk.Models;
using Speckle.Sdk.Models.Collections;
using Speckle.Sdk.Models.Extensions;
namespace Speckle.Sdk.Tests.Unit.Models.Extensions;
[TestFixture]
[TestOf(nameof(BaseExtensions))]
public class BaseExtensionsTests
{
[SetUp]
public void Setup()
{
TypeLoader.Reset();
TypeLoader.Initialize(typeof(Base).Assembly);
}
[Test]
[TestCase("myDynamicProp")]
[TestCase("elements")]
public void GetDetachedPropName_Dynamic(string propertyName)
{
var data = new TestBase();
var result = data.GetDetachedPropName(propertyName);
var expected = $"@{propertyName}";
Assert.That(result, Is.EqualTo(expected));
}
[Test]
[TestCase(nameof(TestBase.myProperty))]
[TestCase(nameof(TestBase.myOtherProperty))]
public void GetDetachedPropName_Instance(string propertyName)
{
var data = new TestBase();
var result = data.GetDetachedPropName(propertyName);
Assert.That(result, Is.EqualTo(propertyName));
}
[Test]
public void TraverseWithPath()
{
var collection = new Collection() { name = "collection" };
var subCollection = new Collection { name = "subCollection" };
collection.elements.Add(subCollection);
var data1 = new Base();
subCollection.elements.Add(data1);
var basePaths = collection.TraverseWithPath((obj => obj is not Collection)).ToList();
Assert.That(basePaths.Count, Is.EqualTo(3));
Assert.That(basePaths[0].Item2.speckle_type, Is.EqualTo("Speckle.Core.Models.Collection"));
Assert.That(basePaths[0].Item2["name"], Is.EqualTo("collection"));
Assert.That(basePaths[0].Item1, Is.EqualTo(new List<string>()));
Assert.That(basePaths[1].Item2.speckle_type, Is.EqualTo("Speckle.Core.Models.Collection"));
Assert.That(basePaths[1].Item2["name"], Is.EqualTo("subCollection"));
Assert.That(basePaths[1].Item1, Is.EqualTo(new List<string>() { "collection" }));
Assert.That(basePaths[2].Item2.speckle_type, Is.EqualTo("Base"));
Assert.That(basePaths[2].Item1, Is.EqualTo(new List<string>() { "collection", "subCollection" }));
}
[SpeckleType("Speckle.Core.Tests.Unit.Models.Extensions.BaseExtensionsTests+TestBase")]
public class TestBase : Base
{
public string myProperty { get; set; }
public string myOtherProperty { get; set; }
}
}