Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="System.Drawing.Common" Version="10.0.13" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\HTTP_Adapter\HTTP_Adapter.csproj" />
<ProjectReference Include="..\..\..\HTTP_Engine\HTTP_Engine.csproj" />
<ProjectReference Include="..\..\..\HTTP_oM\HTTP_oM.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="Adapter_oM">
<HintPath>..\..\..\..\..\ProgramData\BHoM\Assemblies\Adapter_oM.dll</HintPath>

Check failure on line 29 in .ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

.ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj#L29

Project reference for 'Adapter_oM' should be set to '$(ProgramData)\BHoM\Assemblies\Adapter_oM.dll'

Check failure on line 29 in .ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

.ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj#L29

Project reference for 'Adapter_oM' should set specific version as false
</Reference>
<Reference Include="BHoM">
<HintPath>..\..\..\..\..\ProgramData\BHoM\Assemblies\BHoM.dll</HintPath>

Check failure on line 32 in .ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

.ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj#L32

Project reference for 'BHoM' should be set to '$(ProgramData)\BHoM\Assemblies\BHoM.dll'

Check failure on line 32 in .ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

.ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj#L32

Project reference for 'BHoM' should set specific version as false
</Reference>
<Reference Include="BHoM_Adapter">
<HintPath>..\..\..\..\..\ProgramData\BHoM\Assemblies\BHoM_Adapter.dll</HintPath>

Check failure on line 35 in .ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

.ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj#L35

Project reference for 'BHoM_Adapter' should be set to '$(ProgramData)\BHoM\Assemblies\BHoM_Adapter.dll'

Check failure on line 35 in .ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

.ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj#L35

Project reference for 'BHoM_Adapter' should set specific version as false
</Reference>
<Reference Include="BHoM_Engine">
<HintPath>..\..\..\..\..\ProgramData\BHoM\Assemblies\BHoM_Engine.dll</HintPath>

Check failure on line 38 in .ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

.ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj#L38

Project reference for 'BHoM_Engine' should be set to '$(ProgramData)\BHoM\Assemblies\BHoM_Engine.dll'

Check failure on line 38 in .ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

.ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj#L38

Project reference for 'BHoM_Engine' should set specific version as false
</Reference>
<Reference Include="Data_oM">
<HintPath>..\..\..\..\..\ProgramData\BHoM\Assemblies\Data_oM.dll</HintPath>

Check failure on line 41 in .ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

.ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj#L41

Project reference for 'Data_oM' should be set to '$(ProgramData)\BHoM\Assemblies\Data_oM.dll'

Check failure on line 41 in .ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

.ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj#L41

Project reference for 'Data_oM' should set specific version as false
</Reference>
<Reference Include="Diffing_oM">
<HintPath>..\..\..\..\..\ProgramData\BHoM\Assemblies\Diffing_oM.dll</HintPath>

Check failure on line 44 in .ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

.ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj#L44

Project reference for 'Diffing_oM' should be set to '$(ProgramData)\BHoM\Assemblies\Diffing_oM.dll'

Check failure on line 44 in .ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

.ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj#L44

Project reference for 'Diffing_oM' should set specific version as false
</Reference>
<Reference Include="Geometry_oM">
<HintPath>..\..\..\..\..\ProgramData\BHoM\Assemblies\Geometry_oM.dll</HintPath>

Check failure on line 47 in .ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

.ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj#L47

Project reference for 'Geometry_oM' should be set to '$(ProgramData)\BHoM\Assemblies\Geometry_oM.dll'

Check failure on line 47 in .ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

.ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj#L47

Project reference for 'Geometry_oM' should set specific version as false
</Reference>
<Reference Include="Serialiser_Engine">
<HintPath>..\..\..\..\..\ProgramData\BHoM\Assemblies\Serialiser_Engine.dll</HintPath>

Check failure on line 50 in .ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

.ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj#L50

Project reference for 'Serialiser_Engine' should be set to '$(ProgramData)\BHoM\Assemblies\Serialiser_Engine.dll'

Check failure on line 50 in .ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj

View check run for this annotation

BHoMBot-CI / project-compliance

.ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/HTTP_Adapter_Tests.csproj#L50

Project reference for 'Serialiser_Engine' should set specific version as false
</Reference>
</ItemGroup>

<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>

</Project>
133 changes: 133 additions & 0 deletions .ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/PullTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2026, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.Adapter.HTTP;
using BH.oM.Adapters.HTTP;
using BH.oM.Base;
using BH.oM.Base.Debugging;
using BH.oM.Geometry;

namespace HTTP_Adapter_Tests
{
public class PullTests
{
private HTTPAdapter _adapter = default!;

/***************************************************/
/**** Setup ****/
/***************************************************/

[OneTimeSetUp]
[Description("One time set up.")]
public void OneTimeSetUp()
{
_adapter = new HTTPAdapter("http://localhost:5068");
}

/***************************************************/

[SetUp]
[Description("These tests need the TestAPI project running to work properly. If the api is not running, then all tests will be marked as inconclusive.")]
public void SetUp()
{
try
{
using HttpResponseMessage message = _adapter.HttpClient.GetAsync("TestAPI/health").Result;

//the test API (a simple API that returns and accepts BHoM Point objects) isn't running, so report as inconclusive.
if (message.StatusCode != System.Net.HttpStatusCode.OK)
Assert.Inconclusive("Test reported as inconclusive as the test API is not responding, maybe it isn't running?");
}
catch (Exception ex)
{
Assert.Inconclusive("Test reported as inconclusive as the test API is not responding, maybe it isn't running?");
}
}

/***************************************************/
/**** Tests ****/
/***************************************************/

[Test]
[Description("Tests the default behaviour of GETting with the adapter. The endpoint should return a point.")]
public void TestDefaultPull()
{
GetRequest request = new GetRequest() { BaseUrl = "TestAPI/default" };

List<object> objs = _adapter.Pull(request).ToList();

Assert.That(objs, Is.Not.Null);
Assert.That(objs, Is.Not.Empty);
Assert.That(objs, Has.Count.EqualTo(1));
Assert.That(objs[0], Is.Not.Null);
Assert.That(objs[0], Is.TypeOf<Point>());
Assert.That(objs[0], Has.Property("X").EqualTo(1));
Assert.That(objs[0], Has.Property("Y").EqualTo(2));
Assert.That(objs[0], Has.Property("Z").EqualTo(3));
}

/***************************************************/

[Test]
[Description("Tests pulling with query parameters, the TestAPI puts the parameters in a custom object to allow verification.")]
public void TestPullWithParameters()
{
GetRequest request = new GetRequest() { BaseUrl = "TestAPI/parameters", Parameters = new Dictionary<string, object>() { { "parameter1", "p1" }, { "parameter2", 2 } } };

List<object> objs = _adapter.Pull(request).ToList();

Assert.That(objs, Is.Not.Null);
Assert.That(objs, Is.Not.Empty);
Assert.That(objs, Has.Count.EqualTo(1));
Assert.That(objs[0], Is.Not.Null);
Assert.That(objs[0], Is.TypeOf<CustomObject>());

CustomObject co = (CustomObject)objs[0];

Assert.That(co.CustomData, Has.ItemAt("parameter1").EqualTo("p1"));
Assert.That(co.CustomData, Has.ItemAt("parameter2").EqualTo(2));
}

/***************************************************/

[Test]
[Description("Tests getting as a string while setting force deserialisation to false, where the content type of the return is not set to 'application/bhom'.")]
public void TestPullProducesJson()
{
GetRequest request = new GetRequest() { BaseUrl = "TestAPI/producesJson"};
HttpPullConfig config = new HttpPullConfig() { ForceDeserialiseAsBHoM = false };

List<object> objs = _adapter.Pull(request, config).ToList();

Assert.That(objs, Is.Not.Null);
Assert.That(objs, Is.Not.Empty);
Assert.That(objs, Has.Count.EqualTo(1));
Assert.That(objs[0], Is.Not.Null);
Assert.That(objs[0], Is.TypeOf<string>());

object rtn = BH.Engine.Serialiser.Convert.FromJson((string)objs[0]);

Assert.That(rtn, Is.TypeOf<Point>());
Assert.That(rtn, Has.Property("X").EqualTo(1));
}
}
}
139 changes: 139 additions & 0 deletions .ci/HTTP_Toolkit_Tests/HTTP_Adapter_Test/PushTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2026, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.Adapter.HTTP;
using BH.Engine.Serialiser;
using BH.oM.Adapters.HTTP;
using BH.oM.Base;
using BH.oM.Base.Debugging;
using BH.oM.Geometry;

namespace HTTP_Adapter_Tests
{
public class PushTests
{
private HTTPAdapter _adapter = default!;

/***************************************************/
/**** Setup ****/
/***************************************************/

[OneTimeSetUp]
[Description("One time set up.")]
public void OneTimeSetUp()
{
_adapter = new HTTPAdapter("http://localhost:5068");
}

/***************************************************/

[SetUp]
[Description("These tests need the TestAPI project running to work properly. If the api is not running, then all tests will be marked as inconclusive.")]
public void SetUp()
{
try
{
using HttpResponseMessage message = _adapter.HttpClient.GetAsync("TestAPI/health").Result;

//the test API (a simple API that returns and accepts BHoM Point objects) isn't running, so report as inconclusive.
if (message.StatusCode != System.Net.HttpStatusCode.OK)
Assert.Inconclusive("Test reported as inconclusive as the test API is not responding, maybe it isn't running?");
}
catch (Exception ex)
{
Assert.Inconclusive("Test reported as inconclusive as the test API is not responding, maybe it isn't running?");
}
}

/***************************************************/
/**** Tests ****/
/***************************************************/

[Test]
[Description("Tests the default behaviour of POSTing with the adapter using a point. The endpoint should return the same point.")]
public void TestDefaultPush()
{
Point point = new Point() { X = 4 };

List<object> objs = _adapter.Push(new List<object>() { point }, actionConfig: new HttpPushConfig() { RequestURL = "TestAPI/default"});

Assert.That(objs, Is.Not.Null);
Assert.That(objs, Is.Not.Empty);
Assert.That(objs, Has.Count.EqualTo(1));
Assert.That(objs[0], Is.Not.Null);
Assert.That(objs[0], Is.TypeOf(typeof(Point)));
Assert.That(objs[0], Has.Property("X").EqualTo(4));
Assert.That(objs[0], Has.Property("Y").EqualTo(0));
Assert.That(objs[0], Has.Property("Z").EqualTo(0));
}

/***************************************************/

[Test]
[Description("Tests pushing with query parameters, the TestAPI puts the parameters in the custom object to allow verification.")]
public void TestPushWithParameters()
{
CustomObject obj = new CustomObject() { CustomData = new Dictionary<string, object>() { { "existingProp", 1 } } };
HttpPushConfig config = new HttpPushConfig() { RequestURL = "TestAPI/parameters", Parameters = new Dictionary<string, object>() { { "parameter1", "p1" }, { "parameter2", 2 } } };

List<object> objs = _adapter.Push(new List<object>() { obj }, actionConfig: config);

Assert.That(objs, Is.Not.Null);
Assert.That(objs, Is.Not.Empty);
Assert.That(objs, Has.Count.EqualTo(1));
Assert.That(objs[0], Is.Not.Null);
Assert.That(objs[0], Is.TypeOf<CustomObject>());

CustomObject co = (CustomObject)objs[0];

Assert.That(co.CustomData, Has.ItemAt("existingProp").EqualTo(1));
Assert.That(co.CustomData, Has.ItemAt("parameter1").EqualTo("p1"));
Assert.That(co.CustomData, Has.ItemAt("parameter2").EqualTo(2));
}

/***************************************************/

[Test]
[Description("Tests pushing with content type set to 'application/json', where the content type of the return is not set to 'application/bhom'.")]
public void TestPushJsonProducesJson()
{
Point point = new Point() { X = 4 };
HttpPushConfig config = new HttpPushConfig() { RequestURL = "TestAPI/producesAndAcceptsJson", PushedContentType = "application/json" };

List<object> objs = _adapter.Push(new List<object>() { point }, actionConfig: config);

List<Event> events = BH.Engine.Base.Query.CurrentEvents();

Assert.That(objs, Is.Not.Null);
Assert.That(objs, Is.Not.Empty);
Assert.That(objs, Has.Count.EqualTo(1));
Assert.That(objs[0], Is.Not.Null);
Assert.That(objs[0], Is.TypeOf<string>());

object rtn = BH.Engine.Serialiser.Convert.FromJson((string)objs[0]);

Assert.That(rtn, Is.TypeOf<Point>());
Assert.That(rtn, Has.Property("X").EqualTo(4));
Assert.That(rtn, Has.Property("Y").EqualTo(4));
}
}
}
Loading
Loading