diff --git a/AdSecGH/Helpers/Populator.cs b/AdSecGH/Helpers/BusinessExtensions.cs similarity index 65% rename from AdSecGH/Helpers/Populator.cs rename to AdSecGH/Helpers/BusinessExtensions.cs index 58540b3..1e7007c 100644 --- a/AdSecGH/Helpers/Populator.cs +++ b/AdSecGH/Helpers/BusinessExtensions.cs @@ -10,14 +10,11 @@ using Oasys.Business; -using OasysGH; -using OasysGH.Components; - using Attribute = Oasys.Business.Attribute; namespace Oasys.GH.Helpers { - public static class Populator { + public static class BusinessExtensions { private static readonly Dictionary> ToGhParam = new Dictionary> { @@ -91,75 +88,6 @@ public static void PopulateOutputParams(this IBusinessComponent businessComponen } } - public abstract class BusinessOasysDropdownGlue : GH_OasysDropDownComponent, IDefaultValues - where T : IBusinessComponent { - private readonly T _businessComponent = Activator.CreateInstance(); - - public BusinessOasysDropdownGlue() : base("", "", "", "", "") { - Name = _businessComponent.Metadata.Name; - NickName = _businessComponent.Metadata.NickName; - Description = _businessComponent.Metadata.Description; - Category = _businessComponent.Organisation.Category; - SubCategory = _businessComponent.Organisation.SubCategory; - } - - public override Guid ComponentGuid { get; } - - public override OasysPluginInfo PluginInfo { get; } - - public void SetDefaultValues() { _businessComponent.SetDefaultValues(this); } - - protected override void RegisterInputParams(GH_InputParamManager pManager) { - _businessComponent.PopulateInputParams(this); - } - - protected override void RegisterOutputParams(GH_OutputParamManager pManager) { - _businessComponent.PopulateOutputParams(this); - } - - public override void SetSelected(int i, int j) { } - - protected override void SolveInternal(IGH_DataAccess da) { - _businessComponent.Compute(); - _businessComponent.SetOutputValues(this, da); - } - - protected override void InitialiseDropdowns() { - _spacerDescriptions = new List(); - _dropDownItems = new List>(); - _selectedItems = new List(); - _isInitialised = true; - } - } - - public abstract class BusinessOasysGlue : GH_OasysComponent, IDefaultValues where T : IBusinessComponent { - - private readonly T _businessComponent = Activator.CreateInstance(); - - public BusinessOasysGlue(string name, string nickname, string description, string category, string subCategory) : - base(name, nickname, description, category, subCategory) { } - - public override OasysPluginInfo PluginInfo { get; } = AdSecGH.PluginInfo.Instance; - public void SetDefaultValues() { _businessComponent.SetDefaultValues(this); } - - protected override void RegisterInputParams(GH_InputParamManager pManager) { - _businessComponent.PopulateInputParams(this); - } - - protected override void RegisterOutputParams(GH_OutputParamManager pManager) { - _businessComponent.PopulateOutputParams(this); - } - - protected override void SolveInstance(IGH_DataAccess DA) { - _businessComponent.Compute(); - _businessComponent.SetOutputValues(this, DA); - } - } - - public interface IDefaultValues { - void SetDefaultValues(); - } - public class DummyBusiness : IBusinessComponent { public DoubleParameter Alpha { get; set; } = new DoubleParameter { @@ -221,7 +149,7 @@ public DummyOasysComponent() : base("Oasys Component Glue", "OCG", Test.thisIsFo protected override void SolveInstance(IGH_DataAccess DA) { } } - public class DummyOasysDropdown : BusinessOasysDropdownGlue { + public class Dummy : BusinessGlue { public override GH_Exposure Exposure { get; } = GH_Exposure.hidden; public override Guid ComponentGuid => new Guid("CAA08C9E-417C-42AE-B704-91F214C8C871"); } diff --git a/AdSecGH/Helpers/BusinessGlue.cs b/AdSecGH/Helpers/BusinessGlue.cs new file mode 100644 index 0000000..93a1056 --- /dev/null +++ b/AdSecGH/Helpers/BusinessGlue.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; + +using Grasshopper.Kernel; + +using Oasys.Business; + +using OasysGH; +using OasysGH.Components; + +namespace Oasys.GH.Helpers { + + public abstract class BusinessOasysGlue : GH_OasysComponent, IDefaultValues where T : IBusinessComponent { + + private readonly T _businessComponent = Activator.CreateInstance(); + + public BusinessOasysGlue(string name, string nickname, string description, string category, string subCategory) : + base(name, nickname, description, category, subCategory) { } + + public override OasysPluginInfo PluginInfo { get; } = AdSecGH.PluginInfo.Instance; + public void SetDefaultValues() { _businessComponent.SetDefaultValues(this); } + + protected override void RegisterInputParams(GH_InputParamManager pManager) { + _businessComponent.PopulateInputParams(this); + } + + protected override void RegisterOutputParams(GH_OutputParamManager pManager) { + _businessComponent.PopulateOutputParams(this); + } + + protected override void SolveInstance(IGH_DataAccess DA) { + _businessComponent.Compute(); + _businessComponent.SetOutputValues(this, DA); + } + } + + public interface IDefaultValues { + void SetDefaultValues(); + } + + public abstract class BusinessGlue : GH_OasysDropDownComponent, IDefaultValues where T : IBusinessComponent { + private readonly T _businessComponent = Activator.CreateInstance(); + + public BusinessGlue() : base("", "", "", "", "") { + Name = _businessComponent.Metadata.Name; + NickName = _businessComponent.Metadata.NickName; + Description = _businessComponent.Metadata.Description; + Category = _businessComponent.Organisation.Category; + SubCategory = _businessComponent.Organisation.SubCategory; + } + + public override Guid ComponentGuid { get; } + + public override OasysPluginInfo PluginInfo { get; } + + public void SetDefaultValues() { _businessComponent.SetDefaultValues(this); } + + protected override void RegisterInputParams(GH_InputParamManager pManager) { + _businessComponent.PopulateInputParams(this); + } + + protected override void RegisterOutputParams(GH_OutputParamManager pManager) { + _businessComponent.PopulateOutputParams(this); + } + + public override void SetSelected(int i, int j) { } + + protected override void SolveInternal(IGH_DataAccess da) { + _businessComponent.Compute(); + _businessComponent.SetOutputValues(this, da); + } + + protected override void InitialiseDropdowns() { + _spacerDescriptions = new List(); + _dropDownItems = new List>(); + _selectedItems = new List(); + _isInitialised = true; + } + } +} diff --git a/AdSecGHTests/Helpers/BusinessComponentNameTest.cs b/AdSecGHTests/Helpers/BusinessComponentNameTest.cs new file mode 100644 index 0000000..3b2d0e2 --- /dev/null +++ b/AdSecGHTests/Helpers/BusinessComponentNameTest.cs @@ -0,0 +1,41 @@ +using Oasys.GH.Helpers; + +using Xunit; + +namespace AdSecGHTests.Helpers { + [Collection("GrasshopperFixture collection")] + public class BusinessComponentNameTest { + private readonly Dummy component; + private readonly DummyBusiness dummyBusiness; + + public BusinessComponentNameTest() { + dummyBusiness = new DummyBusiness(); + component = new Dummy(); + } + + [Fact] + public void ShouldHaveNameFromBusiness() { + Assert.Equal(dummyBusiness.Metadata.Name, component.Name); + } + + [Fact] + public void ShouldHaveNicknameFromBusiness() { + Assert.Equal(dummyBusiness.Metadata.NickName, component.NickName); + } + + [Fact] + public void ShouldHaveDescriptionFromBusiness() { + Assert.Equal(dummyBusiness.Metadata.Description, component.Description); + } + + [Fact] + public void ShouldBeAtTheRightCategory() { + Assert.Equal(dummyBusiness.Organisation.Category, component.Category); + } + + [Fact] + public void ShouldBeAtTheRightSubCategory() { + Assert.Equal(dummyBusiness.Organisation.SubCategory, component.SubCategory); + } + } +} diff --git a/AdSecGHTests/Helpers/DataConvertorTest.cs b/AdSecGHTests/Helpers/DataConvertorTest.cs index bf8c34c..720801e 100644 --- a/AdSecGHTests/Helpers/DataConvertorTest.cs +++ b/AdSecGHTests/Helpers/DataConvertorTest.cs @@ -6,50 +6,14 @@ namespace AdSecGHTests.Helpers { - [Collection("GrasshopperFixture collection")] - public class BusinessComponentNameTest { - private readonly DummyOasysDropdown component; - private readonly DummyBusiness dummyBusiness; - - public BusinessComponentNameTest() { - dummyBusiness = new DummyBusiness(); - component = new DummyOasysDropdown(); - } - - [Fact] - public void ShouldHaveNameFromBusiness() { - Assert.Equal(dummyBusiness.Metadata.Name, component.Name); - } - - [Fact] - public void ShouldHaveNicknameFromBusiness() { - Assert.Equal(dummyBusiness.Metadata.NickName, component.NickName); - } - - [Fact] - public void ShouldHaveDescriptionFromBusiness() { - Assert.Equal(dummyBusiness.Metadata.Description, component.Description); - } - - [Fact] - public void ShouldBeAtTheRightCategory() { - Assert.Equal(dummyBusiness.Organisation.Category, component.Category); - } - - [Fact] - public void ShouldBeAtTheRightSubCategory() { - Assert.Equal(dummyBusiness.Organisation.SubCategory, component.SubCategory); - } - } - [Collection("GrasshopperFixture collection")] public class DataConvertorTest { private readonly DummyBusiness dummyBusiness; - private readonly DummyOasysDropdown oasysDropdown; + private readonly Dummy oasysDropdown; public DataConvertorTest() { dummyBusiness = new DummyBusiness(); - oasysDropdown = new DummyOasysDropdown(); + oasysDropdown = new Dummy(); } [Fact] diff --git a/AdSecGHTests/Helpers/DropIntoGhDocumentTest.cs b/AdSecGHTests/Helpers/DropIntoGhDocumentTest.cs index 6bb660e..61d4af8 100644 --- a/AdSecGHTests/Helpers/DropIntoGhDocumentTest.cs +++ b/AdSecGHTests/Helpers/DropIntoGhDocumentTest.cs @@ -11,12 +11,12 @@ namespace AdSecGHTests.Helpers { [Collection("GrasshopperFixture collection")] public class DropIntoGhDocumentTest { private readonly GH_Document _document; - private readonly DummyOasysDropdown oasysDropdown; + private readonly Dummy oasysDropdown; public DropIntoGhDocumentTest() { string tempPath = Path.Combine(Path.GetTempPath(), "AdSecGHTests", "DropIntoGhDocumentTest.gh"); - oasysDropdown = new DummyOasysDropdown(); + oasysDropdown = new Dummy(); _document = new GH_Document(); _document.AddObject(oasysDropdown, true); _document.NewSolution(true);