Skip to content

Commit

Permalink
added test for GBXML pushing
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-Kingstone committed Oct 27, 2023
1 parent 1f58714 commit ac9d9ed
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
43 changes: 42 additions & 1 deletion .ci/unit-tests/XML_Adapter_Tests/PushTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@
using BH.oM.Adapters.XML;
using BH.oM.Adapter;
using BH.Engine.Adapter;
using BH.oM.Adapters.XML.Settings;
using BH.oM.Base;
using BH.oM.Data.Requests;
using BH.oM.Environment.Elements;
using BH.oM.Physical.Constructions;
using BH.Engine.Environment;

namespace BH.Tests.Adapter.XML
{
public class PushTests
{
XMLAdapter m_adapter;
XMLConfig m_config;
GBXMLSettings m_settings;

[OneTimeSetUp]
public void OneTimeSetUp()
Expand All @@ -27,8 +34,9 @@ public void OneTimeSetUp()
m_adapter = new XMLAdapter();
m_config = new XMLConfig()
{
File = new FileSettings() { Directory = ModelsPath, FileName = "PushedModel.xml"}
File = new FileSettings() { Directory = ModelsPath, FileName = "PushedModel.xml"},
};
m_settings = new GBXMLSettings();
}

[SetUp]
Expand All @@ -51,5 +59,38 @@ public void TearDown()
}
}
}

[Test]
public void PushGBXML()
{
m_config.Schema = oM.Adapters.XML.Enums.Schema.GBXML;
m_settings.IncludeConstructions = true;
m_config.Settings = m_settings;
FilterRequest request = new FilterRequest();

List<IBHoMObject> jsonObjs = BH.Engine.Adapters.File.Compute.ReadFromJsonFile(Path.Combine(m_config.File.Directory, "TestModel.json"), true).Cast<IBHoMObject>().ToList();

//Push, then pull objects.
m_adapter.Push(jsonObjs, actionConfig: m_config);
List<IBHoMObject> objs = m_adapter.Pull(request, actionConfig: m_config).Cast<IBHoMObject>().ToList();

List<Panel> pulledPanels = BH.Engine.Environment.Query.Panels(objs);
List<Panel> jsonPanels = BH.Engine.Environment.Query.Panels(jsonObjs);
List<Construction> constructions = objs.Where(x => x.GetType() == typeof(Construction)).Cast<Construction>().ToList();
List<Construction> jsonConstructions = objs.Where(x => x.GetType() == typeof(Construction) && x.Name == "generic_construction").Cast<Construction>().ToList();

pulledPanels = BH.Engine.Data.Query.OrderBy(pulledPanels, "Name");
jsonPanels = BH.Engine.Data.Query.OrderBy(jsonPanels, "Name");

pulledPanels.Count.Should().Be(jsonPanels.Count, "There was a different number of panels pushed then pulled compared to expected.");
for (int i = 0; i < pulledPanels.Count; i++)
{
pulledPanels[i].Name.Should().Be(jsonPanels[i].Name, "The name of the panel pulled was not the same as the json panel.");
pulledPanels[i].IsIdentical(jsonPanels[i]).Should().BeTrue("The panel with name {pulledPanels[i].Name} was not identical to the json panel with the same name.");
}
constructions.Count.Should().Be(jsonConstructions.Count, "There is only one type of construction (generic_construction) used in the building.");


}
}
}
5 changes: 5 additions & 0 deletions .ci/unit-tests/XML_Adapter_Tests/XML_Adapter_Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@
<SpecificVersion>False</SpecificVersion>
<Private>True</Private>
</Reference>
<Reference Include="TriangleNet_Engine">
<HintPath>$(ProgramData)\BHoM\Assemblies\TriangleNet_Engine.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>True</Private>
</Reference>
</ItemGroup>

</Project>

0 comments on commit ac9d9ed

Please sign in to comment.