Skip to content

Commit

Permalink
refactor: moved test objects to separate project, only used from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
psarras committed Nov 1, 2024
1 parent f87b3aa commit 7964541
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 96 deletions.
9 changes: 6 additions & 3 deletions AdSecCoreTests/AdSecCoreTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.extensibility.core" Version="2.7.0" />
<PackageReference Include="xunit" Version="2.7.0"/>
<PackageReference Include="xunit.extensibility.core" Version="2.7.0"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
6 changes: 6 additions & 0 deletions AdSecGH.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdSecCore", "AdSecCore\AdSe
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdSecCoreTests", "AdSecCoreTests\AdSecCoreTests.csproj", "{DF259C79-A298-44B9-B702-573D4206A3C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestGrasshopperObjects", "TestGrasshopperObjects\TestGrasshopperObjects.csproj", "{9D376477-DEDE-4DCC-B12F-7361BF763BFF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -51,6 +53,10 @@ Global
{DF259C79-A298-44B9-B702-573D4206A3C2}.Debug|x64.Build.0 = Debug|Any CPU
{DF259C79-A298-44B9-B702-573D4206A3C2}.Release|x64.ActiveCfg = Release|Any CPU
{DF259C79-A298-44B9-B702-573D4206A3C2}.Release|x64.Build.0 = Release|Any CPU
{9D376477-DEDE-4DCC-B12F-7361BF763BFF}.Debug|x64.ActiveCfg = Debug|Any CPU
{9D376477-DEDE-4DCC-B12F-7361BF763BFF}.Debug|x64.Build.0 = Debug|Any CPU
{9D376477-DEDE-4DCC-B12F-7361BF763BFF}.Release|x64.ActiveCfg = Release|Any CPU
{9D376477-DEDE-4DCC-B12F-7361BF763BFF}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
61 changes: 42 additions & 19 deletions AdSecGH/Components/3_Section/FlattenRebar.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,61 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;

using AdSecGH.Helpers;
using AdSecGH.Helpers.GH;
using AdSecGH.Parameters;
using AdSecGH.Properties;

using Grasshopper.Kernel;

using Oasys.AdSec;
using Oasys.AdSec.Reinforcement.Groups;
using Oasys.AdSec.Reinforcement.Preloads;
using Oasys.Business;
using Oasys.GH.Helpers;
using Oasys.Profiles;

using OasysGH;
using OasysGH.Components;
using OasysGH.Parameters;
using OasysGH.Units;

using OasysUnits;

using Attribute = Oasys.Business.Attribute;

namespace AdSecGH.Components {
public class FlattenRebar : GH_OasysComponent {
public override Guid ComponentGuid => new Guid("879ecac6-464d-4286-9113-c15fcf03e4e6");
public override GH_Exposure Exposure => GH_Exposure.tertiary | GH_Exposure.obscure;
public override OasysPluginInfo PluginInfo => AdSecGH.PluginInfo.Instance;
protected override System.Drawing.Bitmap Icon => Properties.Resources.FlattenRebar;

public FlattenRebar() : base(
"FlattenRebars",
"FRb",
"Flatten all rebars in a section into single bars.",
CategoryName.Name(),
SubCategoryName.Cat4()) {
public class FlattenRebarComponent : IBusinessComponent {

public ComponentAttribute Metadata { get; set; } = new ComponentAttribute {
Name = "FlattenRebar",
NickName = "FRb",
Description = "Flatten all rebars in a section into single bars.",
};
public ComponentOrganisation Organisation { get; set; } = new ComponentOrganisation {
Category = CategoryName.Name(),
SubCategory = SubCategoryName.Cat4(),
};
public Attribute[] GetAllInputAttributes() { throw new NotImplementedException(); }

Check warning on line 40 in AdSecGH/Components/3_Section/FlattenRebar.cs

View check run for this annotation

Codecov / codecov/patch

AdSecGH/Components/3_Section/FlattenRebar.cs#L40

Added line #L40 was not covered by tests

public Attribute[] GetAllOutputAttributes() { throw new NotImplementedException(); }

Check warning on line 42 in AdSecGH/Components/3_Section/FlattenRebar.cs

View check run for this annotation

Codecov / codecov/patch

AdSecGH/Components/3_Section/FlattenRebar.cs#L42

Added line #L42 was not covered by tests

public void UpdateInputValues(params object[] values) { throw new NotImplementedException(); }

Check warning on line 44 in AdSecGH/Components/3_Section/FlattenRebar.cs

View check run for this annotation

Codecov / codecov/patch

AdSecGH/Components/3_Section/FlattenRebar.cs#L44

Added line #L44 was not covered by tests

public void Compute() { throw new NotImplementedException(); }

Check warning on line 46 in AdSecGH/Components/3_Section/FlattenRebar.cs

View check run for this annotation

Codecov / codecov/patch

AdSecGH/Components/3_Section/FlattenRebar.cs#L46

Added line #L46 was not covered by tests
}

public class FlattenRebar : BusinessOasysGlue<FlattenRebarComponent> {

public FlattenRebar() {
Hidden = true;
}

public override Guid ComponentGuid => new Guid("879ecac6-464d-4286-9113-c15fcf03e4e6");
public override GH_Exposure Exposure => GH_Exposure.tertiary | GH_Exposure.obscure;
public override OasysPluginInfo PluginInfo => AdSecGH.PluginInfo.Instance;
protected override Bitmap Icon => Resources.FlattenRebar;

Check warning on line 58 in AdSecGH/Components/3_Section/FlattenRebar.cs

View check run for this annotation

Codecov / codecov/patch

AdSecGH/Components/3_Section/FlattenRebar.cs#L57-L58

Added lines #L57 - L58 were not covered by tests

protected override void RegisterInputParams(GH_InputParamManager pManager) {
pManager.AddGenericParameter("Section", "Sec", "AdSec Section to get single rebars from", GH_ParamAccess.item);
Expand All @@ -50,17 +70,20 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager) {
IQuantity force = new Force(0, DefaultUnits.ForceUnit);
string forceUnitAbbreviation = string.Concat(force.ToString().Where(char.IsLetter));

pManager.AddGenericParameter("Position [" + lengthUnitAbbreviation + "]", "Vx", "Rebar position as 2D vertex in the section's local yz-plane ", GH_ParamAccess.list);
pManager.AddGenericParameter("Position [" + lengthUnitAbbreviation + "]", "Vx",
"Rebar position as 2D vertex in the section's local yz-plane ", GH_ParamAccess.list);
pManager.HideParameter(0);
pManager.AddGenericParameter("Diameter [" + lengthUnitAbbreviation + "]", "Ø", "Bar Diameter", GH_ParamAccess.list);
pManager.AddGenericParameter("Diameter [" + lengthUnitAbbreviation + "]", "Ø", "Bar Diameter",
GH_ParamAccess.list);
pManager.AddIntegerParameter("Bundle Count", "N", "Count per bundle (1, 2, 3 or 4)", GH_ParamAccess.list);
pManager.AddGenericParameter("PreLoad", "P", "The pre-load per reinforcement bar. Positive value is tension.", GH_ParamAccess.list);
pManager.AddGenericParameter("PreLoad", "P", "The pre-load per reinforcement bar. Positive value is tension.",
GH_ParamAccess.list);
pManager.AddGenericParameter("Material", "Mat", "Material Type", GH_ParamAccess.list);
}

protected override void SolveInstance(IGH_DataAccess DA) {
// get section input
AdSecSection section = AdSecInput.AdSecSection(this, DA, 0);
var section = AdSecInput.AdSecSection(this, DA, 0);

Check warning on line 86 in AdSecGH/Components/3_Section/FlattenRebar.cs

View check run for this annotation

Codecov / codecov/patch

AdSecGH/Components/3_Section/FlattenRebar.cs#L86

Added line #L86 was not covered by tests

// create flattened section
ISection flat = null;
Expand All @@ -79,11 +102,11 @@ protected override void SolveInstance(IGH_DataAccess DA) {
var materialType = new List<string>();

// loop through rebar groups in flattened section
foreach (IGroup rebargrp in flat.ReinforcementGroups) {
foreach (var rebargrp in flat.ReinforcementGroups) {
try // first try if not a link group type
{
var snglBrs = (ISingleBars)rebargrp;
foreach (IPoint pos in snglBrs.Positions) {
foreach (var pos in snglBrs.Positions) {
// position
pointGoos.Add(new AdSecPointGoo(pos));

Expand Down
65 changes: 0 additions & 65 deletions AdSecGH/Helpers/BusinessExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,69 +88,4 @@ public static void PopulateOutputParams(this IBusinessComponent businessComponen
}
}

public class DummyBusiness : IBusinessComponent {

public DoubleParameter Alpha { get; set; } = new DoubleParameter {
Name = "Alpha",
NickName = "A",
Description = "Alpha description",
Default = 1,
};
public DoubleParameter Beta { get; set; } = new DoubleParameter {
Name = "Beta",
NickName = "B",
Description = "Beta description",
Default = 2,
};

public ComponentAttribute Metadata { get; set; } = new ComponentAttribute {
Name = "Dummy Business",
NickName = "DB",
Description = "Dummy Business Description",
};
public ComponentOrganisation Organisation { get; set; } = new ComponentOrganisation {
Category = "Dummy Category",
SubCategory = "Dummy SubCategory",
};

public Attribute[] GetAllInputAttributes() {
return new[] {
Alpha,
};
}

public Attribute[] GetAllOutputAttributes() {
return new[] {
Beta,
};
}

public void UpdateInputValues(params object[] values) { }

public void Compute() { Beta.Value = (Alpha.Value * 2) + 10; }

public void GetDefaultValues() { throw new NotImplementedException(); }
}

public static class Test {

public const string thisIsForTestingPurposesOnly = "this is for testing purposes only";
}

public class DummyOasysComponent : BusinessOasysGlue<DummyBusiness> {

public DummyOasysComponent() : base("Oasys Component Glue", "OCG", Test.thisIsForTestingPurposesOnly, "Oasys",
"dummy") { }

public override GH_Exposure Exposure { get; } = GH_Exposure.hidden;

public override Guid ComponentGuid => new Guid("CAA08C9E-417C-42AE-B734-91F214C8B87F");

protected override void SolveInstance(IGH_DataAccess DA) { }
}

public class Dummy : BusinessGlue<DummyBusiness> {
public override GH_Exposure Exposure { get; } = GH_Exposure.hidden;
public override Guid ComponentGuid => new Guid("CAA08C9E-417C-42AE-B704-91F214C8C871");
}
}
9 changes: 7 additions & 2 deletions AdSecGH/Helpers/BusinessGlue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ public abstract class BusinessOasysGlue<T> : GH_OasysComponent, IDefaultValues w

private readonly T _businessComponent = Activator.CreateInstance<T>();

public BusinessOasysGlue(string name, string nickname, string description, string category, string subCategory) :
base(name, nickname, description, category, subCategory) { }
public BusinessOasysGlue() : base("", "", "", "", "") {
Name = _businessComponent.Metadata.Name;
NickName = _businessComponent.Metadata.NickName;
Description = _businessComponent.Metadata.Description;
Category = _businessComponent.Organisation.Category;
SubCategory = _businessComponent.Organisation.SubCategory;
}

public override OasysPluginInfo PluginInfo { get; } = AdSecGH.PluginInfo.Instance;
public void SetDefaultValues() { _businessComponent.SetDefaultValues(this); }

Check warning on line 26 in AdSecGH/Helpers/BusinessGlue.cs

View check run for this annotation

Codecov / codecov/patch

AdSecGH/Helpers/BusinessGlue.cs#L26

Added line #L26 was not covered by tests
Expand Down
1 change: 1 addition & 0 deletions AdSecGHTests/AdSecGHTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

<ItemGroup>
<ProjectReference Include="..\AdSecGH\AdSecGH.csproj"/>
<ProjectReference Include="..\TestGrasshopperObjects\TestGrasshopperObjects.csproj"/>
</ItemGroup>
<ItemGroup>
<None Update="xunit.runner.json">
Expand Down
4 changes: 1 addition & 3 deletions AdSecGHTests/Helpers/BusinessComponentNameTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Oasys.GH.Helpers;

using Xunit;
using Xunit;

namespace AdSecGHTests.Helpers {
[Collection("GrasshopperFixture collection")]
Expand Down
2 changes: 0 additions & 2 deletions AdSecGHTests/Helpers/DataConvertorTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Grasshopper.Kernel;

using Oasys.GH.Helpers;

using Xunit;

namespace AdSecGHTests.Helpers {
Expand Down
2 changes: 0 additions & 2 deletions AdSecGHTests/Helpers/DropIntoGhDocumentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

using Grasshopper.Kernel;

using Oasys.GH.Helpers;

using Xunit;

namespace AdSecGHTests.Helpers {
Expand Down
13 changes: 13 additions & 0 deletions TestGrasshopperObjects/Dummy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

using Grasshopper.Kernel;

using Oasys.GH.Helpers;

namespace AdSecGHTests.Helpers {

public class Dummy : BusinessGlue<DummyBusiness> {
public override GH_Exposure Exposure { get; } = GH_Exposure.hidden;
public override Guid ComponentGuid => new Guid("CAA08C9E-417C-42AE-B704-91F214C8C871");
}
}
51 changes: 51 additions & 0 deletions TestGrasshopperObjects/DummyBusiness.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;

using Oasys.Business;

using Attribute = Oasys.Business.Attribute;

namespace AdSecGHTests.Helpers {
public class DummyBusiness : IBusinessComponent {

public DoubleParameter Alpha { get; set; } = new DoubleParameter {
Name = "Alpha",
NickName = "A",
Description = "Alpha description",
Default = 1,
};
public DoubleParameter Beta { get; set; } = new DoubleParameter {
Name = "Beta",
NickName = "B",
Description = "Beta description",
Default = 2,
};

public ComponentAttribute Metadata { get; set; } = new ComponentAttribute {
Name = "Dummy Business",
NickName = "DB",
Description = "Dummy Business Description",
};
public ComponentOrganisation Organisation { get; set; } = new ComponentOrganisation {
Category = "Dummy Category",
SubCategory = "Dummy SubCategory",
};

public Attribute[] GetAllInputAttributes() {
return new[] {
Alpha,
};
}

public Attribute[] GetAllOutputAttributes() {
return new[] {
Beta,
};
}

public void UpdateInputValues(params object[] values) { }

Check warning on line 45 in TestGrasshopperObjects/DummyBusiness.cs

View check run for this annotation

Codecov / codecov/patch

TestGrasshopperObjects/DummyBusiness.cs#L45

Added line #L45 was not covered by tests

public void Compute() { Beta.Value = (Alpha.Value * 2) + 10; }

public void GetDefaultValues() { throw new NotImplementedException(); }

Check warning on line 49 in TestGrasshopperObjects/DummyBusiness.cs

View check run for this annotation

Codecov / codecov/patch

TestGrasshopperObjects/DummyBusiness.cs#L49

Added line #L49 was not covered by tests
}
}
16 changes: 16 additions & 0 deletions TestGrasshopperObjects/DummyOasysComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

using Grasshopper.Kernel;

using Oasys.GH.Helpers;

namespace AdSecGHTests.Helpers {
public class DummyOasysComponent : BusinessOasysGlue<DummyBusiness> {

public override GH_Exposure Exposure { get; } = GH_Exposure.hidden;

Check warning on line 10 in TestGrasshopperObjects/DummyOasysComponent.cs

View check run for this annotation

Codecov / codecov/patch

TestGrasshopperObjects/DummyOasysComponent.cs#L10

Added line #L10 was not covered by tests

public override Guid ComponentGuid => new Guid("CAA08C9E-417C-42AE-B734-91F214C8B87F");

Check warning on line 12 in TestGrasshopperObjects/DummyOasysComponent.cs

View check run for this annotation

Codecov / codecov/patch

TestGrasshopperObjects/DummyOasysComponent.cs#L12

Added line #L12 was not covered by tests

protected override void SolveInstance(IGH_DataAccess DA) { }

Check warning on line 14 in TestGrasshopperObjects/DummyOasysComponent.cs

View check run for this annotation

Codecov / codecov/patch

TestGrasshopperObjects/DummyOasysComponent.cs#L14

Added line #L14 was not covered by tests
}
}
20 changes: 20 additions & 0 deletions TestGrasshopperObjects/TestGrasshopperObjects.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Grasshopper" Version="6.27.20176.5001"/>
<PackageReference Include="RhinoCommon" Version="6.27.20176.5001"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AdSecGH\AdSecGH.csproj"/>
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>

</Project>

0 comments on commit 7964541

Please sign in to comment.