-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: moved classes to separate files
- Loading branch information
Showing
5 changed files
with
127 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<T> : GH_OasysComponent, IDefaultValues where T : IBusinessComponent { | ||
|
||
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 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<T> : GH_OasysDropDownComponent, IDefaultValues where T : IBusinessComponent { | ||
private readonly T _businessComponent = Activator.CreateInstance<T>(); | ||
|
||
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<string>(); | ||
_dropDownItems = new List<List<string>>(); | ||
_selectedItems = new List<string>(); | ||
_isInitialised = true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters