Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6.1 Deployment #359

Merged
merged 116 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
578cf39
Upgrade AssemblyFileVersion to 6.1.0.0
BHoMBot Jan 3, 2023
6bf0cb0
Apply suggestions from code review
Jan 3, 2023
00f162d
Update copyright headers to 2023
BHoMBot Jan 4, 2023
e012298
Wip - first iteration
alelom Dec 13, 2022
0c05b53
Changed recursive function
alelom Dec 13, 2022
3270547
Version for PR
alelom Dec 13, 2022
e516fbf
Update UpdateOnly.cs
alelom Dec 13, 2022
9113876
Better error message when Push input objects are of wrong type.
alelom Dec 13, 2022
a287318
Update GetDependencySortedObjects.cs
alelom Dec 13, 2022
7338023
Improved PushTests
alelom Dec 13, 2022
ce0feed
Update Adapter_Engine/Query/GetDependencyRecursive.cs
alelom Dec 14, 2022
b6fb151
Update Adapter_Engine/Query/GetDependencyRecursive.cs
alelom Dec 14, 2022
28e64d8
Removed Exit 0
alelom Dec 14, 2022
1b775b3
Update BaseTypes.cs
alelom Dec 14, 2022
e14d708
Added copyright headers
alelom Dec 14, 2022
736f690
Update Adapter_Engine/Query/GetDependencySortedObjects.cs
alelom Dec 14, 2022
c1afc5e
Moved TestFragment
alelom Dec 14, 2022
a27db64
Make dependency types look for all interfaces and base types as well
IsakNaslundBh Dec 14, 2022
ec339bf
Fix management of push type together with getting out the dependencie…
IsakNaslundBh Dec 14, 2022
584bc25
Remove handle dependencies from CreateOnly and UpdateOnly
IsakNaslundBh Dec 14, 2022
70ae20d
Fix reference
IsakNaslundBh Dec 14, 2022
40fa11c
Adding more tests for UpdateOnly and update references
IsakNaslundBh Dec 14, 2022
8727afb
removing commented out block
IsakNaslundBh Dec 14, 2022
8d7fc91
SOme additional comments and descriptions
IsakNaslundBh Dec 14, 2022
37e866d
Move tests out of main sln
alelom Dec 15, 2022
d59e653
Update BHoM_Adapter.sln
alelom Dec 15, 2022
29d3cb3
Logic to prioritize UpdateOnly over FullPush for same types
alelom Jan 3, 2023
819903f
Using Reflection_Engine method
alelom Jan 3, 2023
0cdb24b
Update PushTests.cs
alelom Jan 3, 2023
a684904
Update GetDependencySortedObjects.cs
alelom Jan 3, 2023
be92d30
compliance
alelom Jan 4, 2023
979e577
compliance
alelom Jan 4, 2023
82c6dbd
Adding ref to StructureAdapterModules
alelom Jan 4, 2023
52e0688
Update GetDependencyObjects.cs
alelom Jan 4, 2023
c9fc163
Copyright fixes
alelom Jan 4, 2023
9313bc3
Update GetObjectsAndRecursiveDependencies.cs
alelom Jan 4, 2023
7b1fb9e
Moved TestFragment
alelom Dec 14, 2022
517ae0f
Fix management of push type together with getting out the dependencie…
IsakNaslundBh Dec 14, 2022
d51c189
removing commented out block
IsakNaslundBh Dec 14, 2022
c249978
Move tests out of main sln
alelom Dec 15, 2022
84e713a
Update GetDependencySortedObjects.cs
alelom Jan 4, 2023
1b79892
Update .ci/code/BHoM_Adapter_Tests/PushTests.cs
IsakNaslundBh Jan 6, 2023
341aee2
Add module getting objects with no set ID from loads
IsakNaslundBh Dec 9, 2022
b12c6d0
Fix capital D
IsakNaslundBh Dec 9, 2022
508efb6
Dummy commit to force filename change
IsakNaslundBh Dec 9, 2022
c066793
Correct filename
IsakNaslundBh Dec 9, 2022
a042b12
Update Structure_AdapterModules/GetLoadElementsWithoutID.cs
IsakNaslundBh Jan 9, 2023
cbab762
Only add list of dependency objects if the list contains any items
IsakNaslundBh Jan 9, 2023
a68690b
Adding AdapterId to the test adapter and loading adapter modules
IsakNaslundBh Jan 9, 2023
ae21a0e
Adding Push tests testing added functionality of the PR
IsakNaslundBh Jan 9, 2023
016c0b3
Update desc
IsakNaslundBh Jan 9, 2023
5daa597
Improve comments
IsakNaslundBh Jan 9, 2023
00b997c
Add specific module for gravity loads
IsakNaslundBh Jan 9, 2023
f61acf7
Fix correct output types for gravity load and add test
IsakNaslundBh Jan 9, 2023
4a3ef32
Enableing additional step of checking identity before calling Update …
IsakNaslundBh Oct 21, 2022
64d3f1d
Update Adapter_oM/Settings-Config/AdapterSettings.cs
IsakNaslundBh Oct 24, 2022
e6747ca
Apply suggestions from code review
IsakNaslundBh Jan 10, 2023
a5c0497
Remove the additional comparers in favour of only relying on the hash…
IsakNaslundBh Jan 10, 2023
ce9305d
Make the test adapter read created objects
IsakNaslundBh Jan 10, 2023
1e69034
Add unittest for updating
IsakNaslundBh Jan 10, 2023
ba0d193
remove emtpy line added
IsakNaslundBh Jan 10, 2023
465caf9
Update Adapter_oM/Settings-Config/AdapterSettings.cs
IsakNaslundBh Jan 10, 2023
e1396f9
Update BHoM_Adapter/AdapterActions/_PushMethods/CRUDDispatchers/FullC…
IsakNaslundBh Jan 10, 2023
0e9bd95
MOve OnlyUpdateChangedObjects to the settings initialisation
IsakNaslundBh Jan 10, 2023
583860a
always pass ActionConfig to GetComparerForType
IsakNaslundBh Jan 10, 2023
dff7610
Add caching system
IsakNaslundBh Jan 17, 2023
cbc16d1
Ensure cache is cleared for all actions
IsakNaslundBh Jan 17, 2023
b8ef52f
Make crud dispatchers call the cache methods
IsakNaslundBh Jan 17, 2023
c332178
Default ids to null
IsakNaslundBh Jan 17, 2023
c646f22
Adding AdapterSetting to toggle caching mechanism
alelom Jan 17, 2023
1c3b025
Update AdapterSettings.cs
alelom Jan 17, 2023
3ca52b5
Renaming of cache methods to be more explicit it what they are doing
IsakNaslundBh Jan 17, 2023
aae230e
Bug fix: provide correct pushtype in FullCrud
alelom Jan 18, 2023
d500d56
FullCRUD: Only call Create if there are Objects to be created
alelom Jan 18, 2023
72240d7
Adding tests and test logic to count CRUD calls per type
alelom Jan 18, 2023
d71608f
Consolidate GetCachedOrRead to single method
IsakNaslundBh Jan 18, 2023
f9f6582
Add method for getting single item out from Cache or model
IsakNaslundBh Jan 18, 2023
4b8d184
Apply suggestions from code review
IsakNaslundBh Jan 20, 2023
7a38926
Fix for test calling the correct cache method
IsakNaslundBh Jan 20, 2023
558475d
Change default value for UpdateOnlyChangedObjects to true
IsakNaslundBh Jan 20, 2023
07accb9
Adding non-generic method for GetDependencyTypes
IsakNaslundBh Feb 1, 2023
773a34e
Update structural adapter tin test to call the non-generic method for…
IsakNaslundBh Feb 1, 2023
0d95dae
Update sorting based on dependency types
IsakNaslundBh Feb 1, 2023
0032e67
Update Create order for failing tests
IsakNaslundBh Feb 1, 2023
bce49f9
Adding new test pushing only loads
IsakNaslundBh Feb 1, 2023
99d5708
Adding recorderror message
alelom Feb 9, 2023
f32bf1f
Moved and renamed Test solution
alelom Feb 14, 2023
c2d1d7e
New Test build configuration, adjusted build events
alelom Feb 14, 2023
57a9ba4
Adding method to unpack objects provided in Push
alelom Feb 10, 2023
868afb3
Added build events in test project
alelom Feb 21, 2023
3c19609
#347 Add push preproccing module for additional preproccing to be do…
IsakNaslundBh Mar 1, 2023
f077d87
#348 add module for pre-processing loads
IsakNaslundBh Mar 1, 2023
1769112
Initial test added - not passing on this commit
IsakNaslundBh Mar 1, 2023
b5d04e0
Remove temporary return in method used to test
IsakNaslundBh Mar 1, 2023
5efbc76
Add NextFreeId method for StructuralAdapter to enable ID based functions
IsakNaslundBh Mar 1, 2023
599cf54
Update tests failing
IsakNaslundBh Mar 1, 2023
0273f4f
Update IPushPreProcessModule to return list of objects
IsakNaslundBh Mar 1, 2023
2b0ed1d
Add missing copyright header
IsakNaslundBh Mar 1, 2023
9bd5ca8
.
IsakNaslundBh Mar 1, 2023
22ec7ae
Update ProcessObjectsForPush.cs
alelom Mar 2, 2023
4821bd7
Adding tests to handle edge cases
IsakNaslundBh Mar 3, 2023
1b2ff89
Fix test cases added
IsakNaslundBh Mar 3, 2023
47e36c2
Checking warning not raised for cases when it should not be
IsakNaslundBh Mar 3, 2023
9101261
Adding new test showcasing failing case, and second test to check id …
IsakNaslundBh Mar 6, 2023
a0b14fd
Adding methods for grouping by comparer type, and calling copy Proper…
IsakNaslundBh Mar 6, 2023
a3d81af
Remove `class` restriction on copy properties
IsakNaslundBh Mar 6, 2023
744b1da
Call base CopyBHoMObjectPRoeprties method from grouping method
IsakNaslundBh Mar 6, 2023
606141f
Move to HelperMethods from Support folder
IsakNaslundBh Mar 6, 2023
6668ade
Update FullCrud and CreateOnly to make use of new functionality
IsakNaslundBh Mar 6, 2023
bd4b5de
Make use of groups for updating adapter Ids
IsakNaslundBh Mar 6, 2023
148396e
Update COpyNodes properties module to raise Notes for conflicts found
IsakNaslundBh Mar 6, 2023
6334717
Clarifying comment
IsakNaslundBh Mar 6, 2023
6a02360
Add description
IsakNaslundBh Mar 6, 2023
7124839
Add descriptions to new tests
IsakNaslundBh Mar 7, 2023
1fe4007
Update StructuralAdapter putting the setting of the AdapterIdFragment…
IsakNaslundBh Mar 8, 2023
b848f32
Fix GetElementsFromLoad modules
IsakNaslundBh Mar 8, 2023
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
60 changes: 60 additions & 0 deletions .ci/unit-tests/BHoM_Adapter_Tests.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32922.545
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BHoM_Adapter_Tests", "BHoM_Adapter_Tests\BHoM_Adapter_Tests.csproj", "{2693899C-1398-4486-BED2-02809FB43BE9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Adapter_oM", "..\..\Adapter_oM\Adapter_oM.csproj", "{C62FB82E-FDAB-4FF4-98B6-5EBD695B579F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Adapter_Engine", "..\..\Adapter_Engine\Adapter_Engine.csproj", "{CE56A0D0-EB5B-4A49-B20F-0432E1832937}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BHoM_Adapter", "..\..\BHoM_Adapter\BHoM_Adapter.csproj", "{C389BC62-717D-4639-BACD-864CF97336BB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Structure_AdapterModules", "..\..\Structure_AdapterModules\Structure_AdapterModules.csproj", "{3E8F16BF-4EB2-47C8-B5D6-9A370A55B902}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Test|Any CPU = Test|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2693899C-1398-4486-BED2-02809FB43BE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2693899C-1398-4486-BED2-02809FB43BE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2693899C-1398-4486-BED2-02809FB43BE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2693899C-1398-4486-BED2-02809FB43BE9}.Release|Any CPU.Build.0 = Release|Any CPU
{2693899C-1398-4486-BED2-02809FB43BE9}.Test|Any CPU.ActiveCfg = Test|Any CPU
{2693899C-1398-4486-BED2-02809FB43BE9}.Test|Any CPU.Build.0 = Test|Any CPU
{C62FB82E-FDAB-4FF4-98B6-5EBD695B579F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C62FB82E-FDAB-4FF4-98B6-5EBD695B579F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C62FB82E-FDAB-4FF4-98B6-5EBD695B579F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C62FB82E-FDAB-4FF4-98B6-5EBD695B579F}.Release|Any CPU.Build.0 = Release|Any CPU
{C62FB82E-FDAB-4FF4-98B6-5EBD695B579F}.Test|Any CPU.ActiveCfg = Test|Any CPU
{C62FB82E-FDAB-4FF4-98B6-5EBD695B579F}.Test|Any CPU.Build.0 = Test|Any CPU
{CE56A0D0-EB5B-4A49-B20F-0432E1832937}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CE56A0D0-EB5B-4A49-B20F-0432E1832937}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE56A0D0-EB5B-4A49-B20F-0432E1832937}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE56A0D0-EB5B-4A49-B20F-0432E1832937}.Release|Any CPU.Build.0 = Release|Any CPU
{CE56A0D0-EB5B-4A49-B20F-0432E1832937}.Test|Any CPU.ActiveCfg = Test|Any CPU
{CE56A0D0-EB5B-4A49-B20F-0432E1832937}.Test|Any CPU.Build.0 = Test|Any CPU
{C389BC62-717D-4639-BACD-864CF97336BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C389BC62-717D-4639-BACD-864CF97336BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C389BC62-717D-4639-BACD-864CF97336BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C389BC62-717D-4639-BACD-864CF97336BB}.Release|Any CPU.Build.0 = Release|Any CPU
{C389BC62-717D-4639-BACD-864CF97336BB}.Test|Any CPU.ActiveCfg = Test|Any CPU
{C389BC62-717D-4639-BACD-864CF97336BB}.Test|Any CPU.Build.0 = Test|Any CPU
{3E8F16BF-4EB2-47C8-B5D6-9A370A55B902}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3E8F16BF-4EB2-47C8-B5D6-9A370A55B902}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E8F16BF-4EB2-47C8-B5D6-9A370A55B902}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E8F16BF-4EB2-47C8-B5D6-9A370A55B902}.Release|Any CPU.Build.0 = Release|Any CPU
{3E8F16BF-4EB2-47C8-B5D6-9A370A55B902}.Test|Any CPU.ActiveCfg = Test|Any CPU
{3E8F16BF-4EB2-47C8-B5D6-9A370A55B902}.Test|Any CPU.Build.0 = Test|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {763D45C4-AF11-4244-B502-01ADEC9953BC}
EndGlobalSection
EndGlobal
67 changes: 67 additions & 0 deletions .ci/unit-tests/BHoM_Adapter_Tests/BHoM_Adapter_Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<IsPackable>false</IsPackable>

<Configurations>Debug;Release;Test</Configurations>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoBogus" Version="2.13.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="Shouldly" Version="4.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Adapter_Engine\Adapter_Engine.csproj" />
<ProjectReference Include="..\..\..\Adapter_oM\Adapter_oM.csproj" />
<ProjectReference Include="..\..\..\BHoM_Adapter\BHoM_Adapter.csproj" />
<ProjectReference Include="..\..\..\Structure_AdapterModules\Structure_AdapterModules.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="Analytical_oM">
<HintPath>C:\ProgramData\BHoM\Assemblies\Analytical_oM.dll</HintPath>
</Reference>
<Reference Include="BHoM">
<HintPath>C:\ProgramData\BHoM\Assemblies\BHoM.dll</HintPath>
</Reference>
<Reference Include="BHoM_Engine">
<HintPath>C:\ProgramData\BHoM\Assemblies\BHoM_Engine.dll</HintPath>
</Reference>
<Reference Include="Dimensional_oM">
<HintPath>C:\ProgramData\BHoM\Assemblies\Dimensional_oM.dll</HintPath>
</Reference>
<Reference Include="Geometry_Engine">
<HintPath>C:\ProgramData\BHoM\Assemblies\Geometry_Engine.dll</HintPath>
</Reference>
<Reference Include="Geometry_oM">
<HintPath>C:\ProgramData\BHoM\Assemblies\Geometry_oM.dll</HintPath>
</Reference>
<Reference Include="Physical_oM">
<HintPath>C:\ProgramData\BHoM\Assemblies\Physical_oM.dll</HintPath>
</Reference>
<Reference Include="Spatial_oM">
<HintPath>C:\ProgramData\BHoM\Assemblies\Spatial_oM.dll</HintPath>
</Reference>
<Reference Include="Structure_Engine">
<HintPath>C:\ProgramData\BHoM\Assemblies\Structure_Engine.dll</HintPath>
</Reference>
<Reference Include="Structure_oM">
<HintPath>C:\ProgramData\BHoM\Assemblies\Structure_oM.dll</HintPath>
</Reference>
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="if not &quot;$(ConfigurationName)&quot; == &quot;Test&quot; (xcopy &quot;$(TargetDir)$(TargetFileName)&quot; &quot;C:\ProgramData\BHoM\Assemblies&quot; /Y)&#xD;&#xA;&#xD;&#xA;if not &quot;$(ConfigurationName)&quot; == &quot;Test&quot; xcopy &quot;$(TargetDir)Bogus.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y&#xD;&#xA;if not &quot;$(ConfigurationName)&quot; == &quot;Test&quot; xcopy &quot;$(TargetDir)System.Data.DataSetExtensions.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y&#xD;&#xA;if not &quot;$(ConfigurationName)&quot; == &quot;Test&quot; xcopy &quot;$(TargetDir)Microsoft.VisualStudio.CodeCoverage.Shim.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y&#xD;&#xA;if not &quot;$(ConfigurationName)&quot; == &quot;Test&quot; xcopy &quot;$(TargetDir)Microsoft.TestPlatform.*.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y&#xD;&#xA;if not &quot;$(ConfigurationName)&quot; == &quot;Test&quot; xcopy &quot;$(TargetDir)testhost.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y&#xD;&#xA;if not &quot;$(ConfigurationName)&quot; == &quot;Test&quot; xcopy &quot;$(TargetDir)NuGet.Frameworks.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y&#xD;&#xA;if not &quot;$(ConfigurationName)&quot; == &quot;Test&quot; xcopy &quot;$(TargetDir)System.Reflection.Metadata.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y&#xD;&#xA;if not &quot;$(ConfigurationName)&quot; == &quot;Test&quot; xcopy &quot;$(TargetDir)Newtonsoft.Json.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y&#xD;&#xA;if not &quot;$(ConfigurationName)&quot; == &quot;Test&quot; xcopy &quot;$(TargetDir)nunit.framework.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y&#xD;&#xA;if not &quot;$(ConfigurationName)&quot; == &quot;Test&quot; xcopy &quot;$(TargetDir)DiffEngine.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y&#xD;&#xA;if not &quot;$(ConfigurationName)&quot; == &quot;Test&quot; xcopy &quot;$(TargetDir)System.Management.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y&#xD;&#xA;if not &quot;$(ConfigurationName)&quot; == &quot;Test&quot; xcopy &quot;$(TargetDir)EmptyFiles.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y" />
</Target>

</Project>
43 changes: 43 additions & 0 deletions .ci/unit-tests/BHoM_Adapter_Tests/Create/RandomObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, 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.Engine.Base;
using BH.oM.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BH.Adapter.Tests
{
public static partial class Create
{
public static T RandomObject<T>() where T : IObject
{
if (typeof(T).IsInterface)
return default(T);

return (T)BH.Engine.Base.Create.RandomObject(typeof(T));
}
}
}
87 changes: 87 additions & 0 deletions .ci/unit-tests/BHoM_Adapter_Tests/Create/RandomObjects.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, 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.Engine.Base;
using BH.oM.Base;
using BH.Tests.Adapter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BH.Adapter.Tests
{
public static partial class Create
{
public static List<T> RandomObjects<T>(int count = 100, bool assignIdFragmentWithProgressiveId = false, bool assignObjectName = false, string objectNamePrefix = "bar_") where T : IObject
{
return RandomBHoMObjects(typeof(T), count, assignIdFragmentWithProgressiveId, assignObjectName, objectNamePrefix).OfType<T>().ToList();
}

public static List<IBHoMObject> RandomBHoMObjects(Type t, int count = 100, bool assignIdFragmentWithProgressiveId = false, bool assignObjectName = false, string objectNamePrefix = "bar_")
{
List<IBHoMObject> objs = new List<IBHoMObject>();

for (int i = 0; i < count; i++)
{
IObject obj = BH.Engine.Base.Create.RandomObject(t);

if (obj == null)
throw new ArgumentException($"Could not create a Random Object of type {t.FullName}.");

if (assignIdFragmentWithProgressiveId)
{
IBHoMObject bhomObj = obj as IBHoMObject;
TestFragment testIdFragment = new TestFragment() { SomeProp = i };
bhomObj = bhomObj.AddFragment(testIdFragment);
obj = bhomObj;
}

if (assignObjectName)
{
IBHoMObject bhomObj = obj as IBHoMObject;
bhomObj.Name = objectNamePrefix + i.ToString();
obj = bhomObj;
}

objs.Add(obj as dynamic);
}

return objs;
}

public static List<IObject> RandomIObjects(Type t, int count = 100)
{
List<IObject> objs = new List<IObject>();

for (int i = 0; i < count; i++)
{
IObject obj = BH.Engine.Base.Create.RandomObject(t);

objs.Add(obj);
}

return objs;
}
}
}
Loading