Skip to content

Commit

Permalink
test: make sure metadata and organisational elements are specified
Browse files Browse the repository at this point in the history
  • Loading branch information
psarras committed Oct 31, 2024
1 parent 0f7dce1 commit c681165
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 5 deletions.
18 changes: 17 additions & 1 deletion AdSecCore/IBusinessComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,26 @@
namespace Oasys.Business {

public interface IBusinessComponent {

ComponentAttribute Metadata { get; set; }
ComponentOrganisation Organisation { get; set; }
Attribute[] GetAllInputAttributes();
Attribute[] GetAllOutputAttributes();

void UpdateInputValues(params object[] values);
void Compute();
}

public class ComponentAttribute {
public string Name { get; set; }
public string NickName { get; set; }
public string Description { get; set; }
}

public class ComponentOrganisation {
public string Category { get; set; }
public string SubCategory { get; set; }
}

public class Attribute {

public string Name { get; set; }
Expand Down Expand Up @@ -63,6 +76,9 @@ public void Compute() {
Point.Value = IPoint.Create(new Length(Y.Value, LengthUnit.Meter), new Length(Z.Value, LengthUnit.Meter));
}

public ComponentAttribute Metadata { get; set; }
public ComponentOrganisation Organisation { get; set; }

public Attribute[] GetAllInputAttributes() {
return new[] {
Y,
Expand Down
21 changes: 17 additions & 4 deletions AdSecGH/Helpers/Populator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,13 @@ public abstract class BusinessOasysDropdownGlue<T> : GH_OasysDropDownComponent,
where T : IBusinessComponent {
private readonly T _businessComponent = Activator.CreateInstance<T>();

public BusinessOasysDropdownGlue(
string name, string nickname, string description, string category, string subCategory) : base(name, nickname,
description, category, subCategory) { }
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; }

Expand Down Expand Up @@ -171,6 +175,16 @@ public class DummyBusiness : IBusinessComponent {
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,
Expand Down Expand Up @@ -208,7 +222,6 @@ protected override void SolveInstance(IGH_DataAccess DA) { }
}

public class DummyOasysDropdown : BusinessOasysDropdownGlue<DummyBusiness> {
public DummyOasysDropdown() : base("Business Dropdown Glue", "BDG", "description", "Oasys", "Dummy") { }
public override GH_Exposure Exposure { get; } = GH_Exposure.hidden;
public override Guid ComponentGuid => new Guid("CAA08C9E-417C-42AE-B704-91F214C8C871");
}
Expand Down
36 changes: 36 additions & 0 deletions AdSecGHTests/Helpers/DataConvertorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,42 @@

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;
Expand Down

0 comments on commit c681165

Please sign in to comment.