Files
speckle-sharp-sdk/tests/Speckle.Sdk.Tests.Unit/Models/Extensions/BaseExtensionsTests.cs
T
Adam Hathcock 14d959834f Convert to Xunit (#196)
* xunit unit tests

* most pass with formatting

* convert objects to xunit

* remove nunit

* format

* merge fixes

* switch objects to fluent assertions

* update to fluent assertions

* more FA

* convert all to FA

* Format

* Fix tests

* formatting

* hopefully made credential test better

* Catch more specific exception

* use another more specific exception

* Fix tests

* update to xunit

* update packages
2025-01-09 15:32:28 +00:00

73 lines
2.2 KiB
C#

using FluentAssertions;
using Speckle.Sdk.Host;
using Speckle.Sdk.Models;
using Speckle.Sdk.Models.Collections;
using Speckle.Sdk.Models.Extensions;
using Xunit;
namespace Speckle.Sdk.Tests.Unit.Models.Extensions;
public class BaseExtensionsTests
{
public BaseExtensionsTests()
{
TypeLoader.Reset();
TypeLoader.Initialize(typeof(Base).Assembly);
}
[Theory]
[InlineData("myDynamicProp")]
[InlineData("elements")]
public void GetDetachedPropName_Dynamic(string propertyName)
{
var data = new TestBase();
var result = data.GetDetachedPropName(propertyName);
var expected = $"@{propertyName}";
result.Should().Be(expected);
}
[Theory]
[InlineData(nameof(TestBase.myProperty))]
[InlineData(nameof(TestBase.myOtherProperty))]
public void GetDetachedPropName_Instance(string propertyName)
{
var data = new TestBase();
var result = data.GetDetachedPropName(propertyName);
result.Should().Be(propertyName);
}
[Fact]
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();
basePaths.Count.Should().Be(3);
basePaths[0].Item2.speckle_type.Should().Be("Speckle.Core.Models.Collections.Collection");
basePaths[0].Item2["name"].Should().Be("collection");
basePaths[0].Item1.Should().BeEquivalentTo(new List<string>());
basePaths[1].Item2.speckle_type.Should().Be("Speckle.Core.Models.Collections.Collection");
basePaths[1].Item2["name"].Should().Be("subCollection");
basePaths[1].Item1.Should().BeEquivalentTo(new List<string>() { "collection" });
basePaths[2].Item2.speckle_type.Should().Be("Base");
basePaths[2].Item1.Should().BeEquivalentTo(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; }
}
}